var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx } from "react/jsx-runtime";
import { ToolButton } from "../components/tool-button";
import { useRefValue } from "../../hooks/use-ref-value";
import { getTextDirection } from "../../extensions/text-direction";
import { CodeBlock } from "../../extensions/code-block";
function TextDirectionTool(props) {
    const { editor, direction } = props, toolProps = __rest(props, ["editor", "direction"]);
    const directionRef = useRefValue(direction);
    return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => editor.chain().focus().setTextDirection(directionRef.current).run(), disabled: editor.isActive(CodeBlock.name), toggled: false })));
}
export function TextDirection(props) {
    const { editor } = props;
    const textDirection = getTextDirection(editor);
    const newTextDirection = textDirection ? undefined : "rtl";
    const icon = textDirection ? "rtl" : "ltr";
    return (_jsx(TextDirectionTool, Object.assign({ direction: newTextDirection }, props, { icon: icon })));
}
