"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import dynamic from "next/dynamic";
import { useCallback } from "react";
import { getRichTextProfile } from "../services/contentService";
import { useRichTextProfileParsed } from "./richtext/hooks/useRichTextProfile";
const RichTextEditorComponent = dynamic(() => import("./RichTextEditorComponent").then((dnd) => dnd.RichTextEditorComponent), { ssr: false });
export function RichTextEditor({ field, readOnly, updateFieldValue, isFocusedField, }) {
    const profilePath = field.customProperties?.profile;
    const itemId = field.descriptor.item.id;
    const profileServiceCall = useCallback((path) => getRichTextProfile(path, itemId), [itemId]);
    const { profile, loading, error } = useRichTextProfileParsed(profilePath, profileServiceCall);
    // Show loading state while profile is being fetched
    if (loading) {
        return (_jsx("div", { style: { padding: "8px", color: "#666" }, children: "Loading editor profile..." }));
    }
    // Show error state if profile failed to load
    if (error) {
        return (_jsxs("div", { style: { padding: "8px", color: "#d32f2f" }, children: ["Error loading RTE profile from ", profilePath, ": ", error.message] }));
    }
    return (_jsx(RichTextEditorComponent, { field: field, readOnly: readOnly, profile: profile, updateFieldValue: updateFieldValue, showControls: isFocusedField }));
}
//# sourceMappingURL=RichTextEditor.js.map