"use strict";
(function ($) {
    $.field_colorpicker = 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);
            $element.find('.color-item').on('click',function (e) {
                $element.find('.color-item').removeClass('active');
                $(this).addClass('active');
                let color = $(this).data('color');
                $element.find(`input[name="${plugin.settings.input_name}"]`).val(color);
            });
        };
        plugin.example_function = function () {
        };
        plugin.init();
    }
    
    $.fn.field_colorpicker = function (options) {
        
        return this.each(function () {
            
            if (undefined == $(this).data('field_colorpicker')) {
                var plugin = new $.field_colorpicker(this, options);
                $(this).data('field_colorpicker', plugin);
            }
        });
    }
})(jQuery);