{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="{{ easy_visibility }} pull-right easy-mode ">
                <img src="view/image/entegrasyon/logo.png" />
            </div>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>

        </div>


    </div><div style="border-top: 2px solid #27ad5e;
    padding-top: 11px;"></div>


    <div class="container-fluid">{% if message %}
            <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ marketplace_info.name }} {{ message }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        {% endif %}

        <div class="container-fluid">{% if error_warning %}
                <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                </div>
            {% endif %}
            {% 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 %}


            <div class="row well {% if not status %} hidden {% endif %}"  style="border-top: 2px solid #27ad5e;">


                <div class="col-sm-1">
                    <img class="img-responsive" src="view/image/entegrasyon/bilgi.png"/>
                </div>
                <div class="col-sm-11">
                    <h3 style="color:#27ad5e;font-weight: bolder ">Bilgilendirme</h3>
                    <p class="lead">
                        {{ marketplace_info.name }} Mağazanızda yer alan tüm ürünler aşağıda listelenmiştir.  Listedeki ürünleri mağazanıza aktarmak için ürünün karşında yer alan indir butonuna tıklayınız. Ürünü belli bir kategori ve marka ile aktarmak için her ürün satırında yer alan bölümden kategori ve marka seçebilirsiniz.

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


            <div class="panel-body" >

                <div class="row" >


                    <div  class="col-xs-6 col-md ">
                        <label class="control-label" for="input-model">Ürün Adı</label>
                        <input type="text" name="filter_name" value="{{ filter_name }}" placeholder="Ürün Adı" id="input-name" class="form-control" />
                    </div>
                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Model</label>
                        <input type="text" name="filter_model" value="{{ filter_model }}" placeholder="Model Girin" id="input-model" class="form-control" />
                    </div>

                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-price">Barcode</label>
                        <input type="text" name="filter_barcode" value="{{ filter_barcode }}" placeholder="Barkod Girin" id="input-barcode" class="form-control" />
                    </div>


                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Stok</label>

                        <select name="filter_stock_prefix" class="form-control filter_stock_prefix" >
                            <option selected value="*">Tümü</option>

                            {% if filter_stock_prefix == '=' %}
                                <option selected value="=">Şuna Eşit</option>
                                <option  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_stock_prefix =='>'  %}
                                <option  value="=">Şuna Eşit</option>
                                <option selected  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_stock_prefix =='<'  %}

                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option selected value="<">Şundan Küçük</option>
                            {% else %}
                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% endif %}



                        </select>

                        <input placeholder="stok adedi" value="{{ filter_stock }}" class="form-control {% if not filter_stock  %}  hidden {% endif %} filter_stock" type="number" name="filter_stock" />

                    </div>
                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Görüntüleme</label>

                        <select name="filter_total_view_prefix" class="form-control filter_total_view_prefix" >
                            <option selected value="*">Tümü</option>

                            {% if filter_total_view_prefix == '=' %}
                                <option selected value="=">Şuna Eşit</option>
                                <option  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_view_prefix =='>'  %}
                                <option  value="=">Şuna Eşit</option>
                                <option selected  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_view_prefix =='<'  %}

                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option selected value="<">Şundan Küçük</option>
                            {% else %}
                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% endif %}



                        </select>

                        <input placeholder="Toplam Görüntüleme sayısı" value="{{ filter_total_view }}" class="form-control {% if not filter_total_view  %}  hidden {% endif %} filter_total_view" type="number" name="filter_total_view" />

                    </div>

                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Satış</label>

                        <select name="filter_total_sale_prefix" class="form-control filter_total_sale_prefix" >
                            <option selected value="*">Tümü</option>

                            {% if filter_total_sale_prefix == '=' %}
                                <option selected value="=">Şuna Eşit</option>
                                <option  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_sale_prefix =='>'  %}
                                <option  value="=">Şuna Eşit</option>
                                <option selected  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_sale_prefix =='<'  %}

                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option selected value="<">Şundan Küçük</option>
                            {% else %}
                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% endif %}



                        </select>

                        <input placeholder="Toplam Satış sayısı" value="{{ filter_total_sale }}" class="form-control {% if not filter_total_sale  %}  hidden {% endif %} filter_total_sale" type="number" name="filter_total_sale" />

                    </div>


                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Listeye Ekleme</label>

                        <select name="filter_total_add_to_list_prefix" class="form-control filter_total_add_to_list_prefix" >
                            <option selected value="*">Tümü</option>

                            {% if filter_total_add_to_list_prefix == '=' %}
                                <option selected value="=">Şuna Eşit</option>
                                <option  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_add_to_list_prefix =='>'  %}
                                <option  value="=">Şuna Eşit</option>
                                <option selected  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_total_add_to_list_prefix =='<'  %}

                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option selected value="<">Şundan Küçük</option>
                            {% else %}
                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% endif %}



                        </select>

                        <input placeholder="Toplam Görüntüleme sayısı" value="{{ filter_total_add_to_list }}" class="form-control {% if not filter_total_add_to_list  %}  hidden {% endif %} filter_total_add_to_list" type="number" name="filter_total_add_to_list" />

                    </div>

                    <div class="col-md col-xs-6">
                        <label class="control-label" for="input-model">Fiyat</label>

                        <select name="filter_price_prefix" class="form-control filter_price_prefix" >
                            <option selected value="*">Tümü</option>

                            {% if filter_price_prefix == '=' %}
                                <option selected value="=">Şuna Eşit</option>
                                <option  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_price_prefix =='>'  %}
                                <option  value="=">Şuna Eşit</option>
                                <option selected  value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% elseif filter_price_prefix =='<'  %}

                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option selected value="<">Şundan Küçük</option>
                            {% else %}
                                <option  value="=">Şuna Eşit</option>
                                <option   value=">">Şundan Büyük</option>
                                <option value="<">Şundan Küçük</option>
                            {% endif %}



                        </select>

                        <input placeholder="Fiyat" value="{{ filter_price }}" class="form-control {% if not filter_price  %}  hidden {% endif %} filter_price" type="number" name="filter_price" />

                    </div>



                    <div class="col-md  filter_marketplace_do col-xs-6">
                        <label class="control-label" for="input-model">Durumu</label>

                        <select name="filter_marketplace_do" class="form-control" >


                            {% if filter_marketplace_do == 1 %}
                                <option   value="*">Tümü</option>
                                <option selected value="1">Satışa Açık</option>
                                <option  value="0">Satışa Kapalı</option>
                            {% elseif filter_marketplace_do == "*"  %}
                                <option  selected value="*">Tümü</option>
                                <option  value="1">Satışa Açık</option>
                                <option  value="0">Satışa Kapalı</option>
                            {% elseif filter_marketplace_do == 0   %}
                                <option   value="*">Tümü</option>
                                <option  value="1">Satışa Açık</option>
                                <option selected value="0">Satışa Kapalı</option>


                            {% endif %}



                        </select>
                    </div>

                    <div class="col-md  filter_match col-xs-6">
                        <label class="control-label" for="input-model">Senkronize Durumu</label>

                        <select name="filter_match" class="form-control" >


                            {% if filter_match == 1 %}
                                <option   value="*">Tümü</option>
                                <option selected value="1">Senkronize Edilmiş</option>
                                <option  value="0">Senkronize Edilmemiş</option>
                            {% elseif filter_match == "*"  %}
                                <option  selected value="*">Tümü</option>
                                <option  value="1">Senkronize Edilmiş</option>
                                <option  value="0">Senkronize Edilmemiş</option>
                            {% elseif filter_match == 0   %}
                                <option   value="*">Tümü</option>
                                <option  value="1">Senkronize Edilmiş</option>
                                <option selected value="0">Senkronize Edilmemiş</option>


                            {% endif %}



                        </select>
                    </div>

                    <div class="form-group text-right" style="padding-top: 22px;
    padding-bottom: 0px;
    margin-bottom: 0;">
                        <button type="button" id="button-filter" class="btn btn-primary"><i class="fa fa-filter"></i> {{ button_filter }}</button>
                    </div>
                </div>



            </div>

            <div id="progres_bar"></div>

            <div class="row">

                <div id="report"></div>

                <div class="panel panel-default" style="border-top: 2px solid #27ad5e;width: 100%">
                    <div class="panel-heading">
                        <h2 class="panel-title hidden"><i class="fa fa-list"></i> {{ marketplace_info.name }} Mağazanızda yer alan ürünler</h2>

                        <button class="btn btn-primary btnBulk" style="margin-right: -2px;"><i class="fa fa-plug"></i> <span
                                    class="hidden-xs">Toplu İşlem Yap</span></button>



                    </div>

                    <div class="panel-body ">

                        {% if status %}
                            <form action="">

                                <div class="table-responsive">

                                    <table class="table table-bordered table-hover" style="width: 100%">
                                        <thead>
                                        <tr>
                                            <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                                            <td class="text-left">Görsel</td>
                                            <td class="text-left">Ürün adı</td>
                                            <td class="text-left">Stok</td>
                                            <td class="text-left">Adet</td>
                                            <!-- Görüntüleme Sıralama Linki -->
                                            <td class="text-left">
                                                <a href="{{ sort_total_view }}">
                                                    Görüntüleme
                                                    {% if sort == 'total_view' %}
                                                        <i class="fa fa-sort-{{ order == 'ASC' ? 'asc' : 'desc' }}"></i>
                                                    {% endif %}
                                                </a>
                                            </td>

                                            <!-- Listeye Ekleme Sıralama Linki -->
                                            <td class="text-left">
                                                <a href="{{ sort_total_add_list }}">                                                    Listeye Ekleme
                                                    {% if sort == 'total_add_list' %}
                                                        <i class="fa fa-sort-{{ order == 'ASC' ? 'asc' : 'desc' }}"></i>
                                                    {% endif %}
                                                </a>
                                            </td>

                                            <!-- Satış Sıralama Linki -->
                                            <td class="text-left">
                                                <a href="{{ sort_sale }}">
                                                    Satış
                                                    {% if sort == 'total_sale' %}
                                                        <i class="fa fa-sort-{{ order == 'ASC' ? 'asc' : 'desc' }}"></i>
                                                    {% endif %}
                                                </a>
                                            </td>

                                            <td class="text-right">Alış fiyatı</td>
                                            <td class="text-right">kampanya fiyatı</td>
                                            <td class="text-right">Liste fiyatı</td>
                                            <td class="text-right">Satış fiyatı</td>
                                            <td class="text-right">Satış durumu</td>


                                            <td class="text-center">Eylem</td>


                                        </tr>
                                        </thead>
                                        <tbody>

                                        {% if products %}
                                            {% for product in products %}
                                                <tr

                                                >

                                                    <td class="text-center ">{% if product.product_id in selected %}
                                                            <input class="select" type="checkbox" name="selected[]" value="{{ product.market_product_id }}" checked="checked" />
                                                        {% else %}
                                                            <input class="select" type="checkbox" name="selected[]"  value="{{ product.market_product_id }}" />
                                                        {% endif %}</td>


                                                    {% if  not product.image  %} <td></td>  {% else %}
                                                        <td class="text-center " >
                                                            {% if product.sale_status %}

                                                                <img  style="width: 100px; border-radius: 10px; border: 2px #13af54 solid" src="{{ product.image }}" alt="">
                                                            {% else %}
                                                                <img style="width: 100px; border-radius: 10px; border: 2px #c43030 solid" src="{{ product.image }}" alt="">

                                                            {% endif %}
                                                        </td>
                                                    {% endif %}

                                                    <td class="text-left">

                                                        <p> {{ product.name }} <br><span style="font-size: x-small"> <strong>Model:</strong> {{ product.model }}</span> <br><span style="font-size: x-small"> <strong>Stok Kodu:</strong> {{ product.stock_code }}</span><br><span style="font-size: x-small"> <strong>{{ marketplace_info.name }} Ürün Kodu:</strong> {{ product.marketplace_product_id }} </span>{% if product.url %}<br><span style="font-size: x-small"> <strong> Trendyol Linki:</strong> <a target="_blank" href="https://www.trendyol.com{{ product.url }}">Gör</a> </span>{% endif %}{% if product.url %}<br><span style="font-size: x-small"> <strong> Mağaza Linki:</strong> <a target="_blank" href="{{ product.marketplace_url }}">Gör</a> </span>{% endif %}<br><span style="font-size: x-small"> <strong> Son Güncelleme:</strong> <label class="label label-primary">{{ product.last_update }}</label> </span></p>

                                                    </td>
                                                    <td class="text-left">
                                                        <label class="label {% if(product.status) %} label-success {% else %} label-danger {% endif %}">{% if(product.status) %} Mevcut {% else %} Tükendi! {% endif%}  </label></td>
                                                     <td class="text-left">
                                                        <label>{{ product.quantity }}  </label></td>
                                                    <td class="text-left">
                                                    <label>{{ product.total_view }}  </label></td>
                                                    <td class="text-left">
                                                    <label>{{ product.total_add_list }}  </label></td>
                                                    <td class="text-left">
                                                    <label>{{ product.total_sale }}  </label></td>

                                                    <td class="text-right">{{ product.orginal_price }}</td>
                                                    <td class="text-right"><a class="editable "
                                                                              data-type="text" data-pk="{{ product.product_url_id }}"
                                                                              data-value="{{ product.special_price }}"
                                                                              data-emptytext="Yeni Satış Fiyatı Girin"
                                                                              data-url="index.php?route=entegrasyon/market_product/update_price&{{ token_link }}"
                                                                              data-title="Satış Fiyatı Girin">{{ product.special_price }}</a></td>
                                                    <td class="text-right">{{ product.list_price }}</td>
                                                    <td class="text-right">{{ product.sale_price }}</td>
                                                    <td class="text-right">{{ product.sale_status_text }}</td>

                                                    <td class="text-right">
                                                        <a  id="product{{ product.marketplace_product_id }}" product_id="{% if code=='ty' %}{{ product.barcode }}{%  elseif code=='cs'   %}{{ product.stock_code }}{% else %}{{ product.marketplace_product_id }}{% endif %}"  {% if product.status %} disabled {% endif %} name="{{ product.name }}"  data-toggle="tooltip" title="{% if product.status %} Ürün mağazanızda Mevcut  {% else %} Ürünü Mağazanıza Aktarın {% endif %}" class="btn  {% if  product.status %} btn-default {% else %}   btn-primary {% endif %} btnDownload" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"><i class="fa {% if product.status %} fa-check  fa-times {% else %} fa-download {% endif %}  "></i></a>


                                                    </td>

                                                </tr>
                                            {% endfor %}
                                        {% else %}
                                            <tr>
                                                <td class="text-center" colspan="8">{{ text_no_results }}</td>
                                            </tr>
                                        {% endif %}

                                        </tbody>

                                    </table>
                                </div>
                            </form>
                        {% else %}

                            <p class="lead text-danger">  {{ message }} </p>

                        {% endif %}
                        <div class="row">
                            <div class="col-sm-6 text-left">{{ pagination }}</div>
                            <div class="col-sm-6 text-right">{{ results }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>



        <script>
            $('.filter_stock_prefix').change(function(){
                var selected=$(this).val();
                if(selected!='*'){

                    $('.filter_stock').removeClass('hidden');
                    $('.filter_stock').fadeTo(100, 0.1).fadeTo(200, 1.0);


                }else {

                    $('.filter_stock').addClass('hidden');

                }

            });

        </script>
        <script>
            $('.filter_total_view_prefix').change(function(){
                var selected=$(this).val();
                if(selected!='*'){

                    $('.filter_total_view').removeClass('hidden');
                    $('.filter_total_view').fadeTo(100, 0.1).fadeTo(200, 1.0);


                }else {

                    $('.filter_total_view').addClass('hidden');

                }

            });

        </script>


        <script>
            $('.filter_total_add_to_list_prefix').change(function(){
                var selected=$(this).val();
                if(selected!='*'){

                    $('.filter_total_add_to_list').removeClass('hidden');
                    $('.filter_total_add_to_list').fadeTo(100, 0.1).fadeTo(200, 1.0);


                }else {

                    $('.filter_total_add_to_list').addClass('hidden');

                }

            });

        </script>

        <script>
            $('.filter_total_sale_prefix').change(function(){
                var selected=$(this).val();
                if(selected!='*'){

                    $('.filter_total_sale').removeClass('hidden');
                    $('.filter_total_sale').fadeTo(100, 0.1).fadeTo(200, 1.0);


                }else {

                    $('.filter_total_sale').addClass('hidden');

                }

            });

        </script>

        <script>
            $('.filter_price_prefix').change(function(){
                var selected=$(this).val();
                if(selected!='*'){

                    $('.filter_price').removeClass('hidden');
                    $('.filter_price').fadeTo(100, 0.1).fadeTo(200, 1.0);


                }else {

                    $('.filter_price').addClass('hidden');

                }

            });

        </script>

        <script type="text/javascript">
            $('#button-filter').on('click', function() {
                var url = '';


                var filter_marketplace_do = $('select[name=\'filter_marketplace_do\']').val();

                if (filter_marketplace_do) {
                    url += '&filter_marketplace_do=' + encodeURIComponent(filter_marketplace_do);
                }

                var filter_match = $('select[name=\'filter_match\']').val();

                if (filter_match) {
                    url += '&filter_match=' + encodeURIComponent(filter_match);
                }

                var filter_stock_prefix = $('select[name=\'filter_stock_prefix\']').val();

                if (filter_stock_prefix) {
                    url += '&filter_stock_prefix=' + encodeURIComponent(filter_stock_prefix);
                }
                var filter_total_view_prefix = $('select[name=\'filter_total_view_prefix\']').val();

                if (filter_total_view_prefix) {
                    url += '&filter_total_view_prefix=' + encodeURIComponent(filter_total_view_prefix);
                }


                var filter_total_sale_prefix = $('select[name=\'filter_total_sale_prefix\']').val();

                if (filter_total_sale_prefix) {
                    url += '&filter_total_sale_prefix=' + encodeURIComponent(filter_total_sale_prefix);
                }


                var filter_total_sale = $('input[name=\'filter_total_sale\']').val();

                if (filter_total_sale) {
                    url += '&filter_total_sale=' + encodeURIComponent(filter_total_sale);
                }



                var filter_total_add_to_list_prefix = $('select[name=\'filter_total_add_to_list_prefix\']').val();

                if (filter_total_add_to_list_prefix) {
                    url += '&filter_total_add_to_list_prefix=' + encodeURIComponent(filter_total_add_to_list_prefix);
                }


                var filter_total_add_to_list = $('input[name=\'filter_total_add_to_list\']').val();

                if (filter_total_add_to_list) {
                    url += '&filter_total_add_to_list=' + encodeURIComponent(filter_total_add_to_list);
                }


                var filter_price_prefix = $('select[name=\'filter_price_prefix\']').val();

                if (filter_price_prefix) {
                    url += '&filter_price_prefix=' + encodeURIComponent(filter_price_prefix);
                }

                var filter_stock = $('input[name=\'filter_stock\']').val();

                if (filter_stock) {
                    url += '&filter_stock=' + encodeURIComponent(filter_stock);
                }
                var filter_total_view = $('input[name=\'filter_total_view\']').val();

                if (filter_total_view) {
                    url += '&filter_total_view=' + encodeURIComponent(filter_total_view);
                }
                var filter_price = $('input[name=\'filter_price\']').val();

                if (filter_price) {
                    url += '&filter_price=' + encodeURIComponent(filter_price);
                }

                var filter_name = $('input[name=\'filter_name\']').val();

                if (filter_name) {
                    url += '&filter_name=' + encodeURIComponent(filter_name);
                }


                var filter_model = $('input[name=\'filter_model\']').val();

                if (filter_model) {
                    url += '&filter_model=' + encodeURIComponent(filter_model);
                }

                var filter_barcode = $('input[name=\'filter_barcode\']').val();

                if (filter_barcode) {
                    url += '&filter_barcode=' + encodeURIComponent(filter_barcode);
                }

                url += '&code='+'{{ code }}';

                location = 'index.php?route=entegrasyon/market_product&{{ token_link }}' + url;
            });
            //--></script>


        <script>

            $('.btnMatch').on('click', function () {

                var thisBtn = $(this);
                var name = thisBtn.attr('product_name');
                var get_name =thisBtn.attr('product_name').replaceAll(" ", "**");
                var get_name2 =get_name.replaceAll("#", "**");
                var get_name4 =get_name2.replaceAll("&#39;", "");
                var get_name3 =get_name4.replaceAll("'", "");
                var barcode = thisBtn.attr('product_id').replaceAll(" ", "**");


                BootstrapDialog.show({
                    title: name,
                    closable: true,
                    size: BootstrapDialog.SIZE_WIDE,

                    message: function (dialog) {
                        var $message = $('<div></div>');
                        var pageToLoad = dialog.getData('pageToLoad');
                        $message.load(pageToLoad);
                        return $message;
                    },
                    data: {
                        'pageToLoad': 'index.php?route=entegrasyon/product/product_match_form&code={{ code }}&barcode='+barcode+'&get_name='+get_name3+'&{{ token_link }}'
                    }
                });




            })

        </script>


        <script>

            $('.btnDownload').on('click',function (e) {

                var thisbtn=$(this);
                var product_id=thisbtn.attr('product_id');

                thisbtn.button('loading');
                $.post('index.php?route=entegrasyon/market_product/download_product&code={{ code }}&{{ token_link }}',{product_id:product_id},function (json) {

                    thisbtn.button('reset');

                    if(json['status']){
                        $.toast({heading: 'Başarılı İşlem',text: json['message'], position: 'top-right',loader: true,allowToastClose: false,showHideTransition: 'slide',icon: 'success'});

                        thisbtn.removeClass('btn-primary');
                        thisbtn.addClass('btn-default');
                        $('#product'+product_id).prop("disabled",true );
                        $('#product'+product_id).text('<i class=fa fa-check"></i>');

                        $.each(json['download_image_data'],function (index,value){

                            var image_type = value.type=='product'?1:2;
                            var primary_index = value.primary_index;

                            $.post('index.php?route=entegrasyon/image/upload_image&{{ token_link }}',{product_id:primary_index,product_type:image_type},function (json) {
                                $.toast({heading: 'Ürün Görseller Yüklendi!',text: json['message'], position: 'top-right',loader: true,allowToastClose: false,showHideTransition: 'slide',icon: 'success'});

                            },'JSON');


                        })


                        /*    $.post('index.php?route=entegrasyon/image/upload_image&{{ token_link }}',{product_id:json['result_id'],product_type:json['product_type']},function (json) {
                            $.toast({heading: 'Ürün Görseller Yüklendi!',text: json['message'], position: 'top-right',loader: true,allowToastClose: false,showHideTransition: 'slide',icon: 'success'});

                        },'JSON');*/

                    }else {

                        Swal.fire('Hata',json['message'],'warning');
                        // $.toast({heading: 'Başarız İşlem',text: json['message'], position: 'top-right',loader: true,allowToastClose: false,showHideTransition: 'slide',icon: 'warning'});

                    }

                },'JSON');

            })

        </script>




        <script>

            var thisinput=null;


            $("input[name=\'manufacturer\'],input[name=\'category\'],input[name=\'categorybulk\'],input[name=\'manufacturerbulk\']").on('click',function () {

                thisinput=$(this);


            });

            $('input[name=\'manufacturer\']').autocomplete({
                'source': function(request, response) {
                    $.ajax({
                        url: 'index.php?route=catalog/manufacturer/autocomplete&{{ token_link }}&filter_name=' + encodeURIComponent(request),
                        dataType: 'json',
                        success: function(json) {
                            json.unshift({
                                manufacturer_id: 0,
                                name: '{{ text_none }}'
                            });

                            response($.map(json, function(item) {
                                return {
                                    label: item['name'],
                                    value: item['manufacturer_id']
                                }
                            }));
                        }
                    });
                },
                'select': function(item) {
                    thisinput.val(item['label']);
                    $('#manufacturer_'+thisinput.attr('id')).val(item['value']);
                }
            });


            $('input[name=\'category\']').autocomplete({
                'source': function(request, response) {
                    $.ajax({
                        url: 'index.php?route=catalog/category/autocomplete&{{ token_link }}&filter_name=' + encodeURIComponent(request),
                        dataType: 'json',
                        success: function(json) {

                            json.unshift({
                                category_id: 0,
                                name: '{{ text_none }}'
                            });

                            response($.map(json, function(item) {
                                return {
                                    label: item['name'],
                                    value: item['category_id']
                                }
                            }));
                        }
                    });
                },
                'select': function(item) {

                    thisinput.val(item['label']);
                    $('#category_'+thisinput.attr('id')).val(item['value']);


                }
            });

            $('input[name=\'categorybulk\']').autocomplete({
                'source': function(request, response) {
                    $.ajax({
                        url: 'index.php?route=catalog/category/autocomplete&{{ token_link }}&filter_name=' + encodeURIComponent(request),
                        dataType: 'json',
                        success: function(json) {

                            json.unshift({
                                category_id: 0,
                                name: '{{ text_none }}'
                            });

                            response($.map(json, function(item) {
                                return {
                                    label: item['name'],
                                    value: item['category_id']
                                }
                            }));
                        }
                    });
                },
                'select': function(item) {

                    thisinput.val(item['label']);
                    $('#bulk_category_id').val(item['value']);


                }
            });

            $('input[name=\'manufacturerbulk\']').autocomplete({
                'source': function(request, response) {
                    $.ajax({
                        url: 'index.php?route=catalog/manufacturer/autocomplete&{{ token_link }}&filter_name=' + encodeURIComponent(request),
                        dataType: 'json',
                        success: function(json) {

                            json.unshift({
                                category_id: 0,
                                name: '{{ text_none }}'
                            });

                            response($.map(json, function(item) {
                                return {
                                    label: item['name'],
                                    value: item['manufacturer_id']
                                }
                            }));
                        }
                    });
                },
                'select': function(item) {

                    thisinput.val(item['label']);
                    $('#bulk_manufacturer_id').val(item['value']);


                }
            });


        </script>


        <script>

            var whichproducts = 0;
            var whichmarketplace = '{{ code }}';
            var product_list = [];
            var list_type = '';

            $('.btnBulk').on('click', function () {

                whichproducts = 0;
                product_list = [];
                whichmarketplace = 0;
                list_type = '';
                Swal.fire({
                    title: 'Lütfen Seçim Yapın!',
                    text: "İşlemi tüm ürünlere mi, yoksa sadace seçtiğiniz ürünlere mi yapacaksınız ?",
                    icon: 'question',
                    showCancelButton: true,
                    showDenyButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#439407',
                    width: 400,
                    denyButtonText: `Seçilenlere`,
                    confirmButtonText: 'Tümüne',
                    cancelButtonText: 'Filtrelenmiş Tüm Ürünlere'

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

                        whichproducts = 'all';

                        selectMarket();

                    } else if (result.isDenied) {
                        whichproducts = 'selected';
                        selectMarket();
                    } else {
                        whichproducts = 'all_filter';
                        selectMarket();

                    }


                })

            });


            function selectMarket() {

                if (whichproducts == 'selected') {

                    $(".table .select:checked").each(function () {
                        var product_id = $(this).val();
                        product_list.push(product_id);
//GEL
                    });

                   // console.log(product_list);


                    if (product_list.length != 0) {
                        list_type = "selected";
                        Swal.fire('Seçilen ürünler için işleme başlanıyor');
                        start_bulk()
                    } else {

                        Swal.fire('Hiç Bir Ürün seçmediniz!');

                    }

                } else if (whichproducts == 'all_filter') {

                    list_type = "all_filter";
                    Swal.fire('Seçilen ürünler için işleme başlanıyor');
                    start_bulk()

                } else {
                    list_type = "all";
                    Swal.fire('Tüm ürünler için işleme başlanıyor');
                    start_bulk()
                }


            }




           function start_bulk() {
                var filter_marketplace = '{{ filter_marketplace }}';
                var filter_marketplace_do = '{{ filter_marketplace_do }}';
                var filter_model = '{{ filter_model }}';
                var filter_name = '{{ filter_name }}';
                var filter_manufacturer = '{{ filter_manufacturer }}';
                var filter_category = '{{ filter_category }}';
                var filter_stock_prefix = '{{ filter_stock_prefix }}';
                var filter_stock = '{{ filter_stock }}';
                var filter_price_prefix = '{{ filter_price_prefix }}';
                var filter_price = '{{ filter_price }}';
                var filter_status = '{{ filter_status }}';
               var filter_total_sale = '{{ filter_total_sale }}';
               var filter_total_sale_prefix = '{{ filter_total_sale_prefix }}';
               var filter_total_view = '{{ filter_total_view }}';
               var filter_total_view_prefix = '{{ filter_total_view_prefix }}';
               var filter_total_add_to_list = '{{ filter_total_add_to_list }}';
               var filter_total_add_to_list_prefix = '{{ filter_total_add_to_list_prefix }}';

               // alert(filter_price);

               var url_prefix='filter_marketplace='+filter_marketplace+'&filter_marketplace_do='+filter_marketplace_do+'&filter_model='+filter_model+'&filter_name='+encodeURI(filter_name)+'&filter_manufacturer='+filter_manufacturer+'&filter_category='+filter_category+'&filter_stock_prefix='+filter_stock_prefix+'&filter_total_sale='+filter_total_sale+'&filter_total_sale_prefix='+filter_total_sale_prefix+'&filter_stock='+filter_stock+'&filter_total_view='+filter_total_view+'&filter_total_view_prefix='+filter_total_view_prefix+'&filter_total_add_to_list='+filter_total_add_to_list+'&filter_total_add_to_list_prefix='+filter_total_add_to_list_prefix+'&filter_price_prefix='+filter_price_prefix+'&filter_price='+filter_price+'&filter_status='+filter_status;

                console.log(product_list);


                Swal.close();
                whichmarketplace = $(this).attr('id');
                if (list_type != 'selected') {
                    var url = 'index.php?route=entegrasyon/market_product/bulk_actions&{{ token_link }}&list_type=' + list_type + '&code={{ code }}&' + url_prefix;

                } else {

                    var url = 'index.php?route=entegrasyon/market_product/bulk_actions&{{ token_link }}&list_type=' + list_type + '&code={{ code }}&product_list=' + product_list + '&' + url_prefix;

                }

                loadBulkActionDialog(url);


            }


            function loadBulkActionDialog(url) {


                BootstrapDialog.show({
                    title: 'Toplu Ürün İşlemleri',
                    size: BootstrapDialog.SIZE_WIDE,
                    draggable: true,
                    message: function (dialog) {
                        var $message = $('<div></div>');
                        var pageToLoad = dialog.getData('pageToLoad');
                        $message.load(pageToLoad);
                        return $message;
                    },
                    data: {
                        'pageToLoad': url
                    }
                });
            }

        </script>


        <script>

                $('.editable').editable({
                inputclass: 'intclass input-sm', success: function (json, newValue) {


                if (json['status']) {

                $.toast({
                heading: 'Başarılı',
                text: json['message'],
                position: 'top-right',
                loader: true,
                allowToastClose: false,
                showHideTransition: 'slide',
                icon: 'success'
            });


            } else {

                Swal.fire('Hata', json['message'], 'warning');


            }

            }
            });

        </script>

        <script>

            $.fn.editableform.buttons =
                '<button type="submit" class="btn btn-primary btn-sm editable-submit">' +
                '<i class="fa fa-check"></i>' +
                '</button>' +
                '<button type="button" class="btn btn-danger btn-sm editable-cancel">' +
                '<i class="fa fa-times"></i>' +
                '</button>';

        </script>

{{ footer }}