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