@use '../../sass/variables' as *;
@use '../../sass/global' as *;

.collapsible {
  padding-left: 0;
  list-style-type: none;
  background-color: var(--md-sys-color-surface);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  border-left: 1px solid var(--md-sys-color-outline-variant);
  margin: $element-top-margin 0 $element-bottom-margin 0;
  // @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Front/style/scss/component_enhance.scss
  // Matches the 12px corner radius used across cards, dropdowns and
  // collections instead of square corners.
  border-radius: 12px;
  @extend .z-depth-1;

  // @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Front/style/scss/component_enhance.scss
  // Only clip to the rounded corners while every item is closed - an open
  // last item's body needs to be able to grow past the list's own bottom
  // edge instead of being cut off by it.
  &:not(:has(li:last-child.active)) {
    overflow: hidden;
  }
}

.collapsible-header {
  display: flex;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.5;
  padding: 1rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);

  &:focus {
    outline: 0
  }

  > i {
    width: 2rem;
    font-size: 1.6rem;
    display: inline-block;
    text-align: center;
    margin-right: 1rem;
  }
}

// Keep one glyph throughout the transition so opening and closing can reverse
// smoothly, including a second activation before the first turn has finished.
.collapsible-header::after {
  content: '\e5cf';
  display: inline-block;
  flex: 0 0 1em;
  align-self: center;
  width: 1em;
  height: 1em;
  margin-inline-start: auto;
  font-family: 'Material Symbols Outlined', 'Material Symbols Rounded', 'Material Symbols Sharp', 'Material Icons';
  font-size: 25px;
  line-height: 1;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  transform: rotate(0deg);
  transform-origin: center;
  transition: transform var(--collapsible-arrow-duration, 300ms) var(--collapsible-arrow-easing, cubic-bezier(0.4, 0, 0.2, 1));
}

// Only the owning item controls its chevron; expanded ancestors must not turn
// the arrows of closed nested sections.
.collapsible > li.active > .collapsible-header::after {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .collapsible-header::after { transition: none; }
}

.keyboard-focused .collapsible-header:focus {
  background-color: rgba(0, 0, 0, 0.12);
}

.collapsible-header-content {
  flex-grow: 1;
}

.collapsible-body {
  max-height: 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  box-sizing: border-box;
  padding: 0 2rem;
  overflow: hidden;
}

// @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Front/style/scss/component_enhance.scss
// Round the corners of the first/last item's own header/body so they
// follow the list's rounded outline instead of showing a square edge
// inside it. Longhand corners (not the `border-radius` shorthand) so that
// a single-item accordion - where the same <li> is both first and last -
// gets all 4 corners rounded instead of the last-child rule's shorthand
// wiping out the top corners the first-child rule just set.
.collapsible > li:first-child .collapsible-header {
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.collapsible > li:last-child {
  &:not(.active) .collapsible-header {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    transition-delay: 250ms;
    transition-property: border-radius;
  }

  &.active .collapsible-body {
    border-radius: 0 0 12px 12px;
  }
}

// CSS resolves border-radius per-corner, not per-rule: once the
// :not(.active) rule above stops matching, nothing here fixes the bottom
// corners back to square, so a more specific rule elsewhere (e.g. the
// sidenav's `li > a { border-radius: 100px; }` pill styling, which also
// matches .collapsible-header since it's an <a> inside a sidenav <li>)
// is free to fill that gap and leave the header rounded on all 4 corners
// while expanded. Force it explicitly instead of leaving it implicit.
.collapsible > li.active .collapsible-header {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

// Popout Collapsible

.collapsible.popout {
  border: none;
  box-shadow: none;

  > li {
    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    // transform: scaleX(.92);
    margin: 0 24px;
    transition: margin .35s cubic-bezier(0.250, 0.460, 0.450, 0.940);
  }

  > li.active {
    box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
    margin: 16px 0;
    // transform: scaleX(1);
  }
}
