@extends('layouts.app')

@section('content')
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Edit / Add</div>
                <div class="card-body">
                	<form method="post" action="{{ url('admin/languages/'.($language? $language->id : '')) }}" enctype="multipart/form-data">
                		@if($language && $language->id)
                			@method('PUT')
                		@endif
					    @CSRF
					    <div class="row">
					           <div class="col-md-2" align="right">
					            <h3>Name</h3>
					           </div>
					           <div class="col-md-2" align="right">
					            <input name="name" class="form-control" value="{{ old('name', $language->name ?? '') }}" />
					           </div>

					           <div class="col-md-2" align="right">
					            <h3>local</h3>
					           </div>
					           <div class="col-md-4">
					            <br />
					               <input type="text" name="local" class="form-control" value="{{ old('local', $language->local ?? '') }}" />
					           </div>
					           <div class="col-md-2">
					            <br />
					               <button type="submit" class="btn btn-success">save</button>
					           </div>
					       </div>
					   </form>
					   <br />
					   @if(count($errors) > 0)
					    <div class="alert alert-danger">
					           <ul>
					           @foreach($errors->all() as $error)
					            <li>{{ $error }}</li>
					           @endforeach
					           </ul>
					       </div>
					   @endif
	                    @if (session('status'))
	                        <div class="alert alert-success" role="alert">
	                            {{ session('status') }}
	                        </div>
	                    @endif

	                     <div class="input-group">
						   <span class="input-group-btn">
						     <a id="lfm" data-input=".thumbnail" data-preview=".holder" class="lfm btn btn-primary">
						       <i class="fa fa-picture-o"></i> Choose
						     </a>
						   </span>
						   <input id="thumbnail" class="thumbnail form-control" type="text" name="filepath">
						 </div>
						 <img id="holder" class="holder" style="margin-top:15px;max-height:100px;">
	                    
						<textarea name="content" class="form-control my-editor">{!! old('content', $content ?? '') !!}</textarea>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
	var route_prefix = "{{ url(config('lfm.prefix')) }}";
</script>
<script>
  var editor_config = {
    path_absolute : "/",
    selector: "textarea.my-editor",
    plugins: [
      "advlist autolink lists link image charmap print preview hr anchor pagebreak",
      "searchreplace wordcount visualblocks visualchars code fullscreen",
      "insertdatetime media nonbreaking save table contextmenu directionality",
      "emoticons template paste textcolor colorpicker textpattern"
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media",
    relative_urls: false,
    file_browser_callback : function(field_name, url, type, win) {
      var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
      var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

      var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
      if (type == 'image') {
        cmsURL = cmsURL + "&type=Images";
      } else {
        cmsURL = cmsURL + "&type=Files";
      }

      tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'Filemanager',
        width : x * 0.8,
        height : y * 0.8,
        resizable : "yes",
        close_previous : "no"
      });
    }
  };

  tinymce.init(editor_config);
</script>

<script src="/vendor/laravel-filemanager/js/stand-alone-button.js"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/lfm.js') }}"></script>
<script>
//{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/lfm.js')) !!}
</script>
<script>
$('.lfm').filemanager('image', {prefix: route_prefix});
</script>



@endsection
