import { j as jsxRuntimeExports } from "../../../../../_virtual/jsx-runtime.js";
import FormNavigator from "./json-form/FormNavigator.js";
import { b as S } from "../../../../sdk/dist/shared/chunk-QGYZ7CG5.js";
import "../../../../sdk/dist/shared/chunk-AFVJZPLS.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-A3GF4PYW.js";
import "../../../../sdk/dist/shared/chunk-W33JMRRN.js";
import { useMemo, useCallback } from "react";
import { merge, set } from "lodash-es";
import { getNavItemsFromManifest } from "./json-form/form-utils.js";
import { usePreviewMode, useEditorHelpers } from "../../../../../use-editor.js";
import { useDraft } from "../../../../../use-page-data.js";
function AttributesSettingsView({
  attributes,
  attributesSchema,
  title,
  group,
  type
}) {
  const previewMode = usePreviewMode();
  const editorHelpers = useEditorHelpers();
  const draft = useDraft();
  const filter = (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);
  };
  const navItems = getNavItemsFromManifest(attributesSchema, filter);
  const formData = useMemo(() => {
    const defProps = S(attributesSchema);
    return merge({}, defProps, attributes ?? {});
  }, [attributes, attributesSchema]);
  const onChange = useCallback(
    (data, propertyChanged) => {
      console.log("attributes -> propertyChanged", propertyChanged);
      if (type === "page") {
        if (data[propertyChanged] === null) {
          draft.deletePageAttribute(propertyChanged);
        } else {
          const props = {};
          set(props, propertyChanged, data[propertyChanged]);
          draft.updatePageAttributes(props);
        }
      } else {
        if (data[propertyChanged] === null) {
          draft.deleteSiteAttribute(propertyChanged);
        } else {
          const props = {};
          set(props, propertyChanged, data[propertyChanged]);
          draft.updateSiteAttributes(props);
        }
      }
    },
    [attributes]
  );
  const onNavigate = (item) => {
    if (!item) {
      editorHelpers.setAttributesGroup(void 0);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    FormNavigator,
    {
      onNavigate,
      brickId: "none",
      title,
      initialGroup: group,
      navItems,
      formSchema: attributesSchema,
      className: "h-full",
      formData,
      onChange
    },
    `${type}-attributes-form-${group || "all"}`
  );
}
export {
  AttributesSettingsView as default
};
//# sourceMappingURL=AttributesSettingsView.js.map
