@extends('layouts.template')

{{-- @section('page-header')
    @include('components.page-header', [
        'pageTitle' => 'Dashboard',
        'pageSubtitle' => '',
        'pageIcon' => 'feather icon-home',
        'parentMenu' => '',
        'current' => 'Dashboard',
    ])
@endsection --}}

@section('content')
  <script src="https://cdn.tiny.cloud/1/r3qqyu0qnlntsbjedd3ylvp8iqhqdsmt7iq9uq7h2vgf0e8f/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
  <script>
        tinymce.init({
            selector: 'textarea',

            image_class_list: [
            {title: 'img-responsive', value: 'img-responsive'},
            ],
            height: 500,
            setup: function (editor) {
                editor.on('init change', function () {
                    editor.save();
                });
            },
            plugins: [
                "advlist autolink lists link image charmap print preview anchor",
                "searchreplace visualblocks code fullscreen",
                "insertdatetime media table contextmenu paste imagetools"
            ],
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image ",

            image_title: true,
            automatic_uploads: false,
            images_upload_url: "{{url('mail-templpate/uploadImage')}}",
            file_picker_types: 'image',
            file_picker_callback: function(cb, value, meta) {
                var input = document.createElement('input');
                input.setAttribute('type', 'file');
                input.setAttribute('accept', 'image/*');
                input.onchange = function() {
                    var file = this.files[0];

                    var reader = new FileReader();
                    reader.readAsDataURL(file);
                    reader.onload = function () {
                        var id = 'blobid' + (new Date()).getTime();
                        var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                        var base64 = reader.result.split(',')[1];
                        var blobInfo = blobCache.create(id, file, base64);
                        blobCache.add(blobInfo);
                        cb(blobInfo.blobUri(), { title: file.name });
                    };
                };
                input.click();
            }
        });    
    </script>
    
    @include('components.notification')

    <div class="row mt-4 align-items-center">
        <div class="col-md-12">
            <form method="post" action="{{route('mail-template.update',1)}}" enctype='multipart/form-data'>
                @method('put')
                @csrf
            <label>Subject</label>
            <input type='text' class='form-control' value='{{$email->welcome_subject}}' name='welcome_subject'>
            <br>
          <textarea name="body" id="mytextarea"><?= $email->body ?></textarea>
              <br>
              <label>Attachment <a target='_blank' href='{{asset("picture/".$email->welcome_attach)}}'><small><u> View Attachment</u></small> </a></label>
              <input type='file' name='welcome_attach' class='form-control'>
            <br>
    <button type="submit" class="btn btn-primary mr-2"><i class="fa fa-save"></i> Simpan</button>

            </form>            
        </div>
@endsection
