"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 __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var cloneDeep_1 = require("lodash/cloneDeep");
var React = require("react");
var react_1 = require("@storybook/react");
var addon_actions_1 = require("@storybook/addon-actions");
var storybook_chrome_screenshot_1 = require("storybook-chrome-screenshot");
var with_readme_1 = require("storybook-readme/with-readme");
var __1 = require("../");
var pokedex_1 = require("./assets/pokedex");
var Table_md_1 = require("./README/Table.md");
var prefixNum = function (num) { return (num.toString().length === 1 ? "0" + num : num); };
var getRowClass = function (pokemon) {
    var classNames = ['pokemon'];
    if (pokemon.caught) {
        classNames.push('pokemon--caught');
    }
    if (pokemon.Abilities.length === 1) {
        classNames.push('pokemon--one-dimensional');
    }
    return classNames;
};
var columns = [
    {
        field: 'Name',
        sortable: true
    },
    {
        field: 'pokedex_number',
        label: 'National Pokedex Number',
        sortable: true,
        render: function (value) { return React.createElement("code", null, value); }
    },
    {
        field: 'Category',
        sortable: true
    },
    {
        field: 'first_seen',
        label: 'First Seen',
        sortable: true,
        render: function (value) {
            if (value == null) {
                return null;
            }
            var d = new Date(value);
            return (React.createElement("span", null,
                d.getFullYear(),
                "-",
                prefixNum(d.getMonth() + 1),
                "-",
                prefixNum(d.getDay() + 1)));
        }
    }
];
var HOC = (function (_super) {
    __extends(HOC, _super);
    function HOC() {
        var _this = _super.call(this) || this;
        _this.state = {
            PokeDex: cloneDeep_1.default(pokedex_1.default)
        };
        _this.changeName = _this.changeName.bind(_this);
        return _this;
    }
    HOC.prototype.changeName = function (e) {
        var PokeDex = this.state.PokeDex.slice();
        PokeDex[0] = Object.assign({}, PokeDex[0], { Name: e.target.value });
        this.setState({ PokeDex: PokeDex });
    };
    HOC.prototype.render = function () {
        var PokeDex = this.state.PokeDex;
        return (React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Input, { mb: 3, value: PokeDex[0].Name, onChange: this.changeName }),
            React.createElement(__1.Table, { columns: columns, data: PokeDex })));
    };
    return HOC;
}(React.Component));
react_1.storiesOf('Core/Table', module)
    .addDecorator(with_readme_1.default(Table_md_1.default))
    .addDecorator(storybook_chrome_screenshot_1.withScreenshot())
    .add('Standard', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, onSort: addon_actions_1.action('sorting'), sort: { field: 'Name', reverse: true } }))));
})
    .add('Checkboxes', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onCheck: addon_actions_1.action('items-selected') }))));
})
    .add('Row Click', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onRowClick: addon_actions_1.action('row-clicked') }))));
})
    .add('Row Prefix', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, tbodyPrefix: React.createElement("tr", null,
                    React.createElement("td", { colSpan: columns.length },
                        React.createElement("p", { style: { textAlign: 'center' } }, "This row will always appear at the top of the table"))) }))));
})
    .add('Multiple Row Prefix', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, tbodyPrefix: [
                    React.createElement("tr", { key: 1 },
                        React.createElement("td", { colSpan: columns.length },
                            React.createElement("p", { style: { textAlign: 'center' } }, "Row 1"))),
                    React.createElement("tr", { key: 2 },
                        React.createElement("td", { colSpan: columns.length },
                            React.createElement("p", { style: { textAlign: 'center' } }, "Row 2")))
                ] }))));
})
    .add('Anchor Rows', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, getRowHref: function (row) { return "https://www.pokemon.com/uk/pokedex/" + row.Name; }, rowAnchorAttributes: { target: '_blank' } }))));
})
    .add('Anchor Rows with Checkboxes', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onCheck: addon_actions_1.action('items-selected'), getRowHref: function (row) { return "https://www.pokemon.com/uk/pokedex/" + row.Name; }, rowAnchorAttributes: { target: '_blank' } }))));
})
    .add('Highlighted rows', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', highlightedRows: [2, 5] }))));
})
    .add('Conditional classes', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Box, { m: 3 },
            React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', getRowClass: getRowClass }))));
})
    .add('Updating data in a table', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(HOC, null)));
})
    .add('Pager', function () {
    return (React.createElement(__1.Provider, null,
        React.createElement(__1.Provider, null,
            React.createElement(__1.Box, { m: 3 },
                React.createElement(__1.Table, { columns: columns, data: pokedex_1.default, usePager: true, itemsPerPage: 3 })))));
});
