@extend('admin.layout')
@section('headerinclude')
<title>Destek #{{ $ticket['tid'] }}</title>
<style>
.cke_editable {
    min-height: 300px!important;
}
</style>
@endsection
@section('content')
<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css"/>
<script src="assets/plugins/global/plugins.bundle.js"></script>
<div class="post d-flex flex-column-fluid" id="kt_post">
    <div id="kt_content_container" class="container-xxl">
        <div class="row g-5 g-xl-8 mb-7">
            <div class="col-xl-12">
                <div class="card">
                    <div class="card-header">
                        <div class="card-title">
                            Talebi Görüntüle
                        </div>
                    </div>
                    <div class="card-body pb-0">
                        <div class="d-flex flex-wrap py-5">
                            <div class="flex-equal me-5">
                                <table class="table table-flush fw-semibold gy-1">
                                    <tbody>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Talep ID</td>
                                            <td class="text-gray-800"># {{ $ticket['tid'] }}</td>
                                        </tr>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Sahip Bilgileri</td>
                                            <td class="text-gray-800">
                                                {{ App\System\Model\UserGroupModel::beRenderUserName($ticket['name'].' '.$ticket['surname'],$usergroups[$ticket['usergroup']]['ugnamestyle']) }}
                                                <a href="{{ beGetRoute('admin.user.show',['uid' => $ticket['uid']]) }}">
                                                    <span class="svg-icon svg-icon-2 text-warning">
                                                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                            <path opacity="0.3" d="M4.7 17.3V7.7C4.7 6.59543 5.59543 5.7 6.7 5.7H9.8C10.2694 5.7 10.65 5.31944 10.65 4.85C10.65 4.38056 10.2694 4 9.8 4H5C3.89543 4 3 4.89543 3 6V19C3 20.1046 3.89543 21 5 21H18C19.1046 21 20 20.1046 20 19V14.2C20 13.7306 19.6194 13.35 19.15 13.35C18.6806 13.35 18.3 13.7306 18.3 14.2V17.3C18.3 18.4046 17.4046 19.3 16.3 19.3H6.7C5.59543 19.3 4.7 18.4046 4.7 17.3Z" fill="currentColor"></path>
                                                            <rect x="21.9497" y="3.46448" width="13" height="2" rx="1" transform="rotate(135 21.9497 3.46448)" fill="currentColor"></rect>
                                                            <path d="M19.8284 4.97161L19.8284 9.93937C19.8284 10.5252 20.3033 11 20.8891 11C21.4749 11 21.9497 10.5252 21.9497 9.93937L21.9497 3.05029C21.9497 2.498 21.502 2.05028 20.9497 2.05028L14.0607 2.05027C13.4749 2.05027 13 2.52514 13 3.11094C13 3.69673 13.4749 4.17161 14.0607 4.17161L19.0284 4.17161C19.4702 4.17161 19.8284 4.52978 19.8284 4.97161Z" fill="currentColor"></path>
                                                        </svg>
                                                    </span>
                                                </a>    
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Başlık</td>
                                            <td class="text-gray-800">{{ $ticket['tsubject'] }}</td>
                                        </tr>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Son Mesaj</td>
                                            <td class="text-gray-800"><span class="text-success">{{ $ticket['tlastreply'] == 'admin' ? 'Müşteri Cevabı Bekleniyor':'Yetkili Cevabı Bekleniyor' }}</span></td>
                                        </tr>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Başlangıç Tarihi</td>
                                            <td class="text-gray-800">{{ beSpecialTime($ticket['tdateline']) }}</td>
                                        </tr>
                                        <tr>
                                            <td class="text-muted min-w-125px w-125px">Etkilenen Hizmetler</td>
                                            <td class="text-gray-800">
                                                @if($ticket['upid'])
                                                <code class="ms-0">{{ $ticket['upname'].' - '.$ticket['uptag']  }}</code>
                                                <a href="{{ beGetRoute('admin.order.show',['upid' => $ticket['upid']]) }}">
                                                    <span class="svg-icon svg-icon-2 text-warning">
                                                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                            <path opacity="0.3" d="M4.7 17.3V7.7C4.7 6.59543 5.59543 5.7 6.7 5.7H9.8C10.2694 5.7 10.65 5.31944 10.65 4.85C10.65 4.38056 10.2694 4 9.8 4H5C3.89543 4 3 4.89543 3 6V19C3 20.1046 3.89543 21 5 21H18C19.1046 21 20 20.1046 20 19V14.2C20 13.7306 19.6194 13.35 19.15 13.35C18.6806 13.35 18.3 13.7306 18.3 14.2V17.3C18.3 18.4046 17.4046 19.3 16.3 19.3H6.7C5.59543 19.3 4.7 18.4046 4.7 17.3Z" fill="currentColor"></path>
                                                            <rect x="21.9497" y="3.46448" width="13" height="2" rx="1" transform="rotate(135 21.9497 3.46448)" fill="currentColor"></rect>
                                                            <path d="M19.8284 4.97161L19.8284 9.93937C19.8284 10.5252 20.3033 11 20.8891 11C21.4749 11 21.9497 10.5252 21.9497 9.93937L21.9497 3.05029C21.9497 2.498 21.502 2.05028 20.9497 2.05028L14.0607 2.05027C13.4749 2.05027 13 2.52514 13 3.11094C13 3.69673 13.4749 4.17161 14.0607 4.17161L19.0284 4.17161C19.4702 4.17161 19.8284 4.52978 19.8284 4.97161Z" fill="currentColor"></path>
                                                        </svg>
                                                    </span>
                                                </a>
                                                @else
                                                    -
                                                @endif
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <div class="mb-9 mt-5">
                                                    <a class="btn btn-primary beLoginAdmin" data-uid="{{ $ticket['uid'] }}">Müşteri Olarak Giriş Yap</a>
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="flex-equal me-5">
                            </div>
                        </div>
                        <hr>
                        <div class="d-flex flex-wrap py-5">
                            <div class="flex-equal me-5">
                                <div class="d-flex justify-content-between" style="width:100%">
                                    <div class="d-flex justify-content-between" style="width:60%">
                                        <div class="d-flex">
                                            @if($ticket['tstatus'] == 'active')
                                            <button class="btn btn-primary d-block mx-1 statusSaveForm" data-status="1">İşleme Al</button>
                                            @endif
                                            @if($ticket['tstatus'] == 'inprocess')
                                            <button class="btn btn-info d-block mx-1 statusSaveForm" data-status="0">İşlemden Çıkar</button>
                                            @endif
                                            @if($ticket['tstatus'] == 'closed')
                                            <button class="btn btn-primary d-block mx-1 statusSaveForm" data-status="0">Talebi Aç</button>
                                            @else
                                            <button class="btn btn-danger d-block mx-1 statusSaveForm" data-status="-1">Talebi Kapat</button>
                                            @endif
                                            @foreach($buttons as $key => $value)
                                            {{ $value['button'] }}
                                            @endforeach
                                        </div>
                                        <div class="d-flex">
                                            <button class="btn btn-info d-block mx-1 createInvoice">Fatura Oluştur</button>
                                        </div>
                                        <div class="d-flex">
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-center" style="width:40%">
                                        <div class="mx-1 w-50">
                                            <select class="form-control form-control-select-user" name="admin" id="adminSelect">
                                                @if($ticket['adminuid'])
                                                    <option value="{{ $ticket['adminuid'] }}">{{ $ticket['adminname'].' '.$ticket['adminsurname']  }}</option>
                                                @endif
                                            </select>
                                        </div>
                                        <div class="mx-1 w-50">
                                            <select class="form-control form-control-select" name="depertment" id="depertmentSelect">
                                                @foreach($depertments as $key => $depertment)
                                                <option value="{{ $key }}"{{ $key == $ticket['tdepertment'] ? ' selected':'' }}>{{ $depertment['tdname'] }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="invoiceContent" style="display:none">
                            <form id="invoiceForm">
                                <div class="row">
                                    <div class="col-8 mb-9">
                                        <div class="input-group input-group-solid mb-5">
                                            <input type="text" name="name" id="invoiceName" class="form-control" placeholder="Fatura adı" aria-label="Fatura adı">
                                            <span class="input-group-text">@</span>
                                            <input type="text" name="total" id="invoiceTotal" class="form-control" placeholder="Tutar" aria-label="Tutar">
                                        </div>
                                    </div>
                                    <div class="col-2 mb-9">
                                        <select class="form-control form-control-select" id="invoiceCurrency">
                                            @foreach($currencies as $key => $currency)
                                            <option value="{{ $key }}">{{ $currency['cname'] }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-2 mb-9">
                                        <button class="btn btn-success d-block m-auto invoiceCreateForm">Oluştur</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="d-flex flex-column flex-lg-row">
            <div class="flex-lg-row-fluid">
                <div class="card" id="kt_chat_messenger">
                    <div class="card-header" id="kt_chat_messenger_header">
                        <div class="card-title">
                            <div class="d-flex justify-content-center flex-column me-3">
                                <a href="#" class="fs-4 fw-bold text-gray-900 text-hover-primary me-1 mb-2 lh-1">{{ $ticket['tsubject'] }}</a>
                                <div class="mb-0 lh-1">
                                    <span class="badge badge-{{ $status[$ticket['tstatus']][1] }} badge-circle w-10px h-10px me-1"></span>
                                    <span class="fs-7 fw-semibold text-muted">{{ $status[$ticket['tstatus']][0] }}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body" id="kt_chat_messenger_body">
                        <div class="scroll-y me-n5 pe-5 h-300px h-lg-auto" data-kt-element="messages" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_header, #kt_app_header, #kt_app_toolbar, #kt_toolbar, #kt_footer, #kt_app_footer, #kt_chat_messenger_header, #kt_chat_messenger_footer" data-kt-scroll-wrappers="#kt_content, #kt_app_content, #kt_chat_messenger_body" data-kt-scroll-offset="5px" style="max-height: 28px;">
                            @php $lastpost = 0; @endphp    
                            @foreach($posts as $post)
                            <div class="d-flex justify-content-{{ $ticket['uid'] == $post['uid'] ? 'start':'end' }} mb-10 ">
                                <div class="d-flex flex-column align-items-start">
                                    <div class="d-flex align-items-center mb-2">
                                        <div>
                                            <a href="{{ beGetRoute('admin.user.show',['uid' => $post['uid']]) }}" class="fs-5 fw-bold text-gray-900 text-hover-primary me-1">{{ App\System\Model\UserGroupModel::beRenderUserName($post['name'].' '.$post['surname'],$usergroups[$post['usergroup']]['ugnamestyle']) }}</a>
                                        </div>
                                    </div>
                                    <div class="p-5 rounded bg-light-info fw-semibold mw-lg-400px" data-kt-element="message-text">
                                        {{ $post['tpmessage'] }}      
                                        <div class="mt-3">
                                            <span class="text-muted fs-7 mb-1">{{ beSpecialTime($post['tpdateline']) }}</span>
                                            <span class="text-muted fs-7 mb-1">{{ $post['tpipaddress'] }}</span>
                                        </div>      
                                        <div class="mt-3">
                                            @if($post['attachments'])
                                            @foreach($post['attachments'] as $attachment)
                                            <div class="card bg-light p-3 mb-3">
                                                <div class="d-flex align-items-center">
                                                    <span class="svg-icon svg-icon-2x svg-icon-primary me-4">
                                                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                            <path opacity="0.3" d="M19 22H5C4.4 22 4 21.6 4 21V3C4 2.4 4.4 2 5 2H14L20 8V21C20 21.6 19.6 22 19 22Z" fill="currentColor"></path>
                                                            <path d="M15 8H20L14 2V7C14 7.6 14.4 8 15 8Z" fill="currentColor"></path>
                                                        </svg>
                                                    </span>
                                                    <a href="{{ beGetRoute('file.show',['slug' => $attachment['aslug'],'aid' => $attachment['aid']]) }}" target="_blank" class="text-gray-800 text-hover-primary">{{ $attachment['aname'] }}</a>
                                                </div>
                                                <div class="mt-2 d-flex justify-content-between">
                                                    <span style="opacity:.5">{{ beConvertSize($attachment['asize']) }}</span>
                                                    <span style="opacity:.5">{{ beSpecialTime($attachment['adateline']) }}</span>
                                                </div>
                                            </div>
                                            @endforeach
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                            @php 
                                if(!$lastpost){
                                    $lastpost = $post['tpid'];
                                }
                            @endphp
                            @endforeach
                        </div>
                    </div>
                    <div class="card-footer pt-4">
                        <div class="row mb-4">
                            @foreach($predefinedreplies as $predefinedrepy)
                                <div class="col-4">
                                    <code class="beShowReplies ms-0" data-tpcid="{{ $predefinedrepy['tpcid'] }}" role="button">{{ $predefinedrepy['tpcname'] }}</code>
                                </div>
                            @endforeach
                        </div>
                        <hr>
                        @foreach($predefinedreplies as $predefinedrepy)
                        <div class="predefinedreplies predefinedreplies{{ $predefinedrepy['tpcid'] }} my-5" style="display: none;">
                            @foreach($predefinedrepy['messages'] as $message)
                                <div class="col-4">
                                    <code class="beGetReply ms-0" data-tprid="{{ $message['tprid'] }}" role="button">{{ $message['tprname'] }}</code>
                                </div>
                            @endforeach
                        </div>
                        @endforeach
                        <textarea class="form-control form-control-flush mb-3" rows="5" placeholder="Lütfen mesajınızı yazınız" id="messageArea">{{ $signature['tasmessage'] }}</textarea>
                        <div class="d-flex flex-stack">
                            <div class="d-flex align-items-center me-2">
                                <input type="file" id="fileUpload" multiple style="display:none">
                                <button class="btn btn-sm btn-icon btn-active-light-primary me-1 uploadButton" type="button" data-bs-toggle="tooltip" aria-label="Coming soon" data-bs-original-title="Coming soon" data-kt-initialized="1"><i class="bi bi-paperclip fs-3"></i></button>
                            </div>
                            <button class="btn btn-primary messageSendForm" type="button">Gönder</button>
                        </div>
                        <div class="row flex-column p-3" id="uploadList">

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

@endsection
@section('js')
<script src="assets/plugins/custom/tinymce/tinymce.bundle.js"></script>
<script>
    $(".beLoginAdmin").on("click",function(){
        var uid = $(this).data("uid");
        $.ajax({
            url: "{{ beGetRoute('admin.user.loginfromadmin.post') }}",
            type: "post",
            async: true,
            data: {uid:uid},
            dataType: "json",
            crossDomain: true,
            success: function(response){
                if(response.status){
                    Swal.fire("Başarılı",response.message,"success");
                    setTimeout(function(){
                        window.location.href = response.url;
                    },1000);
                }
                else{
                    Swal.fire("Bir Hata Oluştu",response.message,"error");
                }
            }
        });
    });
    var counter = 0;
    var wait1 = false;
    $(".statusSaveForm").on("click",function(){
        var item = $(this);
        var text = item.html();
        var status = item.data("status");
        if(!wait1){
            wait1 = true;
            item.html('Bekleyin <span class="spinner-border spinner-border-sm align-middle ms-2"></span>');
            $.ajax({
                url: "{{ beGetRoute('admin.ticket.status.save.post') }}",
                type: "post",
                async: true,
                data: "status="+status+"&tid={{ $ticket['tid'] }}",
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait1 = false;
                    item.html(text);
                    if(response.status){
                        Swal.fire("Başarılı",response.message,"success");
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                    }
                }
            });
        }
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
    var wait2 = false;
    $("#depertmentSelect").on("change",function(){
        if(!wait2){
            wait2 = true;
            $.ajax({
                url: "{{ beGetRoute('admin.ticket.depertment.save.post') }}",
                type: "post",
                async: true,
                data: "depertment="+$("#depertmentSelect").val()+"&tid={{ $ticket['tid'] }}",
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait2 = false;
                    if(response.status){
                        Swal.fire("Başarılı",response.message,"success");
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                    }
                }
            });
        }
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
    var wait3 = false;
    $("#adminSelect").on("change",function(){
        if(!wait3){
            wait3 = true;
            $.ajax({
                url: "{{ beGetRoute('admin.ticket.admin.save.post') }}",
                type: "post",
                async: true,
                data: "admin="+$("#adminSelect").val()+"&tid={{ $ticket['tid'] }}",
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait3 = false;
                    if(response.status){
                        Swal.fire("Başarılı",response.message,"success");
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                    }
                }
            });
        }
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
    var wait4 = false;
    var checkpost = 1;
    $(".messageSendForm").on("click",function(){
        if(!wait4){
            wait4 = true;
            var message = tinymce.activeEditor.getContent();
            var aidlist = [];
            for(let i = 0; i < counter+1; i++){
                var aid = $("#uploadItemProcess"+i).data("aid");
                if(aid){
                    aidlist.push(aid);
                }
            }
            $(".messageSendForm").html('Bekleyin <span class="spinner-border spinner-border-sm align-middle ms-2"></span>');
            $.ajax({
                url: "{{ beGetRoute('admin.ticket.newmesssage.post') }}",
                type: "post",
                async: true,
                data: {chekpost:checkpost,message:message,aidlist:aidlist,lastpost:{{ $lastpost }},tid:{{ $ticket['tid'] }}},
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait4 = false;
                    $(".messageSendForm").html("Kaydet");
                    if(response.status){
                        tinymce.remove();
                        Swal.fire("Başarılı",response.message,"success");
                        setTimeout(function(){
                            location.reload();
                        },1000)
                    }
                    else{
                        if(response.askoverride){
                            Swal.fire({
                                html: "Siz bu mesajı yazarken biri bir mesaj yazdı yine de göndermek ister misin ?",
                                icon: "info",
                                buttonsStyling: false,
                                showCancelButton: true,
                                confirmButtonText: "Gönder",
                                cancelButtonText: "Vazgeçtim",
                                customClass: {
                                    confirmButton: "btn btn-primary",
                                    cancelButton: "btn btn-danger"
                                }
                            }).then((result) => {
                                if(result.isConfirmed) {
                                    checkpost = 0;
                                    $(".messageSendForm").trigger("click");
                                }
                            });
                        }
                        else{
                            Swal.fire("Bir Hata Oluştu",response.message,"error");
                        }
                    }
                }
            });
        }
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
    var wait5 = false;invoiceName-invoiceTotal
    $(".invoiceCreateForm").on("click",function(){
        if(!wait5){
            wait5 = true;
            $.ajax({
                url: "{{ beGetRoute('admin.invoice.add.post') }}",
                type: "post",
                async: true,
                data: {
                    name:$("#invoiceName").val(),
                    description:$("#invoiceName").val(),
                    currency:$("#invoiceCurrency").val(),
                    type:3,
                    bill:0,
                    user:{{ $ticket['uid'] }},
                    expiredate:{{ BE_TIME+(86400*3) }},
                    dateline:{{ BE_TIME }},
                    itemCount:0,
                    rowName0:$("#invoiceName").val(),
                    rowPrice0:$("#invoiceTotal").val(),
                    rowCount0:1,
                    rowUnitType0:"quanity",
                    rowCurrency0:$("#invoiceCurrency").val()
                },
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait5 = false;
                    if(response.status){
                        Swal.fire("Başarılı",response.message,"success");
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                    }
                }
            });
        }
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
    $(".createInvoice").on("click",function(){
        $(".invoiceContent").show();
        return false;
    });

    $(".beShowReplies").on("click",function(){
        var tpcid = $(this).data("tpcid");
        $(".predefinedreplies").hide();
        $(".predefinedreplies"+tpcid).show("slow");
    });
    $(".beGetReply").on("click",function(){
        var tprid = $(this).data("tprid");
        $.ajax({
            url: "{{ beGetRoute('admin.ticket.predefinedreply.get.post') }}",
            type: "post",
            async: true,
            data: "tprid="+tprid+"&tid={{ $ticket['tid'] }}",
            dataType: "json",
            crossDomain: true,
            success: function(response){
                if(response.status){
                    tinymce.activeEditor.insertContent(response.definedreply);
                }
            }
        });
    });

    $(".uploadButton").on("click",function(){
        $("#fileUpload").trigger("click");
    });
    $("#fileUpload").change(function(e){
        uploadFiles(e.target.files);
    });
    $("#uploadList").on("click",".btnDeleteUploadItem",function(){
        var aid = $(this).data("aid");
        var key = $(this).data("key");
        $.ajax({
                url: "{{ beGetRoute('client.file.delete') }}",
                type: "post",
                async: true,
                data: {aid:aid},
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    if(response.status){
                        $("#uploadItem"+key).remove();
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                    }
                }
            });
    });
    function uploadFiles(files){
        var formdata = new FormData();
        var length = files.length;
        var i;
        for (i = 0; i < length; i++) {
            counter += 1;
            formdata.append("file",files[i]);
            uploadFile(formdata,counter);
            $("#uploadList").append('\
                <div class="col-md-4 mb-3 d-flex justify-content-between bg-light-primary p-5 rounded" id="uploadItem'+counter+'">\
                    <div>\
                        <span>'+files[i]["name"]+'<span>\
                        <span class="d-block">'+Number((files[i]["size"]/1000000).toFixed(1))+' MB<span>\
                    </div>\
                    <div>\
                        <div class="d-flex flex-column" style="width:100px">\
                            <div class="d-flex justify-content-between mt-auto mb-2">\
                                <span class="fw-bold fs-6" id="uploadItemProgess'+counter+'">0%</span>\
                                <a data-bs-toggle="tooltip" title="Sil" class="btnDeleteUploadItem" id="uploadItemProcess'+counter+'">\
                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" fill="currentColor"><path fill="none" d="M0 0h24v24H0z"></path><path d="M7 4V2h10v2h5v2h-2v15a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6H2V4h5zM6 6v14h12V6H6zm3 3h2v8H9V9zm4 0h2v8h-2V9z"></path></svg>\
                                </a>\
                            </div>\
                            <div class="h-5px bg-light mb-3" style="width:100px">\
                                <div class="bg-success rounded h-5px" role="progressbar" style="width: 0%;" id="uploadItemProgessWidth'+counter+'"></div>\
                            </div>\
                        </div>\
                    </div>\
                </div>\
            ');
        }	
    }
    function uploadFile(file,i){
        $.ajax({
            url: "{{ beGetRoute('client.file.upload') }}",
            type : "post",
            data : file,
            contentType : false,
            processData : false,
            dataType : "json",
            crossDomain: true,
            xhr: function() {
                var xhr = new window.XMLHttpRequest();
                xhr.upload.addEventListener("progress",function(e){
                    if(e.lengthComputable){
                        var percentComplete = (e.loaded/e.total)*100;
                        $("#uploadItemProgess"+i).html(Number((percentComplete).toFixed())+"%");
                        $("#uploadItemProgessWidth"+i).width(percentComplete+"%");
                    }
                }, false);
                return xhr;
            },
            success:function(response){
                if(response.status){
                    $("#uploadItemProcess"+i).attr("data-aid",response.aid);
                    $("#uploadItemProcess"+i).attr("data-key",i);
                }
                else{
                    $("#uploadItem"+i).removeClass("bg-light-primary").addClass("bg-light-danger");
                    Swal.fire("Bir Hata Oluştu",response.message,"error");
                }
            }
        });
    }
    /*if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
	    CKEDITOR.tools.enableHtml5Elements( document );

    CKEDITOR.config.width = 'auto';
    CKEDITOR.config.removePlugins = 'image';
    var initSample = ( function() {
        return function() {
            var editorElement = CKEDITOR.document.getById('messageArea');
            editorElement.setHtml("sea");
            editorElement.setAttribute( 'contenteditable', 'true' );
            CKEDITOR.inline( 'messageArea' );
        };
    } )();
    initSample();*/

    $(document).ready(function(){
        var options = {selector:"#messageArea",height:"480",entity_encoding:"raw",verify_html:false,plugins:'code searchreplace autolink directionality visualblocks visualchars image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap emoticons autosave fullscreen',toolbar: "undo redo print spellcheckdialog formatpainter | blocks fontfamily fontsize | bold italic underline forecolor backcolor | link image | alignleft aligncenter alignright alignjustify | code"};
        if(KTThemeMode.getMode() === "dark"){
            options["skin"] = "oxide-dark";
            options["content_css"] = "dark";
        }
        tinymce.init(options);
    });

    $(".form-control-select").select2();
    $(".form-control-select-user").select2({
        placeholder: "Lütfen aramak istediğiniz kullanıcının isim yada soyisimini giriniz",
        minimumInputLength: 2,
        tags: false,
        ajax: {
            url: "{{ beGetRoute('admin.user.find.post') }}",
            dataType: "json",
            type: "post",
            quietMillis: 50,
            data: function (term) {
                return term;
            },
            processResults: function (data){
                return {
                    results: $.map(data, function (item) {
                        return {
                            text: item.namesurname,
                            id: item.uid
                        }
                    })
                };
            },
            cache: true
        }
    });
</script>
@endsection