"use strict";
(function ($) {
    $.field_pages = function (element, options) {
        var defaults = {
            input_name:'',
            value:''
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element), 
            element = element;
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.list-page').select2();
            let value = plugin.settings.value;
            let input_name = plugin.settings.input_name;
            $element.find(`input[name="${input_name}"]`).val(value);
            $element.find('select.list-page').on('change', function (e) {
                let val = $(this).val();
                $element.find(`input[name="${input_name}"]`).val(val);
            })

        };
        plugin.example_function = function () {
        };
        plugin.init();
    }
    
    $.fn.field_pages = function (options) {
        
        return this.each(function () {
            
            if (undefined == $(this).data('field_pages')) {
                var plugin = new $.field_pages(this, options);
                $(this).data('field_pages', plugin);
            }
        });
    }
})(jQuery);