{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">

        <div class="container-fluid">
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>
            <div class="pull-right easy-mode {{ easy_visibility }}">
                <img src="view/image/entegrasyon/logo.png" />
            </div>
        </div>
    </div>
    <div class="container-fluid"> {% if success %}
            <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        {% endif %}
        {% if error %}
            {% for error_message in error %}
                <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_message }}</div>
            {% endfor %}
        {% endif %}
        <div class="panel panel-default" style="border-top: 2px solid #27ad5e;">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-puzzle-piece"></i> Pazaryerleri</h3>

                {% if logout %}
                    <ul style="cursor : pointer"  class="nav pull-right  {% if not permission %} hidden  {% else %} easy-mode {{ easy_visibility }} {% endif %} ">
                        <a class="dropdown pull-right"><a class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user fa-lg"></i> {{ mir_username }} <i class="fa fa-chevron-down " aria-hidden="true"></i></a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li class="dropdown-header">Hesap Bilgileri</li>
                                <li><a href="index.php?route=entegrasyon/setting/account_info&{{ token_link }}"><i class="fa fa-user" aria-hidden="true"></i> Hesabım</a></li>
                                <li class="{% if not permission %}hidden{% endif %}"><a href="{{ logout }}" target="_blank"><i class="fa fa-sign-out" aria-hidden="true"></i> Çıkış Yap</a></li>
                            </ul>
                        </a>
                    </ul>

                {% endif  %}

            </div>
            <div class="panel-body">


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

    <script>

        $(function (data) {

            $('.panel-body').load('index.php?route=entegrasyon/setting/main&form={{ form }}&{{ token_link }}');

        })

    </script>


    <script>

        $(document).on('click','.btnKaydet',function (event) {
            var thisButton = $(this);

            var code=thisButton.attr('code');
            var name=thisButton.attr('name');
            var data=$("form").serialize();
            var error=false;
            //thisButton.button('loading');


            if(!error) {

                $.post('index.php?route=entegrasyon/setting/'+code+'&{{ token_link }}',data, function (json) {
                    thisButton.button('reset');
                    if (json['status']) {


                        Swal.fire({
                            title: 'Başarılı',
                            text: name+" Api bilgileriniz Doğrulandı, Ayarlar Sayfasına Dönmek İstermisiniz ?",
                            icon: 'success',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: "Evet",
                            cancelButtonText: "Hayır!",
                        }).then((result) => {
                            if (result.value) {

                                $('.btnVazgec').click();

                            }
                        });

                        //$('#diger').removeClass('hidden');
                    } else {

                        Swal.fire('Başarız',json['message'],'warning');



                    }

                }, 'JSON')

            }

        })

    </script>

    <script>

        $(document).on('change','#shippingTime', function() {
            var secilen = this.value;

            if(secilen=='today'){
                $('.time').removeClass('hidden')
            }else {

                $('.time').addClass('hidden')

            }
        })

    </script>

    <script>
        $(document).on('change','#shipping_template',function () {



            if($(this).val()=='B'){

                $('#extra_shipping_price').removeClass('hidden')

            }else {

                $('#extra_shipping_price').addClass('hidden')

            }

        })
    </script>

    <script>

        $(document).on('click','.btnSave', function () {


            var error=false;
            var data =$('form').serializeArray();
            var thisButton = $(this);
            var code=thisButton.attr('code');
            thisButton.button('loading');

            if(!error) {

                $.post('index.php?route=entegrasyon/setting/edit_'+code+'&{{ token_link }}', data, function (json) {
                    thisButton.button('reset');
                    if (json['status']) {


                        Swal.fire({
                            title: 'Başarılı',
                            text:  "Ayarlar Kaydedildi. Anasayfaya dönmek ister misiniz?",
                            icon: 'success',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: 'Evet!',
                            cancelButtonText: "Hayır!",

                        }).then((result) => {
                            if (result.value) {


                                $('.btnVazgec').click();

                            }
                        })


                    } else {

                        Swal.fire('Başarız',json['message'],'warning');


                    }

                }, 'JSON')

            }

        })



    </script>


    <script>

        $(document).on('click','.btnReset', function () {

            var thisButton=$(this);
            var code=thisButton.attr('code');
            var name=thisButton.attr('name');

            Swal.fire({
                title: 'Dikkat!',
                text: name+" Api Bilgileriniz Silinecektir. Onaylıyormusunuz ?",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Evet, Onaylıyorum!',
                cancelButtonText: "Hayır!",

            }).then((result) => {
                if (result.value) {
                    thisButton.button('loading');

                    $.post('index.php?route=entegrasyon/setting/reset&code='+code+'&{{ token_link }}', {}, function (json) {
                        thisButton.button('reset');


                        Swal.fire({
                            title: 'Başarılı',
                            text: name+" Api bilgileriniz Silinmiştir, Ayarlar Sayfasına Dönmek İstermisiniz ?",
                            icon: 'info',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: 'Evet!',
                            cancelButtonText: "Hayır!",

                        }).then((result) => {
                            if (result.value) {


                                $('.btnVazgec').click();

                            }
                        })
                    }, 'JSON')
                }
            });


        })

    </script>




    <script>

        $(document).on('click','.btnPazar',function (event) {

            var $thisBtn=$(this);
            $thisBtn.button('loading');

            var $code= $thisBtn.attr('code');
            $('.panel-body').load('index.php?route=entegrasyon/setting/'+$code+'&{{ token_link }}',function (json) {
                $thisBtn.button('reset');
            });

        })

    </script>

    <script>

        $(document).on('click','.btnDown',function (event) {

            var $thisBtn=$(this);
            $thisBtn.button('loading');
            var $code= $thisBtn.attr('code');
            if($code=='hb' || $code=='eptt'){
                $thisBtn.button('reset');
                Swal.fire("Bilgi","Ne Yazıkki, Hepsiburada ve Eptt Mağazalarından Ürün aktarımı yapılamamaktadır!",'warning');
                return;
            }
            window.location.replace('index.php?route=entegrasyon/product/get_marketplace_products&code='+$code+'&{{ token_link }}')


        })

    </script>

    <script>

        $(document).on('click','.btnEdit',function (event) {

            var $thisBtn=$(this);
            $thisBtn.button('loading');

            var $code= $thisBtn.attr('code');
            $('.panel-body').load('index.php?route=entegrasyon/setting/edit_'+$code+'&{{ token_link }}',function (json) {
                $thisBtn.button('reset');
            });

        })

    </script>


    <script>

        $(document).on('click','.btnSync',function (event) {

            var $thisBtn=$(this);
            // $thisBtn.button('loading');
            var $code= $thisBtn.attr('code');

            BootstrapDialog.show({
                title:'Ürün Eşitleme',
                message: function(dialog) {
                    var $message = $('<div></div>');
                    var pageToLoad = dialog.getData('pageToLoad');
                    $message.load(pageToLoad);
                    return $message;
                },
                data: {

                    'pageToLoad': 'index.php?route=entegrasyon/setting/sync_form&code='+$code+'&{{ token_link }}'
                }
            });


        })

    </script>




    <script>

        $(document).on('click','.btnVazgec',function (data) {

            $(this).button('loading');

            $('.panel-body').load('index.php?route=entegrasyon/setting/main&{{ token_link }}');


        })


    </script>

    {{ footer }}
