@extends('admin.master')

@section('top')
	<div class="top-breadcrumb">
		<h5>SEO设置</h5>
	</div>
@endsection

@section('ordersearch')
@if(config('managerLang') == config('setting.lang'))
<div class="order-search mb-10">
	<div class="clearfix">
		<div class="pull-left">
			@include('admin.common.translate_models', ['translateModel' => 'setting', 'translateModelName' => 'SEO设置', 'translateSettings' => ['site_title' => '标题', 'meta_keywords' => '关键词', 'meta_description' => '描述', 'tag_description' => 'Tags描述']])
		</div>
	</div>
</div>
@endif

@endsection

@section('content')
{!! Form::open(['route' => 'admin.setting.update', 'method'=>'post', 'class'=>'form-horizontal form-detail']) !!}
	<div class="tab-content">
		<div class="tab-content">
			<div role="tabpanel" class="tab-pane active" id="language-{{ $managerLang }}">
				<div class="form-group">
					<label class="col-sm-2 control-label label-width">首页标题：</label>
					<div class="col-sm-5">
						{!! Form::text("description[{$managerLang}][site_title]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang]->pluck('value', 'name')->get('site_title') : '', ['class'=>'form-control']) !!}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label label-width">首页关键词：</label>
					<div class="col-sm-5">
						{!! Form::text("description[{$managerLang}][meta_keywords]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang]->pluck('value', 'name')->get('meta_keywords') : '', ['class'=>'form-control']) !!}
						<span class="pl-10 mt-5 text-muted inline-block">( 多关键词用英文,分割 )</span>
						@if(config('managerLang') == config('setting.lang'))
						<div class="meta-setting-header-btn" style="float: right; margin-top: 5px;">
							<i class="iconfont icon-shengcheng"></i><span>智能生成描述</span>
						</div>
						@endif
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label label-width">首页描述：</label>
					<div class="col-sm-5">
						{!! Form::textarea("description[{$managerLang}][meta_description]", isset($descriptions[$managerLang]) ? $descriptions[$managerLang]->pluck('value', 'name')->get('meta_description') : '', ['class'=>'form-control', 'rows'=>5]) !!}
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
	        <label class="col-sm-3 control-label label-width"></label>
	        <div class="col-sm-5">
	            {!! Form::submit('提交', ['class'=>'btn btn-primary']) !!}
	        </div>
	    </div>
	</div>
{!! Form::close() !!}
@endsection

@section('foot')
  @if(config('managerLang') == config('setting.lang'))
    <script type="text/javascript">
        $(function () {
            var status = false
            $(".meta-setting-header-btn").click(function() {
                if (status) {
                    alert('请不要重复点击！')
                    return
                }
                const keywords = $('[name="description[{{$managerLang}}][meta_keywords]').val();
                if (!keywords) {
                    alert('请输入关键词!')
                    return
                }
                status = true
                $.ajax({
                    type: 'get',
                    url: '{{url("/admin/seo/home")}}',
                    timeout: 10000,
                    data: {
                        keywords: keywords
                    },
                    success: function (res) {
                        if (res.status === 'success') {
                            $('[name="description[{{$managerLang}}][meta_description]').val(res.data)
                        }
                        status = false
                    },
                    error: function (error) {
                        console.log(error)
                        status = false
                    }
                })
            })
        })

    </script>
  @endif
@endsection