import { e as w } from "../../../../sdk/dist/shared/chunk-GOMXZC4B.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-PSCN3VVA.js";
import "../../../../sdk/dist/shared/chunk-R6ATC4TC.js";
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 { merge, get } from "lodash-es";
import "../../../../sdk/dist/shared/chunk-SY6DZLTC.js";
import "../../../../sdk/dist/shared/chunk-7A2JNQX3.js";
import "../../../../sdk/dist/shared/chunk-3YVJ2ELD.js";
import { b as S, d as b } from "../../../../sdk/dist/shared/chunk-QGYZ7CG5.js";
import "../../../../sdk/dist/shared/chunk-AFVJZPLS.js";
import "../../../../sdk/dist/shared/chunk-A3GF4PYW.js";
import "../../../../sdk/dist/shared/chunk-W33JMRRN.js";
import { extractStylePath, brickStylesHelpersMap, brickWrapperStylesHelpersMap } from "../styles/helpers.js";
import { tx as D, css as E } from "../../../../style-system/dist/twind.js";
import { getStyleProperties } from "../styles/style-props.js";
import { usePageAttributes } from "../../../../../use-page-data.js";
function useSectionStyle({
  section,
  selected,
  editable,
  previewMode,
  isDropTarget
}) {
  const stylesProps = getStyleProperties(w);
  const classes = useClassesFromStyleProps(stylesProps, section);
  return D(
    // @mobile:flex-col @desktop:flex-row
    "flex flex-wrap w-full @container/section group/section overflow-visible relative mx-auto max-sm:max-w-dvw",
    [
      Object.values(classes),
      section.props.maxWidth,
      typeof section.props.minHeight === "string" && section.props.minHeight !== "full" && `min-h-[${section.props.minHeight}]`,
      // full height
      section.props.minHeight === "full" && (editable ? "min-h-[calc(100dvh-60px)]" : "min-h-dvh"),
      E({
        "&:has([data-no-section-padding])": {
          // This is a hack to ensure that the navbar is not affected by the section's padding
          paddingInline: "0px !important",
          paddingBlock: "0px !important"
        }
      }),
      // Section editor styles
      getSectionEditorStyles({ editable, previewMode, selected, isDropTarget }),
      // Manage the section order using css "order" (flex) property
      E({
        order: section.order
      })
    ]
  );
}
function getSectionEditorStyles({ editable, selected, previewMode, isDropTarget }) {
  if (!editable) {
    return null;
  }
  return [
    "select-none relative outline-dashed outline-2 -outline-offset-2",
    !isDropTarget && !selected && "outline-transparent",
    selected || isDropTarget ? "outline-upstart-500/40" : "hover:outline-upstart-500/40",
    // this is the grid overlay shown when dragging
    previewMode && E`
      &:has(.moving), &:has(.moving) ~ section {
        & [data-floating-ui-portal] {
          display: none;
        }
        & .resizable-handle {
          display: none;
        }
      }`
  ];
}
const sectionDefaultProps = S(w);
function useClassesFromStyleProps(stylesProps, section) {
  const { props, mobileProps } = section;
  const pageAttributes = usePageAttributes();
  const mergedProps = merge({}, sectionDefaultProps, props);
  const filtered = Object.entries(stylesProps).reduce((acc, [key, value]) => {
    const manifestField = get(w.properties, key);
    if (manifestField) {
      const resolvedField = b(manifestField);
      if (resolvedField.metadata?.filter) {
        const filter = resolvedField.metadata.filter;
        if (!filter(resolvedField, mergedProps, pageAttributes)) {
          acc.push(key);
        }
      }
    }
    return acc;
  }, []);
  const classes = Object.entries(stylesProps).reduce(
    (acc, [path, styleId]) => {
      const helper = brickStylesHelpersMap[styleId] ?? brickWrapperStylesHelpersMap[styleId];
      if (!helper) {
        console.warn("No helper found for styleId", styleId);
        return acc;
      }
      if (filtered.includes(path)) {
        console.warn("Filtered out section path", path);
        return acc;
      }
      const part = extractStylePath(path);
      acc[part] = acc[part] ?? [];
      const resolvedProps = get(mergedProps, path);
      const resolvedMobileProps = get(mobileProps, path);
      const schema = get(w.properties, path);
      acc[part].push(
        // @ts-expect-error
        D(helper?.(resolvedProps, resolvedMobileProps, schema))
      );
      return acc;
    },
    {}
  );
  return classes;
}
export {
  useSectionStyle
};
//# sourceMappingURL=use-section-style.js.map
