@use "sass:color" as sass-color;
@use "colors" as color;
@use "variables" as var;

/*
  Mixins
*/

@mixin breakpoint($point) {
  @if $point == phone-sm {
    // smartphones, portrait iPhone, small portrait Android
    @media (max-width: 320px) {
      @content;
    }
  } @else if $point == phone-lrg {
    // smartphones, Android phones, landscape iPhone
    @media (max-width: 481px) {
      @content;
    }
  } @else if $point == tablet-sm {
    // portrait tablets, portrait iPad, e-readers (Nook/Kindle), smaller landscape Android
    @media (max-width: 641px) {
      @content;
    }
  } @else if $point == tablet-md {
    // tablet, landscape iPad, lo-res laptops ands desktops
    @media (max-width: 961px) {
      @content;
    }
  } @else if $point == tablet-lrg {
    // big landscape tablets, laptops, and desktops
    @media (max-width: 1025px) {
      @content;
    }
  } @else if $point == tablet-lrg {
    // hi-res laptops and desktops
    @media (max-width: 1281px) {
      @content;
    }
  } @else {
    @media (max-width: $point) {
      @content;
    }
  }
}

@function space($space: 0.5) {
  @return $space * var.$base-space;
}

@mixin custom-scroll($trackColor, $thumbColor) {
  // Let's get this party started
  &::-webkit-scrollbar {
    width: var.$base-space;
    height: var.$base-space;
  }

  // Track
  &::-webkit-scrollbar-track {
    background-color: $trackColor;
  }

  // Handle
  &::-webkit-scrollbar-thumb {
    background: $thumbColor;
  }

  &::-webkit-scrollbar-thumb:window-inactive {
    background: $thumbColor;
  }

  overflow: auto;
}

@mixin display-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  flex-wrap: nowrap;
  align-content: stretch;
  align-items: stretch;
}

@mixin display-column {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

@mixin input-style {
  font-size: 100%;
  font-family: inherit;
  height: 2.1em;
  line-height: 1.5;
  margin: 0;
  border: var.$input-border;
  border-radius: var.$input-border-radius;
  background-color: color.$white;
  width: 100%;
  padding: var.$input-padding;
  box-sizing: border-box;

  &:focus {
    border: 1px solid color.$input-focus;
    outline: none;
  }
}

@mixin no-list-style {
  margin: 0;
  padding: 0;
  list-style: none;
}

@mixin field-control {
  cursor: move;
  list-style: none;
  margin: -1px 0 0;
  border: 1px solid color.$gray-lighter;
  text-align: left;
  background: color.$white;
  user-select: none;
  overflow: hidden;

  &.control-moving {
    border-radius: var.$border-radius;
    animation: DRAG_GHOST 500ms forwards;
  }

  &::before {
    margin-right: space(1);
    font-size: 16px;
  }

  &:hover {
    background-color: sass-color.adjust(color.$white, $lightness: -5%);
  }

  button {
    box-sizing: border-box;
    font-size: 1em;
    line-height: 1.8em;
    display: flex;
    height: 100%;
    width: 100%;
    background: transparent;
    border: 0 none;
    text-align: left;
    padding: space(1);
    border-radius: 0;

    &:focus {
      outline: 0 none;
      background-color: sass-color.adjust(color.$white, $lightness: -5%);
      box-shadow: 0 0 0 1px color.$input-focus inset;
      border-radius: 0 !important;
    }

    &:active {
      transform: none;
    }

    &:hover {
      filter: none;
    }
  }

  .control-icon {
    margin-right: space(1);
    text-align: center;
    width: var.$icon-size;
    height: var.$icon-size;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  [dir="rtl"] & {
    button {
      text-align: right !important;
    }

    svg {
      float: right !important;
      margin: 0 0 0 space(1) !important;
    }
  }
}

@mixin button-style {
  border-radius: var.$input-border-radius;
  border: 1px solid color.$gray;
  color: color.$gray-dark;
  background-color: color.$white;
  padding: space() space(1);

  &:active {
    transform: scale(0.97);
  }

  &:hover {
    filter: brightness(0.9);
  }
}

@mixin states {
  &.primary,
  &.success,
  &.warning,
  &.error {
    color: color.$white;
  }

  &.primary {
    background-color: color.$brand-primary;
    border-color: color.$brand-primary-dark;
  }

  &.success {
    background-color: color.$brand-success;
    border-color: color.$brand-success-dark;
  }

  &.warning {
    background-color: color.$brand-warning;
    border-color: color.$brand-warning-dark;
  }

  &.error {
    background-color: color.$brand-error;
    border-color: color.$brand-error-dark;
  }

  &[disabled] {
    background-color: color.$gray-lighter;
    color: color.$white;
  }

  &:focus {
    border: 1px solid color.$input-focus;
  }

  &:hover,
  &:focus {
    outline: 0 none;
  }
}

@mixin clearfix {
  &::after {
    content: "";
    display: table;
    clear: both;
  }
}

@mixin hideConditionField {
  max-width: 0%;
  padding: 0;
  border: 0 none;
  overflow: hidden;
}
