"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_2 = require("@storybook/react");
const addon_info_1 = require("@storybook/addon-info");
const index_1 = __importDefault(require("./index"));
const lodash_1 = __importDefault(require("lodash"));
let counter = 0;
class DemoTable extends react_1.Component {
    constructor(props) {
        super(props);
        this._onRequestSort = column => {
            let { columnData } = this.state;
            let orderBy = column.id;
            let order = '';
            if (column.sorted) {
                let newColumn = column;
                newColumn.sorted = true;
                if (column.order === 'asc') {
                    order = 'desc';
                }
                else if (column.order === 'desc') {
                    order = 'asc';
                }
                newColumn.order = order;
                let pos = lodash_1.default.findIndex(columnData, { id: column.id });
                columnData[pos] = newColumn;
                this.setState({ columnData });
            }
            else {
                let pos = lodash_1.default.findIndex(columnData, { id: column.id });
                let alreadySortedColumn = lodash_1.default.find(columnData, { sorted: true });
                alreadySortedColumn.sorted = false;
                columnData[pos].sorted = true;
                columnData[pos].order = 'asc';
                order = 'asc';
                this.setState({ columnData });
            }
            const data = order === 'desc'
                ? this.state.data.sort((a, b) => (b[orderBy] < a[orderBy] ? -1 : 1))
                : this.state.data.sort((a, b) => (a[orderBy] < b[orderBy] ? -1 : 1));
            this.setState({ data });
        };
        this._onRemoveClicked = row => {
            let { data } = this.state;
            lodash_1.default.remove(data, { id: row.id });
            this.setState({ data });
        };
        const columnData = [
            { id: 'firstName', label: 'First Name', type: 'string' },
            { id: 'lastName', label: 'Last Name', type: 'string' },
            {
                id: 'email',
                label: 'Email',
                sorted: true,
                order: 'asc',
                type: 'string',
            },
            { id: 'title', label: 'Title', type: 'string' },
        ];
        let data = [
            {
                id: 3,
                firstName: 'Eloy',
                lastName: 'Roberts',
                email: 'Anabel40@yahoo.com',
                title: 'Customer Interactions Associate',
            },
            {
                id: 6,
                firstName: 'Adolphus',
                lastName: 'Cormier',
                email: 'Anne35@hotmail.com',
                title: 'Dynamic Accountability Administrator',
            },
            {
                id: 4,
                firstName: 'Dewitt',
                lastName: 'Kozey',
                email: 'Cletus_King@gmail.com',
                title: 'Internal Interactions Orchestrator',
            },
            {
                id: 5,
                firstName: 'Fausto',
                lastName: 'Bahringer',
                email: 'Deja5@gmail.com',
                title: 'Dynamic Infrastructure Orchestrator',
            },
            {
                id: 2,
                firstName: 'Shemar',
                lastName: 'Ledner',
                email: 'Guillermo16@yahoo.com',
                title: 'Global Metrics Consultant',
            },
            {
                id: 1,
                firstName: 'Toney',
                lastName: 'Ritchie',
                email: 'Hester40@yahoo.com',
                title: 'Future Integration Assistant',
            },
            {
                id: 8,
                firstName: 'Al',
                lastName: 'Willms',
                email: 'Itzel76@hotmail.com',
                title: 'Lead Identity Supervisor',
            },
            {
                id: 9,
                firstName: 'Kamren',
                lastName: 'Wyman',
                email: 'Magdalena50@yahoo.com',
                title: 'Lead Security Agent',
            },
            {
                id: 0,
                firstName: 'Ricardo',
                lastName: 'Heidenreich',
                email: 'Nathanael.Aufderhar@yahoo.com',
                title: 'Dynamic Metrics Representative',
            },
            {
                id: 7,
                firstName: 'Martin',
                lastName: 'Harvey',
                email: 'Vickie18@hotmail.com',
                title: 'Global Intranet Orchestrator',
            },
        ].sort((a, b) => (a.email < b.email ? -1 : 1));
        this.state = {
            columnData,
            data,
        };
    }
    render() {
        const { columnData, data } = this.state;
        return (react_1.default.createElement(index_1.default, { columnData: columnData, data: data, sortable: true, onRequestSort: this._onRequestSort, onRemoveClicked: this._onRemoveClicked, loading: true }));
    }
}
exports.default = DemoTable;
react_2.storiesOf('Table', module).add('Default', addon_info_1.withInfo('Default')(() => (react_1.default.createElement("div", { style: { margin: '10px' } },
    react_1.default.createElement(DemoTable, null)))));
//# sourceMappingURL=index.story.js.map