{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <button type="button" data-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-product').toggleClass('hidden-sm hidden-xs');" class="btn btn-default hidden-md hidden-lg"><i class="fa fa-filter"></i></button>
                <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
                <button type="submit" form="form-product" formaction="{{ copy }}" data-toggle="tooltip" title="{{ button_copy }}" class="btn btn-default"><i class="fa fa-copy"></i></button>
                <button type="button" form="form-product" formaction="{{ delete }}" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button>
            </div>
            <h1>{{ heading_title }}</h1>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row">

            <div class="col-md-12  col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list"></i> Satiştaki ürünler</h3>
                    </div>


                    <div class="panel-body">

                        <div class="well">


                            <form action="{{ delete }}" method="post" enctype="multipart/form-data" id="form-product">

                                <div class="table-responsive">

                                    <div class="input-group">
                                        <input name="filter_name" value="{{ filter_name }}" type="text" class="form-control">

                                        <div class="input-group-btn">
                                            <button id="button-filter" type="button" class="btn btn-primary"  aria-expanded="false"> Filte </button>
                                        </div>

                                    </div>



                                        <div class="form-check-inline pull-right" style="margin-left: 10px">
                                            <label class="form-check-label">
                                                <input id="filter_seller" name="filter_special" {% if filter_seller %} checked {% endif%} type="checkbox" class="form-check-input" >satıcı
                                            </label>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>

                                    <div class="btn-group">

                                        <a  data-type="pz"  data-toggle="tooltip" title="Pazaramada Satışa aç" style="background:purple; color: white" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn  btnSellBulk"><i class="fa fa-tag"></i> PZ'de GÜNCELLE</a>

                                    </div>
                                    <table class="table table-bordered table-hover">

                                        <thead>
                                        <tr>
                                            <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>

                                            <td>barcode</td>
                                            <td>fiyat</td>

                                            <td>Eylem</td>

                                        </tr>

                                        </thead>

                                        <tbody>

                                        {% if products %}
                                            {% for key,product in products %}
                                                <tr style="{%  if product.url_info and product.url_info.user_id!=user_id %} background: #fff; {% endif %}" id="{{ key }}">
                                                    <td class="text-center">{% if product.url in selected %}
                                                            <input data-id="{{ key }}" type="checkbox" class="select" name="selected[]" value="{{ product.url }}" checked="checked" />
                                                        {% else %}
                                                            <input data-id="{{ key }}" type="checkbox" class="select" name="selected[]" value="{{ product.url }}" />
                                                        {% endif %}</td>
                                                    <td class="text-left">{{ product.barcode }} </td>
                                                    <td class="text-right">{{ product.sale_price }}</span></td>




                                                    <td class="text-right">

                                                        {% if product.cs %}
                                                         <label class="label label-success">{{ product.sale_price }}</label>
                                                          {% else %}
                                                              <a   data-url="{{ product.url }}" data-type="cs"  data-toggle="tooltip" title="Çiçeksepetinde Satışa Aç" style="background:purple;color: white" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn  btn-block btnSell"><i class="fa fa-tag"></i> CS Aç </a>
                                                        {% endif %}
                                                    </td>


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

                                    </table>

                            </form>
                            <div class="row">


                                <div class="col-sm-6 text-right"><a class="btn" href="{{ previous_page }}"> < Önceki Sayfa </a> <label class="label label-success">{{ current_page }}</label>  <a class="btn" href="{{ next_page }}">Sonraki Sayfa ></a></div>
                                <div class="col-sm-6 text-right">{{ results }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>




        $('.btnSellBulk').on('click',function (event) {



            var $this = $(this);
            $this.button('loading');
            var data_type=$(this).attr("data-type");


            $(".table .select:checked").each(function () {
                var url = $(this).val();
                var key = $(this).attr('data-id');

                $.post('index.php?route=catalog/product_finder/sell_product&hediye={{ hediye }}&user_token={{ user_token }}',{url:url,data_type:data_type},function (json) {

                    if(json['status']){

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


                        //thisbtn.prop("value",json['price']+' TL');

                        //$('#'+key).hide('slow');

                        //thisbtn.prop('disabled', true)


                    }else {

                        $.toast({
                            heading: 'HATA!',
                            text: json['message'],
                            position: 'top-right',
                            loader: true,
                            allowToastClose: false,
                            showHideTransition: 'slide',
                            icon: 'danger'
                        });

                        // Swal.fire('Uyarı',json['message'],'warning');

                    }

                },'JSON');



            });

            $this.button("reset");



        })
        $('.btnSell').on('click',function (event) {

            var url=$(this).attr('data-url');
            var data_type=$(this).attr("data-type");
            var thisbtn=$(this);
            thisbtn.button("loading");
            $.post('index.php?route=catalog/market_product/update_product&user_token={{ user_token }}',{url:url,data_type:data_type},function (json) {

                if(json['status']){

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

                    //thisbtn.prop("value",json['price']+' TL');

                    thisbtn.hide('slown')


                }else {
                    $.toast({
                        heading: 'Uyarı!',
                        text: json['message'],
                        position: 'top-right',
                        loader: true,
                        allowToastClose: false,
                        showHideTransition: 'slide',
                        icon: 'danger'
                    });

                }
                thisbtn.button("reset");

            },'JSON');


        })

    </script>
{{ footer }}