(function ($) {
    $.field_customaddress = function (element, options) {
        var defaults = {
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element), 
            element = element;    
        
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.wrapper-custom-address').addClass('hide-element');
            $element.find('.list-address').select2();
            $element.find('.list-address').change(function (e) {
                let location_id = $(this).val();
                plugin.change_location(location_id);
            });

        }
        plugin.example_function = function () {
        };
        plugin.change_location = function (location_id) {
            if (location_id !== "") {
                $element.find('.wrapper-custom-address').hide();
            } else {
                $element.find('.wrapper-custom-address').show();
            }
        };
        plugin.init();
    }
    
    $.fn.field_customaddress = function (options) {
        
        return this.each(function () {
            
            if (undefined == $(this).data('field_customaddress')) {
                var plugin = new $.field_customaddress(this, options);
                $(this).data('field_customaddress', plugin);
            }
        });
    }
})(jQuery);
