@extends('admin.layout')
<style type="text/css">

</style>
@section('header')

@endsection

@section('content')
<div id="sg-main-container-sg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{{ '编辑' . $model_name }}</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12 pull-right">
                                <a href="{{ $pre_uri . 'index?type' . $type }}" class="btn btn-sm btn-primary pull-right">返回列表</a>
                            </div>
                        </div>
                        <form class="form-horizontal" method="POST" action="{{ $pre_uri . 'update' }}" enctype="multipart/form-data">
                            {{ csrf_field() }}

                            <input type="hidden" name="data[type]" value="{{ $type }}">
                            <input type="hidden" name="id" value="{{ $item->id }}">
                            <div class="form-group row">
                                <label class="col-sm-2 col-sm-offset-1 control-label">标题</label>
                                <div class="col-sm-8">
                                    <input type="text" name="data[title]" class="form-control" placeholder="请输入标题" value="{{ $item->title }}" required>
                                </div>
                                @if($errors->has('title'))
                                    <span class="help-block">{{ $errors->first('title') }}</span>
                                @endif
                            </div>

                            @if($type != 3)
                                <div class="form-group row">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">内容</label>
                                    <div class="col-sm-8">
                                        <script id="content-editor" name="data[content]" type="text/plain">{!! $item->content !!}</script>
                                    </div>
                                    @if($errors->has('title'))
                                        <span class="help-block">{{ $errors->first('title') }}</span>
                                    @endif
                                </div>
                            @else
                                <div class="form-group row">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">视频</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input type="text" class="form-control" placeholder="上传视频文件" value="{{ $item->content }}" readonly id="upload-video-path">
                                            <input type="file" name="video" accept="video/*" style="display: none" id="upload-video-input">
                                            <span class="input-group-btn" id="upload-video-btn">
                                                <button class="btn btn-success" type="button">上传新文件</button>
                                            </span>
                                        </div>
                                    </div>
                                    @if($errors->has('content'))
                                        <span class="help-block">{{ $errors->first('content') }}</span>
                                    @endif
                                </div>
                                <div class="form-group row">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">视频封面</label>
                                    <div class="col-sm-8">
                                        {!!  widget('Tools.ImgUpload')->single('video-cover', 'data[pic_url]', $item->pic_url) !!}
                                    </div>
                                    @if($errors->has('pic_url'))
                                        <span class="help-block">{{ $errors->first('pic_url') }}</span>
                                    @endif
                                </div>
                            @endif

                            <div class="form-group row">
                                <label class="col-sm-2 col-sm-offset-1 control-label">排序</label>
                                <div class="col-sm-8">
                                    <input type="text" name="data[sort]" class="form-control" placeholder="请输入排序" value="{{ $item->sort }}">
                                </div>
                                @if($errors->has('sort'))
                                    <span class="help-block">{{ $errors->first('sort') }}</span>
                                @endif
                            </div>

                            <div class="form-group row">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button type="submit" class="btn btn-sm btn-primary">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('footer')
<script type="text/javascript">
$(function () {
    $('#upload-video-btn').on('click', function () {
        $('#upload-video-input').click();
    });
    $('#upload-video-input').change(function () {
        if(this['files'].length > 0) {
            $('#upload-video-path').val(this['files'][0]['name']);
        }
    });

    UE.getEditor('content-editor');
})
</script>
@endsection