import { j as jsxRuntimeExports } from "../../../../../_virtual/jsx-runtime.js";
import { b as ne } from "../../../../sdk/dist/shared/chunk-PSCN3VVA.js";
import "../../../../sdk/dist/shared/chunk-R6ATC4TC.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-CFF6Q7O7.js";
import "../../../../sdk/dist/shared/chunk-IKC3FK7L.js";
import "../../../../sdk/dist/shared/chunk-E6XEI7IK.js";
import "../../../../sdk/dist/shared/chunk-SQ5T4AT5.js";
import "../../../../sdk/dist/shared/chunk-G5CJU6RD.js";
import "../../../../sdk/dist/shared/chunk-PSTFJ5IJ.js";
import "../../../../sdk/dist/shared/chunk-NJGXC7D6.js";
import "../../../../sdk/dist/shared/chunk-SXHDQ64Z.js";
import "../../../../sdk/dist/shared/chunk-QX6OGRRT.js";
import "../../../../sdk/dist/shared/chunk-FLOMNC6J.js";
import "../../../../sdk/dist/shared/chunk-PLSV746R.js";
import "../../../../sdk/dist/shared/chunk-WBZW5LVH.js";
import "../../../../sdk/dist/shared/chunk-WYVJE6J5.js";
import "../../../../sdk/dist/shared/chunk-I3VL6SRH.js";
import "../../../../sdk/dist/shared/chunk-B3EATRFX.js";
import "../../../../sdk/dist/shared/chunk-IKHZD2JH.js";
import "../../../../sdk/dist/shared/chunk-PXI7AHWS.js";
import "../../../../sdk/dist/shared/chunk-SY6DZLTC.js";
import "../../../../sdk/dist/shared/chunk-7A2JNQX3.js";
import "../../../../sdk/dist/shared/chunk-3YVJ2ELD.js";
import "../../../../sdk/dist/shared/chunk-AFVJZPLS.js";
import "../../../../sdk/dist/shared/chunk-A3GF4PYW.js";
import "../../../../sdk/dist/shared/chunk-W33JMRRN.js";
import { a as m } from "../../../../sdk/dist/shared/chunk-OIY3EPHO.js";
import { tx as D } from "../../../../style-system/dist/twind.js";
import { get, set } from "lodash-es";
import { useCallback, useMemo } from "react";
import { usePreviewMode } from "../../../../../use-editor.js";
import { useDraftHelpers, useBrick } from "../../../../../use-page-data.js";
import { useBrickManifest } from "../../shared/hooks/use-brick-manifest.js";
import { getNavItemsFromManifest } from "./json-form/form-utils.js";
import FormNavigator from "./json-form/FormNavigator.js";
const defaultFilter = (category) => category === "settings" || !category;
function BrickSettingsView({
  brick,
  label,
  group,
  categoryFilter = defaultFilter
}) {
  const { updateBrickProps } = useDraftHelpers();
  const manifest = useBrickManifest(brick.type);
  const previewMode = usePreviewMode();
  const brickInfo = useBrick(brick.id);
  const filter = useCallback(
    (prop) => {
      return (typeof prop.metadata?.["ui:responsive"] === "undefined" || prop.metadata?.["ui:responsive"] === true || prop.metadata?.["ui:responsive"] === previewMode) && (typeof prop["ui:responsive"] === "undefined" || prop["ui:responsive"] === true || prop["ui:responsive"] === previewMode) && categoryFilter(prop.metadata?.category);
    },
    [previewMode, categoryFilter]
  );
  const navItems = useMemo(() => getNavItemsFromManifest(manifest.props, filter), [filter, manifest.props]);
  const formData = useMemo(() => {
    const defProps = ne[brick.type].props;
    return previewMode === "mobile" ? m({}, defProps, brick.props, brick.mobileProps ?? {}) : m({}, defProps, brick.props ?? {});
  }, [brick, previewMode]);
  const onChange = useCallback(
    (data, propertyChangedPath) => {
      if (!propertyChangedPath) {
        console.warn("propertyChangedPath is missing in onChange");
        return;
      }
      if (manifest.isGlobalBrick) {
        console.log("Updating global brick, mutating site attributes instead of brick props");
        return;
      }
      const manifestField = get(manifest.props.properties, propertyChangedPath);
      const isMobileProps = previewMode === "mobile" && manifestField?.metadata?.category !== "content";
      const props = structuredClone(
        isMobileProps ? brickInfo?.mobileProps ?? {} : brickInfo?.props ?? {}
      );
      set(props, propertyChangedPath, data[propertyChangedPath]);
      console.debug("Props update for brick %s: %o", brick.id, props);
      updateBrickProps(brick.id, props, isMobileProps);
    },
    [brick.id, manifest, previewMode, updateBrickProps, brickInfo]
  );
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    FormNavigator,
    {
      title: `${manifest.name} ${label ?? "settings"}`,
      initialGroup: group,
      navItems,
      formSchema: manifest.props,
      className: D("flex-grow"),
      formData,
      onChange,
      brickId: brick.id
    },
    `brick-nav-${brick.id}-${previewMode}`
  );
}
export {
  BrickSettingsView as default
};
//# sourceMappingURL=BrickSettingsView.js.map
