@import "../../patternfly-imports";

/* stylelint-disable */

// New breakpoints
$pf-global--breakpoint--mobile: 599px;
$pf-global--breakpoint--tablet: 600px;
$pf-global--breakpoint--desktop: 1200px;

// Add name to breakpoints
$mobile-only: $pf-global--breakpoint--mobile, -mobile-only;
$tablet: $pf-global--breakpoint--tablet, -tablet;
$desktop: $pf-global--breakpoint--desktop, -desktop;

@mixin responsive-definitions($classname, $list...) {
  #{$classname} {
    @content;
  }

  @each $item in $list {
    $selector: $classname;
    $breakpoint: nth($item, 1);
    $breakpoint-name: nth($item, 2);

    @if (str-index($classname, " > *")) {
      $index: str-index($classname, " > *");
      $selector: str-insert($classname, $breakpoint-name, $index);
    } @else {
      $selector: #{$selector}#{$breakpoint-name};
    }

    // @warn $selector;

    $range: "min-width";

    @if $breakpoint-name == "-mobile-only" {
      $range: "max-width";
    }

    #{$selector} {
      @media screen and ($range: $breakpoint) {
        @content;
      }
    }
  }
}

@include responsive-definitions(".pf-l-flex.pf-m-space-items-none > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: 0; }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-xs > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--xs); }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-sm > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--sm); }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-md > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--md); }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-lg > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--lg); }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-xl > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--xl); }

@include responsive-definitions(".pf-l-flex.pf-m-space-items-2xl > *", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--2xl); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-xs", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: 0; }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-xs", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--xs); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-sm", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--sm); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-md", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--md); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-lg", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--lg); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-xl", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--xl); }

@include responsive-definitions(".pf-l-flex .pf-m-spacer-2xl", $mobile-only, $tablet, $desktop) { --pf-l-flex--spacer: var(--pf-global--spacer--2xl); }

/* stylelint-enable */

.pf-l-flex {
  // Base spacer
  --pf-l-flex--spacer--base: var(--pf-global--spacer--md);
  --pf-l-flex--row-gap--base: var(--pf-global--spacer--md);

  // This value gets reset based on modifier usage
  --pf-l-flex--spacer: var(--pf-l-flex--spacer--base);
  --pf-l-flex--row-gap: var(--pf-l-flex--row-gap--base);

  // Margins
  --pf-l-flex-item--sm--MarginRight: var(--pf-global--spacer--sm);
  --pf-l-flex-item--sm--MarginLeft: var(--pf-global--spacer--sm);
  --pf-l-flex-item--md--MarginRight: var(--pf-global--spacer--md);
  --pf-l-flex-item--md--MarginLeft: var(--pf-global--spacer--md);
  --pf-l-flex-item--lg--MarginRight: var(--pf-global--spacer--lg);
  --pf-l-flex-item--lg--MarginLeft: var(--pf-global--spacer--lg);
  --pf-l-flex-item--xl--MarginRight: var(--pf-global--spacer--xl);
  --pf-l-flex-item--xl--MarginLeft: var(--pf-global--spacer--xl);


  // reset nested flex spacers
  // & > & {
  // 	--pf-l-flex--spacer: var(--pf-global--spacer--md);
  // 	background: red;
  // }

  display: flex;
  flex-wrap: wrap;
  row-gap: var(--pf-l-flex--row-gap);

  // &.pf-m-nowrap {}

  // Initiate base spacing
  & > :not(:last-child) {
    margin-right: var(--pf-l-flex--spacer);
  }

  // Modifiers
  &.pf-m-justify-flex-end {
    justify-content: flex-end;

    > * {
      margin-right: 0;
    }

    > :not(:first-child) {
      margin-left: var(--pf-l-flex--spacer);
    }
  }

  // &[class*="pf-m-row-gap"] {
  //   margin-top: calc((var(--pf-l-flex--spacer) / 2) * -1);
  //   margin-bottom: calc((var(--pf-l-flex--spacer) / 2) * -1);

  //   > * {
  //     margin-top: calc(var(--pf-l-flex--spacer) / 2);
  //     margin-bottom: calc(var(--pf-l-flex--spacer) / 2);
  //   }
  // }

  // reset spacer if nested flex
  // & .pf-l-flex:not([class*="pf-m-spacer"]):not([class*="pf-m-space-items"]) > * {
  //   --pf-l-flex--spacer: var(--pf-l-flex--spacer--base);
  // }

  &.pf-m-fill-items-mobile-only > .pf-l-flex {
    @media screen and (max-width: $pf-global--breakpoint--mobile) {
      --pf-l-flex--spacer: 0;

      flex: 1 100%;

      // &:not(:first-child) {
      //   margin-top: var(--pf-l-flex--row-gap);
      // }
    }
  }

  & .pf-l-flex > * {
    --pf-l-flex--spacer: var(--pf-l-flex--spacer--base);
  }

  // reset spacing value for children
  [class*="pf-m-spacer"] > * {
    --pf-l-flex--spacer: var(--pf-l-flex--spacer--base);
  }

  // &.pf-m-space-items-none > * {
  //   --pf-l-flex--spacer: 0;
  // }

  // &.pf-m-space-items-xs > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--xs);
  // }

  // &.pf-m-space-items-sm > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--sm);
  // }

  // &.pf-m-space-items-md > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--md);
  // }

  // &.pf-m-space-items-lg > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--lg);
  // }

  // &.pf-m-space-items-xl > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--xl);
  // }

  // &.pf-m-space-items-2xl > * {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--2xl);
  // }

  // // spacer modifiers
  // .pf-m-spacer-none {
  //   --pf-l-flex--spacer: 0;
  // }

  // .pf-m-spacer-xs {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--xs);
  // }

  // .pf-m-spacer-sm {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--sm);
  // }

  // .pf-m-spacer-md {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--md);
  // }

  // .pf-m-spacer-lg {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--lg);
  // }

  // .pf-m-spacer-xl {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--xl);
  // }

  // .pf-m-spacer-2xl {
  //   --pf-l-flex--spacer: var(--pf-global--spacer--2xl);
  // }


  .pf-m-full-width {
    flex: 1 0 100%;
  }

  &.pf-m-inline {
    display: inline-flex;
  }

  .pf-m-section {
    border: 1px dashed;
  }

  &.pf-m-align-center {
    align-items: center;
  }

  // if set on child
  .pf-m-align-center {
    align-self: center;
  }

  // if set on child
  &.pf-m-align-flex-start {
    align-items: flex-start;
  }

  &.pf-m-align-right,
  .pf-m-align-right {
    margin-left: auto;
  }

  &.pf-m-overflow-scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  &.pf-m-nowrap {
    flex-wrap: nowrap;
  }

  &.pf-m-columns {
    flex-direction: column;

    > *:not(:first-child) {
      margin-top: var(--pf-l-flex--spacer);
    }
  }
}

/* stylelint-disable */
.pf-l-flex {

  // > *:not(:last-child) {
  //   flex: 1;
  //   margin-right: var(--pf-l-flex--spacer);
  // }

  // > *:not(.pf-flex__section) {
  //   @media screen and (min-width: 380px) {
  //     margin-right: 12px;
  //   }
  // }

  .pf-m-flex-1 {
    flex: 1;
  }

  .pf-m-stretch {
    flex: 1 auto;
  }

  &.pf-m-justify-space-between {
    justify-content: space-between;
  }

  &.pf-m-justify-center {
    justify-content: center;
  }

  &.pf-m-justify-space-around {
    justify-content: space-around;
  }

  // if set on parent
  &.pf-m-justify-space-between,
  &.pf-m-justify-center,
  &.pf-m-space-between {
    > * {
      margin-right: 0;
      margin-left: 0;
    }
  }
}

.pf-l-flex-section,
.pf-l-flex__section {
  display: flex;
  flex: 1 100%;
}
