import { Box, Divider, FormField, InfoIcon, SegmentedToggle } from "@wix/design-system";
import React, { useContext } from "react";
import { RicosContext, ZIndexContext } from "./../../../ricos-context/index.js";
import {
  PollData_Layout_PollLayout_Direction,
  PollData_Layout_PollLayout_Type
} from "./../../../ricos-schema/next-schema/index.js";
import { logInvariant } from "./../../../_shared/log-invariant.js";
import { useNodeAttrs } from "./../../../_shared/use-node-attrs.js";
import { LTRIcon, RTLIcon } from "./../../../plugin-commons/index.js";
import {
  ThumbnailPicker,
  ToggleButton,
  usePanelContainerElement
} from "./../../../ui-components/index.js";
import { LayoutGridIcon } from "../../assets/icons/layout-grid-icon.js";
import { LayoutListIcon } from "../../assets/icons/layout-list-icon.js";
import {
  LAYOUT_SETTINGS_DIRECTION_TOGGLE,
  LAYOUT_SETTINGS_IMAGE_TO_ANSWERS_TOGGLE,
  LAYOUT_SETTINGS_IMAGE_TO_QUESTION_TOGGLE,
  LAYOUT_SETTINGS_LAYOUT_THUMBNAIL,
  LAYOUT_SETTINGS_LAYOUT_THUMBNAIL_PICKER
} from "../../data-hooks.js";
import { Section } from "./section.js";
const LayoutSettingsSection = ({ nodeId, logBi }) => {
  const { t } = useContext(RicosContext);
  const zIndexService = useContext(ZIndexContext);
  const { pmNodeAttrs, patchPmNodeAttrs } = useNodeAttrs(nodeId, "POLL");
  const containerEl = usePanelContainerElement();
  if (!pmNodeAttrs) {
    logInvariant(Error("Poll settings: node attrs not found"));
    return null;
  }
  const { poll, options } = pmNodeAttrs.layout ?? {};
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Section, { title: t("Poll_PollSettings_Tab_Layout_Section_Question_Header") }, /* @__PURE__ */ React.createElement(
    ToggleButton,
    {
      checked: Boolean(poll?.enableImage),
      title: t("Poll_PollSettings_Tab_Layout_Section_Question_Image"),
      dataHook: LAYOUT_SETTINGS_IMAGE_TO_QUESTION_TOGGLE,
      onChange: () => {
        logBi({
          dataHook: LAYOUT_SETTINGS_IMAGE_TO_QUESTION_TOGGLE,
          value: !poll?.enableImage
        });
        patchPmNodeAttrs({
          layout: { ...pmNodeAttrs.layout, poll: { ...poll, enableImage: !poll?.enableImage } }
        });
      },
      size: "small"
    }
  )), /* @__PURE__ */ React.createElement(Box, { marginInline: "-18px" }, /* @__PURE__ */ React.createElement(Divider, null)), /* @__PURE__ */ React.createElement(Section, { title: t("Poll_PollSettings_Tab_Layout_Section_Answers_Header") }, /* @__PURE__ */ React.createElement(
    ThumbnailPicker,
    {
      dataHook: LAYOUT_SETTINGS_LAYOUT_THUMBNAIL_PICKER,
      logBi,
      dataSource: [
        {
          dataHook: LAYOUT_SETTINGS_LAYOUT_THUMBNAIL + PollData_Layout_PollLayout_Type.LIST,
          value: PollData_Layout_PollLayout_Type.LIST,
          label: t("Poll_PollSettings_Tab_Layout_Section_Answers_Layout_List"),
          renderBackgroundImage: (props) => /* @__PURE__ */ React.createElement(LayoutListIcon, { ...props })
        },
        {
          dataHook: LAYOUT_SETTINGS_LAYOUT_THUMBNAIL + PollData_Layout_PollLayout_Type.GRID,
          value: PollData_Layout_PollLayout_Type.GRID,
          label: t("Poll_PollSettings_Tab_Layout_Section_Answers_Layout_Grid"),
          renderBackgroundImage: (props) => /* @__PURE__ */ React.createElement(LayoutGridIcon, { ...props })
        }
      ],
      selectedValue: poll?.type ?? PollData_Layout_PollLayout_Type.LIST,
      title: t("Poll_PollSettings_Tab_Layout_Section_Answers_Layout"),
      onChange: (type) => {
        patchPmNodeAttrs({
          layout: {
            ...pmNodeAttrs.layout,
            poll: { ...poll, type }
          }
        });
        window.dispatchEvent(new Event("resize"));
      }
    }
  ), /* @__PURE__ */ React.createElement(
    ToggleButton,
    {
      checked: Boolean(options?.enableImage),
      title: t("Poll_PollSettings_Tab_Layout_Section_Answers_Image"),
      dataHook: LAYOUT_SETTINGS_IMAGE_TO_ANSWERS_TOGGLE,
      onChange: () => {
        logBi({
          dataHook: LAYOUT_SETTINGS_IMAGE_TO_ANSWERS_TOGGLE,
          value: !options?.enableImage
        });
        patchPmNodeAttrs({
          layout: {
            ...pmNodeAttrs.layout,
            options: { ...options, enableImage: !options?.enableImage }
          }
        });
      },
      size: "small"
    }
  )), /* @__PURE__ */ React.createElement(Box, { marginInline: "-18px" }, /* @__PURE__ */ React.createElement(Divider, null)), /* @__PURE__ */ React.createElement(
    Section,
    {
      title: /* @__PURE__ */ React.createElement(React.Fragment, null, t("Poll_PollSettings_Tab_Layout_Section_TextDirection_Header"), " ", /* @__PURE__ */ React.createElement(
        InfoIcon,
        {
          content: t("Poll_PollSettings_Tab_Layout_Section_TextDirection_Header_Tooltip"),
          size: "small",
          tooltipProps: {
            appendTo: containerEl,
            zIndex: zIndexService.getZIndex("TOOLTIP")
          }
        }
      ))
    },
    /* @__PURE__ */ React.createElement(
      FormField,
      {
        label: t("CollapsibleList_CollapsibleListSettings_Tab_Settings_Direction_Title")
      },
      /* @__PURE__ */ React.createElement(Box, { marginTop: "SP1" }),
      /* @__PURE__ */ React.createElement(
        SegmentedToggle,
        {
          size: "small",
          selected: pmNodeAttrs.layout?.poll?.direction,
          defaultSelected: pmNodeAttrs.layout?.poll?.direction,
          onClick: (_, direction) => {
            logBi({
              dataHook: LAYOUT_SETTINGS_DIRECTION_TOGGLE,
              value: direction
            });
            patchPmNodeAttrs({
              layout: {
                ...pmNodeAttrs.layout,
                poll: { ...poll, direction }
              }
            });
          },
          dataHook: LAYOUT_SETTINGS_DIRECTION_TOGGLE
        },
        /* @__PURE__ */ React.createElement(
          SegmentedToggle.Button,
          {
            key: PollData_Layout_PollLayout_Direction.LTR,
            value: PollData_Layout_PollLayout_Direction.LTR,
            size: "small",
            prefixIcon: /* @__PURE__ */ React.createElement(LTRIcon, null)
          },
          t("Poll_PollSettings_Tab_Layout_Section_TextDirection_LTR")
        ),
        /* @__PURE__ */ React.createElement(
          SegmentedToggle.Button,
          {
            key: PollData_Layout_PollLayout_Direction.RTL,
            value: PollData_Layout_PollLayout_Direction.RTL,
            size: "small",
            prefixIcon: /* @__PURE__ */ React.createElement(RTLIcon, null)
          },
          t("Poll_PollSettings_Tab_Layout_Section_TextDirection_RTL")
        )
      )
    )
  ));
};
export {
  LayoutSettingsSection
};
//# sourceMappingURL=layout-settings-section.js.map
