import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useState } from 'react';
import { TextInput } from '@gravity-ui/uikit';
import { i18n } from "../i18n/forms/index.js";
import { enterKeyHandler } from "../utils/handlers.js";
import { TextInputFixed } from "./TextInput.js";
import { UrlInputRow } from "./UrlInputRow.js";
import Form from "./base/index.js";
export const LinkForm = memo(function LinkForm({ className, autoFocus, initialUrl, initialText, readOnlyText, onSubmit, onCancel, }) {
    const [url, setUrl] = useState(initialUrl ?? '');
    const [text, setText] = useState(initialText ?? '');
    const handleSubmit = () => {
        onSubmit({ url, text });
    };
    const inputEnterKeyHandler = enterKeyHandler(handleSubmit);
    return (_jsxs(Form.Form, { className: className, children: [_jsxs(Form.Layout, { children: [_jsx(Form.Row, { label: i18n('common_link'), help: i18n('link_url_help'), control: _jsx(UrlInputRow, { href: url, input: _jsx(TextInputFixed, { size: "s", view: "normal", value: url, onUpdate: setUrl, autoFocus: autoFocus, placeholder: "https://", onKeyPress: inputEnterKeyHandler }) }) }), _jsx(Form.Row, { label: i18n('link_text'), help: i18n('link_text_help'), control: _jsx(TextInput, { size: "s", view: "normal", value: text, onUpdate: setText, disabled: readOnlyText, onKeyPress: inputEnterKeyHandler }) })] }), _jsx(Form.Footer, { onCancel: onCancel, onSubmit: handleSubmit })] }));
});
//# sourceMappingURL=LinkForm.js.map
