<?php

/**
 * Created by PhpStorm.
 * User: Kavand
 * Date: 2/28/2019
 * Time: 4:30 AM
 */
?>
<!-- Form -->
<div class="col-lg-12 bg-white">
    <div class="card fBTitrBold">
        <div class="header text-center ">
            <h2>پنل کاربری</h2>

            <script type="text/javascript">
                (function ($) {
                    $(document).ready(function () {
                        $('h6.full-name').text("خوش آمدید " + client_service_data.name)
                    });
                }(jQuery));
            </script>
            <h6 class="full-name"></h6>
        </div>

        <div class=" body ">
            <div class="col-md-12 text-center">
                <ul class="nav nav-tabs tab-col-orange justify-content-center" role="tablist">
                    <div class="client_service_data-0">
                        <li role="presentation" class="">
                            <a href="#tab0" data-toggle="tab">پنل کاربران</a>
                        </li>
                        <li role="presentation" class="">
                            <a href="#tab1" data-toggle="tab">پنل پذیرندگان</a>
                        </li>
                        <li role="presentation" class="">
                            <a href="#tab2" data-toggle="tab">پذیرنده</a>
                        </li>
                        <li role="presentation" class="">
                            <a href="#tab3" data-toggle="tab">کاربر</a>
                        </li>
                        <li role="presentation" class="">
                            <a href="#tab4" data-toggle="tab">گزارش</a>
                        </li>
                    </div>
                    <div class="client_service_data-1">
                        <li role="presentation" class="hidden">
                            <a href="#tab0" data-toggle="tab">پنل کاربران</a>
                        </li>
                        <li role="presentation" class="hidden">
                            <a href="#tab1" data-toggle="tab">پنل پذیرندگان</a>
                        </li>
                        <li role="presentation" class="hidden">
                            <a href="#tab2" data-toggle="tab">پذیرنده</a>
                        </li>
                        <li role="presentation" class="hidden">
                            <a href="#tab3" data-toggle="tab">کاربر</a>
                        </li>
                        <li role="presentation" class="hidden">
                            <a href="#tab4" data-toggle="tab">گزارش</a>
                        </li>
                    </div>
                </ul>
                <!-- Tab panes -->
                <div class="tab-content">
                    <!--client-->
                    <div role="tabpanel" class="tab-pane animated fadeIn" id="tab0">
                        <div class="row clearfix text-center">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                                <div class="card ">
                                    <div class="header">
                                        <h2>ویرایش مشخصات کاربری</h2>
                                    </div>
                                    <div class="body ">
                                        <div class="row">
                                            <div class="col-md-12 acceptor-slide-image">


                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--acceptor-->
                    <div role="tabpanel" class="tab-pane animated fadeIn" id="tab1">
                        <div class="row clearfix text-center">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                                <div class="card ">
                                    <div class="header">
                                        <h2>پنل پذیرنده</h2>
                                    </div>
                                    <div class="body ">
                                        <div class="row">
                                            <div class="col-md-12 acceptor-slide-image">


                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--visitor-->
                    <div role="tabpanel" class="tab-pane animated fadeIn" id="tab2">
                        <div class="card">
                            <div class="header text-center">
                                <h2 class="content-title">ثبت پذیرنده جدید</h2>
                            </div>
                            <div class="body">
                                <form id="form-acceptor-add" action="#" role="form" method="get">
                                    <div class="row rtl" dir="rtl">
                                        <div class="col-md-12">
                                            <div class="col-md-4">
                                                <input id="fName" class="effect-7" type="text"
                                                       placeholder="نام" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-4">
                                                <input id="lName" class="effect-7" type="text"
                                                       placeholder="نام خانوادگی" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-4">
                                                <input id="pNumber" class="effect-7" type="text"
                                                       placeholder="شماره تماس" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="btn btn-lg btn-info full_width "
                                                 id="google-map"
                                                 style="height: 350px"></div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="col-md-3">
                                                <input id="sName" class="effect-7" type="text"
                                                       placeholder="نام محل" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-3">
                                                <select id="category"
                                                        class="form-control full_width full_height"
                                                        title="دسته بندی"></select>
                                            </div>
                                            <div class="col-md-3">
                                                <input id="placeNumber" class="effect-7" type="text"
                                                       placeholder="شماره محل" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-3">
                                                <input id="sPhoto" class="effect-7" type="text"
                                                       placeholder="آدرس تصویر محل">
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="col-md-4">
                                                                                 <textarea id="sAP"
                                                                                           class="effect-7 form-control full_width"
                                                                                           type="text" required
                                                                                           placeholder="درباره محل"></textarea>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-4">
                                                <input style="font-size: 10px" id="sLocation"
                                                       class="effect-7" type="text"
                                                       placeholder="موقعیت" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-4">
                                                <input id="sAddress" class="effect-7" type="text"
                                                       placeholder="آدرس" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="col-md-4 text-center">
                                                <button type="button" data-toggle="tooltip"
                                                        data-placement="bottom"
                                                        title="شروع قرار داد"
                                                        class="btn btn-warning btn-lg waves-effect sStart"
                                                        id="sStart"
                                                        name="sStart">
                                                    <i class="material-icons">perm_contact_calendar</i>
                                                    <span>شروع قرار داد</span>
                                                </button>
                                            </div>
                                            <div class="col-md-4 text-center">
                                                <button type="button" data-toggle="tooltip"
                                                        data-placement="bottom"
                                                        title="پایان قرارداد"
                                                        class="btn btn-warning btn-lg waves-effect sEnd"
                                                        id="sEnd"
                                                        name="sEnd">
                                                    <i class="material-icons">perm_contact_calendar</i>
                                                    <span>پایان قرارداد</span>
                                                </button>
                                            </div>


                                            <div class="col-md-4">
                                                <input id="sDiscount" class="effect-7 full_width"
                                                       type="number" min="1" max="100"
                                                       placeholder="درصد تخفیف" required>
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="col-md-3">
                                                <input id="sSite" class="effect-7" type="text"
                                                       placeholder="سایت">
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-3">
                                                <input id="sInstagram" class="effect-7" type="text"
                                                       placeholder="اینستاگرام">
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-3">
                                                <input id="sFacebook" class="effect-7" type="text"
                                                       placeholder="فیسبوک">
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                            <div class="col-md-3">
                                                <input id="sTelegram" class="effect-7" type="text"
                                                       placeholder="تلگرام">
                                                <span class="focus-border"><i></i></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12 text-center ">
                                            <button type="submit"
                                                    class="btn btn-success action-db waves-effect">
                                                ثبت داده
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane animated fadeIn" id="tab3">
                        <div class="row clearfix text-center">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                                <div class="card ">
                                    <div class="header">
                                        <h2>ثبت کاربران</h2>
                                    </div>
                                    <div class="body ">
                                        <div class="row">
                                            <div class="col-md-12 ">
                                                <form id="add-client-nafis" method="get" class="add-client-nafis">
                                                    <div class="row">

                                                        <div class="col-md-3">
                                                            <input placeholder="نام"
                                                                   class="form-control fBRoya"
                                                                   type="text" name="fName"
                                                                   value="مسافر" required="required"
                                                                   dir="rtl">
                                                        </div>
                                                        <div class="col-md-4">
                                                            <input placeholder="نام خانوادگی"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="lName"
                                                                   value="نوروزی"
                                                                   required="required" dir="rtl"/>
                                                        </div>
                                                        <!--  <div class="col-md-5">
                                                              <input placeholder="کد ملی"
                                                                     class="form-control fBRoya"
                                                                     type="text" name="nCode"
                                                                     required="required" dir="rtl"
                                                                     minlength="10" maxlength="10"/>
                                                          </div>-->
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <input
                                                                    id="credit-card"
                                                                    placeholder="شماره کارت بانکی 9999-9999-9999-9999"
                                                                    class="form-control fBRoya card-number card-number credit-card"
                                                                    type="tel"
                                                                    name="bank"
                                                                    required="required" dir="ltr"
                                                                    minlength="16" maxlength="16"/>
                                                        </div>
                                                        <div class="col-md-4">
                                                            <input placeholder="شماره موبایل 936xxxxxxx"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="mobile"
                                                                   required="required" dir="rtl"
                                                                   minlength="10" maxlength="10"/>
                                                        </div>
                                                        <div class="col-md-4">
                                                            <input placeholder="تاریخ انقضای کارت"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="Ex"
                                                                   required="required" dir="rtl"
                                                                   minlength="10" maxlength="10"
                                                                   value="1400/01/01"/>
                                                        </div>
                                                    </div>
                                                    <hr>
                                                    <div class="row">
                                                        <div class="col-md-3">
                                                            <input placeholder="کد 12 رقمی پشت کاشان کارت"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="bnCode"
                                                                   dir="rtl" minlength="12"
                                                                   maxlength="12"/>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <input placeholder="شماره شناسنامه"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="IdNo"
                                                                   dir="rtl" minlength="10"
                                                                   maxlength="10"/>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <input placeholder="نام پدر"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="FatherName"
                                                                   dir="rtl"/>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <input placeholder="تاریخ تولد"
                                                                   class="form-control fBRoya"
                                                                   type="text"
                                                                   name="BirthDate"
                                                                   dir="rtl" minlength="10"
                                                                   maxlength="10"/>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="row hidden">
                                                            <input value="1" name="Mode"
                                                                   type="hidden">
                                                        </div>
                                                    </div>
                                                    <div class="sign-up">
                                                        <input class="btn btn-success waves-effect"
                                                               type="submit" value="ثبت نام"/>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane animated fadeIn" id="tab4">
                        <div class="row clearfix text-center">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                                <div class="card ">
                                    <div class="header">
                                        <h2>جستوجو پذیرنده</h2>
                                    </div>
                                    <div class="body ">
                                        <div class="row">
                                            <div class="col-md-12 ">
                                                <div class="table-responsive text-center p-t-20 align-center no-overflow-y">
                                                    <table class="table table-bordered table-striped table-hover no-overflow-y dataTable js-exportable text-center full_width"
                                                           style="overflow-y: hidden">
                                                        <thead>
                                                        <tr>
                                                            <td class="text-center">تنظیمات</td>
                                                            <td class="text-center">نام محل</td>
                                                            <td class="text-center">نام - نام
                                                                خانوادگی
                                                            </td>
                                                            <td class="text-center">کد پذیرنده
                                                            </td>
                                                            <td class="text-center">شماره</td>
                                                        </tr>
                                                        </thead>
                                                        <tbody class="bordered">


                                                        </tbody>
                                                        <tfoot>
                                                        <tr>
                                                            <td class=" text-center">تنظیمات
                                                            </td>
                                                            <td class="text-center">نام محل</td>
                                                            <td class="text-center">نام - نام
                                                                خانوادگی
                                                            </td>
                                                            <td class="text-center">کد پذیرنده
                                                            </td>
                                                            <td class="text-center">شماره</td>
                                                        </tr>
                                                        </tfoot>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="defaultModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header text-right">
                <h4 class="modal-title " id="defaultModalLabel">ویرایش اسلاید شو</h4>
            </div>
            <div class="modal-body">
                <div class="row clearfix ">
                    <div class="card">
                        <div class="body">
                            <div id="aniimated-thumbnials" class="list-unstyled row clearfix">
                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-shenasname">
                                        <div class="caption">
                                            <label for="file1" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی شناسنامه صفحه اول</strong>
                                            </label>
                                            <input type="file" name="copy-shenasname" id="file1"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-cart-meli">
                                        <div class="caption">
                                            <label for="file2" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی کارت ملی</strong>
                                            </label>
                                            <input type="file" name="copy-cart-meli" id="file2"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-cart-meli-posht">
                                        <div class="caption">
                                            <label for="file3" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی پشت کارت ملی</strong>
                                            </label>
                                            <input type="file" name="copy-cart-meli-posht" id="file3"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-javaz-kasb">
                                        <div class="caption">
                                            <label for="file4" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی جواز کسب </strong>
                                            </label>
                                            <input type="file" name="copy-javaz-kasb" id="file4"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-bargh-gaz-ab">
                                        <div class="caption">
                                            <label for="file5" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی قبض برق آب یا گاز</strong>
                                            </label>
                                            <input type="file" name="copy-bargh-gaz-ab" id="file5"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-md-3">
                                    <div class="thumbnail">
                                        <img src="http://placehold.it/500x300" width="500" height="300"
                                             id="copy-gharardad">
                                        <div class="caption">
                                            <label for="file6" class="btn waves-effect btn-primary btn-block">
                                                <strong>کپی صفحه اول قرارداد </strong>
                                            </label>
                                            <input type="file" name="copy-gharardad" id="file6"
                                                   class="inputfile hidden"
                                                   data-multiple-caption="{count} files selected"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">بستن</button>
            </div>
        </div>
    </div>
</div>
<!-- #END# Form -->
<script type="text/javascript">
    (function ($) {

        let acceptorDocumentID = -1;

        function initInput() {
            /*$('.inputfile').unbind()
                .bind("tap ", function () {
                    let btn = $(this);
                    alert(1);
                });*/

            $('.modal-body').find("input:file").change(function (event) {
                let input = event.target;
                let image = $(this).attr("name");
                let reader = new FileReader();
                let file = input.files[0];
                reader.onload = function () {
                    let dataURL = reader.result;
                    $("#" + image).attr("src", dataURL);
                };
                reader.readAsDataURL(file);
                uploadImage(file, image);
            });
        }

        function uploadImage(file, tag) {
            let data = new Promise((resolve, reject) => {
                const reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = () => resolve(reader.result);
                reader.onerror = error => reject(error);
            });

            data.then((successMessage) => {
                UpdateDocument(acceptorDocumentID, successMessage, tag);
            });
        }

        function UpdateDocument(forId, data, forField) {
            LoadData({
                request: 'proxy',
                object: {
                    ID: forId,
                    field: forField,
                    copy: data
                },
                action: 'edit-document-acceptor',
            }, null, false, function (data) {
                if (data === '1') {
                    swal("ویرایش شد", "این مورد ویرایش شد", "success");
                } else {
                    swal("خطا", "این درخواست انجام نشد", "error");
                }
            });
        }


        let geoCoder = new google.maps.Geocoder();

        let e = {
            fName: null,
            lName: null,
            pNumber: null,
            /**********/
            sName: null,
            sGuild: null,
            sNumber: null,
            sPhoto: null,
            /**********/
            sAP: null,
            sLocation: null,
            sAddress: null,
            /**********/
            sStart: null,
            sEnd: null,
            sDiscount: null,
            /**********/
            sTelegram: null,
            sSite: null,
            sInstagram: null,
            sFacebook: null
        };

        let InsertDB, LoadDB, ListItem, OnInitEvent, table = null, btnInsert, LoadGuild;
        let Map = null, initGoogleMap;
        InsertDB = function (e, id = 0) {
            LoadData({
                    request: 'proxy',
                    object: {
                        mode: 'limit',
                        fName: e.fName.val(),
                        lName: e.lName.val(),
                        pNumber: e.pNumber.val(),
                        /**********/
                        sName: e.sName.val(),
                        sGuild: e.sGuild.val(),
                        sNumber: e.sNumber.val(),
                        sPhoto: e.sPhoto.val(),
                        /**********/
                        sAP: e.sAP.val(),
                        sLocation: e.sLocation.val(),
                        sAddress: e.sAddress.val(),
                        /**********/
                        sStart: e.sStart.find('span').text(),
                        sEnd: e.sEnd.find('span').text(),
                        sDiscount: e.sDiscount.val(),
                        /**********/
                        sTelegram: e.sTelegram.val(),
                        sSite: e.sSite.val(),
                        sInstagram: e.sInstagram.val(),
                        sFacebook: e.sFacebook.val(),
                        'page-mode': client_service_data.p_mode,
                        'page-id': client_service_data.p_id,
                        id: id,
                    },
                    action: (id === 0 ? 'add-acceptor' : 'edit-acceptor')
                },
                null, false, function (data) {
                    if (data === '1') {
                        LoadDB();
                        btnInsert.text('ثبت داده');
                        $('#form-acceptor-add')[0].reset();
                        swal("ثبت شد.", "این مورد ثبت شد.", "success");
                    } else {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    }
                }
            )
            ;
        };

        LoadGuild = function (id = 0) {
            let cat = $("#category");
            cat.append().empty();
            LoadData({
                    request: 'proxy',
                    action: 'load-category',
                    object: 'load'
                },
                null, true, function (data) {
                    for (let i = 0; i < data.length; i += 1) {
                        let item = data[i];
                        cat.append("<option value='" + item.id + "' " + (item.id === id ? "selected" : "") + " >" + item.name + "</option>")
                    }
                });
        };

        LoadDB = function () {
            LoadData({
                    request: 'proxy',
                    action: 'load-acceptor',
                    object: {
                        mode: 'limit',
                        'page-mode': client_service_data.p_mode,
                        'page-id': client_service_data.p_id,
                    }
                },
                null, true, function (data) {
                    ListItem = data;
                    if (table !== null)
                        table.destroy();
                    table = $('.js-exportable').DataTable({
                        "data": data,
                        "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                            // FieldCounter.p4.c2.

                            OnInitEvent();
                        },
                        "columns": [
                            {"data": "button-edit"},
                            {"data": "sName"},
                            {"data": "full-name"},
                            {"data": "acceptor-code"},
                            {"data": "counter"},
                        ],
                        // dom: 'Bfrtip',
                        responsive: true,
                        /* buttons: [
                             'copy', 'csv', 'excel', 'pdf', 'print'
                         ],*///  to _END_ of _TOTAL_ entries
                        "language": {
                            "lengthMenu": "Display _MENU_ records per page",
                            "zeroRecords": " چیزی یافت نشد",
                            "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                            "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                            "infoFiltered": "(filtered from _MAX_ total records)",
                            "paginate": {
                                "next": "بعدی",
                                "previous": "قبلی"
                            }
                        }
                    });

                }
            );
        };

        OnInitEvent = function () {
            $('.dataTable').find('button').unbind()//, click"
                .bind("tap ", function () {
                    let btn = $(this);
                    let tr = btn.parents('tr');
                    switch (btn.attr('data-action')) {
                        /*     case 'edit-item':
                                 OnEditItem(btn.attr('data-id'), btn.attr('data-index'));
                                 break;
                             case 'delete-item':
                                 DeleteItem(btn.attr('data-id'), tr);
                                 break;
                             case 'show-item':
                                 ActiveItem(btn, btn.attr('data-id'), btn.attr('data-value'));
                                 break;*/
                        case 'add-document':
                            acceptorDocumentID = btn.attr('data-id');
                            Model.find("input:file").val("");
                            Model.find("img").attr("src", "http://placehold.it/500x300");

                            if (ListItem[btn.attr("data-index")].hasOwnProperty('document')) {
                                let target = ListItem[btn.attr("data-index")]['document'];
                                for (let key in target) {
                                    if (typeof target[key] !== 'function' && target[key] !== null && typeof target[key] === "string") {
                                        if (target[key].length > 0)
                                            $("#" + key).attr("src", target[key]);
                                    }
                                }
                            }
                            Model.modal('show');
                            break;
                        default:
                            break;
                    }
                });
        };

        function DeleteItem(id, tr) {
            swal({
                title: "آیا این مورد حذف شود؟",
                text: "شما قادر به بازگردانی این مورد نخواهید بود",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله حذف شود",
                cancelButtonText: "نه حذف نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        action: 'delete-acceptor',
                        id: id
                    }, null, false, function (data) {
                        if (data === '1') {
                            tr.fadeOut(function (e) {
                                table.row(tr)
                                    .remove()
                                    .draw();
                            });
                            swal("حذف شد", "این مورد حذف شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        }

        function ActiveItem(btn, id, show) {
            LoadData({
                request: 'proxy',
                action: 'active-acceptor',
                id: id,
                show: show
            }, null, false, function (data) {
                if (data === '1') {
                    btn.attr('data-value', (show === '1') ? 0 : 1);
                    btn.removeClass((show === '1') ? 'btn-warning' : 'btn-info');
                    btn.addClass((show === '0') ? 'btn-warning' : 'btn-info');
                    btn.find('i').empty().append((show === '0') ? 'visibility_off' : 'visibility');
                }
            });
        }


        function OnEditItem(id, index) {
            if (ListItem[index].ID === id) {
                let object = ListItem[index];
                init(e, object, false);
            } else {
                swal("خطا", "این درخواست انجام نشد", "error");
            }
        }

        function init(element = {}, object = {}, flag = true) {
            $.AdminBSB.input.activate();
            btnInsert = $('.action-db');

            e.sStart.persianDatepicker({
                element: e.sStart
            });

            e.sEnd.persianDatepicker({
                element: e.sEnd
            });

            if (!flag && object !== {}) {
                element.fName.val(object['fName']);
                element.lName.val(object['lName']);
                element.pNumber.val(object['pNumber']);
                element.sName.val(object['sName']);
                element.sGuild.val(object['sGuild']);
                element.sNumber.val(object['sNumber']);
                element.sPhoto.val(object['sPhoto']);
                element.sAP.val(object['sAP']);
                element.sLocation.val(object['sLocation']);
                element.sAddress.val(object['sAddress']);
                element.sStart.find('span').text(object['sStart']);
                element.sEnd.find('span').text(object['sEnd']);
                element.sDiscount.val(object['sDiscount']);
                element.sTelegram.val(object['sTelegram']);
                element.sSite.val(object['sSite']);
                element.sInstagram.val(object['sInstagram']);
                element.sFacebook.val(object['sFacebook']);
                btnInsert.text('ویرایش');
                LoadGuild(object['sGuild']);
            } else {
                btnInsert.text('ثبت داده');
                LoadGuild(0);
            }


            $('#form-acceptor-add').submit(function (ee) {
                    ee.preventDefault();

                    console.log();
                    if (flag && typeof object === 'object' && $.isEmptyObject(object)) {
                        //  insert
                        InsertDB(e);
                    } else {
                        //  update
                        InsertDB(e, object.ID);
                    }
                }
            );
        }

        initGoogleMap = function (location = null) {
            if (Map == null) {
                Map = new google.maps.Map($('#google-map')[0], {
                    center: new google.maps.LatLng(33, 55),
                    zoom: 5
                });
                google.maps.event.addListener(Map, 'click', function (event) {
                    addMarker(event.latLng);
                });
            }

            if (location == null) {
                moveToLocation(33, 55, 5);
            } else {
                let loc = location.split(',');
                // loc.replace()
                moveToLocation(33, 55, 5);
            }


        };

        let singleMarker;
        let addMarker = function (latLng) {
            //if marker exists, erase marker
            if (singleMarker) {
                singleMarker.setMap(null);
            }
            $('#sLocation').val(latLng);
            singleMarker = new google.maps.Marker({
                position: latLng, //mouse click position
                map: Map,
                draggable: true,
                icon: "http://www.google.com/mapfiles/marker_green.png"
            });
            geoCoder.geocode({
                'latLng': latLng
            }, function (results, status) {
                if (status === google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        $('#sAddress').val(results[0].formatted_address);
                    }
                }
            });
        };
        let moveToLocation = function (lat, lng, zoom) {
            let center = new google.maps.LatLng(lat, lng);
            // using global variable:
            Map.setZoom(zoom);
            Map.panTo(center);
            addMarker(center);
        };
        $(document).ready(function () {

            e = {
                fName: $("#fName"),
                lName: $("#lName"),
                pNumber: $("#pNumber"),
                /**********/
                sName: $("#sName"),
                sGuild: $("#category"),
                sNumber: $("#placeNumber"),
                sPhoto: $("#sPhoto"),
                /**********/
                sAP: $("#sAP"),
                sLocation: $("#sLocation"),
                sAddress: $("#sAddress"),
                /**********/
                sStart: $("#sStart"),
                sEnd: $("#sEnd"),
                sDiscount: $("#sDiscount"),
                /**********/
                sTelegram: $("#sTelegram"),
                sSite: $("#sSite"),
                sInstagram: $("#sInstagram"),
                sFacebook: $("#sFacebook")
            };
            init(e);
            LoadDB();
            initGoogleMap();

            initInput();
        });

        let Model = $('#defaultModal');
        /*Model.unbind().bind('hidden.bs.modal', function () {
            // alert(1);
        });*/

    }(jQuery));
    (function ($) {
        // console.log();

        if (client_service_data.p_id === '6') {
            $('.client_service_data-0').show();
            $('.client_service_data-1').hide();
        } else {
            $('.client_service_data-1').show();
            $('.client_service_data-0').hide();
        }


        $(document).ready(function () {
            if(client_service_data.p_id === '6'){

                if (client_service_data.p_roll === 'client' && client_service_data.p_mode === '1') {
                    $('a[href*=tab0]').parents('li').removeClass('hidden').addClass('active');

                    $('#tab0').addClass('active');
                } else if (client_service_data.p_roll === 'client' && client_service_data.p_mode === '2') {
                    // $('a[href*=tab2]').parents('li').removeClass('hidden');
                    $('a[href*=tab3]').parents('li').removeClass('hidden').addClass('active');
                    // $('a[href*=tab4]').parents('li').removeClass('hidden').addClass('active');
                    //
                    $('#tab3').addClass('active');
                } else if (client_service_data.p_roll === 'acceptor') {
                    $('a[href*=tab1]').parents('li').removeClass('hidden').addClass('active');

                    $('#tab1').addClass('active');
                }
            }else{
                $('a[href*=tab4]').parents('li').removeClass('hidden');
                $('a[href*=tab3]').parents('li').removeClass('hidden');
                $('a[href*=tab2]').parents('li').removeClass('hidden');
                $('a[href*=tab1]').parents('li').removeClass('hidden');
                $('a[href*=tab0]').parents('li').removeClass('hidden').addClass('active');
                $('#tab0').addClass('active');
            }


            // let item = $('.acceptor-slide-image');
            // if (client_service_data.image_slide_count > 0) {
            //     for (let i = 0; i < client_service_data.image_slide_count; i += 1) {
            //         let src = null, id = null;
            //         if (client_service_data.image_slide.length > i)
            //             src = client_service_data.image_slide[i]['src'];
            //         if (client_service_data.image_slide.length > i)
            //             id = client_service_data.image_slide[i]['id'];
            //         item.append(LoadImageButton(client_service_data.cceptor_id, src, id, i));
            //     }
            // }
            // else {
            //     item.append("<span dir='rtl'> شما حق دسترسی ندارید.</span>");
            //     swal("اخطار!", "شما اجازه ویرایش محتوای این بخش را ندارید.", "warning");
            // }
            initInputEvent();
        });


        /**
         * @return {string}
         */
        function LoadImageButton(id, src, srcId, number) {
            let block = '';
            let itemId = 'aks-acceptor-id-' + number;
            let itemName = 'aks-acceptor-name-' + number;
            block += '<div class="col-sm-6 col-md-3 ">';
            block += '    <div class="thumbnail">';
            block += '        <img class="img-responsive thumbnail" src="' + (src != null ? src : "http://placehold.it/150x75") + '" width="300" height="150"';
            block += '             id="' + itemName + '">';
            block += '        <div class="caption btn-group btn-group-lg" role="group" aria-label="Large button group">';
            block += '            <label for="' + itemId + '" class="btn waves-effect btn-primary btn-block">';
            block += '                <strong>تصوی شماره ' + (number + 1) + '</strong>';
            block += '            </label>';
            block += '            <button image-id="' + itemName + '" input-id="' + (srcId != null ? srcId : -1) + '"  class="btn btn-danger remove-image btn-block waves-effect' + (srcId != null ? '' : ' hidden ') + '">';
            block += 'حذف';
            block += '            </button>';
            block += '            <input type="file" data-for="slider" image-index=' + number + ' id="' + itemId + '" input-id="' + (srcId != null ? srcId : -1) + '" id-for=' + id + ' name="' + itemName + '"';
            block += '                   class="inputfile hidden"/>';
            block += '        </div>';
            block += '    </div>';
            block += '</div>';
            return block
        }


        function initInputEvent() {
            $('.remove-image').unbind().bind('tap', function () {
                let SlideId = $(this).attr('input-id');
                let Image = $(this).attr('image-id');
                LoadData({
                    request: 'proxy',
                    object: {
                        slide: SlideId,
                        'image-mode': 'delete-mode'
                    },
                    action: 'edit-slide-acceptor'
                }, null, false, function (data) {
                    if (data === '1') {
                        $("#" + Image).attr("src", "http://placehold.it/150x75");
                        swal("ویرایش شد", "این مورد ویرایش شد", "success");
                    } else {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    }
                });
            });

            $('.acceptor-slide-image').find("input:file").change(function (event) {
                let input = event.target;
                let image = $(this).attr("name");
                let reader = new FileReader();
                let file = input.files[0];
                let parentID = $(this).attr('id-for');
                let inputId = $(this).attr('input-id');
                let Index = $(this).attr('image-index');
                reader.onload = function () {
                    let dataURL = reader.result;
                    $("#" + image).attr("src", dataURL);
                    UpdateDataImageSlide(parentID, inputId, dataURL, Index);
                };
                reader.readAsDataURL(file);
            });
        }

        function UpdateDataImageSlide(AcceptorID, SlideId, Photo, Index) {
            LoadData({
                request: 'proxy',
                object: {
                    acceptor: AcceptorID,
                    slide: SlideId,
                    image: Photo,
                    index: Index,
                    'image-mode': 'edit-mode'
                },
                action: 'edit-slide-acceptor'
            }, null, false, function (data) {
                if (data === '1') {
                    swal("ویرایش شد", "این مورد ویرایش شد", "success");
                } else {
                    if (data === '0') {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    } else {
                        swal("خطا", data, "error");
                    }
                }
            });
        }

    }(jQuery));
    //addclient nafis
    (function ($) {

        function CreaditCard($id) {
            let input = document.querySelector($id),
                oldValue,
                oldCursor,
                regex = new RegExp(/^\d{0,16}$/g),
                mask = function (value) {
                    let output = [];
                    for (let i = 0; i < value.length; i++) {
                        if (i !== 0 && i % 4 === 0) {
                            output.push("-"); // add the separator
                        }
                        output.push(value[i]);
                    }
                    return output.join("");
                },
                unmask = function (value) {
                    let output = value.replace(new RegExp(/[^\d]/, 'g'), ''); // Remove every non-digit character
                    return output;
                },
                checkSeparator = function (position, interval) {
                    return Math.floor(position / (interval + 1));
                },
                keydownHandler = function (e) {
                    let el = e.target;

                    oldValue = el.value;
                    oldCursor = el.selectionEnd;
                },
                inputHandler = function (e) {
                    let el = e.target,
                        newCursorPosition,
                        newValue = unmask(el.value)
                    ;

                    if (newValue.match(regex)) {
                        newValue = mask(newValue);

                        newCursorPosition = oldCursor - checkSeparator(oldCursor, 4) + checkSeparator(oldCursor + (newValue.length - oldValue.length), 4) + (unmask(newValue).length - unmask(oldValue).length);

                        if (newValue !== "") {
                            el.value = newValue;
                        } else {
                            el.value = "";
                        }
                    } else {
                        el.value = oldValue;
                        newCursorPosition = oldCursor;
                    }
                    el.setSelectionRange(newCursorPosition, newCursorPosition);
                }
            ;

            input.addEventListener('keydown', keydownHandler);
            input.addEventListener('input', inputHandler);
        }


        $(document).ready(function () {
            // $('.credit-card').inputmask('9999-9999-9999-9999', {placeholder: '____-____-____-____'});

            // CreaditCard('#credit-card');
            $('input').css({"height": '30px', 'padding': '10px'});
            $('div.card').css({"margin": '0px', 'padding': '0px'});

            $(".add-client-nafis").submit(function (event) {
                event.preventDefault();
                let result = {};
                $.each($(this).serializeArray(), function () {
                    result[this.name] = this.value;
                });
                //
                swal({
                    title: "ثبت کاربر",
                    text: "این کاربر ثبت شود؟",
                    type: "info",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    showLoaderOnConfirm: true,
                }, function () {
                    addClientMobile(result, $('#add-client-nafis'));
                });

            });
        });

        function addClient(data, form) {
            LoadData({
                request: 'proxy',
                action: 'WebServicesController',
                object: {
                    GroupCode: 3131,
                    CategoryCode: 220744,
                    Mode: data['Mode'],
                    RegFrom: client_service_data.p_id,
                    bnCode: data['bnCode'],
                    CardPan: data['bank'].replace(/-/g, ""),
                    FirstName: data['fName'],
                    LastName: data['lName'],
                    FatherName: data['FatherName'],
                    IdNo: data['IdNo'],
                    BirthDate: data['BirthDate'],
                    NationalCode: data['nCode'],
                    Mobile: data['mobile'],
                    CardExpireDate: data['Ex']
                },
                'data-header': 'NoCodeCustomerServiceNafis',
            }, null, true, function (data) {
                if (data.length === 1) {
                    data = data[0];
                    if (data.error !== undefined && data.error === 1 || data.error !== 'no error') {
                        swal("خطا", (data.message !== undefined ? data.message : data.error), "error");
                    } else {
                        let response = data.response;
                        if (form !== null) form[0].reset();
                        let client = response.client;
                        let card = response.card;
                        if (client.ResponseCode === "0000") {
                            swal({
                                title: "ثبت شد.",
                                text: "این درخواست ثبت شد.",
                                type: "success"
                            }, function () {
                                setTimeout(function (e) {
                                    if (card.ResponseCode === "0000") {
                                        let card = response.card;
                                        swal("ثبت شد.", "این درخواست ثبت شد.", "success");
                                    } else {
                                        swal(card.ErrorFieldName, card.ResponseMessage, "error");
                                    }
                                }, 500);
                            });
                        } else {
                            swal({
                                title: client.ErrorFieldName,
                                text: client.ResponseMessage,
                                type: "error"
                            }, function () {
                                setTimeout(function (e) {
                                    if (card.length !== 0 && typeof card === 'object' || card != null)
                                        if (card.ResponseCode === "0000") {
                                            swal("ثبت شد.", "این درخواست ثبت شد.", "success");
                                        } else {
                                            swal(card.ErrorFieldName, card.ResponseMessage, "error");
                                        }
                                }, 500);
                            });
                        }
                    }
                } else {
                    swal("خطا", "این درخواست انجام نشد", "error");
                }
            });
        }

        function addClientMobile(data, form) {
            LoadData({
                request: 'proxy',
                action: 'WebServicesController',
                object: {
                    GroupCode: 3131,
                    CategoryCode: 220744,
                    Mode: data['Mode'],
                    RegFrom: client_service_data.p_id,
                    bnCode: data['bnCode'],
                    CardPan: data['bank'].replace(/-/g, ""),
                    FirstName: data['fName'],
                    LastName: data['lName'],
                    FatherName: data['FatherName'],
                    IdNo: data['IdNo'],
                    BirthDate: data['BirthDate'],
                    Mobile: data['mobile'],
                    CardExpireDate: data['Ex']
                },
                'data-header': 'MobileCustomerService',
            }, null, true, function (data) {
                if (data.length === 1) {
                    data = data[0];
                    if (data.error !== undefined && data.error === 1) {
                        swal("خطا", (data.message !== undefined ? data.message : data.error), "error");
                    } else {
                        let response = data.message;
                        if (form !== null) form[0].reset();
                        let client = response.client;
                        let card = response.card;
                        if (client.ResponseCode === "0000") {
                            swal({
                                title: "ثبت شد.",
                                text: "این درخواست ثبت شد.",
                                type: "success"
                            }, function () {
                                setTimeout(function (e) {
                                    if (card.ResponseCode === "0000") {
                                        swal("ثبت شد.", "این کارت ثبت شد.", "success");
                                    } else {
                                        swal(card.ErrorFieldName, card.ResponseMessage, "error");
                                    }
                                }, 500);
                            });
                        } else {
                            swal({
                                title: client.ErrorFieldName,
                                text: client.ResponseMessage,
                                type: "error"
                            }, function () {
                                setTimeout(function (e) {
                                    if (card.length !== 0 && typeof card === 'object' || card != null)
                                        if (card.ResponseCode === "0000") {
                                            swal("ثبت شد.", "این کارت ثبت شد.", "success");
                                        } else {
                                            swal(card.ErrorFieldName, card.ResponseMessage, "error");
                                        }
                                }, 500);
                            });
                        }
                    }
                } else {
                    swal("خطا", "این درخواست انجام نشد", "error");
                }
            });
        }
    }(jQuery));
</script>