@extends('admin.master')

@section('style')
  <style>
    .sun .content-box {
        box-shadow: none;
        background: none;
    }
  </style>
@endsection

@section('top')
<div class="top-breadcrumb pull-left">
    <h5>查看留言</h5>
    <a class="btn btn-xs btn-default goback" onclick="javascript:history.go(-1);">
			<i class="iconfont icon-back-copy"></i><span>返回</span>
    </a>
</div>
@endsection

@section('content')
  <div class="message-cont">
    <div class="message-shadow message-l">
      <div class="message-l-t">
        <li>
          <i class="iconfont icon-fajianren"></i>
          <span>
            @if(auth()->user()->isMaster() || auth()->user()->isAdmin() || in_array('name', auth()->user()->inquiry_permissions ?: []))
            {{ $data->name }}
            @else
              暂无权限查看
            @endif
          </span>
        </li>
        <li>
          <i class="iconfont icon-dianhua"></i>
          <span>
            @if(auth()->user()->isMaster() || auth()->user()->isAdmin() || in_array('phone', auth()->user()->inquiry_permissions ?: []))
            {{ $data->phone }}
            @else
              暂无权限查看
            @endif
          </span>
        </li>
        <li>
          <i class="iconfont icon-youxiang"></i>
          <span>
            @if(auth()->user()->isMaster() || auth()->user()->isAdmin() || in_array('email', auth()->user()->inquiry_permissions ?: []))
              <a href="mailto:{{ $data->email }}" style="color: #fff">{{ $data->email }}</a>
            @else
              暂无权限查看
            @endif
          </span>
        </li>
      </div>
      <div class="message-l-b">
        <li>
          <div class="icon">
            <i class="iconfont icon-diquguanli"></i>
          </div>
          <div class="text">
            <span>国家/地区：</span>
            <p>{{ $data->country }}</p>
          </div>
        </li>
        <li>
          <div class="icon">
            <i class="iconfont icon-ip"></i>
          </div>
          <div class="text">
            <span>IP：</span>
            <p>{{ $data->ip }}</p>
          </div>
        </li>
        <li>
          <div class="icon">
            <i class="iconfont icon-lianjie"></i>
          </div>
          <div class="text">
            <span>来源页面：</span>
            <p><a class="btn-link" href="{{ $data->referer }}" target="_blank">{{ $data->referer }}</a></p>
          </div>
        </li>
      </div>
    </div>
    <div class="message-shadow message-show message-detail">
      {!! Form::model($data, ['route' => ['admin.message.update', $data->id], 'method'=>'put', 'class'=>'form-horizontal form-detail']) !!}
      <li class="message-show-list">
        <ul class="message-r-b">
          <li>
            <span>公司：</span>
            <p>{{ $data->company }}</p>
          </li>
            <li>
              <span>主题：</span>
              <p>{{ $data->subject }}</p>
            </li>
          <li>
            <span>日期：</span>
            <p>{{ $data->created_at }}</p>
          </li>
        </ul>
        <ul class="message-r-t">
          <li>
            <span>内容：</span>
            <p id="translate-content">{{ $data->content }}</p>
          </li>
          <li class="translate">
            <a href="javascript:void(0);" class="btn btn-outline-primary ml-10 translate-btn" data-source="{{ $data->lang }}">翻译</a>
          </li>
          <li>
            <span>回复：</span>
            <p>
              @if($data->reply)
                {{ $data->reply }}
              @else
                {!! Form::textarea("reply", null, ['class' => 'form-control', 'rows' => 10, 'cols' => 200]) !!}
              @endif
            </p>
          </li>
          <li style="margin-top: 20px">
            <span>有效性：</span>
            <div class="pretty-box" style="padding-top: 0">
              <div class="pretty p-default p-round p-smooth">
                {!! Form::radio('valid', 1, null) !!}
                <div class="state p-success-o"><label>有效询盘</label></div>
              </div>
              <div class="pretty p-default p-round p-smooth">
                {!! Form::radio('valid', 2, null) !!}
                <div class="state p-success-o"><label>无效询盘</label></div>
              </div>
            </div>
          </li>
        </ul>
        <div class="message-show-back">
          @if(!$data->reply)
            {!! Form::submit('提交', ['class'=>'btn btn-primary']) !!}
          @endif
          <button type="button" class="btn btn-primary" onclick="javascript:history.go(-1);">返回</button>
        </div>

      {!! Form::close() !!}
    </div>
  </div>

@endsection

@section('foot')
    <script type="text/javascript">
        $(".translate-btn").click(function () {
            var source = $(this).data('source')
          var text = $("#translate-content").text()
            if (text) {
                $.ajax({
                    url: HOME_URL + '/admin/message/translate',
                    type: 'POST',
                    data: {
                        q: text,
                        source: source
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            $("#translate-content").text(data.message)
                        }
                    },
                    error: function (err) {
                    }
                })
            }
        })
    </script>
@endsection