"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __extends = (this && this.__extends) || (function () {
    var 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 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 _ = require("lodash");
var React = require("react");
var react_1 = require("@storybook/react");
var with_readme_1 = require("storybook-readme/with-readme");
var styled_components_1 = require("styled-components");
var _1 = require("../");
var pokedex_1 = require("./assets/pokedex");
var Readme = require("./README/Table.md");
var Container = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  margin: 30px;\n"], ["\n  margin: 30px;\n"])));
var prefixNum = function (num) { return (num.toString().length === 1 ? "0" + num : num); };
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(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(Container, null,
            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(Readme))
    .add('Standard', function () {
    return (React.createElement(Container, null,
        React.createElement(_1.Table, { columns: columns, data: pokedex_1.default })));
})
    .add('Checkboxes', function () {
    return (React.createElement(Container, null,
        React.createElement(_1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onCheck: react_1.action('items-selected') })));
})
    .add('Row Click', function () {
    return (React.createElement(Container, null,
        React.createElement(_1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onRowClick: react_1.action('row-clicked') })));
})
    .add('Row Prefix', function () {
    return (React.createElement(Container, null,
        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(Container, null,
        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(Container, null,
        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(Container, null,
        React.createElement(_1.Table, { columns: columns, data: pokedex_1.default, rowKey: 'pokedex_number', onCheck: react_1.action('items-selected'), getRowHref: function (row) { return "https://www.pokemon.com/uk/pokedex/" + row.Name; }, rowAnchorAttributes: { target: '_blank' } })));
})
    .add('Updating data in a table', function () {
    return React.createElement(HOC, null);
});
var templateObject_1;
