"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EditModeDateValueEditor = exports.EditorDateListEditor = exports.DisplayModeDateValueEditor = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@material-ui/core");
const react_1 = tslib_1.__importStar(require("react"));
const styled_components_1 = tslib_1.__importDefault(require("styled-components"));
const DeleteGrayIcon_1 = require("../Icon/DeleteGrayIcon");
const DesignUI_1 = require("./DesignUI");
const Link_1 = require("../BuilderUI/Link");
var DisplayModeRender_1 = require("./DisplayModeRender");
Object.defineProperty(exports, "DisplayModeDateValueEditor", { enumerable: true, get: function () { return DisplayModeRender_1.DisplayModeValueEditor; } });
const EditorDateListEditor = (props) => {
    const [values, setValues] = (0, react_1.useState)(props.values);
    (0, react_1.useEffect)(() => {
        setValues([...props.values]);
    }, [props.values, setValues]);
    const update = (vals) => {
        props.updateCallback(vals);
        setValues([...vals]);
    };
    const onChange = (event, selectedLine) => {
        if (selectedLine >= 0) {
            values[selectedLine] = event.target.value;
            update(values);
        }
    };
    const add = () => {
        values.push("");
        update(values);
    };
    const remove = (index) => {
        values.splice(index, 1);
        update(values);
    };
    return ((0, jsx_runtime_1.jsxs)(StyledDateList, { className: "PropertyList-Wrapper DateList-Wrapper", children: [(0, jsx_runtime_1.jsx)("div", { className: "DateList", children: values &&
                    values.map((val, idx) => ((0, jsx_runtime_1.jsxs)(DesignUI_1.Row, { children: [(0, jsx_runtime_1.jsx)(core_1.TextField, { value: val, onChange: (e) => onChange(e, idx), type: props.type || "date", autoFocus: props.autFocus && idx === 0 }), (0, jsx_runtime_1.jsx)(DesignUI_1.DeleteButton, { onClick: () => remove(idx), className: "ValueEditor-delete-line", children: (0, jsx_runtime_1.jsx)(DeleteGrayIcon_1.DeleteGrayIcon, {}) })] }, idx))) }), (0, jsx_runtime_1.jsx)(Link_1.StyledLink, { onClick: add, color: "primary", classes: { root: "PropertyList-Add" }, children: "Add" })] }));
};
exports.EditorDateListEditor = EditorDateListEditor;
exports.EditModeDateValueEditor = react_1.default.forwardRef(({ value, forData, onUpdate }, ref) => {
    let values = forData.list
        ? Array.isArray(value) && typeof value !== "string"
            ? value
            : value
                ? [value]
                : []
        : Array.isArray(value) && typeof value !== "string"
            ? value[0]
            : value;
    const onValueUpdate = (newValues) => {
        onUpdate(newValues);
    };
    if (forData.list) {
        return (0, jsx_runtime_1.jsx)(exports.EditorDateListEditor, { values: values, updateCallback: onValueUpdate });
    }
    return ((0, jsx_runtime_1.jsx)(core_1.TextField, { variant: "outlined", size: "small", value: value, type: forData.storeTime ? "datetime-local" : "date", onChange: (event) => {
            onUpdate(event.target.value);
        }, placeholder: forData.name, "data-testid": `ValueEditor-Edit-date`, inputProps: {
            min: forData.lowerBounds,
            max: forData.upperBounds,
        }, InputLabelProps: { shrink: true, required: true }, inputRef: ref }));
});
const StyledDateList = styled_components_1.default.div `
    width: 100%;
    text-align: right;

    .DateList {
        display: flex;
        flex-direction: column;
        margin-bottom: 10px;

        > * {
            margin-top: 10px;
        }

        input[type="date"] {
            position: relative;

            &::-webkit-calendar-picker-indicator {
                position: absolute;
                right: 20px;
                top: 50%;
                transform: translateY(-50%);
                height: 16px;
                width: 16px;
                opacity: 0;
                color: rgba(39, 41, 50, 0.5);
            }

            &:hover::-webkit-calendar-picker-indicator {
                opacity: 1;
            }
        }
    }

    .DateList-Label {
        color: rgba(0, 0, 0, 0.54);

        font-style: normal;
        font-weight: 600;
        margin-bottom: 5px;
    }

    .DateList-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
`;
//# sourceMappingURL=Date.js.map