"use client";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import { Modal } from "../../../components/molecules/Modal";
import { Button } from "../../../components/atoms/Button";
export const LinkEditorModal = ({ isOpen, onClose, onSubmit, defaultText = "", defaultUrl = "", }) => {
    const [text, setText] = useState(defaultText);
    const [url, setUrl] = useState(defaultUrl);
    useEffect(() => {
        if (isOpen) {
            setText(defaultText);
            setUrl(defaultUrl);
        }
    }, [isOpen, defaultText, defaultUrl]);
    const handleSubmit = () => {
        const trimmedUrl = url.trim();
        if (!trimmedUrl)
            return;
        onSubmit({
            text: text.trim(),
            url: trimmedUrl,
        });
        onClose();
    };
    return (_jsx(Modal, { isOpen: isOpen, onClose: onClose, title: "Insert Link", size: "md", footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: onClose, children: "Cancel" }), _jsx(Button, { variant: "primary", onClick: handleSubmit, children: "Insert" })] }), children: _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { className: "text-sm font-medium", children: "Preview Text" }), _jsx("input", { type: "text", value: text, onChange: (e) => setText(e.target.value), className: "px-3 py-2 rounded-md border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white", placeholder: "Text to display" })] }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { className: "text-sm font-medium", children: "URL" }), _jsx("input", { type: "text", value: url, onChange: (e) => setUrl(e.target.value), className: "px-3 py-2 rounded-md border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white", placeholder: "https://example.com" })] })] }) }));
};
export default LinkEditorModal;
