"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Accordion_exports = {};
__export(Accordion_exports, {
  default: () => Accordion_default
});
module.exports = __toCommonJS(Accordion_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_prop_types = require("prop-types");
var import_yoga_icons = require("@gympass/yoga-icons");
var import__ = require("../..");
var import_Content = __toESM(require("./Content"));
const AccordionWrapper = import_styled_components.default.div`
  background-color: ${({ theme }) => theme.yoga.colors.white};
  border: none;
  display: flex;
  flex-direction: column;
  position: relative;
  width: 100%;
  z-index: 1;

  ${({
  disabled,
  theme: {
    yoga: {
      colors: { elements }
    }
  }
}) => disabled && import_styled_components.css`
      background-color: ${elements.backgroundAndDisabled};
    `}

  hr {
    bottom: 0;
    left: 0;
    margin: 0;
    position: absolute;
    z-index: -1;
  }
`;
const getVerticalPadding = (accordion, small) => {
  if (small)
    return accordion.padding.small;
  return accordion.padding.large;
};
const getHorizontalPadding = (accordion, hasHorizontalPadding) => {
  if (hasHorizontalPadding)
    return accordion.padding.standard;
  return accordion.padding.zero;
};
const Header = import_styled_components.default.button`
  align-items: center;
  background-color: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  width: 100%;

  ${({
  theme: {
    yoga: {
      components: { accordion }
    }
  },
  small,
  hasHorizontalPadding
}) => {
  return `
  padding:${getVerticalPadding(accordion, small)}px ${getHorizontalPadding(
    accordion,
    hasHorizontalPadding
  )}px;
`;
}}

  &:focus-visible {
    ${({
  theme: {
    yoga: {
      colors: { elements }
    }
  }
}) => {
  return `
    background: ${elements.backgroundAndDisabled};

  `;
}}
  }

  ${({ disabled }) => disabled && import_styled_components.css`
      cursor: not-allowed;
    `}
`;
const Title = import_styled_components.default.div`
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  text-align: start;

  ${({
  theme: {
    yoga: {
      components: { accordion }
    }
  },
  subtitle
}) => {
  return `
  gap: ${subtitle ? accordion.gap.header : 0}px;
  margin: ${subtitle ? 0 : `${accordion.paddingArrow.total}px 0`};
`;
}}

  ${({ disabled }) => disabled && import_styled_components.css`
      ${({
  theme: {
    yoga: {
      colors: { text }
    }
  }
}) => {
  return `
      color: ${text.secundary};
    `;
}}
    `}
`;
const AccordionContent = import_styled_components.default.div`
  height: auto;
  max-height: ${({ isOpen }) => isOpen ? "9999px" : "0"};
  overflow: hidden;
  transition: max-height 200ms ease-in-out;

  ${({
  theme: {
    yoga: {
      components: { accordion }
    }
  },
  small
}) => small && import_styled_components.css`
      ${import_Content.default} {
        padding-bottom: ${accordion.padding.small}px;
      }
    `}

  ${({ hasHorizontalPadding }) => !hasHorizontalPadding && import_styled_components.css`
      ${import_Content.default} {
        padding-left: 0;
        padding-right: 0;
      }
    `}
`;
const ArrowWrapper = import_styled_components.default.div`
  align-items: center;
  display: flex;
  justify-content: center;

  svg {
    transform: ${({ isOpen }) => isOpen ? "rotate(180deg)" : "rotate(0deg)"};
    transition: all 200ms ease-out 0s;

    ${({
  theme: {
    yoga: {
      colors: { primary, text }
    }
  },
  disabled
}) => {
  return `
      fill: ${disabled ? text.secondary : primary};
    `;
}}
  }

  ${({
  theme: {
    yoga: {
      components: { accordion }
    }
  }
}) => {
  return `
  padding: ${accordion.paddingArrow.total}px;
`;
}}
`;
const Accordion = (_a) => {
  var _b = _a, {
    title,
    subtitle,
    children,
    disabled = false,
    expanded = false,
    small = false,
    hasHorizontalPadding = true
  } = _b, props = __objRest(_b, [
    "title",
    "subtitle",
    "children",
    "disabled",
    "expanded",
    "small",
    "hasHorizontalPadding"
  ]);
  const [open, setOpen] = (0, import_react.useState)(expanded);
  const [summary, ...contentChildren] = import_react.default.Children.toArray(children);
  const hasSummary = summary.type.displayName === "Accordion.Summary";
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AccordionWrapper, __spreadProps(__spreadValues({ disabled }, props), { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      Header,
      {
        disabled,
        onClick: () => {
          setOpen((o) => !o);
        },
        small,
        hasHorizontalPadding,
        children: [
          hasSummary ? summary : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Title, { subtitle, children: [
            small ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Text.Small, { color: disabled ? "text.disabled" : "text.primary", children: title }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import__.Text.Body1,
              {
                bold: true,
                color: disabled ? "text.disabled" : "text.primary",
                children: title
              }
            ),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Text.Small, { color: "deep", children: subtitle })
          ] }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowWrapper, { isOpen: open, disabled, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_yoga_icons.ChevronDown, { width: 24, height: 24 }) })
        ]
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      AccordionContent,
      {
        isOpen: open,
        small,
        hasHorizontalPadding,
        children: hasSummary ? contentChildren : children
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Divider, {})
  ] }));
};
Accordion.propTypes = {
  title: import_prop_types.string,
  subtitle: import_prop_types.string,
  children: import_prop_types.node.isRequired,
  disabled: import_prop_types.bool,
  expanded: import_prop_types.bool,
  small: import_prop_types.bool,
  hasHorizontalPadding: import_prop_types.bool
};
var Accordion_default = Accordion;
