"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Link = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const uikit_1 = require("@gravity-ui/uikit");
const classname_1 = require("../classname.js");
const forms_1 = require("../i18n/forms/index.js");
const handlers_1 = require("../utils/handlers.js");
const TextInput_1 = require("./TextInput.js");
require("./Link.css");
const b = (0, classname_1.cn)('link');
exports.Link = (0, react_1.memo)(function LinkForm({ autoFocus, initialUrl = '', initialText = '', readOnlyText, onSubmit, onUrlChange, onTextChange, }) {
    const [url, setUrl] = (0, react_1.useState)(initialUrl);
    const [text, setText] = (0, react_1.useState)(initialText);
    const handleUrlUpdate = (v) => {
        setUrl(v);
        onUrlChange?.(v);
    };
    const handleTextUpdate = (v) => {
        setText(v);
        onTextChange?.(v);
    };
    const handleSubmit = () => {
        onSubmit({ url, text });
    };
    const inputEnterKeyHandler = (0, handlers_1.enterKeyHandler)(handleSubmit);
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(), children: [(0, jsx_runtime_1.jsx)(TextInput_1.TextInputFixed, { size: "l", hasClear: true, value: url, className: b('input'), onUpdate: handleUrlUpdate, placeholder: (0, forms_1.i18n)('link-href-placeholder'), autoFocus: autoFocus, onKeyDown: inputEnterKeyHandler }), (0, jsx_runtime_1.jsx)(TextInput_1.TextInputFixed, { size: "l", hasClear: true, value: text, className: b('input'), onUpdate: handleTextUpdate, placeholder: (0, forms_1.i18n)('link-name-placeholder'), disabled: readOnlyText, onKeyDown: inputEnterKeyHandler }), (0, jsx_runtime_1.jsx)(uikit_1.Button, { disabled: !url, className: b('submit-button'), view: "action", size: "l", onClick: handleSubmit, children: (0, forms_1.i18n)('link_add') })] }));
});
//# sourceMappingURL=Link.js.map
