import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { TextField } from "@material-ui/core";
import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { DeleteGrayIcon } from "../Icon/DeleteGrayIcon";
import { Row, DeleteButton } from "./DesignUI";
import { StyledLink } from "../BuildUI/Link";
export { DisplayModeValueEditor as DisplayModeDateValueEditor } from "./DisplayModeRender";
export const EditorDateListEditor = (props) => {
    const [values, setValues] = useState(props.values);
    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 (_jsxs(StyledDateList, Object.assign({ className: "PropertyList-Wrapper DateList-Wrapper" }, { children: [_jsx("div", Object.assign({ className: "DateList" }, { children: values &&
                    values.map((val, idx) => (_jsxs(Row, { children: [_jsx(TextField, { value: val, onChange: (e) => onChange(e, idx), type: props.type || "date", autoFocus: props.autFocus && idx === 0 }, void 0),
                            _jsx(DeleteButton, Object.assign({ onClick: () => remove(idx), className: "ValueEditor-delete-line" }, { children: _jsx(DeleteGrayIcon, {}, void 0) }), void 0)] }, idx))) }), void 0),
            _jsx(StyledLink, Object.assign({ onClick: add, color: "primary", classes: { root: "PropertyList-Add" } }, { children: "Add" }), void 0)] }), void 0));
};
export const EditModeDateValueEditor = React.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 _jsx(EditorDateListEditor, { values: values, updateCallback: onValueUpdate }, void 0);
    }
    return (_jsx(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 }, void 0));
});
const StyledDateList = styled.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-family: Mulish;
        font-style: normal;
        font-weight: 600;
        margin-bottom: 5px;
    }

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