"use strict";
const jsxRuntime = require("react/jsx-runtime");
const assert = require("assert");
const React = require("react");
const styles_lib_css_atoms_sprinkles_css_cjs = require("../../css/atoms/sprinkles.css.cjs");
const dedent = require("dedent");
const styles_lib_components_Box_Box_cjs = require("../Box/Box.cjs");
const styles_lib_components_Stack_Stack_cjs = require("../Stack/Stack.cjs");
const styles_lib_components_Divider_Divider_cjs = require("../Divider/Divider.cjs");
const _interopDefaultCompat = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const assert__default = /* @__PURE__ */ _interopDefaultCompat(assert);
const dedent__default = /* @__PURE__ */ _interopDefaultCompat(dedent);
const buildDataAttributes = ({ data, validateRestProps }) => {
  if (process.env.NODE_ENV !== "production") {
    if (validateRestProps !== false) {
      const dataAttrs = Object.keys(validateRestProps).filter(
        (prop) => prop.startsWith("data-")
      );
      const formatter = (v) => {
        if (typeof v === "boolean") {
          return v ? "" : `={false}`;
        }
        if (typeof v === "number") {
          return `={${v}}`;
        }
        return `="${v}"`;
      };
      if (dataAttrs.length > 0) {
        console.warn(
          dedent__default.default`
          Braid components do not support the native data attribute format. Use the “data” prop instead.
            <Component
          %c${dataAttrs.map((attr) => `-    ${attr}${formatter(validateRestProps[attr])}`).join("\n")}
          %c+    data={{
          ${dataAttrs.map((attr) => {
            const attributeName = attr.replace(/^data-/, "");
            const property = attributeName.includes("-") ? `'${attributeName}'` : attributeName;
            return `+      ${property}: ${typeof validateRestProps[attr] === "string" ? `'${validateRestProps[attr]}'` : validateRestProps[attr]},`;
          }).join("\n")}
          +    }}
            %c/>
           For more details, see the “Data Attributes” documentation:
           https://seek-oss.github.io/braid-design-system/components/Box#data-attributes
        `,
          "color: red",
          "color: green",
          "color: inherit"
        );
      }
    }
  }
  if (!data) {
    return;
  }
  const keys = Object.keys(data);
  const dataAttributes = {};
  for (const key of keys) {
    dataAttributes[`data-${key}`] = data[key];
  }
  return dataAttributes;
};
const validTones = ["neutral", "secondary"];
const AccordionContext = React.createContext(
  null
);
const validSpaceValues = ["medium", "large", "xlarge"];
const defaultSpaceForSize = {
  divided: {
    xsmall: "medium",
    small: "medium",
    standard: "medium",
    large: "large"
  },
  undivided: {
    xsmall: "large",
    small: "large",
    standard: "large",
    large: "large"
  }
};
const Accordion = ({
  children,
  size = "large",
  tone,
  weight,
  space: spaceProp,
  dividers = true,
  data,
  ...restProps
}) => {
  assert__default.default(
    spaceProp === void 0 || Object.values(styles_lib_css_atoms_sprinkles_css_cjs.normalizeResponsiveValue(spaceProp)).every(
      (value) => value === void 0 || validSpaceValues.includes(value)
    ),
    `To ensure adequate space for touch targets, 'space' prop values must be one of the following: ${validSpaceValues.map((x) => `"${x}"`).join(", ")}`
  );
  assert__default.default(
    tone === void 0 || validTones.includes(tone),
    `The 'tone' prop should be one of the following: ${validTones.map((x) => `"${x}"`).join(", ")}`
  );
  const contextValue = React.useMemo(
    () => ({ size, tone, weight }),
    [size, tone, weight]
  );
  const space = spaceProp ?? defaultSpaceForSize[dividers ? "divided" : "undivided"][size];
  return /* @__PURE__ */ jsxRuntime.jsx(AccordionContext.Provider, { value: contextValue, children: !dividers ? /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Stack_Stack_cjs.Stack, { space, data, children }) : /* @__PURE__ */ jsxRuntime.jsxs(styles_lib_components_Box_Box_cjs.Box, { ...buildDataAttributes({ data, validateRestProps: restProps }), children: [
    /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Divider_Divider_cjs.Divider, {}),
    /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Box_Box_cjs.Box, { paddingY: space, children: /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Stack_Stack_cjs.Stack, { space, dividers: true, children }) }),
    /* @__PURE__ */ jsxRuntime.jsx(styles_lib_components_Divider_Divider_cjs.Divider, {})
  ] }) });
};
exports.Accordion = Accordion;
exports.AccordionContext = AccordionContext;
exports.buildDataAttributes = buildDataAttributes;
exports.validSpaceValues = validSpaceValues;
exports.validTones = validTones;
