"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Input = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const CrossOutlineMd_1 = require("../../../icons/CrossOutlineMd");
const DownOutlineMd_1 = require("../../../icons/DownOutlineMd");
const IconButton_1 = require("../../IconButton");
const Loader_1 = require("../../Loader");
const constants_1 = require("./constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const ClearButton = ({ disabled, onClick }) => ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, onClick: onClick, title: constants_1.CLEAR_TEXT, "aria-label": constants_1.CLEAR_TEXT, children: (0, jsx_runtime_1.jsx)(CrossOutlineMd_1.CrossOutlineMd, {}) }));
exports.Input = (0, react_1.forwardRef)(({ disabled, onChange: propsOnChange, value, inputRef, hideHelperText = false, onClick, isLoading, ...restProps }, forwardedRef) => {
    const { isVisibleClearButton, isVisibleTagsList, onChange, textFieldProps, onClearAll, } = (0, useLogic_1.useLogic)({
        inputRef,
        value,
        onChange: propsOnChange,
        disabled,
        onClick,
        isLoading,
    });
    return ((0, jsx_runtime_1.jsx)(styles_1.StyledTextField, { ...restProps, hideHelperText: hideHelperText, ref: forwardedRef, disabled: disabled, inputProps: { readOnly: true }, ...textFieldProps, startAdornment: isVisibleTagsList && ((0, jsx_runtime_1.jsx)(styles_1.StyledTagsList, { data: value, keyId: "id", isDisabled: disabled, getOptionLabel: (option) => option.label, onClick: onClick, onChange: onChange })), endAdornment: (0, jsx_runtime_1.jsxs)(styles_1.IconWrapper, { children: [isVisibleClearButton && ((0, jsx_runtime_1.jsx)(ClearButton, { disabled: disabled, onClick: onClearAll })), isLoading ? ((0, jsx_runtime_1.jsx)(Loader_1.Loader, { size: "small" })) : ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, children: (0, jsx_runtime_1.jsx)(DownOutlineMd_1.DownOutlineMd, {}) }))] }) }));
});
