import { jsx } from "react/jsx-runtime";
import { createContext, useContext } from "react";
import { Box } from "../Box/Box.mjs";
import { buildDataAttributes } from "../Accordion/Accordion.mjs";
import { column, width, columnContent } from "./Column.css.mjs";
const optimizeResponsiveArray = (value) => {
  let lastValue;
  const values = value.map((v) => {
    if (v !== lastValue && v !== null) {
      lastValue = v;
      return v;
    }
    return null;
  });
  return [
    values[0] ?? null,
    values[1] ?? null,
    values[2] ?? null,
    values[3] ?? null
  ];
};
const validColumnsComponents = ["div", "span"];
const ColumnsContext = createContext({
  collapseMobile: false,
  collapseTablet: false,
  collapseDesktop: false,
  mobileSpace: "none",
  tabletSpace: "none",
  desktopSpace: "none",
  wideSpace: "none",
  collapsibleAlignmentChildProps: null,
  component: "div"
});
const Column = ({
  children,
  data,
  width: width$1,
  ...restProps
}) => {
  const {
    collapseMobile,
    collapseTablet,
    collapseDesktop,
    mobileSpace,
    tabletSpace,
    desktopSpace,
    wideSpace,
    collapsibleAlignmentChildProps,
    component
  } = useContext(ColumnsContext);
  return /* @__PURE__ */ jsx(
    Box,
    {
      component,
      display: component === "span" ? "block" : void 0,
      minWidth: 0,
      width: width$1 !== "content" ? "full" : void 0,
      flexShrink: width$1 === "content" ? 0 : void 0,
      flexGrow: 1,
      className: [
        column,
        width$1 !== "content" ? width[width$1] : null
      ],
      ...buildDataAttributes({ data, validateRestProps: restProps }),
      children: /* @__PURE__ */ jsx(
        Box,
        {
          component,
          paddingLeft: optimizeResponsiveArray([
            collapseMobile ? "none" : mobileSpace,
            collapseTablet ? "none" : tabletSpace,
            collapseDesktop ? "none" : desktopSpace,
            wideSpace
          ]),
          paddingTop: collapseMobile || collapseTablet || collapseDesktop ? optimizeResponsiveArray([
            collapseMobile ? mobileSpace : "none",
            collapseTablet ? tabletSpace : "none",
            collapseDesktop ? desktopSpace : "none",
            "none"
          ]) : void 0,
          height: "full",
          ...collapsibleAlignmentChildProps,
          className: columnContent,
          children
        }
      )
    }
  );
};
export {
  Column,
  ColumnsContext,
  optimizeResponsiveArray,
  validColumnsComponents
};
