import classNames from "classnames";
import React from "react";
import { ConvertersContext } from "./../pm-converters/context.js";
import {
  DevContext,
  EditorContextProvider,
  ModalServiceContext,
  PluginsContextProvider,
  PluginsEventsContextProvider,
  RicosContextProvider,
  UploadContextProvider,
  ZIndexContextProvider
} from "./../ricos-context/index.js";
import { LocaleResourceProvider } from "./../ricos-editor/RicosContext/locale-resource-provider.js";
import { ModalProvider, useModalService } from "./../ricos-modals/index.js";
import { RicosOrchestrator } from "./../ricos-orchestrator/ricos-orchestrator.js";
import { getStyles } from "./../ricos-styles/get-styles.js";
import { buildThemeCssVars } from "./../ricos-styles/themeStrategy/build-theme-css-vars.js";
import {
  RequestServiceProvider,
  useRequestService
} from "./../_shared/request-service-provider/request-service-provider.js";
import { getLangDir } from ".//index.js";
import { RicosPortal } from "./../editor-common/index.js";
import { UiComponentsProvider } from "./../ui-components/ui-components-provider.js";
import { pluginsMap as staticPluginsMap } from "../_shared/plugins-map.js";
const createRicosComponentStory = (props) => {
  return /* @__PURE__ */ React.createElement(
    DevContext.Provider,
    {
      value: {
        pmNodeAttrs: props.pmNodeAttrs
      }
    },
    /* @__PURE__ */ React.createElement(RequestServiceProvider, null, /* @__PURE__ */ React.createElement(ModalProvider, { modalSettings: {} }, /* @__PURE__ */ React.createElement(LocaleResourceProvider, { locale: props.storyProps.locale, fallback: null }, (locale) => (t) => /* @__PURE__ */ React.createElement(
      ComponentStory,
      {
        t,
        locale,
        isMobile: props.storyProps.isMobile,
        theme: {},
        environment: props.storyProps.environment,
        component: props.component,
        siblingComponent: props.siblingComponent,
        style: props.style,
        mock: props.mock,
        editorProps: props.editorProps
      }
    ))))
  );
};
const ComponentStory = ({
  locale,
  t: translateFn,
  isMobile,
  style,
  component,
  siblingComponent,
  theme = {},
  environment,
  mock,
  editorProps
}) => {
  const platform = "macOs";
  const modalService = useModalService();
  const makeRequestService = useRequestService();
  const orchestrator = new RicosOrchestrator({
    editorProps: { ...editorProps, locale, isMobile, theme },
    t: translateFn,
    platform,
    modalService,
    devService: () => ({}),
    wixInstance: () => ({
      getWixClientPromise: () => Promise.resolve({})
    }),
    makeRequestService,
    pluginsMap: staticPluginsMap
  });
  const {
    modals,
    editor,
    schema,
    zIndexService,
    t,
    plugins,
    uploadService,
    updateService,
    pluginsEvents
  } = orchestrator.getServices();
  const [portalRef, setPortalRef] = React.useState(null);
  const languageDir = getLangDir(locale);
  const documentStyle = schema.getContent().documentStyle || {};
  const cssVars = buildThemeCssVars(theme, documentStyle);
  const stylesPreset = getStyles(environment, isMobile);
  return /* @__PURE__ */ React.createElement(
    "div",
    {
      "data-hook": `ricos-portal`,
      dir: languageDir,
      style: { ...style, ...cssVars },
      className: classNames(stylesPreset)
    },
    /* @__PURE__ */ React.createElement(UiComponentsProvider, { containerEl: portalRef }, /* @__PURE__ */ React.createElement(EditorContextProvider, { editor: mock?.editor ?? editor }, /* @__PURE__ */ React.createElement(ZIndexContextProvider, { zIndexService }, /* @__PURE__ */ React.createElement(ModalServiceContext.Provider, { value: modals }, /* @__PURE__ */ React.createElement(PluginsContextProvider, { plugins }, /* @__PURE__ */ React.createElement(PluginsEventsContextProvider, { pluginsEvents }, /* @__PURE__ */ React.createElement(
      UploadContextProvider,
      {
        uploadService,
        updateService
      },
      /* @__PURE__ */ React.createElement(ConvertersContext.Provider, { value: {} }, /* @__PURE__ */ React.createElement(RicosPortal, { ref: (r) => setPortalRef(r), environment }), portalRef && /* @__PURE__ */ React.createElement(
        RicosContextProvider,
        {
          portal: portalRef ?? void 0,
          t,
          isMobile,
          experiments: {},
          locale,
          localeContent: locale,
          languageDir,
          theme,
          environment
        },
        component
      ), siblingComponent)
    )))))))
  );
};
const action = (name) => (value) => {
  console.log(name, value);
};
export {
  action,
  createRicosComponentStory
};
//# sourceMappingURL=create-ricos-component-story.js.map
