@import '../jnt-variables';
@import '../elements/icon';
@import '../jnt-hosts';
@import '../jnt-functions';

@mixin jnt-collapsible($passed: (), $context: null, $strategy: 'changes') {
  $defs: ();
  $vars: $passed;
  $declare: false;
  $wrapper: null;
  @if $jnt-ng-deep {
    $wrapper: '::ng-deep';
  }
  @if $passed == () or $strategy == 'merge' {
    $vars: recursive-map-merge($defs, $passed);
    $declare: true;
  }
  #{if($context, $context, $jnt-collapsible-host)} {
    @if $declare {
      display: block;
      background-color: $jnt-primary-background;
      padding: $jnt-gutter-normal;
      border-radius: $jnt-corner-normal;
      border: 1px solid $jnt-page-background;
      &[data-orientation='vertical'] {
        display: flex;
        [data-title][child-of=jnt-collapsible-host] {
          padding: $jnt-gutter-normal $jnt-gutter-small;
          [data-icon][child-of=jnt-collapsible-host] {
            transform: rotate(90deg);
          }
          span[child-of=jnt-collapsible-host] {
            writing-mode: vertical-rl;
          }
        }
        [data-content][child-of=jnt-collapsible-host] {
          padding: 0 0 0 $jnt-gutter-normal;
        }
      }
    }
  }
  #{$context} #{$wrapper} [data-title][child-of=jnt-collapsible-host] {
    @if $declare {
      padding: $jnt-gutter-small $jnt-gutter-normal;
      background-color: $jnt-secondary-dark-color;
      border-radius: $jnt-corner-normal;
      color: $jnt-primary-text-color;
      display: flex;
      align-items: center;
      cursor: pointer;
      user-select: none;
      line-height: 1.6;
      &[active='true'] {
        background-color: $jnt-primary-light-color;
        color: $jnt-white-color;
        @include jnt-icon((color: $jnt-white-color));
      }
      &:hover {
        &[active='false'] {
          color: $jnt-primary-light-color;
          @include jnt-icon((color: $jnt-primary-light-color));
        }
      }
      &:focus {
        outline: 0;
        box-shadow: inset $jnt-outline-shadow-small $jnt-primary-light-color;
      }
    }
    span[child-of=jnt-collapsible-host] {
      @if $declare {
        margin: 0 $jnt-gutter-tiny;
      }
    }
  }
  #{$context} #{$wrapper} [data-content][child-of=jnt-collapsible-host] {
    @if $declare {
      padding: $jnt-gutter-normal 0;
      flex: 1;
    }
  }
}
@if $jnt-debug {
  @debug 'collapsible compiled';
}
