import { Box, Divider } from "@wix/design-system";
import React, { useContext } from "react";
import { ModalServiceContext, RicosContext } from "./../../ricos-context/index.js";
import { useBiNext } from "./../../_shared/bi-context-provider/bi-context-provider.js";
import { isCustomUpload } from "./../../_shared/is-custom-upload.js";
import { logInvariant } from "./../../_shared/log-invariant.js";
import { useNodeAttrs } from "./../../_shared/use-node-attrs.js";
import { useSpoilerPlugin } from "./../../_shared/use-spoiler-plugin.js";
import {
  Panel,
  PanelHeader,
  ToggleButton,
  usePanelContainerElement
} from "./../../ui-components/index.js";
import { VIDEO_SETTINGS_MODAL_ID } from "../constants.js";
import { SETTINGS_DISABLE_DOWNLOAD_TOGGLE, SETTINGS_SPOILER_TOGGLE } from "../data-hooks.js";
import { VIDEO_TYPE } from "../types.js";
const SettingsModal = ({ nodeId }) => {
  const { t } = useContext(RicosContext);
  const modalService = useContext(ModalServiceContext) || {};
  const isSpoilerEnabled = useSpoilerPlugin(VIDEO_TYPE);
  const containerEl = usePanelContainerElement();
  const { patchPmNodeAttrs, pmNodeAttrs } = useNodeAttrs(nodeId, "VIDEO");
  const logBi = useBiNext({ pluginId: "video", modalId: VIDEO_SETTINGS_MODAL_ID, nodeId });
  const closeModal = () => modalService.closeModal(VIDEO_SETTINGS_MODAL_ID);
  if (!pmNodeAttrs) {
    logInvariant(new Error("Video settings: node attrs not found"));
    return null;
  }
  const isCustomVideo = !!pmNodeAttrs.disableDownload || pmNodeAttrs.video?.src?.id || isCustomUpload(pmNodeAttrs.video?.src?.url);
  return /* @__PURE__ */ React.createElement(Panel, { closeButtonProps: { onClick: closeModal } }, /* @__PURE__ */ React.createElement(PanelHeader, { title: t("VideoPlugin_Settings_Header") }), /* @__PURE__ */ React.createElement(Box, { direction: "vertical", padding: "SP3", gap: "SP2" }, isCustomVideo ? /* @__PURE__ */ React.createElement(
    ToggleButton,
    {
      title: t("VideoPlugin_Settings_VideoCanBeDownloaded_Label"),
      checked: !pmNodeAttrs.disableDownload,
      size: "small",
      onChange: () => {
        logBi({
          dataHook: SETTINGS_DISABLE_DOWNLOAD_TOGGLE,
          value: !!pmNodeAttrs.disableDownload
        });
        patchPmNodeAttrs({ disableDownload: !pmNodeAttrs.disableDownload });
      },
      infoContent: t("VideoPlugin_Settings_VideoCanBeDownloaded_Tooltip"),
      tooltipAppendTo: containerEl,
      dataHook: SETTINGS_DISABLE_DOWNLOAD_TOGGLE
    }
  ) : null, isCustomVideo && isSpoilerEnabled ? /* @__PURE__ */ React.createElement(Divider, null) : null, isSpoilerEnabled ? /* @__PURE__ */ React.createElement(
    ToggleButton,
    {
      title: t("VideoSettings_Spoiler_Toggle"),
      checked: !!pmNodeAttrs.containerData?.spoiler?.enabled,
      size: "small",
      onChange: () => {
        logBi({
          dataHook: SETTINGS_SPOILER_TOGGLE,
          value: !pmNodeAttrs.containerData?.spoiler?.enabled
        });
        patchPmNodeAttrs({
          containerData: {
            ...pmNodeAttrs.containerData,
            spoiler: {
              ...pmNodeAttrs.containerData?.spoiler,
              enabled: !pmNodeAttrs.containerData?.spoiler?.enabled
            }
          }
        });
      },
      infoContent: t("Spoiler_Toggle_Tooltip"),
      tooltipAppendTo: containerEl,
      dataHook: SETTINGS_SPOILER_TOGGLE
    }
  ) : null));
};
export {
  SettingsModal
};
//# sourceMappingURL=settings-modal.js.map
