{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <div class="pull-right easy-mode {{ easy_visibility }}">
                    <img src="view/image/entegrasyon/logo.png"/>
                </div>

            </div>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>
    <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 %}
            <script>
                const Toast = Swal.mixin({
                    toast: true,
                    position: 'top-end',
                    showConfirmButton: false,
                    timer: 3000,
                    timerProgressBar: true,
                    didOpen: (toast) => {
                        toast.addEventListener('mouseenter', Swal.stopTimer);
                        toast.addEventListener('mouseleave', Swal.resumeTimer)
                    }
                });

                Toast.fire({
                    icon: 'success',
                    title: 'Soru Başarılı bir şekilde silindi'
                })

            </script>
        {% endif %}

        <div class="row well" style="bquestion-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="" style="font-size: larger">Son 24 saat içerisinde pazaryerlerinden aldığınız sorularınızı
                    <strong>Soruları Güncelle</strong> butonuna tıklayarak görebilirsiniz. Ürün sorularının stabilitesi pazaryerlerlerine bağlı olarak değişmektedir.</p>

            </div>
        </div>


        <div class="col-md-10 col-sm-10">
            <div class="panel panel-default" style="bquestion-top: 2px solid #27ad5e;">
                <div class="panel-heading">
                    <h2 class="panel-title"style="margin: 10px;"><i class="fa fa-list"></i> {{ text_list }}</h2>
                    <div class="pull-right" >
                         <button id="btnCheckquestion" data-toggle="tooltip" title="Yeni soruları kontrol et"
                                data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Sorular güncelleniyor"
                                class="btn btn-primary"><i class="fa fa-refresh"></i> Soruları Güncelle
                        </button>    <button id="btBulkDelete" data-toggle="tooltip" title="Yeni soruları kontrol et"
                                data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"
                                class="btn btn-danger"><i class="fa fa-trash"></i> Seçilenleri Sil
                        </button>
                    </div>
                </div>
                <div class="panel-body">
                    <td method="post" action="" enctype="multipart/form-data" id="form-question">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <td style="width: 1px;"  class="text-center checkbox_check"><input type="checkbox"
                                    onclick="$('input[name*=\'selected\']').prop('checked', this.checked);"/>
                                    </td>





                                    <td class="text-left"><a>{{ column_question_id }}</a></td>
                                    <td class="text-center"><a>Mağaza</a></td>

                                    <td class="text-left"><a>{{ column_status }}</a></td>


                                    <td class="text-left"><a>{{ column_date_added }}</a>
                                    </td>


                                    <td class="text-right"><a>{{ column_action }}</a></td>
                                </tr>
                                </thead>
                                <tbody>

                                {% if questions %}
                                    {% for question in questions %}



                                        <tr id="tr_{{ question.product_question_id }}" {% if question.is_rejected %}
                                            style="background: rgba(255,0,70,0.22)"

                                            {% elseif question.answered %}

                                        {% else %}

                                            style="background: rgba(255,255,0,0.22) "

                                        {% endif %} >

                                            <td class="text-left"> {% if question.question_id in selected %}
                                                    <input class="checkbox_check" type="checkbox" name="selected[]"
                                                           value="{{ question.product_question_id }}" checked="checked"/>
                                                {% else %}
                                                    <input class="checkbox_check" type="checkbox" name="selected[]"
                                                           value="{{ question.product_question_id }}"/>
                                                {% endif %}

                                            <td class="text-left">{{ question.question_id }}</td>
                                            <td class="text-center"><img
                                                        src="https://www.egitimsetleri.com/tr/image/cache/entegrasyon-logo/{{ question.code }}-logo-40x40.png"/>
                                            </td>


                                            <td>{% if question.is_rejected  %} <b>Onaylanmadı </b>{% elseif question.answered %} Cevaplandı
                                                {% else %} <strong>Yeni Mesaj </strong>  {% endif %}</td>

                                            <td class="text-left">{{ question.date_added }}</td>

                                            <td class="text-right">
                                                <div style="    min-width: 120px;">


                                                       <a data-toggle="tooltip"
                                                       title="{% if question.answered %} Görüntüle {% else %} Cevapla  {% endif %}"
                                                       code="{{ question.code }}"
                                                       question_id="{{ question.question_id }}"
                                                       class="btn {% if question.is_rejected %} btn-danger {% elseif question.answered %} btn-info {% else %} btn-primary {% endif %} btnReply"><i
                                                                class="fa {% if  question.is_rejected %} fa-eye {% elseif question.answered %} fa-eye {% else %} fa-send {% endif %} "></i>
                                                    </a>
                                                    <a class="btn btn-danger" href="index.php?route=entegrasyon/product_question/delete_question&{{ token_link }}&product_question_id={{ question.product_question_id }}"> <i class="fa fa-trash-o" ></i> </a>


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

                            </table>
                        </div>
                </div>
                </form>
                <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 id="filter-question" class="col-md-2 col-sm-2 hidden-sm hidden-xs">
            <div class="panel panel-default" style="bquestion-top: 2px solid #27ad5e;">
                <div class="panel-heading">
                    <h2 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h2>
                </div>




                <div class="panel-body">


                    <div >

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

                            {% for marketplace in marketplaces %}

                                {% if marketplace.code=='gg' or marketplace.code=='ty' or marketplace.code=='n11' %}
                                {% if marketplace.status %}

                                    {% if filter_marketplace==marketplace.code %}
                                        <option selected value="{{ marketplace.code }}">{{ marketplace.name }}</option>
                                    {% else %}
                                        <option value="{{ marketplace.code }}">{{ marketplace.name }}</option>

                                    {% endif %}

                                {% endif %}
                                {% endif %}

                            {% endfor %}


                        </select>
                    </div>


                    <div >
                        <button style="margin-top: 10px" type="button" id="button-filter" class="btn btn-primary btn-block"><i
                                    class="fa fa-filter"></i> {{ button_filter }}</button>
                    </div>
                </div>
            </div>

            <div class="container my-5 col-md-2 col-sm-2 ">

                <!--Section: Content-->
                <section>

                    <div class="card">
                        <div class="card-body px-0 pb-0">

                            <h5 class="text-center font-weight-bold mb-4">Mesaj İstatislikleri</h5>

                            <hr>



                            <!--Grid column-->
                            <div class="col-12 pt-4 mt-2 mb-4 mb-md-0 mx-auto">

                                <div class="list-group">
                                    <a href="#!" class="list-group-item list-group-item-action rounded-0 border-left-0 border-right-0 d-flex justify-content-between align-items-center">Trendyol
                                        <span class="text-primary">{{total_ty}}</span>
                                    </a>
                                    <a href="#!" class="list-group-item list-group-item-action rounded-0 border-left-0 border-right-0 d-flex justify-content-between align-items-center">N11
                                        <span class="text-success"> {{total_n11}}</span>
                                    </a>
                                    <a href="#!" class="list-group-item list-group-item-action border-bottom-0 border-left-0 border-right-0 rounded-bottom-left rounded-bottom-right d-flex justify-content-between align-items-center">GittiGidiyor
                                        <span class="text-warning"> {{total_gg}}</span>
                                    </a>
                                </div>

                            </div>
                            <!--Grid column-->

                        </div>
                        <!--Grid row-->

                    </div>

                </section>
                <!--Section: Content-->

            </div>

        </div>



    </div>
</div>


<script>



    $('#btBulkDelete').on('click', function (event) {
        var $btn = $(this);
        $btn.button('loading');
        var bulk_delete = 1;

        $('.checkbox_check').each(function () {




            if($(this).is(':checked')) {
                var  product_question_id = $(this).val();
                $.post('index.php?route=entegrasyon/product_question/delete_question&{{ token_link }}&bulk_delete='+bulk_delete+'&product_question_id=' + product_question_id + '', function (json) {
                    if (json['status']) {

                        $('#tr_'+product_question_id).hide();

                        $btn.button('reset');

                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'top-end',
                            showConfirmButton: false,
                            timer: 3000,
                            timerProgressBar: true,
                            didOpen: (toast) => {
                                toast.addEventListener('mouseenter', Swal.stopTimer)
                                toast.addEventListener('mouseleave', Swal.resumeTimer)
                            }
                        })

                        Toast.fire({
                            icon: 'success',
                            title: 'Başarılı, Sorular Silindi.'
                        })
                    }
                }, "JSON");



            }


        });

    })

</script>

<script>

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

        var thisBtn = $(this);

        var code = thisBtn.attr('code');
        var question_id = thisBtn.attr('question_id');
        BootstrapDialog.show({
            title:   "Soru Detayı" ,
            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_question/reply_form&code=' + code + '&question_id=' + question_id + '&{{ token_link }}'
            }
        });


    })

</script>


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

        /*
                var filter_question_status = $('select[name=\'filter_question_status\']').val();

                if (filter_question_status !== '') {
                    url += '&filter_question_status=' + encodeURIComponent(filter_question_status);
                }
        */
        var filter_marketplace = $('select[name=\'filter_marketplace\']').val();

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


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


<script>
    $('#btnCheckquestion').on('click', function (event) {

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

        $.post('{{ catalog_url }}index.php?route=entegrasyon/update/questions', {}, function (data) {

            $btn.button('reset');
            if (data['total'] > 0) {

                Swal.fire({
                    title: 'Ürün Sorusu Kontrol',
                    text: 'Toplam' + data['total'] + ' Yeni Sorularınız Var. Sorular Sayfasını Yenilecenektir.',
                    icon: 'info',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Sayfayı Yenile!'
                }).then((result) => {
                    if (result.value) {

                        window.location.href = 'index.php?route=entegrasyon/product_question&{{ token_link }}';

                    }
                })

            } else {

                if (data['message']) {

                    Swal.fire({
                        title: 'Ürün Sorusu Kontrol',
                        icon: 'warning',
                        text: data['message'],
                        confirmButtonColor: '#3085d6',
                        icon: 'warning',
                        confirmButtonText: 'Tamam'
                    })

                } else {

                    Swal.fire({
                        title: 'Ürün Sorusu Kontrol',
                        icon: 'info',
                        text: 'Hiç Yeni Soru Yok!.',
                        confirmButtonColor: '#3085d6',
                        icon: 'success',
                        confirmButtonText: 'Tamam!'
                    })
                }

            }


        }, 'JSON');

    })

</script>


</div>


{{ footer }}