'use client';

import { c as _c } from "react/compiler-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
import { ShimmerEffect } from '@payloadcms/ui';
import React, { lazy, Suspense, useEffect, useState } from 'react';
import { defaultEditorLexicalConfig } from '../lexical/config/client/default.js';
import { loadClientFeatures } from '../lexical/config/client/loader.js';
import { sanitizeClientEditorConfig } from '../lexical/config/client/sanitize.js';
const RichTextEditor = /*#__PURE__*/lazy(() => import('./Field.js').then(module => ({
  default: module.RichText
})));
export const RichTextField = props => {
  const $ = _c(14);
  const {
    admin: t0,
    clientFeatures,
    featureClientSchemaMap,
    field,
    lexicalEditorConfig: t1,
    schemaPath
  } = props;
  let t2;
  if ($[0] !== t0) {
    t2 = t0 === undefined ? {} : t0;
    $[0] = t0;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const admin = t2;
  const lexicalEditorConfig = t1 === undefined ? defaultEditorLexicalConfig : t1;
  const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] = useState(null);
  let t3;
  let t4;
  if ($[2] !== admin || $[3] !== clientFeatures || $[4] !== featureClientSchemaMap || $[5] !== field || $[6] !== finalSanitizedEditorConfig || $[7] !== lexicalEditorConfig || $[8] !== schemaPath) {
    t3 = () => {
      if (finalSanitizedEditorConfig) {
        return;
      }
      const featureProvidersLocal = [];
      for (const [_featureKey, clientFeature] of Object.entries(clientFeatures)) {
        if (!clientFeature.clientFeatureProvider) {
          continue;
        }
        featureProvidersLocal.push(clientFeature.clientFeatureProvider(clientFeature.clientFeatureProps));
      }
      const finalLexicalEditorConfig = lexicalEditorConfig ? lexicalEditorConfig : defaultEditorLexicalConfig;
      const resolvedClientFeatures = loadClientFeatures({
        featureClientSchemaMap,
        field,
        schemaPath: schemaPath ?? field.name,
        unSanitizedEditorConfig: {
          features: featureProvidersLocal,
          lexical: finalLexicalEditorConfig
        }
      });
      setFinalSanitizedEditorConfig(sanitizeClientEditorConfig(resolvedClientFeatures, finalLexicalEditorConfig, admin));
    };
    t4 = [lexicalEditorConfig, admin, finalSanitizedEditorConfig, clientFeatures, featureClientSchemaMap, field, schemaPath];
    $[2] = admin;
    $[3] = clientFeatures;
    $[4] = featureClientSchemaMap;
    $[5] = field;
    $[6] = finalSanitizedEditorConfig;
    $[7] = lexicalEditorConfig;
    $[8] = schemaPath;
    $[9] = t3;
    $[10] = t4;
  } else {
    t3 = $[9];
    t4 = $[10];
  }
  useEffect(t3, t4);
  let t5;
  if ($[11] !== finalSanitizedEditorConfig || $[12] !== props) {
    t5 = _jsx(Suspense, {
      fallback: _jsx(ShimmerEffect, {
        height: "35vh"
      }),
      children: finalSanitizedEditorConfig && _jsx(RichTextEditor, {
        ...props,
        editorConfig: finalSanitizedEditorConfig
      })
    });
    $[11] = finalSanitizedEditorConfig;
    $[12] = props;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  return t5;
};
//# sourceMappingURL=index.js.map