"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var prop_types_1 = __importDefault(require("prop-types"));
var utils_1 = require("../utils");
var CommonList_1 = require("../common/CommonList");
var LocalStorage_1 = require("../../../data/LocalStorage");
var List = /** @class */ (function (_super) {
    __extends(List, _super);
    function List(props, context) {
        var _this = _super.call(this, props, context) || this;
        _this.renderItem = _this.renderItem.bind(_this);
        _this.onStoreChange = _this.onStoreChange.bind(_this);
        _this.state = {
            rows: _this.props.store.getData()
        };
        _this._context = {
            listStore: _this.props.store,
            localStorage: new LocalStorage_1.LocalStorage(_this.props.store.stateName || 'List')
        };
        return _this;
    }
    List.prototype.getChildContext = function () {
        return this._context;
    };
    List.prototype.componentDidMount = function () {
        this.props.store.onChange(this.onStoreChange);
    };
    List.prototype.componentWillUnmount = function () {
        this.unmounted = true;
        this.props.store.off('change', this.onStoreChange);
    };
    List.prototype.onStoreChange = function (data) {
        if (this.unmounted) {
            return;
        }
        this.setState({ rows: data });
    };
    List.prototype.highlight = function (text) {
        return utils_1.highlight(this.props.store.textFilterPattern, text);
    };
    List.prototype.getDetails = function () {
        return {
            sortingDirection: this.props.store.getSortingDirection(),
            highlight: this.highlight.bind(this)
        };
    };
    List.prototype.hasItems = function () {
        return this.props.store.getFilteredCount() > 0;
    };
    List.prototype.isEmptyList = function () {
        return (this.props.store.isLoaded() &&
            !this.props.store.hasFilters() &&
            !this.props.store.getTotalCount());
    };
    List.prototype.isEmptyListMessageVisible = function () {
        return this.props.store.isLoaded() && !this.hasItems();
    };
    List.prototype.renderItems = function () {
        return this.state.rows.map(this.renderItem);
    };
    List.childContextTypes = {
        listStore: prop_types_1.default.object,
        localStorage: prop_types_1.default.instanceOf(LocalStorage_1.LocalStorage)
    };
    List.propTypes = __assign({}, CommonList_1.CommonList.propTypes, { store: prop_types_1.default.object.isRequired });
    return List;
}(CommonList_1.CommonList));
exports.List = List;
//# sourceMappingURL=List.js.map