{% if product_variants %}

    <table class="table" style="background: #f5f5f5;">

        <tr>
            <th>Görsel</th>
            <th>Variant</th>
            <th>Barkod</th>
            <th>Adet</th>
            <th>Fiyat</th>
            {% for marketplace in marketplaces %}
                {% if marketplace.status %}
                    <th class="{{ marketplace.code }} "> {{ marketplace.name }}</th>
                {% endif %}
            {% endfor %}
        </tr>
        {% for variant in product_variants %}
            <tr>
                <td>

                  <img style="border: 1px solid #dddddd" src="{{ variant.imagesrc  }}" alt="" title="" class="img-thumbnail img-sm" data-placeholder="görsel" />

                </td>
                <td>
                    {% for variant_option in variant.variant_values %}

                      {{ variant_option.name }}

                    {% endfor %}</td>

                <td>
                    <a href="" id="barcode" class="editable" data-type="text" data-pk="{{ variant.variant_id }}"
                       data-value="{{ variant.barcode }}" data-emptytext="Barkod Giriniz"
                       data-url="index.php?route=entegrasyon/product/update_variant&{{ token_link }}"
                       data-title="Barkod Giriniz."></a></td>
                </td>

                <td>{% if variant.quantity <= 0 %} <a
                            product_variant_id="{{ variant.product_variant_id }}"
                            class="btn btn-warning btn-sm btn-quantity">{{ variant.quantity }}</a> {% elseif variant.quantity <= 5 %}
                        <a product_variant_id="{{ variant.product_variant_id }}"
                           class="btn btn-danger btn-sm btn-quantity">{{ variant.quantity }}</a> {% else %}
                        <a product_variant_id="{{ variant.product_variant_id}}"
                           class="btn btn-success btn-sm btn-quantity">{{ variant.quantity }}</a> {% endif %}</td>
                <td>{{ variant.sale_price }}</td>
                {% for marketplace in marketplaces %}
                    {% if marketplace.status %}
                        <td class="text-center {{ marketplace.code }}">
                            <input id="variant{{ marketplace.code }}{{ variant.variant_id }}" class="inputsw" code="{{ marketplace.code }}" variant_id="{{ variant.variant_id }}" data-action="{% if variant[marketplace.code]['sale_price'] is defined %} {% if variant[marketplace.code]['sale_status'] %}close{% else %}open{% endif %}{% else %}list{% endif %}" type="checkbox" {% if variant[marketplace.code]['sale_status']  %}   checked {% endif %} data-toggle="toggle" data-on="{{ variant[marketplace.code]['sale_price']}} <i class='fa fa-pause'></i>"  data-off="<i class='fa fa-play'></i> {% if variant[marketplace.code] %}{{ variant[marketplace.code]['sale_price']}}{% else %} Listele  {% endif %}" data-offstyle="{% if variant[marketplace.code] %}warning{% else %} default  {% endif %}" data-size="small" >
                        {% if  marketplace.code != 'hb' %}  <br> {% if not variant[marketplace.code] %} <a id="btnVariantMatch{{ marketplace.code }}{{ variant.variant_id }}" class="btnVariantMatch" product_name="{{ variant.product_name }}" matching_words="{{ variant.matching_words }}" primary_id="{{ variant.variant_id }}" code="{{ marketplace.code }}" target="_blank" >Eşleştir</a> {% endif %}{% endif %}
                        </td>
                    {% endif %}

                {% endfor %}


            </tr>

        {% endfor %}

    </table>

{% endif  %}




<script>



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

            if (json['status']) {

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

            }

        }
    });
    

    $.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>
<script>

    $('.inputsw').bootstrapToggle();

    $('.inputsw').on('change',function (event) {

        var thisinput=$(this);
        var variant_id=thisinput.attr('variant_id');
        var code=thisinput.attr('code');
        var action=thisinput.attr('data-action');

        if(thisinput.prop('checked')){

        }else {

        }


        $.post('index.php?route=entegrasyon/product_service/action&{{ token_link }}',{primary_id:variant_id,code:code,action_type:action,product_type:'variant'},function () {

        },'JSON');


    })




</script>

<script>

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

        var thisBtn = $(this);
        var name = thisBtn.attr('product_name');
        var code = thisBtn.attr('code');
        var primary_id = thisBtn.attr('primary_id');
        var matching_words = thisBtn.attr('matching_words');

        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/sync/product_match_form&code='+code+'&matching_words='+matching_words+'&primary_id='+primary_id+'&product_type=2&filter_name='+encodeURI(name)+'&{{ token_link }}'
            }
        });




    })

</script>

