"use strict";
(function ($) {
    $.field_customaddress = function (element, options) {
        var defaults = {
            input_name: ""
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element), 
            element = element;
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            let location_id = $element.find('select.list-address').val();
            plugin.change_location(location_id);
            $element.find('.list-address').select2();
            $element.find('.list-address').on('change',function (e) {
                let location_id = $(this).val();
                plugin.change_location(location_id);
            });
        };
        plugin.change_location = function (location_id) {
            if (location_id !== "") {
                $element.find('.wrapper-custom-address').hide();
            } else {
                $element.find('.wrapper-custom-address').show();
            }
        };
        plugin.example_function = function () {
        };
        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);
