if (Vvveb === undefined) var Vvveb = {};
$(document).on('click', '.delete', function (e) {
    var url = $(this).attr('href');
    var title = $(this).data('title');
    var question = $(this).data('question');
    var no = $(this).data('no');
    var yes = $(this).data('yes');
    e.preventDefault();
    Swal.fire({
        customClass: {
            confirmButton: 'btn btn-success btn-label',
            denyButton: 'btn btn-danger btn-label'
        },
        iconHtml: '<lord-icon src="https://cdn.lordicon.com/gsqxdxog.json" trigger="loop" colors="primary:#f7b84b,secondary:#f06548" style="width:100px;height:100px"></lord-icon>',
        title: title,
        text: question,
        showDenyButton: true,
        showCancelButton: false,
        confirmButtonText: '<i class="bx bx-check label-icon"></i> ' + yes + '',
        denyButtonText: '<i class="bx bx-window-close label-icon "></i> ' + no + '',
    }).then((result) => {

        if (result.isConfirmed) {
            window.location.href = url;
        } else if (result.isDenied) {
            Swal.close();
        }
    });

});
$(document).on('click', '#slider_item_delete', function (e) {
    var title = $(this).data('title');
    var question = $(this).data('question');
    var no = $(this).data('no');
    var yes = $(this).data('yes');
    var id = $(this).data('id');
    var sliderId = $(this).data('slider');
    var type = 'delete';

    e.preventDefault();
    Swal.fire({
        customClass: {
            confirmButton: 'btn btn-success btn-label',
            denyButton: 'btn btn-danger btn-label'
        },
        iconHtml: '<lord-icon src="https://cdn.lordicon.com/gsqxdxog.json" trigger="loop" colors="primary:#f7b84b,secondary:#f06548" style="width:100px;height:100px"></lord-icon>',
        title: title,
        text: question,
        showDenyButton: true,
        showCancelButton: false,
        confirmButtonText: '<i class="bx bx-check label-icon"></i> ' + yes + '',
        denyButtonText: '<i class="bx bx-window-close label-icon "></i> ' + no + '',
    }).then((result) => {

        if (result.isConfirmed) {
            $.ajax({
                url: window.location.origin + '/panel/slideritemsave',
                type: 'POST',
                data: { slider_item_id: id, type: type, slider_id: sliderId },

                success: function (response) {
                    location.reload();
                },
                error: function (xhr, status, error) {
                    console.error(error);
                }
            });
        } else if (result.isDenied) {
            Swal.close();
        }
    });
});
$(document).ready(function () {
    $('#categoryContainer .option').each(function () {
        var level = $(this).data('level');
        if (level > 0) {
            var icon = '<i class="mdi mdi-subdirectory-arrow-right" style="padding-left: ' + (level * 20) + 'px;"></i>';
            $(this).html(icon + $(this).text());
        }
    });

    // Sayfa yüklendiğinde seçili olan kategoriyi göster
    var selectedValue = $('#selectedCategory').val();
    if (selectedValue) {
        var selectedOption = $('#categoryContainer .option[data-value="' + selectedValue + '"]');
        $('#categoryContainer .selected-option').html(selectedOption.text());
        selectedOption.addClass('selected');
    }

    // Seçilen kategoriyi göster ve listeyi aç/kapat
    $('#categoryContainer').click(function () {
        $('.options-list').toggle();
    });

    // Bir kategori seçildiğinde
    $('#categoryContainer .option').click(function () {
        var value = $(this).data('value');
        var text = $(this).text();

        // Seçilen değeri gizli input'a ata
        $('#selectedCategory').val(value);

        // Seçilen kategoriyi üstte göster
        $('#categoryContainer .selected-option').html(text);

        // Seçilen kategoriye "selected" sınıfı ekle
        $('#categoryContainer .option').removeClass('selected');
        $(this).addClass('selected');

        // Listeyi kapat
        $('.options-list').hide();
    });

    // Seçim dışında bir yere tıklanınca listeyi kapat
    $(document).click(function (e) {
        if (!$(e.target).closest('#categoryContainer').length) {
            $('.options-list').hide();
        }
    });

    $('#features_form').submit(function (event) {

        const featuresInputs = $('#featuresInputs').find('input, textarea, select');
        const data = {};

        featuresInputs.each(function () {
            const element = $(this);
            const name = element.attr('name');
            const value = element.val();

            if (name) {
                data[name] = value;
            }
        });
        $('#featuresData').val(JSON.stringify(data));

        $('button[name="save"]').val('save');

    });

    function displayToast(bg, title, message, status_title, id = "top-toast") {
        // Önceki toast'ı kapat
        $("#" + id + " .toast").removeClass("show");

        // Yeni toast'ı oluştur
        $("#" + id + " .toast-body .message").html(message);
        $("#" + id + " .toast-body .badge").html(status_title);
        $("#" + id + " .toast-header").removeClass(["bg-danger", "bg-success"]).addClass(bg).text(title);

        // Yeni toast'ı göster
        $("#" + id + " .toast").addClass("show");
        delay(() => $("#" + id + " .toast").removeClass("show"), 5000);
    }
    $('#slider_item_create').click(function () {
        $('#slider_item_form').find('input[type=text]').val('');
        $('#slider_item_form').find('textarea').val('');
        $('#type').val('save');
        $('#featured-image-thumb').attr('src', window.location.origin + '/admin/template/assets/images/placeholder.svg');


    });

    $('.edit-item-btn').click(function () {
        var itemId = $(this).data('id');
        var type = 'data';
        $.ajax({
            url: window.location.origin + '/panel/slideritemsave',
            type: 'POST',
            data: { slider_item_id: itemId, type: type },
            dataType: 'json',
            success: function (response) {
                $('#item_title').val(response.item_title);
                $('#sub_title').val(response.sub_title);
                $('#description').val(response.description);
                $('#button_label_1').val(response.button_label_1);
                $('#button_link_1').val(response.button_link_1);
                $('#button_label_2').val(response.button_label_2);
                $('#button_link_2').val(response.button_link_2);
                $('#slider_item_id').val(response.slider_item_id);
                $('#short').val(response.short);
                $('#featured-image-input').val(response.image);
                $('#featured-image-thumb').attr('src', window.location.origin + '/media' + response.image);
                $('#type').val('edit');
            },
            error: function (xhr, status, error) {
                console.error(error);
            }
        });
    });


    $('.slider_item_form').submit(function (e) {

        e.preventDefault();
        var formData = new FormData(this);

        $.ajax({

            url: window.location.origin + '/panel/slideritemsave',
            type: 'POST',
            data: formData,
            contentType: false,
            processData: false,
            success: function (response) {
                location.reload();
            },
            error: function (xhr, status, error) {
                console.error(error);
            }
        });
    });
    if ($("#MediaModal").length) {

        if (!Vvveb.MediaModal) {
            Vvveb.MediaModal = new MediaModal(false);
        }
        Vvveb.MediaModal.mediaPath = mediaPath;
        Vvveb.MediaModal.type = "multiple";
        Vvveb.MediaModal.open($("#MediaModal")[0]);
    }

    $(document).on("click", "[data-media-gallery]", function () {

        if (!Vvveb.MediaModal) {
            Vvveb.MediaModal = new MediaModal(true);
        }
        Vvveb.MediaModal.open(this);
    });
});
function clearFeaturedMedia(id = "featured-image") {
    $("#" + id + "-input").val("");
    $("#" + id + "-thumb").attr("src", window.location.origin + '/admin/template/assets/images/placeholder.svg');
}
$(document).ready(function () {
    $('#addImageButton').click(function (event) {
        event.preventDefault();
        var clonedImageItem = $('.image-item').first().clone();
        clonedImageItem.find('[data-v-image]').val('');
        clonedImageItem.find('img').attr('src', window.location.origin + '/admin/template/assets/images/placeholder.svg');
        var currentCount = $('.image-item').length;
        var newId = currentCount + 1;
        var id = 'brand' + newId;
        var idShrap = '#brand' + newId;
        var idthumpsharp = '#brand' + newId + '-thumb';
        var idthump = 'brand' + newId + '-thumb';
        clonedImageItem.find('[data-v-image]').attr('id', id);
        clonedImageItem.find('.img-thumbnail').attr('id', idthump);
        clonedImageItem.find('.img-thumbnail').attr('data-target-input', idShrap);
        clonedImageItem.find('.img-thumbnail').attr('data-target-thumb', idthumpsharp);
        clonedImageItem.find('.setmedia').attr('data-target-thumb', idthumpsharp);
        clonedImageItem.find('.setmedia').attr('data-target-input', idShrap);
        $('#imageRepeater').append(clonedImageItem);
    });
    $(document).on('click', '.removeImageBtn', function () {
        $(this).closest('.image-item').remove(); // Tekrarlayan resim öğesini kaldır
    });


    $(".show-item-details").click(function (e) {
        e.preventDefault();
        var listItem = $(this).closest(".dd-item");
        var listItemdetail = $(this).closest(".show-item-details");
        if (!listItem.hasClass("active")) {
            $(".dd-item").removeClass("active");
            $(".show-item-details").removeClass("active");
            listItem.addClass("active");
            listItemdetail.addClass("active");
        } else {
            listItem.removeClass("active");
            listItemdetail.removeClass("active");

        }
    });
    $(function () {
        var placeholderHeight = 40; // Placeholder yüksekliği
        var maxLayers = 4; // Maksimum katman sayısı

        $.getScript('https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js', function () {
            var group = $("#menuitems").sortable({
                group: 'serialization',
                onDrag: function ($item, container, _super) {
                    placeholderHeight = $item.height();
                    _super($item, container);
                    $('.dd-placeholder').css('height', placeholderHeight);
                },
                onDrop: function ($item, container, _super) {
                    var $parentItem = $item.parent('ul').closest('li.dd-item'); // Öğenin ebeveyn öğesini al
                    var currentLayers = $parentItem.parents('li.dd-item').length + 1; // Öğenin katman sayısını hesapla
                    var menuid = $("#menuitems").data('id');

                    if (currentLayers === maxLayers) {
                        // Öğenin katman sayısı maksimuma ulaştıysa, sonraki öğenin sonrasına yerleştir
                        var $nextItem = $item.next('li.dd-item'); // Sonraki öğeyi al
                        if ($nextItem.length > 0) {
                            $nextItem.before($item); // Sonraki öğenin üstüne ekle
                        } else {
                            var $parentUl = $parentItem.parent('ul'); // Ebeveyn ul elementini al
                            $parentUl.append($item); // Ebeveyn ul içine ekle
                        }
                    }

                    var data = group.sortable("serialize").get();
                    var type = 'menuUpdate'

                    var jsonString = JSON.stringify(data, null, ' ');
                    $.ajax({
                        type: "GET",
                        data: { menuid: menuid, data: jsonString, type: type },
                        url: window.location.origin + '/panel/menuitemsave',
                        success: function (res) {
                        }
                    })
                    // $('#serialize_output').text(jsonString);
                    $('#serialize_input').val(JSON.stringify(data));
                    _super($item, container);
                }
            });
        });

    });

    $('#select-all-pages').click(function (event) {
        if (this.checked) {
            $('#pages-list :checkbox').each(function () {
                this.checked = true;
            });
        } else {
            $('#pages-list :checkbox').each(function () {
                this.checked = false;
            });
        }
    });
    $('#select-all-services').click(function (event) {
        if (this.checked) {
            $('#services-list :checkbox').each(function () {
                this.checked = true;
            });
        } else {
            $('#services-list :checkbox').each(function () {
                this.checked = false;
            });
        }
    });
    $('#select-all-projects').click(function (event) {
        if (this.checked) {
            $('#projects-list :checkbox').each(function () {
                this.checked = true;
            });
        } else {
            $('#projects-list :checkbox').each(function () {
                this.checked = false;
            });
        }
    });
    $('.btn-cancel').click(function () {
        $(this).closest(".dd-item").removeClass('active');
    });

    $('.btn-remove').click(function () {

        var menuid = $(this).data('menuid');
        var id = $(this).data('id');
        var key = $(this).data('key');
        var indis = $(this).data('in');
        var type = ('delete');

        $.ajax({
            type: "get",
            data: { menuid: menuid, id: id, type: type, key: key, indis: indis },
            url: window.location.origin + '/panel/menuitemsave',
            success: function (res) {
                location.reload();
            }
        })

    });

    $('.btn-uptade').click(function () {
        var menuItemId = $(this).closest('.dd-item').data('id');
        var menuItemTitle = $(this).closest('.dd-item').find('[name="menu_item_title"]').val();
        var menuItemUrl = $(this).closest('.dd-item').find('[name="menu_item_url"]').val();
        var menuItemTarget = $(this).closest('.dd-item').find('[name="menu_item_target"]').val();
        var type = ('update');
        // Ajax isteği gönderme
        $.ajax({
            url: window.location.origin + '/panel/menuitemsave',
            type: 'GET',
            data: {
                type: type,
                id: menuItemId,
                title: menuItemTitle,
                url: menuItemUrl,
                target: menuItemTarget
            },
            success: function (response) {
                location.reload();
            },
            error: function (xhr, status, error) {
                // Hata durumunda yapılacak işlemler
                console.error(error);
                alert('An error occurred while saving the menu item.');
            }
        });
    });
    $('#add-pages').click(function () {
        var menuid = $(this).data('id');
        var type = $(this).data('type');
        var checkedInputs = $('input[name="select-pages[]"]:checked');
        var ids = [];
        checkedInputs.each(function () {
            ids.push($(this).val());
        });

        if (ids.length == 0) {
            return false;
        }

        $.ajax({
            type: "get",
            traditional: true,
            data: { menuid: menuid, 'ids[]': ids, type: type },
            url: window.location.origin + '/panel/menuitemsave',
            success: function (res) {
                location.reload();
            }
        });
    });
    $('#add-services').click(function () {
        var menuid = $(this).data('id');
        var type = $(this).data('type');
        var checkedInputs = $('input[name="select-services[]"]:checked');
        var ids = [];
        checkedInputs.each(function () {
            ids.push($(this).val());
        });

        if (ids.length == 0) {
            return false;
        }

        $.ajax({
            type: "get",
            traditional: true,
            data: { menuid: menuid, 'ids[]': ids, type: type },
            url: window.location.origin + '/panel/menuitemsave',
            success: function (res) {
                location.reload();
            }
        });
    });
    $('#add-projects').click(function () {
        var menuid = $(this).data('id');
        var type = $(this).data('type');
        var checkedInputs = $('input[name="select-projects[]"]:checked');
        var ids = [];
        checkedInputs.each(function () {
            ids.push($(this).val());
        });

        if (ids.length == 0) {
            return false;
        }

        $.ajax({
            type: "get",
            traditional: true,
            data: { menuid: menuid, 'ids[]': ids, type: type },
            url: window.location.origin + '/panel/menuitemsave',
            success: function (res) {
                location.reload();
            }
        });
    });

    $("#add-custom-link").click(function () {
        var menuid = $(this).data('id');
        var type = $(this).data('type');
        var url = $('#url').val();
        var link = $('#linktext').val();
        var target = $('#menu-node-target-new').val();
        if (url.length > 0 && link.length > 0) {
            $.ajax({
                type: "get",
                data: { menuid: menuid, url: url, link: link, type: type, target: target },
                url: window.location.origin + '/panel/menuitemsave',
                success: function (res) {
                    location.reload();
                }
            })
        }
    })


    $('#preview').on('load', function () {
        var iframeDoc = $('#preview').contents();
        iframeDoc.find('*').on('click', function (event) {
            event.preventDefault();
        });
    });

    function replaceTurkishChars(text) {
        var turkishChars = {
            'ğ': 'g',
            'Ğ': 'g',
            'ü': 'u',
            'Ü': 'u',
            'ş': 's',
            'Ş': 's',
            'ı': 'i',
            'İ': 'i',
            'ö': 'o',
            'Ö': 'o',
            'ç': 'c',
            'Ç': 'c'
        };

        return text.replace(/[ğĞüÜşŞıİöÖçÇ]/g, function (match) {
            return turkishChars[match];
        });
    }

    function slugify(text) {
        return replaceTurkishChars(text)
            .toLowerCase()
            .replace(/\s+/g, '-')
            .replace(/[^\w\-]+/g, '')
            .replace(/--+/g, '-')
            .replace(/^-+/, '')
            .replace(/-+$/, '');
    }

    function generateSEFURL() {
        var title = $('#title').val();
        var sef = slugify(title);
        var seo_title = $('#seo_title').val();
        var slug = $('#slug').val();

        if (!seo_title) {
            $('#seo_title_preview').text(title);
        } if (!slug) {
            $('#seo_link_preview').text(sef);
            $('#slug').val(sef);
        }
        $('.existed-seo-meta').removeClass('hidden');
        $('.default-seo-description').addClass('hidden');
    }

    $('#title').change('input', function () {
        generateSEFURL();
    });
    $('#slug').change('input', function () {
        var sef = $('#slug').val();
        var slug = slugify(sef);
        $('#slug').val(slug);
        $('#seo_link_preview').text(slug);
        $('.existed-seo-meta').removeClass('hidden');
        $('.default-seo-description').addClass('hidden');
    });
    $('#seo_title').on('input', function () {
        var seo_title = $('#seo_title').val();
        var maxLengthString = $(this).attr('maxlength');
        var maxLength = parseInt(maxLengthString) || 60;
        var currentLength = seo_title.length;
        var remainingChars = maxLength - currentLength;
        remainingChars = remainingChars < 0 ? 0 : remainingChars;
        $('#seo_title_Remaining').text(remainingChars);
        var title = $('#title').val();
        if (seo_title) {
            $('#seo_title_preview').text(seo_title);
        } else {
            $('#seo_title_preview').text(title);

        }
        $('.existed-seo-meta').removeClass('hidden');
        $('.default-seo-description').addClass('hidden');
    });
    $('#seo_description').on('input', function () {
        var seo_description = $('#seo_description').val();
        var maxLengthString = $(this).attr('maxlength');
        var maxLength = parseInt(maxLengthString) || 160;
        var currentLength = seo_description.length;
        var remainingChars = maxLength - currentLength;
        remainingChars = remainingChars < 0 ? 0 : remainingChars;
        $('#seo_description_Remaining').text(remainingChars);
        $('#seo-description-preview').text(seo_description);
        $('.existed-seo-meta').removeClass('hidden');
        $('.default-seo-description').addClass('hidden');
    });
    $('#description').on('input', function () {
        var seo_description = $('#description').val();
        var maxLengthString = $(this).attr('maxlength');
        var maxLength = parseInt(maxLengthString) || 160;
        var currentLength = seo_description.length;
        var remainingChars = maxLength - currentLength;
        remainingChars = remainingChars < 0 ? 0 : remainingChars;
        $('#description_Remaining').text(remainingChars);

    });



    $('#imageSelect').selectize({
        render: {
            option: function (data, escape) {
                return '<div class="option" style="padding-left: 20px;">' +
                    '<img src="' + escape(data.image) + '" alt="' + data.text + '" class="flag" />' +
                    escape(data.text) +
                    '</div>';
            }
        }
    });
    $('#LangSelect').selectize({
        render: {
            option: function (data, escape) {
                return '<div class="option" style="padding-left: 20px;">' +
                    '<img src="' + escape(data.image) + '" alt="' + data.text + '" class="flag" />' +
                    escape(data.text) +
                    '</div>';
            }
        }
    });
    $('#LangSelect').on('change', function () {
        var selectedValue = $(this).val();
        alert(selectedValue);
    });
    if ($('#lang_select').length) {
        var mySelect = $('#lang_select').selectize({
            options: [
                {
                    value: 'za',
                    text: 'Afrikaans - af',
                    datalangname: 'Afrikaans',
                    datalangdriection: 'ltr',
                    datalanglocale: 'af'
                },
                {
                    value: 'ar',
                    text: 'العربية - ar',
                    datalangname: 'العربية',
                    datalangdriection: 'rtl',
                    datalanglocale: 'ar'
                },
                {
                    value: 'ma',
                    text: 'العربية المغربية - ary',
                    datalangname: 'العربية المغربية',
                    datalangdriection: 'rtl',
                    datalanglocale: 'ary'
                },
                {
                    value: 'az',
                    text: 'Azərbaycan - az',
                    datalangname: 'Azərbaycan',
                    datalangdriection: 'ltr',
                    datalanglocale: 'az'
                },
                {
                    value: 'az',
                    text: 'گؤنئی آذربایجان - azb',
                    datalangname: 'گؤنئی آذربایجان',
                    datalangdriection: 'rtl',
                    datalanglocale: 'azb'
                },
                {
                    value: 'by',
                    text: 'Беларуская мова - bel',
                    datalangname: 'Беларуская мова',
                    datalangdriection: 'ltr',
                    datalanglocale: 'bel'
                },
                {
                    value: 'bg',
                    text: 'български - bg_BG',
                    datalangname: 'български',
                    datalangdriection: 'ltr',
                    datalanglocale: 'bg_BG'
                },
                {
                    value: 'bd',
                    text: 'বাংলা - bn_BD',
                    datalangname: 'বাংলা',
                    datalangdriection: 'ltr',
                    datalanglocale: 'bn_BD'
                },
                {
                    value: 'tibet',
                    text: 'བོད་སྐད - bo',
                    datalangname: 'བོད་སྐད',
                    datalangdriection: 'ltr',
                    datalanglocale: 'bo'
                },
                {
                    value: 'ba',
                    text: 'Bosanski - bs_BA',
                    datalangname: 'Bosanski',
                    datalangdriection: 'ltr',
                    datalanglocale: 'bs_BA'
                },
                {
                    value: 'es',
                    text: 'Catalan - ca',
                    datalangname: 'Catalan',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ca'
                },
                {
                    value: 'ph',
                    text: 'Cebuano - ceb',
                    datalangname: 'Cebuano',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ceb'
                },
                {
                    value: 'cz',
                    text: 'Čeština - cs_CZ',
                    datalangname: 'Čeština',
                    datalangdriection: 'ltr',
                    datalanglocale: 'cs_CZ'
                },
                {
                    value: 'wls',
                    text: 'Cymraeg - cy',
                    datalangname: 'Cymraeg',
                    datalangdriection: ', ',
                    datalanglocale: 'cy'
                },
                {
                    value: 'dk',
                    text: 'Dansk - da_DK',
                    datalangname: 'Dansk',
                    datalangdriection: 'ltr',
                    datalanglocale: 'da_DK'
                },
                {
                    value: 'ch',
                    text: 'Deutsch - de_CH',
                    datalangname: 'Deutsch',
                    datalangdriection: 'ltr',
                    datalanglocale: 'de_CH'
                },
                {
                    value: 'ch',
                    text: 'Deutsch - de_CH_informal',
                    datalangname: 'Deutsch',
                    datalangdriection: 'ltr',
                    datalanglocale: 'de_CH_informal'
                },
                {
                    value: 'de',
                    text: 'Deutsch - de_DE',
                    datalangname: 'Deutsch',
                    datalangdriection: 'ltr',
                    datalanglocale: 'de_DE'
                },
                {
                    value: 'de',
                    text: 'Deutsch - de_DE_formal',
                    datalangname: 'Deutsch',
                    datalangdriection: 'ltr',
                    datalanglocale: 'de_DE_formal'
                },
                {
                    value: 'gr',
                    text: 'Ελληνικά - el',
                    datalangname: 'Ελληνικά',
                    datalangdriection: 'ltr',
                    datalanglocale: 'el'
                },
                {
                    value: 'au',
                    text: 'English - en_AU',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_AU'
                },
                {
                    value: 'ca',
                    text: 'English - en_CA',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_CA'
                },
                {
                    value: 'gb',
                    text: 'English - en_GB',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_GB'
                },
                {
                    value: 'nz',
                    text: 'English - en_NZ',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_NZ'
                },
                {
                    value: 'za',
                    text: 'English - en_ZA',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_ZA'
                },
                {
                    value: 'en',
                    text: 'English - en_US',
                    datalangname: 'English',
                    datalangdriection: 'ltr',
                    datalanglocale: 'en_US'
                },
                {
                    value: 'ar',
                    text: 'Español - es_AR',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_AR'
                },
                {
                    value: 'cl',
                    text: 'Español - es_CL',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_CL'
                },
                {
                    value: 'co',
                    text: 'Español - es_CO',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_CO'
                },
                {
                    value: 'es',
                    text: 'Español - es_ES',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_ES'
                },
                {
                    value: 'gt',
                    text: 'Español - es_GT',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_GT'
                },
                {
                    value: 'mx',
                    text: 'Español - es_MX',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_MX'
                },
                {
                    value: 'pe',
                    text: 'Español - es_PE',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_PE'
                },
                {
                    value: 've',
                    text: 'Español - es_VE',
                    datalangname: 'Español',
                    datalangdriection: 'ltr',
                    datalanglocale: 'es_VE'
                },
                {
                    value: 'ee',
                    text: 'Eesti - et',
                    datalangname: 'Eesti',
                    datalangdriection: 'ltr',
                    datalanglocale: 'et'
                },
                {
                    value: 'fr',
                    text: 'Euskara - eu',
                    datalangname: 'Euskara',
                    datalangdriection: 'ltr',
                    datalanglocale: 'eu'
                },
                {
                    value: 'af',
                    text: 'فارسی - fa_AF',
                    datalangname: 'فارسی',
                    datalangdriection: 'rtl',
                    datalanglocale: 'fa_AF'
                },
                {
                    value: 'ir',
                    text: 'فارسی - fa_IR',
                    datalangname: 'فارسی',
                    datalangdriection: 'rtl',
                    datalanglocale: 'fa_IR'
                },
                {
                    value: 'fi',
                    text: 'Suomi - fi',
                    datalangname: 'Suomi',
                    datalangdriection: 'ltr',
                    datalanglocale: 'fi'
                },
                {
                    value: 'fo',
                    text: 'Føroyskt - fo',
                    datalangname: 'Føroyskt',
                    datalangdriection: 'ltr',
                    datalanglocale: 'fo'
                },
                {
                    value: 'be',
                    text: 'Français - fr_BE',
                    datalangname: 'Français',
                    datalangdriection: 'ltr',
                    datalanglocale: 'fr_BE'
                },
                {
                    value: 'fr',
                    text: 'Français - fr_FR',
                    datalangname: 'Français',
                    datalangdriection: 'ltr',
                    datalanglocale: 'fr_FR'
                },
                {
                    value: 'nl',
                    text: 'Frysk - fy',
                    datalangname: 'Frysk',
                    datalangdriection: 'ltr',
                    datalanglocale: 'fy'
                },
                {
                    value: 'sct',
                    text: 'Gàidhlig - gd',
                    datalangname: 'Gàidhlig',
                    datalangdriection: ', ',
                    datalanglocale: 'gd'
                },
                {
                    value: 'gl',
                    text: 'Galego - gl_ES',
                    datalangname: 'Galego',
                    datalangdriection: 'ltr',
                    datalanglocale: 'gl_ES'
                },
                {
                    value: 'in',
                    text: 'ગુજરાતી - gu',
                    datalangname: 'ગુજરાતી',
                    datalangdriection: 'ltr',
                    datalanglocale: 'gu'
                },
                {
                    value: 'af',
                    text: ' هزاره گی - haz',
                    datalangname: 'هزاره گی',
                    datalangdriection: 'rtl',
                    datalanglocale: 'haz'
                },
                {
                    value: 'il',
                    text: 'עברית - he_IL',
                    datalangname: 'עברית',
                    datalangdriection: 'rtl',
                    datalanglocale: 'he_IL'
                },
                {
                    value: 'in',
                    text: 'हिन्दी - hi_IN',
                    datalangname: 'हिन्दी',
                    datalangdriection: 'ltr',
                    datalanglocale: 'hi_IN'
                },
                {
                    value: 'hr',
                    text: 'Hrvatski - hr',
                    datalangname: 'Hrvatski',
                    datalangdriection: 'ltr',
                    datalanglocale: 'hr'
                },
                {
                    value: 'hu',
                    text: 'Magyar - hu_HU',
                    datalangname: 'Magyar',
                    datalangdriection: 'ltr',
                    datalanglocale: 'hu_HU'
                },
                {
                    value: 'am',
                    text: 'Հայերեն - hy',
                    datalangname: 'Հայերեն',
                    datalangdriection: 'ltr',
                    datalanglocale: 'hy'
                },
                {
                    value: 'id',
                    text: 'Bahasa Indonesia - id_ID',
                    datalangname: 'Bahasa Indonesia',
                    datalangdriection: 'ltr',
                    datalanglocale: 'id_ID'
                },
                {
                    value: 'is',
                    text: 'Íslenska - is_IS',
                    datalangname: 'Íslenska',
                    datalangdriection: 'ltr',
                    datalanglocale: 'is_IS'
                },
                {
                    value: 'it',
                    text: 'Italiano - it_IT',
                    datalangname: 'Italiano',
                    datalangdriection: 'ltr',
                    datalanglocale: 'it_IT'
                },
                {
                    value: 'jp',
                    text: '日本語 - ja',
                    datalangname: '日本語',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ja'
                },
                {
                    value: 'id',
                    text: 'Basa Jawa - jv_ID',
                    datalangname: 'Basa Jawa',
                    datalangdriection: 'ltr',
                    datalanglocale: 'jv_ID'
                },
                {
                    value: 'ge',
                    text: 'ქართული - ka_GE',
                    datalangname: 'ქართული',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ka_GE'
                },
                {
                    value: 'kz',
                    text: 'Қазақ тілі - kk',
                    datalangname: 'Қазақ тілі',
                    datalangdriection: 'ltr',
                    datalanglocale: 'kk'
                },
                {
                    value: 'kh',
                    text: 'Cambodia - kh',
                    datalangname: 'Cambodia',
                    datalangdriection: 'ltr',
                    datalanglocale: 'kh'
                },
                {
                    value: 'kr',
                    text: '한국어 - ko_KR',
                    datalangname: '한국어',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ko_KR'
                },
                {
                    value: 'kurdistan',
                    text: 'ckb - کوردی',
                    datalangname: 'کوردی',
                    datalangdriection: 'rtl',
                    datalanglocale: 'ckb'
                },
                {
                    value: 'la',
                    text: 'ພາສາລາວ - lo',
                    datalangname: 'ພາສາລາວ',
                    datalangdriection: 'ltr',
                    datalanglocale: 'lo'
                },
                {
                    value: 'lt',
                    text: 'Lietuviškai - lt_LT',
                    datalangname: 'Lietuviškai',
                    datalangdriection: 'ltr',
                    datalanglocale: 'lt_LT'
                },
                {
                    value: 'lv',
                    text: 'Latviešu valoda - lv',
                    datalangname: 'Latviešu valoda',
                    datalangdriection: 'ltr',
                    datalanglocale: 'lv'
                },
                {
                    value: 'mk',
                    text: 'македонски јазик - mk_MK',
                    datalangname: 'македонски јазик',
                    datalangdriection: 'ltr',
                    datalanglocale: 'mk_MK'
                },
                {
                    value: 'mn',
                    text: 'Монгол хэл - mn',
                    datalangname: 'Монгол хэл',
                    datalangdriection: 'ltr',
                    datalanglocale: 'mn'
                },
                {
                    value: 'in',
                    text: 'मराठी - mr',
                    datalangname: 'मराठी',
                    datalangdriection: 'ltr',
                    datalanglocale: 'mr'
                },
                {
                    value: 'my',
                    text: 'Bahasa Melayu - ms_MY',
                    datalangname: 'Bahasa Melayu',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ms_MY'
                },
                {
                    value: 'mm',
                    text: 'ဗမာစာ - my_MM',
                    datalangname: 'ဗမာစာ',
                    datalangdriection: 'ltr',
                    datalanglocale: 'my_MM'
                },
                {
                    value: 'mv',
                    text: 'Maldives - mv',
                    datalangname: 'Maldives',
                    datalangdriection: 'rtl',
                    datalanglocale: 'mv'
                },
                {
                    value: 'no',
                    text: 'Norsk Bokmål - nb_NO',
                    datalangname: 'Norsk Bokmål',
                    datalangdriection: 'ltr',
                    datalanglocale: 'nb_NO'
                },
                {
                    value: 'np',
                    text: 'नेपाली - ne_NP',
                    datalangname: 'नेपाली',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ne_NP'
                },
                {
                    value: 'nl',
                    text: 'Nederlands - nl_NL',
                    datalangname: 'Nederlands',
                    datalangdriection: 'ltr',
                    datalanglocale: 'nl_NL'
                },
                {
                    value: 'nl',
                    text: 'Nederlands - nl_NL_formal',
                    datalangname: 'Nederlands',
                    datalangdriection: 'ltr',
                    datalanglocale: 'nl_NL_formal'
                },
                {
                    value: 'no',
                    text: 'Norsk Nynorsk - nn_NO',
                    datalangname: 'Norsk Nynorsk',
                    datalangdriection: 'ltr',
                    datalanglocale: 'nn_NO'
                },
                {
                    value: 'pl',
                    text: 'Polski - pl_PL',
                    datalangname: 'Polski',
                    datalangdriection: 'ltr',
                    datalanglocale: 'pl_PL'
                },
                { value: 'af', text: 'پښتو - ps', datalangname: 'پښتو', datalangdriection: 'rtl', datalanglocale: 'ps' },
                {
                    value: 'br',
                    text: 'Português - pt_BR',
                    datalangname: 'Português',
                    datalangdriection: 'ltr',
                    datalanglocale: 'pt_BR'
                },
                {
                    value: 'pt',
                    text: 'Português - pt_PT',
                    datalangname: 'Português',
                    datalangdriection: 'ltr',
                    datalanglocale: 'pt_PT'
                },
                {
                    value: 'ro',
                    text: 'Română - ro_RO',
                    datalangname: 'Română',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ro_RO'
                },
                {
                    value: 'ru',
                    text: 'Русский - ru_RU',
                    datalangname: 'Русский',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ru_RU'
                },
                {
                    value: 'lk',
                    text: 'සිංහල - si_LK',
                    datalangname: 'සිංහල',
                    datalangdriection: 'ltr',
                    datalanglocale: 'si_LK'
                },
                {
                    value: 'sk',
                    text: 'Slovenčina - sk_SK',
                    datalangname: 'Slovenčina',
                    datalangdriection: 'ltr',
                    datalanglocale: 'sk_SK'
                },
                {
                    value: 'si',
                    text: 'Slovenščina - sl_SI',
                    datalangname: 'Slovenščina',
                    datalangdriection: 'ltr',
                    datalanglocale: 'sl_SI'
                },
                {
                    value: 'so',
                    text: 'Af-Soomaali - so_SO',
                    datalangname: 'Af-Soomaali',
                    datalangdriection: 'ltr',
                    datalanglocale: 'so_SO'
                },
                {
                    value: 'al',
                    text: 'Shqip - sq',
                    datalangname: 'Shqip',
                    datalangdriection: 'ltr',
                    datalanglocale: 'sq'
                },
                {
                    value: 'rs',
                    text: 'Српски језик - sr_RS',
                    datalangname: 'Српски језик',
                    datalangdriection: 'ltr',
                    datalanglocale: 'sr_RS'
                },
                {
                    value: 'id',
                    text: 'Basa Sunda - su_ID',
                    datalangname: 'Basa Sunda',
                    datalangdriection: 'ltr',
                    datalanglocale: 'su_ID'
                },
                {
                    value: 'se',
                    text: 'Svenska - sv_SE',
                    datalangname: 'Svenska',
                    datalangdriection: 'ltr',
                    datalanglocale: 'sv_SE'
                },
                {
                    value: 'pl',
                    text: 'Ślōnskŏ gŏdka - szl',
                    datalangname: 'Ślōnskŏ gŏdka',
                    datalangdriection: 'ltr',
                    datalanglocale: 'szl'
                },
                {
                    value: 'lk',
                    text: 'தமிழ் - ta_LK',
                    datalangname: 'தமிழ்',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ta_LK'
                },
                { value: 'th', text: 'ไทย - th', datalangname: 'ไทย', datalangdriection: 'ltr', datalanglocale: 'th' },
                {
                    value: 'ph',
                    text: 'Tagalog - tl',
                    datalangname: 'Tagalog',
                    datalangdriection: 'ltr',
                    datalanglocale: 'tl'
                },
                {
                    value: 'tr',
                    text: 'Türkçe - tr_TR',
                    datalangname: 'Türkçe',
                    datalangdriection: 'ltr',
                    datalanglocale: 'tr_TR'
                },
                {
                    value: 'cn',
                    text: 'Uyƣurqə - ug_CN',
                    datalangname: 'Uyƣurqə',
                    datalangdriection: 'ltr',
                    datalanglocale: 'ug_CN'
                },
                {
                    value: 'ua',
                    text: 'Українська - uk',
                    datalangname: 'Українська',
                    datalangdriection: 'ltr',
                    datalanglocale: 'uk'
                },
                { value: 'pk', text: 'اردو - ur', datalangname: 'اردو', datalangdriection: 'rtl', datalanglocale: 'ur' },
                {
                    value: 'uz',
                    text: 'Oʻzbek - uz_UZ',
                    datalangname: 'Oʻzbek',
                    datalangdriection: 'ltr',
                    datalanglocale: 'uz_UZ'
                },
                {
                    value: 'vn',
                    text: 'Tiếng Việt - vi',
                    datalangname: 'Tiếng Việt',
                    datalangdriection: 'ltr',
                    datalanglocale: 'vi'
                },
                {
                    value: 'cn',
                    text: '中文 (中国) - zh_CN',
                    datalangname: '中文 (中国)',
                    datalangdriection: 'ltr',
                    datalanglocale: 'zh_CN'
                },
                {
                    value: 'hk',
                    text: '中文 (香港) - zh_HK',
                    datalangname: '中文 (香港)',
                    datalangdriection: 'ltr',
                    datalanglocale: 'zh_HK'
                },
                {
                    value: 'tw',
                    text: '中文 (台灣) - zh_TW',
                    datalangname: '中文 (台灣)',
                    datalangdriection: 'ltr',
                    datalanglocale: 'zh_TW'
                },
                { value: 'tj', text: 'Tajik - tg', datalangname: 'Tajik', datalangdriection: 'ltr', datalanglocale: 'tg' }

            ],
            valueField: 'value',
            labelField: 'text',
            searchField: ['text']
        });

        // Selectize.js nesnesini al
        var selectize = mySelect[0].selectize;

        // Change olayını dinle
        selectize.on('change', function (value) {
            // Seçilen değeri ve dataInfo'yu al
            var selectedOption = selectize.options[value];
            var datalangname = selectedOption.datalangname;
            var datalangdriection = selectedOption.datalangdriection;
            var datalanglocale = selectedOption.datalanglocale;
            $('#lang_name').val(datalangname);
            $('#lang_code').val(value);
            $('#lang_locale').val(datalanglocale);

            if (datalangdriection === 'ltr') {
                document.getElementById("lang_ltr").checked = true;
                document.getElementById("lang_rtl").checked = false;
            } else if (datalangdriection === 'rtl') {
                document.getElementById("lang_rtl").checked = true;
                document.getElementById("lang_ltr").checked = false;
            }
            $('#imageSelect-selectized').prevAll('.item').first().remove();
            $('#imageSelect-selectized').parent().prepend('<div class="item" data-value="' + value + '"><img src="https://' + window.location.hostname + '/admin/model/languages/flags/' + value + '.svg " alt="' + datalangname + '"> ' + datalangname + ' </div>');


            $('#imageSelect').find('option').val(value).text(datalangname);


        });

        $('#edit_flag').each(function () {
            var langCode = $(this).data('langcode');
            var langName = $(this).data('langname');

            $('#imageSelect-selectized').prevAll('.item').first().remove();
            $('#imageSelect-selectized').parent().prepend('<div class="item" data-value="' + langCode + '"><img src="https://' + window.location.hostname + '/admin/model/languages/flags/' + langCode + '.svg " alt="' + langName + '"> ' + langName + ' </div>');

        });

    }


});

