"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 });
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = __importDefault(require("react"));
var Text_1 = __importDefault(require("../../../components/Text"));
var styles_1 = __importStar(require("../../../utils/styles"));
var Input = styles_1.default.input(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  height: ", ";\n  padding: ", ";\n  border-radius: 8px;\n  box-sizing: border-box;\n  border: 1px solid\n    ", ";\n  background: ", ";\n  color: ", ";\n  transition: border-color ", " ease-in-out;\n  ", "\n"], ["\n  height: ", ";\n  padding: ", ";\n  border-radius: 8px;\n  box-sizing: border-box;\n  border: 1px solid\n    ", ";\n  background: ", ";\n  color: ", ";\n  transition: border-color ", " ease-in-out;\n  ", "\n"])), function (_a) {
    var $size = _a.$size;
    return $size === 'large' ? '52px' : $size === 'medium' ? '40px' : '36px';
}, function (_a) {
    var $size = _a.$size;
    return $size === 'large'
        ? '16px 16px'
        : $size === 'medium'
            ? '10px 12px'
            : '8px 12px';
}, function (_a) {
    var $isFocus = _a.$isFocus, $isDisabled = _a.$isDisabled;
    return $isDisabled
        ? styles_1.theme.color.semantic.danger
        : $isFocus
            ? styles_1.theme.color.primary.default
            : styles_1.theme.color.gray[200];
}, styles_1.theme.color.gray[200], styles_1.theme.color.extra.black, styles_1.theme.duration, function (_a) {
    var $isInContainer = _a.$isInContainer;
    return $isInContainer
        ? (0, styles_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n          width: 100%;\n        "], ["\n          width: 100%;\n        "]))) : undefined;
});
var MessageContainer = styles_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  height: 22px;\n  overflow: hidden;\n  display: flex;\n  flex-direction: column;\n  justify-content: flex-end;\n"], ["\n  height: 22px;\n  overflow: hidden;\n  display: flex;\n  flex-direction: column;\n  justify-content: flex-end;\n"])));
var MessageText = (0, styles_1.default)(Text_1.default)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n  margin-top: 4px;\n  opacity: ", ";\n  transition: opacity ", " ease-in-out;\n"], ["\n  margin-top: 4px;\n  opacity: ", ";\n  transition: opacity ", " ease-in-out;\n"])), function (_a) {
    var $isDisplay = _a.$isDisplay;
    return ($isDisplay ? 1 : 0);
}, styles_1.theme.duration);
exports.default = react_1.default.forwardRef(function (_a, ref) {
    var _b = _a.size, size = _b === void 0 ? 'medium' : _b, value = _a.value, _c = _a.isDisabled, _isDisabled = _c === void 0 ? false : _c, schema = _a.schema, _d = _a.defaultMessageText, defaultMessageText = _d === void 0 ? '' : _d, _e = _a.disabledMessageText, disabledMessageText = _e === void 0 ? '' : _e, onChangeValue = _a.onChangeValue, onEnter = _a.onEnter, props = __rest(_a, ["size", "value", "isDisabled", "schema", "defaultMessageText", "disabledMessageText", "onChangeValue", "onEnter"]);
    var _f = react_1.default.useState(false), isFocus = _f[0], setIsFocus = _f[1];
    var onChange = react_1.default.useCallback(function (event) {
        return onChangeValue === null || onChangeValue === void 0 ? void 0 : onChangeValue(event.target.value);
    }, [onChangeValue]);
    var onFocus = react_1.default.useCallback(function () { return setIsFocus(true); }, []);
    var onBlur = react_1.default.useCallback(function () { return setIsFocus(false); }, []);
    var isDisabled = react_1.default.useMemo(function () {
        return _isDisabled
            ? true
            : value && schema
                ? !schema.safeParse(value).success
                : false;
    }, [_isDisabled, schema, value]);
    var onKeyUp = react_1.default.useCallback(function (event) {
        if (event.code === 'Enter') {
            onEnter === null || onEnter === void 0 ? void 0 : onEnter();
        }
        event.preventDefault();
    }, [onEnter]);
    return defaultMessageText || disabledMessageText ? ((0, jsx_runtime_1.jsxs)("div", __assign({}, props, { children: [(0, jsx_runtime_1.jsx)(Input, { ref: ref, "$size": size, "$isFocus": isFocus, "$isDisabled": isDisabled, "$isInContainer": true, value: value, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onKeyUp: onKeyUp }), (0, jsx_runtime_1.jsx)(MessageContainer, { children: (0, jsx_runtime_1.jsx)(MessageText, { type: "b8", "$isDisplay": isDisabled || !!defaultMessageText, "$color": isDisabled ? styles_1.theme.color.semantic.danger : styles_1.theme.color.gray[800], "$ellipsis": true, value: isDisabled ? disabledMessageText : defaultMessageText }) })] }))) : ((0, jsx_runtime_1.jsx)(Input, __assign({ ref: ref, "$size": size, "$isFocus": isFocus, "$isDisabled": isDisabled, "$isInContainer": false, value: value, onChange: onChange, onFocus: onFocus, onBlur: onBlur, onKeyUp: onKeyUp }, props)));
});
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
//# sourceMappingURL=index.js.map