"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkForm = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const uikit_1 = require("@gravity-ui/uikit");
const forms_1 = require("../i18n/forms/index.js");
const handlers_1 = require("../utils/handlers.js");
const TextInput_1 = require("./TextInput.js");
const UrlInputRow_1 = require("./UrlInputRow.js");
const base_1 = tslib_1.__importDefault(require("./base/index.js"));
exports.LinkForm = (0, react_1.memo)(function LinkForm({ className, autoFocus, initialUrl, initialText, readOnlyText, onSubmit, onCancel, }) {
    const [url, setUrl] = (0, react_1.useState)(initialUrl ?? '');
    const [text, setText] = (0, react_1.useState)(initialText ?? '');
    const handleSubmit = () => {
        onSubmit({ url, text });
    };
    const inputEnterKeyHandler = (0, handlers_1.enterKeyHandler)(handleSubmit);
    return ((0, jsx_runtime_1.jsxs)(base_1.default.Form, { className: className, children: [(0, jsx_runtime_1.jsxs)(base_1.default.Layout, { children: [(0, jsx_runtime_1.jsx)(base_1.default.Row, { label: (0, forms_1.i18n)('common_link'), help: (0, forms_1.i18n)('link_url_help'), control: (0, jsx_runtime_1.jsx)(UrlInputRow_1.UrlInputRow, { href: url, input: (0, jsx_runtime_1.jsx)(TextInput_1.TextInputFixed, { size: "s", view: "normal", value: url, onUpdate: setUrl, autoFocus: autoFocus, placeholder: "https://", onKeyPress: inputEnterKeyHandler }) }) }), (0, jsx_runtime_1.jsx)(base_1.default.Row, { label: (0, forms_1.i18n)('link_text'), help: (0, forms_1.i18n)('link_text_help'), control: (0, jsx_runtime_1.jsx)(uikit_1.TextInput, { size: "s", view: "normal", value: text, onUpdate: setText, disabled: readOnlyText, onKeyPress: inputEnterKeyHandler }) })] }), (0, jsx_runtime_1.jsx)(base_1.default.Footer, { onCancel: onCancel, onSubmit: handleSubmit })] }));
});
//# sourceMappingURL=LinkForm.js.map
