var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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;
};
import { jsx, jsxs } from "react/jsx-runtime";
import React, { useState } from "react";
import styled, { css } from "styled-components";
import { string, node, bool } from "prop-types";
import { ChevronDown } from "@gympass/yoga-icons";
import { Text, Divider } from "../..";
import Content from "./Content";
const AccordionWrapper = styled.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 && 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 = styled.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 && css`
      cursor: not-allowed;
    `}
`;
const Title = styled.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 && css`
      ${({
  theme: {
    yoga: {
      colors: { text }
    }
  }
}) => {
  return `
      color: ${text.secundary};
    `;
}}
    `}
`;
const AccordionContent = styled.div`
  height: auto;
  max-height: ${({ isOpen }) => isOpen ? "9999px" : "0"};
  overflow: hidden;
  transition: max-height 200ms ease-in-out;

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

  ${({ hasHorizontalPadding }) => !hasHorizontalPadding && css`
      ${Content} {
        padding-left: 0;
        padding-right: 0;
      }
    `}
`;
const ArrowWrapper = styled.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] = useState(expanded);
  const [summary, ...contentChildren] = React.Children.toArray(children);
  const hasSummary = summary.type.displayName === "Accordion.Summary";
  return /* @__PURE__ */ jsxs(AccordionWrapper, __spreadProps(__spreadValues({ disabled }, props), { children: [
    /* @__PURE__ */ jsxs(
      Header,
      {
        disabled,
        onClick: () => {
          setOpen((o) => !o);
        },
        small,
        hasHorizontalPadding,
        children: [
          hasSummary ? summary : /* @__PURE__ */ jsxs(Title, { subtitle, children: [
            small ? /* @__PURE__ */ jsx(Text.Small, { color: disabled ? "text.disabled" : "text.primary", children: title }) : /* @__PURE__ */ jsx(
              Text.Body1,
              {
                bold: true,
                color: disabled ? "text.disabled" : "text.primary",
                children: title
              }
            ),
            /* @__PURE__ */ jsx(Text.Small, { color: "deep", children: subtitle })
          ] }),
          /* @__PURE__ */ jsx(ArrowWrapper, { isOpen: open, disabled, children: /* @__PURE__ */ jsx(ChevronDown, { width: 24, height: 24 }) })
        ]
      }
    ),
    /* @__PURE__ */ jsx(
      AccordionContent,
      {
        isOpen: open,
        small,
        hasHorizontalPadding,
        children: hasSummary ? contentChildren : children
      }
    ),
    /* @__PURE__ */ jsx(Divider, {})
  ] }));
};
Accordion.propTypes = {
  title: string,
  subtitle: string,
  children: node.isRequired,
  disabled: bool,
  expanded: bool,
  small: bool,
  hasHorizontalPadding: bool
};
var Accordion_default = Accordion;
export {
  Accordion_default as default
};
