(function(paw){
    function IdentSearchPopup(settings, localization, $trigger){
        var self = this;
        this.$popup = null;
        this.identSearch = new paw.com.identSearch.IdentSearchComponent(settings, this);
        this.localization = paw.lang.append({
            advancedIdentSearch: "@Loc.AdvancedIdentSearch"
        }, localization);
        this.$trigger = $trigger;

        if(paw.utils.value.isSet($trigger)){
            this.registerTrigger($trigger, function(){
                self.show();
            });
        }

        this.onResize = function () {
            var h = self.$popup.find('.tables-holder').height();
            self.$popup.find('.tables-holder > .result-table-holder').css({
                'min-height': h + 'px',
                'max-height': h + 'px',
                'height': h + 'px'
            });
        };
    }

    IdentSearchPopup.prototype.show = function(){
        this.initModal();
        this.identSearch.init();
    };

    IdentSearchPopup.prototype.hide = function(){
        this.$popup.customModal('close');
    };

    IdentSearchPopup.prototype.initModal = function(){
        var self = this;
        $().customModal({
            id: 'ident-search-popup',
            destroyOnClose: true,
            showCloseButton: true,
            type: "modal",
            title: this.localization.advancedIdentSearch,
            content: '<div class="ident-search-popup paw-nooverflow paw-holder">' + this.identSearch.$view() + '</div>',
            onClose: function(){
                self.identSearch.destroy();
            }
        });
        this.$popup = $('#ident-search-popup');

        this.onResize();

        $(window).on('resize', this.onResize);
    };

    IdentSearchPopup.prototype.destroy = function(){
        this.identSearch.destroy();
        if(paw.utils.value.isSet(this.$trigger)){
            this.$trigger.off('click', this.onTrigger);
        }
        $(window).off('resize', this.onResize);
    };

    IdentSearchPopup.prototype.registerTrigger = function($trigger, onTrigger){
        this.onTrigger = onTrigger;
        $trigger.on('click', this.onTrigger);
        $('.ident-search-trigger-col').removeClass('hidden');
    }

    paw.com.identSearch.IdentSearchPopup = IdentSearchPopup;
})(paw);