"use strict";
const React = require("react");
const styles_lib_css_atoms_sprinkles_css_cjs = require("../css/atoms/sprinkles.css.cjs");
const styles_lib_components_Hidden_Hidden_cjs = require("../components/Hidden/Hidden.cjs");
const styles_lib_components_Column_Column_cjs = require("../components/Column/Column.cjs");
const styles_lib_utils_align_cjs = require("./align.cjs");
function invertAlignment(alignment) {
  if (alignment === "flexStart") {
    return "flexEnd";
  }
  if (alignment === "flexEnd") {
    return "flexStart";
  }
  return alignment;
}
function resolveCollapsibleAlignmentProps({
  align,
  alignY,
  collapseBelow,
  reverse
}) {
  const [collapseMobile, collapseTablet, collapseDesktop] = styles_lib_components_Hidden_Hidden_cjs.resolveResponsiveRangeProps({
    below: collapseBelow
  });
  const rowReverseTablet = collapseMobile && reverse;
  const rowReverseDesktop = (collapseMobile || collapseTablet) && reverse;
  const rowReverseWide = (collapseMobile || collapseTablet || collapseDesktop) && reverse;
  const normalizedAlign = styles_lib_css_atoms_sprinkles_css_cjs.normalizeResponsiveValue(
    styles_lib_utils_align_cjs.alignToFlexAlign(align) || "flexStart"
  );
  const {
    mobile: justifyContentMobile = "flexStart",
    tablet: justifyContentTablet = justifyContentMobile,
    desktop: justifyContentDesktop = justifyContentTablet,
    wide: justifyContentWide = justifyContentDesktop
  } = normalizedAlign;
  return {
    collapseMobile,
    collapseTablet,
    collapseDesktop,
    orderChildren: (children) => {
      const childrenArray = React.Children.toArray(children);
      return !collapseMobile && !collapseTablet && reverse ? childrenArray.reverse() : childrenArray;
    },
    collapsibleAlignmentProps: {
      display: styles_lib_components_Column_Column_cjs.optimizeResponsiveArray([
        collapseMobile ? "block" : "flex",
        collapseTablet ? "block" : "flex",
        collapseDesktop ? "block" : "flex",
        "flex"
      ]),
      flexDirection: styles_lib_components_Column_Column_cjs.optimizeResponsiveArray([
        collapseMobile ? "column" : "row",
        // eslint-disable-next-line no-nested-ternary
        collapseTablet ? "column" : rowReverseTablet ? "rowReverse" : "row",
        // eslint-disable-next-line no-nested-ternary
        collapseDesktop ? "column" : rowReverseDesktop ? "rowReverse" : "row",
        rowReverseWide ? "rowReverse" : "row"
      ]),
      justifyContent: align ? styles_lib_components_Column_Column_cjs.optimizeResponsiveArray([
        justifyContentMobile,
        rowReverseTablet ? invertAlignment(justifyContentTablet) : justifyContentTablet,
        rowReverseDesktop ? invertAlignment(justifyContentDesktop) : justifyContentDesktop,
        rowReverseWide ? invertAlignment(justifyContentWide) : justifyContentWide
      ]) : void 0,
      alignItems: alignY ? styles_lib_utils_align_cjs.alignYToFlexAlign(alignY) : void 0
    },
    collapsibleAlignmentChildProps: {
      display: styles_lib_components_Column_Column_cjs.optimizeResponsiveArray([
        collapseMobile && justifyContentMobile !== "flexStart" ? "flex" : "block",
        collapseTablet && justifyContentTablet !== "flexStart" ? "flex" : "block",
        collapseDesktop && justifyContentDesktop !== "flexStart" ? "flex" : "block",
        "block"
      ]),
      justifyContent: styles_lib_components_Column_Column_cjs.optimizeResponsiveArray([
        justifyContentMobile,
        justifyContentTablet,
        justifyContentDesktop,
        justifyContentWide
      ])
    }
  };
}
exports.resolveCollapsibleAlignmentProps = resolveCollapsibleAlignmentProps;
