// packages/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js
import { useMemo } from "@wordpress/element";
import { __ } from "@wordpress/i18n";
import { useSettings } from "../../use-settings";
import { RANGE_CONTROL_MAX_SIZE } from "../utils";
var EMPTY_ARRAY = [];
var compare = new Intl.Collator("und", { numeric: true }).compare;
function useSpacingSizes() {
  const [
    customSpacingSizes,
    themeSpacingSizes,
    defaultSpacingSizes,
    defaultSpacingSizesEnabled
  ] = useSettings(
    "spacing.spacingSizes.custom",
    "spacing.spacingSizes.theme",
    "spacing.spacingSizes.default",
    "spacing.defaultSpacingSizes"
  );
  const customSizes = customSpacingSizes ?? EMPTY_ARRAY;
  const themeSizes = themeSpacingSizes ?? EMPTY_ARRAY;
  const defaultSizes = defaultSpacingSizes && defaultSpacingSizesEnabled !== false ? defaultSpacingSizes : EMPTY_ARRAY;
  return useMemo(() => {
    const sizes = [
      { name: __("None"), slug: "0", size: 0 },
      ...customSizes,
      ...themeSizes,
      ...defaultSizes
    ];
    if (sizes.every(({ slug }) => /^[0-9]/.test(slug))) {
      sizes.sort((a, b) => compare(a.slug, b.slug));
    }
    return sizes.length > RANGE_CONTROL_MAX_SIZE ? [
      {
        name: __("Default"),
        slug: "default",
        size: void 0
      },
      ...sizes
    ] : sizes;
  }, [customSizes, themeSizes, defaultSizes]);
}
export {
  useSpacingSizes as default
};
//# sourceMappingURL=use-spacing-sizes.js.map
