!(function (a) {
    "use strict";

    function c(c, d) {
        this.element = a(c),
        this.settings = a.extend({}, b, d),
        this.iconPicker = a("<div/>", {
            class: "icons-selector",
            style: "position: relative",
            html:
                '<div class="selector"><span class="selected-icon"><i class="fa-times-circle-o"></i></span><span class="selector-button"><i class="fip-icon-down-dir"></i></span></div><div class="selector-popup" style="display: none;">' +
                (this.settings.hasSearch ? '<div class="selector-search"><input type="text" name="" value="" placeholder="Search icon" class="icons-search-input"/><i class="fip-icon-search"></i></div>' : "") +
                '<div class="selector-category">' +
                '<select name="" class="icon-category-select" style="display: none">' +
                "</select>" +
                "</div>" +
                '<div class="fip-icons-container"></div>' +
                '<div class="selector-footer" style="display:none;">' +
                '<span class="selector-pages">1/2</span>' +
                '<span class="selector-arrows">' +
                '<span class="selector-arrow-left" style="display:none;">' +
                '<i class="fip-icon-left-dir"></i>' +
                "</span>" +
                '<span class="selector-arrow-right">' +
                '<i class="fip-icon-right-dir"></i>' +
                "</span>" +
                "</span>" +
                "</div>" +
                "</div>",
        })),
        this.iconContainer = this.iconPicker.find(".fip-icons-container"),
        this.searchIcon = this.iconPicker.find(".selector-search i"),
        this.iconsSearched = [],
        this.isSearch = !1,
        this.totalPage = 1,
        this.currentPage = 1,
        this.currentIcon = !1,
        this.iconsCount = 0,
        this.open = !1,
        this.searchValues = [],
        this.init();
    }

    var b = {
        theme: "fip-grey",
        source: ['fa-glass', 'fa-music', 'fa-search', 'fa-heart'], // Pass icons dynamically here
        emptyIcon: !0,
        emptyIconValue: "",
        iconsPerPage: 20,
        hasSearch: !0,
    };

    c.prototype = {
        init: function () {
            this.iconPicker.addClass(this.settings.theme),
            this.iconPicker.css({ left: -9999 }).appendTo("body");
            var b = this.iconPicker.outerHeight(),
                c = this.iconPicker.outerWidth();
            if (
                (this.iconPicker.css({ left: "" }),
                this.element.before(this.iconPicker),
                this.element.css({
                    visibility: "hidden",
                    top: 0,
                    position: "relative",
                    zIndex: "-1",
                    left: "-" + c + "px",
                    display: "inline-block",
                    height: b + "px",
                    width: c + "px",
                    padding: "0",
                    margin: "0 -" + c + "px 0 0",
                    border: "0 none",
                    verticalAlign: "top",
                })),
                this.loadIcons(),
                this.iconPicker.find(".selector-button").click(
                    a.proxy(function () {
                        this.toggleIconSelector();
                    }, this)
                ),
                this.iconPicker.find(".icons-search-input").keyup(
                    a.proxy(function (b) {
                        var c = a(b.currentTarget).val();
                        return "" === c
                            ? (this.resetSearch(), void 0)
                            : (this.searchIcon.removeClass("fip-icon-search"),
                              this.searchIcon.addClass("fip-icon-cancel"),
                              (this.isSearch = !0),
                              (this.currentPage = 1),
                              (this.iconsSearched = []),
                              a.grep(
                                  this.settings.source,
                                  a.proxy(function (a, b) {
                                      return a.toLowerCase().includes(c.toLowerCase())
                                          ? ((this.iconsSearched[this.iconsSearched.length] = a), !0)
                                          : void 0;
                                  }, this)
                              ),
                              this.renderIconContainer(),
                              void 0);
                    }, this)
                ),
                this.iconContainer.on(
                    "click",
                    ".fip-box",
                    a.proxy(function (b) {
                        this.setSelectedIcon(a(b.currentTarget).find("i").attr("data-fip-value")), this.toggleIconSelector();
                    }, this)
                ),
                this.iconPicker.click(function (a) {
                    return a.stopPropagation(), !1;
                }),
                a("html").click(
                    a.proxy(function () {
                        this.open && this.toggleIconSelector();
                    }, this)
                );
        },

        loadIcons: function () {
            this.iconContainer.html('<i class="fip-icon-spin3 animate-spin loading"></i>');
            this.renderIconContainer();
        },

        renderIconContainer: function () {
            var c = this.isSearch ? this.iconsSearched : this.settings.source;
            this.iconsCount = c.length;
            this.totalPage = Math.ceil(this.iconsCount / this.settings.iconsPerPage);
            var b = (this.currentPage - 1) * this.settings.iconsPerPage;
            this.iconContainer.html("");
            for (var d = 0; d < c.length; d++) {
                var icon = c[d];
                a("<span/>", {
                    html:
                        '<i data-fip-value="' +
                        icon +
                        '" class="fa ' +
                        icon +
                        '"></i>',
                    class: "fip-box",
                }).appendTo(this.iconContainer);
            }
            this.setSelectedIcon(c[0]);
        },

        setSelectedIcon: function (a) {
            if (this.settings.useAttribute)
                a
                    ? this.iconPicker.find(".selected-icon").html("<i " + this.settings.attributeName + '="' + a + '"></i>')
                    : this.iconPicker.find(".selected-icon").html('<i class="fa-times-circle-o"></i>');
            else
                this.iconPicker.find(".selected-icon").html('<i class="fa ' + (a || "fa-times-circle-o") + '"></i>');
            this.element.val(a || "").trigger("change");
        },

        toggleIconSelector: function () {
            (this.open = this.open ? 0 : 1),
            this.iconPicker.find(".selector-popup").slideToggle(300),
            this.iconPicker.find(".selector-button i").toggleClass("fip-icon-down-dir"),
            this.iconPicker.find(".selector-button i").toggleClass("fip-icon-up-dir"),
            this.open && this.iconPicker.find(".icons-search-input").focus().select();
        },

        resetSearch: function () {
            this.iconPicker.find(".icons-search-input").val(""),
            this.searchIcon.removeClass("fip-icon-cancel"),
            this.searchIcon.addClass("fip-icon-search"),
            this.renderIconContainer();
        },
    };

    a.fn.fontIconPicker = function (b) {
        return this.each(function () {
            a.data(this, "fontIconPicker") || a.data(this, "fontIconPicker", new c(this, b));
        });
    });
})(jQuery);
