/*
 * Flex SCSS Framework
 * A SCSS alternative to @angular/flex-layout
 */

// Variables
$breakpoint-xs: 599px;
$breakpoint-sm: 600px;
$breakpoint-md: 960px;
$breakpoint-lg: 1280px;

$spacing-base: 4px;
$spacing-xs: $spacing-base;
$spacing-sm: $spacing-base * 2;  // 8px
$spacing-md: $spacing-base * 4;  // 16px
$spacing-lg: $spacing-base * 6;  // 24px
$spacing-xl: $spacing-base * 8;  // 32px

// Mixins
@mixin respond-to($breakpoint) {
  @if $breakpoint == xs {
    @media (max-width: $breakpoint-xs) { @content; }
  }
  @else if $breakpoint == sm {
    @media (min-width: $breakpoint-sm) and (max-width: $breakpoint-md - 1) { @content; }
  }
  @else if $breakpoint == md {
    @media (min-width: $breakpoint-md) and (max-width: $breakpoint-lg - 1) { @content; }
  }
  @else if $breakpoint == lg {
    @media (min-width: $breakpoint-lg) { @content; }
  }
}

// Generate spacing utilities
@mixin spacing($type, $side, $size, $value) {
  .#{$type}#{$side}-#{$size} {
    @if $side == "" {
      @if $type == "m" {
        margin: $value;
      } @else if $type == "p" {
        padding: $value;
      }
    } @else if $side == "x" {
      @if $type == "m" {
        margin-left: $value;
        margin-right: $value;
      } @else if $type == "p" {
        padding-left: $value;
        padding-right: $value;
      }
    } @else if $side == "y" {
      @if $type == "m" {
        margin-top: $value;
        margin-bottom: $value;
      } @else if $type == "p" {
        padding-top: $value;
        padding-bottom: $value;
      }
    }
  }
}

/* ------ CONTAINER STYLES ------ */
.flex {
  &-container {
    display: flex;
    box-sizing: border-box;
  }

  &-column {
    flex-direction: column;
  }

  &-row {
    flex-direction: row;
  }

  &-wrap {
    flex-wrap: wrap;
  }

  &-nowrap {
    flex-wrap: nowrap;
  }

  /* ------ ALIGNMENT STYLES ------ */
  /* Justify Content (Main Axis) */
  &-justify {
    &-start {
      justify-content: flex-start;
    }

    &-end {
      justify-content: flex-end;
    }

    &-center {
      justify-content: center;
    }

    &-between {
      justify-content: space-between;
    }

    &-around {
      justify-content: space-around;
    }

    &-evenly {
      justify-content: space-evenly;
    }
  }

  /* Align Items (Cross Axis) */
  &-align {
    &-start {
      align-items: flex-start;
    }

    &-end {
      align-items: flex-end;
    }

    &-center {
      align-items: center;
    }

    &-baseline {
      align-items: baseline;
    }

    &-stretch {
      align-items: stretch;
    }
  }

  /* Align Content (Multiple Rows) */
  &-content {
    &-start {
      align-content: flex-start;
    }

    &-end {
      align-content: flex-end;
    }

    &-center {
      align-content: center;
    }

    &-between {
      align-content: space-between;
    }

    &-around {
      align-content: space-around;
    }

    &-stretch {
      align-content: stretch;
    }
  }

  /* ------ ITEM STYLES ------ */
  /* Flex Grow */
  &-grow {
    @for $i from 0 through 4 {
      &-#{$i} {
        flex-grow: $i;
      }
    }
  }

  /* Flex Shrink */
  &-shrink {
    @for $i from 0 through 2 {
      &-#{$i} {
        flex-shrink: $i;
      }
    }
  }

  /* Flex Basis */
  &-basis {
    &-auto {
      flex-basis: auto;
    }

    &-0 {
      flex-basis: 0;
    }

    &-25 {
      flex-basis: 25%;
    }

    &-33 {
      flex-basis: 33.333%;
    }

    &-50 {
      flex-basis: 50%;
    }

    &-66 {
      flex-basis: 66.666%;
    }

    &-75 {
      flex-basis: 75%;
    }

    &-100 {
      flex-basis: 100%;
    }
  }

  /* Common flex combination */
  &-auto {
    flex: 1 1 auto;
  }

  &-none {
    flex: none;
  }

  &-1 {
    flex: 1;
  }

  /* Align Self (Individual Item Alignment) */
  &-self {
    &-start {
      align-self: flex-start;
    }

    &-end {
      align-self: flex-end;
    }

    &-center {
      align-self: center;
    }

    &-baseline {
      align-self: baseline;
    }

    &-stretch {
      align-self: stretch;
    }
  }

  /* ------ ORDER STYLES ------ */
  &-order {
    @for $i from 0 through 5 {
      &-#{$i} {
        order: $i;
      }
    }
  }
}

/* ------ RESPONSIVE BREAKPOINTS ------ */
@include respond-to(xs) {
  .flex-xs {
    &-column {
      flex-direction: column;
    }

    &-row {
      flex-direction: row;
    }

    &-wrap {
      flex-wrap: wrap;
    }

    &-grow {
      &-0 {
        flex-grow: 0;
      }

      &-1 {
        flex-grow: 1;
      }
    }

    &-basis {
      &-100 {
        flex-basis: 100%;
      }

      &-50 {
        flex-basis: 50%;
      }

      &-33 {
        flex-basis: 33.333%;
      }

      &-25 {
        flex-basis: 25%;
      }
    }

    &-hide {
      display: none;
    }
  }
}

@include respond-to(sm) {
  .flex-sm {
    &-column {
      flex-direction: column;
    }

    &-row {
      flex-direction: row;
    }

    &-wrap {
      flex-wrap: wrap;
    }

    &-grow {
      &-0 {
        flex-grow: 0;
      }

      &-1 {
        flex-grow: 1;
      }
    }

    &-basis {
      &-100 {
        flex-basis: 100%;
      }

      &-50 {
        flex-basis: 50%;
      }

      &-33 {
        flex-basis: 33.333%;
      }

      &-25 {
        flex-basis: 25%;
      }
    }

    &-hide {
      display: none;
    }
  }
}

@include respond-to(md) {
  .flex-md {
    &-column {
      flex-direction: column;
    }

    &-row {
      flex-direction: row;
    }

    &-wrap {
      flex-wrap: wrap;
    }

    &-grow {
      &-0 {
        flex-grow: 0;
      }

      &-1 {
        flex-grow: 1;
      }
    }

    &-basis {
      &-100 {
        flex-basis: 100%;
      }

      &-50 {
        flex-basis: 50%;
      }

      &-33 {
        flex-basis: 33.333%;
      }

      &-25 {
        flex-basis: 25%;
      }
    }

    &-hide {
      display: none;
    }
  }
}

@include respond-to(lg) {
  .flex-lg {
    &-column {
      flex-direction: column;
    }

    &-row {
      flex-direction: row;
    }

    &-wrap {
      flex-wrap: wrap;
    }

    &-grow {
      &-0 {
        flex-grow: 0;
      }

      &-1 {
        flex-grow: 1;
      }
    }

    &-basis {
      &-100 {
        flex-basis: 100%;
      }

      &-50 {
        flex-basis: 50%;
      }

      &-33 {
        flex-basis: 33.333%;
      }

      &-25 {
        flex-basis: 25%;
      }
    }

    &-hide {
      display: none;
    }
  }
}

/* ------ GRID LAYOUT ------ */
.grid {
  &-container {
    display: grid;
    box-sizing: border-box;
  }

  &-gap {
    &-sm {
      gap: $spacing-sm;
    }

    &-md {
      gap: $spacing-md;
    }

    &-lg {
      gap: $spacing-lg;
    }

    &-xl {
      gap: $spacing-xl;
    }
  }

  /* Common grid templates */
  &-cols {
    @for $i from 1 through 4 {
      &-#{$i} {
        grid-template-columns: repeat($i, 1fr);
      }
    }

    /* Auto-sizing grids */
    &-auto {
      grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
  }
}

/* Responsive grids */
@include respond-to(xs) {
  .grid-xs-cols {
    @for $i from 1 through 2 {
      &-#{$i} {
        grid-template-columns: repeat($i, 1fr);
      }
    }
  }
}

@include respond-to(sm) {
  .grid-sm-cols {
    @for $i from 2 through 3 {
      &-#{$i} {
        grid-template-columns: repeat($i, 1fr);
      }
    }
  }
}

@include respond-to(md) {
  .grid-md-cols {
    @for $i from 3 through 4 {
      &-#{$i} {
        grid-template-columns: repeat($i, 1fr);
      }
    }
  }
}

@include respond-to(lg) {
  .grid-lg-cols {
    @for $i from 4 through 5 {
      &-#{$i} {
        grid-template-columns: repeat($i, 1fr);
      }
    }
  }
}

/* ------ SPACING UTILITIES ------ */
// Margins
@for $i from 0 through 5 {
  $value: $i * $spacing-base;
  @include spacing("m", "", $i, $value);
  @include spacing("m", "x", $i, $value);
  @include spacing("m", "y", $i, $value);
}

// Paddings
@for $i from 0 through 5 {
  $value: $i * $spacing-base;
  @include spacing("p", "", $i, $value);
  @include spacing("p", "x", $i, $value);
  @include spacing("p", "y", $i, $value);
}

/* ------ UTILITY CLASSES ------ */
.width-100 {
  width: 100%;
}

.height-100 {
  height: 100%;
}

.display {
  &-none {
    display: none;
  }

  &-block {
    display: block;
  }

  &-inline-block {
    display: inline-block;
  }
}

.position {
  &-relative {
    position: relative;
  }

  &-absolute {
    position: absolute;
  }

  &-fixed {
    position: fixed;
  }
}

.overflow {
  &-auto {
    overflow: auto;
  }

  &-hidden {
    overflow: hidden;
  }

  &-scroll {
    overflow: scroll;
  }
}

.text {
  &-center {
    text-align: center;
  }

  &-left {
    text-align: left;
  }

  &-right {
    text-align: right;
  }
}
