////
/// @group accordion-menu
////

/// Sets if accordion menus have the default arrow styles.
/// @type Boolean
$accordionmenu-arrows: true !default;

/// Sets accordion menu arrow color if arrow is used.
/// @type Color
$accordionmenu-arrow-color: $primary-color !default;

/// Sets accordion menu item padding.
/// @type Color
$accordionmenu-item-background: null !default;

/// Sets accordion menu item border.
/// @type Color
$accordionmenu-border: 1px solid $light-gray !default;

/// Sets accordion menu item padding.
/// @type Color
$accordionmenu-submenu-toggle-background: null !default;

/// Sets accordion menu item padding.
/// @type List
$accordion-submenu-toggle-border: $accordionmenu-border !default;

/// Sets accordion menu submenu toggle background width.
/// @type Number
$accordionmenu-submenu-toggle-width: 40px !default;

/// Sets accordion menu submenu toggle background height.
/// @type Number
$accordionmenu-submenu-toggle-height: $accordionmenu-submenu-toggle-width !default;

/// Sets accordion menu arrow size if arrow is used.
/// @type Length
$accordionmenu-arrow-size: 6px !default;

@mixin foundation-accordion-menu {
  .accordion-menu {
    @if $accordionmenu-border {
      border-bottom: $accordionmenu-border;
    }

    li {
      @if $accordionmenu-border {
        border-top: $accordionmenu-border;
        border-right: $accordionmenu-border;
        border-left: $accordionmenu-border;
      }
    }

    .is-accordion-submenu li {
      @if $accordionmenu-border {
        border-right: 0;
        border-left: 0;
      }
    }

    a {
      @if $accordionmenu-item-background {
        background: $accordionmenu-item-background;
      }
    }

    // Submenu li styling
    .is-accordion-submenu-parent {
      position: relative;

      & > a {
        margin-#{$global-right}: $accordionmenu-submenu-toggle-width;
      }
    }

    // Submenu toggle
    .submenu-toggle {
      position: absolute;
      top: 0;
      #{$global-right}: 0;

      width: $accordionmenu-submenu-toggle-width;
      height: $accordionmenu-submenu-toggle-height;

      border-#{$global-left}: $accordion-submenu-toggle-border;

      @if $accordionmenu-submenu-toggle-background {
        background: $accordionmenu-submenu-toggle-background;
      }

      // Add the arrow to the toggle
      &::after {
        @include css-triangle(6px, $accordionmenu-arrow-color, down);

        top: 0;
        bottom: 0;
        margin: auto;
      }
    }

    // Rotate the arrow when menu is open
    .submenu-toggle[aria-expanded='true']::after {
      transform: scaleY(-1);
      transform-origin: 50% 50%;
    }

    .submenu-toggle-text {
      @include element-invisible;
    }
  }

  // If arrows are enabled, display them
  @if $accordionmenu-arrows {
    .is-accordion-submenu-parent:not(.has-submenu-toggle) > a {
      position: relative;

      &::after {
        @include css-triangle($accordionmenu-arrow-size, $accordionmenu-arrow-color, down);

        position: absolute;
        top: 50%;
        margin-top: -1 * ($accordionmenu-arrow-size / 2);
        #{$global-right}: 1rem;
      }
    }

    .is-accordion-submenu-parent[aria-expanded='true'] > a::after {
      transform: rotate(180deg);
      transform-origin: 50% 50%;
    }
  }
}
