@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/6/tinymce.min.js" referrerpolicy="origin"></script>-->
  <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" id="formBlast" action="{{url('mail-template/submit-blast')}}">
                @csrf
                <label>Subject</label>
                <input type="text" class="form-control" name="blast_subject" value="{{$email->blast_subject}}">
                <br>
                <label>Body</label>
              <textarea name="blast_body" id="mytextarea"><?= $email->blast_body ?></textarea>
              <br>
              <label>Cabang</label>
                <select class="select2 form-control @error('id_branch') is-invalid @enderror" name="id_branch">
                    <option value=''>---Semua Cabang---</option>
                    @foreach($branch as $item)
                        <option value='{{$item->cabang}}' {{old('id_branch') == $item->id ? 'selected' : ''}}>{{$item->cabang}}</option>
                    @endforeach
                </select>
                <br>
                <br>
              <label>Bulan</label>
                <select class="select2 form-control @error('id_month') is-invalid @enderror" name="id_month">
                    <option value=''>---Semua Bulan---</option>
                    @foreach($months as $month)
                        <option value='{{$month}}' {{old('tgl_lahir') == $item ? 'selected' : ''}}>{{ $month }}</option>
                    @endforeach
                </select>
        <br><br>
    <button type="submit" id="btnSubmitBlast" class="btn btn-primary mr-2"><i class="fa fa-save"></i> Simpan</button>

            </form>            
        </div>
@endsection
@push('custom-script')
    <script>
        $("#formBlast").submit(function(){
            $("#btnSubmitBlast").prop('disabled','true')
        })
    </script>
@endpush