


<div class="row">
    <div class="panel panel-default"  style=" width:100%;border-top: 2px solid #27ad5e;">

        <div class="panel-body">
            {% if(message) %}
            <p class=""><strong class="text-danger">Önemli:</strong> {{ message }}</p>
            {% elseif attributes %}
            <form id="myform" >
                {% for index,attribute in attributes.result %}
                    <div class="col-sm-4 form-group">

                        {% if attribute.required %}
                            <label class="required text-danger" style="font-size: 10px;height: 25px;display: block;vertical-align: bottom;" >{{ attribute.attribute_name }}</label>
                        {% else %}

                            <label style="font-size: 10px;height: 25px;display: block;vertical-align: bottom;">{{ attribute.attribute_name }}</label>

                        {% endif %}


                        <a href="#"  id="{{ attribute.market_attribute_id }}" style=" z-index: 9999;   height: 40px;
    display: block;" class="eslestir" data-type="typeaheadjs" attr-id="{{ attribute.market_attribute_id }}"
                           data-pk="{{ product_id }}"  data-value="{% if attribute.selected %} {{ attribute.selected}} {% endif %}"
                           data-emptytext="eşleştir"
                           data-url="index.php?route=entegrasyon/category/save_attribute_value&code={{ code }}&market_attribute_id={{ attribute.market_attribute_id }}&category_id={{ category_id }}&{{ token_link }}"
                           data-title="Lütfen seçenek değeri arayın"></a>


                    </div>

                {% endfor %}
            </form>

        </div>

        <div class="panel-footer hidden">

            <div class="form-group">

                <button id="btn-send" class="btn btn-lg btn-primary btn-block">Kaydet</button>


            </div>

        </div>

    </div>
    {% else %}

        <p style="margin-top: 10px " class="text-info">Bu ürünün bulunduğu kategori için herhangi bir zorunlu Trendyol özelliği bulunmamaktadır. Ürünlerinizi Gönderebilirsiniz.</p>

    {% endif %}



    <span  class="hidden" name="test"  id="attrid" ></span>

    <script>



        var attrid=null;
        $('.eslestir').on('click',function (event){

            $('#attrid').text($(this).attr('attr-id'));

            attrid=$(this).attr('attr-id');
            //   alert( $('#attrid').text());



        })

        $('.eslestir').editable({
            mode: 'inline',

            typeahead: {

                limit: 200,
                remote: {
                    url:"index.php?route=entegrasyon/category/attribute_search&filter_code={{ code }}&{{ token_link }}",
                    replace: function (url, query) {

                        url += "&filter_name="+$('.tt-query').val()+"&filter_attribute_id="+$('#attrid').text();
                        return url;
                    }
                },
                displayKey: 'id',
                valueKey: 'name',
                display: function (item) {
                    return item.name
                },

            }, success: function (json, newValue) {

                if (!json['status']) {

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


                } else {

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

                }

            }
        });


        $('.select2').selectpicker();

        $('#btn-send').on('click',function () {

            var attributes=$('#myform').serializeArray();

            var product_id='{{ product_id}}';

            $.post('index.php?route=entegrasyon/genel/save_setting&code={{ code }}&controller={{ controller }}&{{ token_link }}&product_id='+product_id,{pk:+'{{  primary_id}}',name:'selected_attributes',value:attributes},
                function(datas){
                    $.toast({heading: 'Başarılı',text: 'Ürün Özelliği Güncellendi!', position: 'top-right',loader: false,allowToastClose: false,showHideTransition: 'slide',icon: 'success'});
                    $('#btn-send').html("Güncellendi");
                    $('.ty_default_category_attributes_container').empty().hide('slow');

                },'JSON');
        })
    </script>
</div>