(function(paw, _super){

    paw.lang.extend(IdentSearchReviewTable, _super);
    function IdentSearchReviewTable(searchData, stockDatatable){
        _super.call(this, {
            url: "/IdentSearch/FindIdent",
            tableSelector: '.ident-search-table-review',
            columns: [
                {
                    "data": "Active",
                    render: function (data, type, entity, table) {
                        return '<i class="fa fa-check paw-tc-primary"></i>'
                        return "<input name='ident-search-selection-" + entity.Id + "' class='checkForStatus' type='checkbox' data-ident-search-selection='" + entity.Id + "' />";
                    }
                },
                { "data": "Ident" },
                { "data": "Name" },
                { "data": "Code" },
                { "data": "UM" },
                { "data": "Classification" },
                { "data": "IdentType" },
                { "data": "SecondaryClassification" }
            ]
        });
        this.searchData = searchData;
        this.stockDatatable = stockDatatable;
        this.onRowSelected = function(){

        };
    }

    IdentSearchReviewTable.prototype.request = function(params){
        for(var k in this.searchData){
            if (k === 'FindOnChange' || k === 'Quantity'){
                continue;
            }
            var val = this.searchData[k];
            if(paw.utils.value.isSet(val) && ((paw.utils.value.isString(val) && val.length > 0) || !paw.utils.value.isString(val))){
                params[k] = val;
            }
        }
        return params;
    };

    IdentSearchReviewTable.prototype.onRendered = function () {
        if (this.data.length === 0) {
            this.stockDatatable.setIdent(null);
            this.stockDatatable.clearData();
            return;
        }
        var selected = this.selection[0];
        if (paw.utils.value.isSet(selected) && paw.utils.iterable.exists(this.data, function (item) {
            return item.Id === selected.Id;
        })) {
            this.selectEntity(selected.Id);
            return;
        }
        this.selectEntity(this.data[0].Id);
    };

    IdentSearchReviewTable.prototype.onEntitySelected = function (data) {
        if (this.data.length === 0) {
            return;
        }
        this.stockDatatable.setIdent(data.Ident);
        if(this.stockDatatable.isInit){
            this.stockDatatable.reload();
        }
    };

    paw.com.identSearch.IdentSearchReviewTable = IdentSearchReviewTable;
})(paw, paw.com.identSearch.IdentSearchTable);