{{ 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> TRENDYOL ÜRÜN BULUCU</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="pull-right well" style="margin: 10px">
                                        <div class="form-check-inline pull-right" style="margin-left: 10px">
                                            <label class="form-check-label">
                                                <input id="filter_category" type="checkbox" name="filter_category" {% if filter_category %} checked {% endif %} class="form-check-input" >Kategori
                                            </label>
                                        </div>
                                        <div class="form-check-inline pull-right" style="margin-left: 10px">
                                            <label class="form-check-label">
                                                <input id="filter_manufacturer" name="filter_manufacturer" {% if filter_manufacturer %} checked {% endif%} type="checkbox" class="form-check-input" >Marka
                                            </label>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>

                                    <div class="btn-group">


                                        <a   data-type="old" data-toggle="tooltip" title="Ürüne Satıcı ol" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-primary btnSellBulk"><i class="fa fa-tag"></i> Satıcı olarak aç</a>
                                        <a   data-type="new"  data-toggle="tooltip" style="background:dodgerblue" title="Kopya ürün olarak aç" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-success  btnSellBulk"><i class="fa fa-tag"></i> Kopyasını Aç</a>
                                        <a  data-type="easy"  data-toggle="tooltip" title="Easytekno ile Satışa aç"  data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor"class="btn btn-warning  btnSellBulk"><i class="fa fa-tag"></i> Easytekno markası ile aç</a>
                                        <a  data-type="nikadu"  data-toggle="tooltip" title="Nikadu Satışa aç" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-danger btnSellBulk"><i class="fa fa-tag"></i> Nikadu markası ile aç</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>Görsel</td>
                                            <td>Ürün adı</td>
                                            <td>ürün kodu</td>
                                            <td>Fiyat</td>
                                            <td>Puan</td>
                                            <td></td>
                                            <td>Eylem</td>

                                        </tr>

                                        </thead>

                                        <tbody>

                                        {% if products %}
                                            {% for key,product in products %}
                                                <tr 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-center">{% if product.images[0] %} <img  src="https://cdn.dsmcdn.com/{{ product.images[0] }}" alt="{{ product.name }}" class="{{ product.class }} img-thumbnail" style="width: 200px" /> {% else %} <span class="img-thumbnail list"><i class="fa fa-camera fa-2x"></i></span> {% endif %}</td>
                                                    <td class="text-left"><strong>{{ product.brand.name }} </strong>  <a target="_blank" href="http://www.trendyol.com/{{ product.url }}"> {{ product.name }} <i class="fa fa-link" aria-hidden="true"></i></a>  <br>Kategori:{{ product.categoryName }}</td>
                                                    <td class="text-left">{{ product.id }} / {{ product.merchantId }}</td>
                                                    <td class="text-right">{% if product.variants[0].price.discountedPrice != product.variants[0].price.sellingPrice %} <span style="text-decoration: line-through;">{{ product.variants[0].price.sellingPrice }}</span><br/>

                                                            <div class="text-danger">{{ product.variants[0].price.discountedPrice }} TL</div>

                                                        {% else %}

                                                            {{ product.variants[0].price.sellingPrice }} TL

                                                        {% endif %}</td>
                                                    <td class="text-right">
                                                        {% if  product.ratingScore.averageRating %}
                                                            <div class="rating-2">                                                        <label class="label label-primary">{{ product.ratingScore.totalCount }}</label>
                                                                {% for i in 1..5 %}

                                                                    {% if product.ratingScore.averageRating < i %} <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-1x"></i></span> {% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-1x"></i><i class="fa fa-star-o fa-stack-1x"></i></span>{% endif %}

                                                                {% endfor %} </div>


                                                        {% endif %}


                                                    </td>

                                                    <td class="text-left">{{ product.status }}</td>


                                                    <td class="text-right">

                                                        {% if not product.is_exists_orjinal.num_rows  %}   <a   data-url="{{ product.url }}" data-type="old" data-category-id="{{ product.categoryId }}" data-toggle="tooltip" title="Ürüne Satıcı ol" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-primary btn-block btnSell"><i class="fa fa-tag"></i> Satıcı olarak aç</a>{% else %} <p class="text-success well">Satıcı Satış Fiyatı: {{ product.is_exists_orjinal.sale_price}} TL</p> {% endif %}
                                                        {% if not product.is_exists_copy %}  <a  data-url="{{ product.url }}" data-type="new" data-category-id="{{ product.categoryId }}" data-toggle="tooltip" style="background:dodgerblue" title="Kopya ürün olarak aç" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-success btn-block btnSell"><i class="fa fa-tag"></i> Kopyasını Aç</a> {% else %} <p class="btn">Kopya Satış fiyatı: {{ product.is_exists_copy.sale_price}} TL</p> {% endif %}
                                                        <a data-url="{{ product.url }}" data-type="easy" data-category-id="{{ product.categoryId }}" data-toggle="tooltip" title="Easytekno ile Satışa aç"  data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor"class="btn btn-warning btn-block btnSell"><i class="fa fa-tag"></i> Easytekno markası ile aç</a>
                                                        <a data-url="{{ product.url }}" data-type="nikadu" data-category-id="{{ product.categoryId }}" data-toggle="tooltip" title="Nikadu Satışa aç" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> işlem yapılıyor" class="btn btn-danger btn-block btnSell"><i class="fa fa-tag"></i> Nikadu markası ile aç</a>
                                                        <a data-url="{{ product.url }}" data-type="ellc" data-category-id="{{ product.categoryId }}" data-toggle="tooltip" title="Nikadu Satışa aç" style="background:yellow" 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> eLLC markası ile aç</a>

                                                    </td>


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

                                    </table>
                                </div>
                            </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>
        <script type="text/javascript"><!--
            $('#button-filter').on('click', function() {
                var url = '';

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

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

                var filter_category = $('#filter_category').is(':checked');

                if (filter_category) {
                    url += '&filter_category=1';
                }

                var filter_manufacturer = $('#filter_manufacturer').is(':checked');

                if (filter_manufacturer) {
                    url += '&filter_manufacturer=1';
                }

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

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

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

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


                location = 'index.php?route=catalog/hb_finder&user_token={{ user_token }}' + url;
            });
            //--></script>
    </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/hb_finder/sell_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');

                        $('#'+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/hb_finder/sell_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.prop('disabled', true)


                }else {

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

                }
                thisbtn.button("reset");

            },'JSON');


        })

    </script>
{{ footer }}