"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VersionList = void 0;
const react_1 = __importDefault(require("react"));
const react_router_dom_1 = require("react-router-dom");
const Dropdown_1 = require("../dropdown/Dropdown");
require("../dropdown/dropdown.scss");
require("./version-dropdown.scss");
const formatDate = dateObject => new Date(dateObject).toISOString().split('T')[0];
const VersionList = ({ items, selected, setSelected, className, dateModified, datasetId, hasEdit, }) => {
    const deprecatedItem = (itemTag, itemCreated) => {
        setSelected(itemTag);
    };
    const setVersion = (itemTag, itemCreated) => {
        setSelected(itemTag);
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { className: "active-version" },
            react_1.default.createElement("div", null, selected === 'draft' ? 'Draft' : selected),
            selected === 'draft' ? 'Updated' : 'Created',
            ": ",
            dateModified),
        items.length ? (react_1.default.createElement(Dropdown_1.Dropdown, { className: className, label: react_1.default.createElement("div", { className: "version-list-label" },
                react_1.default.createElement("b", null, "Versions"),
                react_1.default.createElement("i", { className: "fas fa-chevron-up" }),
                react_1.default.createElement("i", { className: "fas fa-chevron-down" })) },
            react_1.default.createElement("div", { className: "version-list-dropdown" },
                react_1.default.createElement("ul", null,
                    react_1.default.createElement("li", { onClick: () => setVersion('draft', dateModified), className: selected === 'draft' ? 'selected' : '' },
                        react_1.default.createElement(react_router_dom_1.Link, { className: "dataset-tool", to: '/datasets/' + datasetId },
                            react_1.default.createElement("span", { className: "label" },
                                "Draft",
                                react_1.default.createElement("span", { className: "active" }, selected === 'draft' ? '*' : '')),
                            dateModified)),
                    items.map((item, index) => (react_1.default.createElement("li", { key: index, onClick: item.deprecated === true
                            ? () => deprecatedItem(item.tag, item.created)
                            : () => setVersion(item.tag, formatDate(item.created)), className: selected === item.tag ? 'selected' : '' },
                        react_1.default.createElement(react_router_dom_1.Link, { className: "dataset-tool", to: '/datasets/' + datasetId + '/versions/' + item.tag },
                            react_1.default.createElement("span", { className: "label" },
                                "v",
                                item.tag,
                                react_1.default.createElement("span", { className: "active" }, selected === item.tag ? '*' : ''),
                                react_1.default.createElement("span", { className: "deprecated" }, item.deprecated === true ? 'Deprecated' : '')),
                            formatDate(item.created))))))))) : hasEdit ? (react_1.default.createElement(react_router_dom_1.Link, { className: "dataset-tool", to: '/datasets/' + datasetId + '/snapshot' }, "Create Version")) : null));
};
exports.VersionList = VersionList;
