import { useCallback } from "react";
import { toggleBold, toggleItalic, toggleStrikethrough } from "./markdown-formatting/index.js";
function useMarkdownShortcuts(textAreaRef, onFormat) {
    return useCallback((e)=>{
        const textarea = textAreaRef.current;
        if (!textarea) return;
        const metaOrCtrl = e.metaKey || e.ctrlKey;
        if (!metaOrCtrl) return;
        let formatFn = null;
        if ('b' !== e.key || e.shiftKey) if ('i' !== e.key || e.shiftKey) {
            if ('x' === e.key && e.shiftKey) formatFn = toggleStrikethrough;
        } else formatFn = toggleItalic;
        else formatFn = toggleBold;
        if (formatFn) {
            e.preventDefault();
            const input = {
                value: textarea.value,
                selectionStart: textarea.selectionStart,
                selectionEnd: textarea.selectionEnd
            };
            onFormat(formatFn(input));
        }
    }, [
        textAreaRef,
        onFormat
    ]);
}
export { useMarkdownShortcuts };
