import { Box } from "@wix/design-system";
import React, { useContext, useMemo, useState } from "react";
import { LINK_PREVIEW_TYPE } from "./../../ricos-content/consts.js";
import { EditorContext, RicosContext, ZIndexContext } from "./../../ricos-context/index.js";
import { Link_Target } from "./../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { AttributesDesktop } from "./../../_shared/link-modal/open-link-modal/attributes/attributes-desktop.js";
const SettingsTab = ({ nodeId }) => {
  const { getPublicCommands } = useContext(EditorContext);
  const { t } = useContext(RicosContext);
  const zIndexService = useContext(ZIndexContext);
  const [containerRef, setContainerRef] = useState(null);
  const initialData = useMemo(
    () => getPublicCommands().getBlockComponentData(nodeId),
    []
  );
  const [componentData, setComponentData] = useState(initialData);
  const tooltipProps = useMemo(
    () => ({
      appendTo: containerRef || void 0,
      fixed: true,
      zIndex: zIndexService.getZIndex("TOOLTIP")
    }),
    [containerRef, zIndexService]
  );
  const handleOnChange = (data) => {
    getPublicCommands().setBlock(nodeId, LINK_PREVIEW_TYPE, {
      ...componentData,
      ...data
    });
  };
  const onChangeAttributes = (rel, target) => {
    if (componentData.link) {
      const newData = {
        ...componentData,
        link: {
          ...componentData.link,
          target,
          rel
        }
      };
      setComponentData(newData);
      handleOnChange(newData);
    }
  };
  return componentData?.link ? /* @__PURE__ */ React.createElement(Box, { direction: "vertical", padding: "SP3", overflow: "auto", ref: setContainerRef }, /* @__PURE__ */ React.createElement(
    AttributesDesktop,
    {
      link: {
        url: componentData.link.url || "",
        target: componentData.link.target || Link_Target.BLANK,
        rel: componentData.link.rel,
        anchor: componentData.link.anchor
      },
      onChange: onChangeAttributes,
      t,
      tooltipProps
    }
  )) : null;
};
export {
  SettingsTab
};
//# sourceMappingURL=settings-tab.js.map
