"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Input = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const styled_components_1 = __importDefault(require("styled-components"));
const react_number_format_1 = __importDefault(require("react-number-format"));
const utils_1 = require("../../theme/utils");
const Grid_1 = require("../Grid");
const Icon_1 = require("../Icon");
const Flex_1 = require("../Flex");
const Text_1 = require("../Text");
const Tooltip_1 = require("../Tooltip");
const InputWrapper = styled_components_1.default(Grid_1.Grid)(({ theme, error, disabled }) => (Object.assign(Object.assign(Object.assign({ backgroundColor: (theme.INPUT || { backgroundColor: 'unset' })
        .backgroundColor, padding: (theme.INPUT || { padding: 0 }).padding, border: (theme.INPUT || { border: 0 }).border, borderRadius: (theme.INPUT || { borderRadius: 0 }).borderRadius, transition: (theme.INPUT || { transition: 'unset' }).transition }, (error ? { borderColor: theme.COLOR.danger } : {})), (theme.INPUT && theme.INPUT['&:focus']
    ? { '&:focus-within': theme.INPUT['&:focus'] }
    : {})), (disabled && theme.INPUT && theme.INPUT['&:disabled']
    ? theme.INPUT['&:disabled']
    : {}))));
const Component = styled_components_1.default.input(({ theme }) => (Object.assign(Object.assign({}, (theme.INPUT || {})), { margin: 0, padding: 0, border: 0, borderRadius: 0, borderColor: 'transparent', WebkitAppearance: 'none', outline: 'none' })));
const Unit = styled_components_1.default.div(({ theme }) => ({
    margin: utils_1.getMargin({ theme, margin: '0 0 0 s' }),
    padding: 0,
    color: theme.COLOR.gray3,
}));
const Input = (_a) => {
    var { variant, margin, type, label, tooltip, icon, unit, error, isDivisible = true, disabled } = _a, props = __rest(_a, ["variant", "margin", "type", "label", "tooltip", "icon", "unit", "error", "isDivisible", "disabled"]);
    const isBasic = variant === 'basic';
    const isAmount = variant === 'amount';
    const componentProps = Object.assign(Object.assign(Object.assign(Object.assign({}, props), { disabled }), (isBasic ? { type } : {})), (isAmount
        ? {
            thousandSeparator: true,
            allowNegative: false,
            decimalScale: isDivisible ? 6 : 0,
            onWheel: (e) => {
                e.currentTarget.blur();
            },
        }
        : {}));
    return (jsx_runtime_1.jsxs(Text_1.Text, Object.assign({ variant: "label", display: "block", margin: margin }, { children: [label && tooltip && (jsx_runtime_1.jsxs(Flex_1.Flex, Object.assign({ variant: "raw", justify: tooltip ? 'spaced' : 'start' }, { children: [jsx_runtime_1.jsx(Text_1.Text, Object.assign({ variant: "span", format: "b2m" }, { children: label }), void 0), tooltip && jsx_runtime_1.jsx(Tooltip_1.Tooltip, { variant: "icon", content: tooltip }, void 0)] }), void 0)), jsx_runtime_1.jsxs(InputWrapper, Object.assign({ variant: "raw", align: "center", cols: `${icon ? 'auto ' : ''}1fr${unit ? ' auto' : ''}`, error: error, disabled: disabled }, { children: [icon && (jsx_runtime_1.jsx(Icon_1.Icon, { icon: icon, variant: "basic", size: "24px", color: "gray3", margin: "0 s 0 0" }, void 0)), jsx_runtime_1.jsx(Component, Object.assign({ as: isAmount ? react_number_format_1.default : 'input' }, componentProps), void 0), unit && jsx_runtime_1.jsx(Unit, { children: unit }, void 0)] }), void 0), error && (jsx_runtime_1.jsx(Text_1.Text, Object.assign({ variant: "span", format: "b3", color: "danger" }, { children: error }), void 0))] }), void 0));
};
exports.Input = Input;
//# sourceMappingURL=Input.js.map