@use 'sass:math';

@mixin outer_shadow() {
  box-shadow: inset $gray_90 1px 1px, transparentize(black, 0.8) 1px 1px,
    transparentize(black, 0.6) 0 1px 5px;
}

// same as outer shadow, but higher
@mixin dropdown_shadow {
  box-shadow: inset $gray_90 1px 1px, transparentize(black, 0.8) 1px 1px,
    transparentize(black, 0.6) 5px 5px 10px;
}

@mixin row_shadow() {
  &:not(:last-child) {
    box-shadow: $gray_90 0 1px, inset transparentize(black, 0.8) 0 -1px;
  }

  &:only-child {
    box-shadow: none;
  }
}

@mixin inner_shadow() {
  box-shadow: inset $gray_90 -1px -1px, inset transparentize(black, 0.9) 1px 1px,
    inset transparentize(black, 0.9) 0 0 10px;
}

@mixin inner_shadow_active() {
  @include inner_shadow;
  transition: background-color 250ms;

  &:hover {
    background: $gray_90;
  }
}

@mixin input_shadow() {
  box-shadow: inset $gray_90 0 -1px, inset transparentize(black, 0.8) 0 1px;
}

@mixin modal_mixin() {
  position: fixed;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

@mixin after_shade($color, $position: relative) {
  position: $position;

  &::after {
    content: ' ';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 120px;
    width: 100%;
    background: linear-gradient(transparent, $color);
    border-radius: $radius;
    pointer-events: none;
    touch-action: none;
  }
}

@mixin phone {
  @media (max-width: 320px) {
    @content;
  }
}

@mixin tablet {
  @media (max-width: 599px) {
    @content;
  }
}

@mixin sidebar_stack_limit {
  @media (max-width: 1000px) {
    @content;
  }
}

@mixin desktop {
  @media (max-width: $content_width) {
    @content;
  }
}

@mixin vertical_at_tablet {
  @media (max-width: 599px) {
    flex-direction: column !important;

    @content;

    & > * {
      margin: $gap * 0.5 0 !important;

      &:first-child {
        margin-top: 0 !important;
      }
      &:last-child {
        margin-bottom: 0 !important;
      }
    }
  }
}

@mixin can_backdrop {
  @supports (
    (-webkit-backdrop-filter: blur(5px)) or (backdrop-filter: blur(5px))
  ) {
    @content;
  }
}

@mixin blur($color: $content_bg_backdrop, $radius: 15px) {
  background: $color;

  @include can_backdrop {
    backdrop-filter: blur($radius);
    -webkit-backdrop-filter: blur($radius);
    background: $color;
  }
}

@mixin title_with_line {
  font: $font_14_semibold;
  text-transform: uppercase;
  color: $gray_25;
  flex-direction: row;
  display: flex;
  align-items: center;

  & > * {
    padding-right: $gap;
  }

  & > :global(.line) {
    flex: 1;
    height: 2px;
    background: $gray_90;
  }
}

@mixin clamp($lines, $line: 1em) {
  display: -webkit-box;
  line-clamp: $lines;
  -webkit-line-clamp: $lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@mixin sidebar {
  @include blur;
}

@mixin sidebar_content($width: 400px) {
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex: 0 1 $width;
  max-width: 100vw;
  position: relative;
  border-radius: $radius 0 0 $radius;
}

@mixin editor_round_button {
  width: $upload_button_height;
  height: $upload_button_height;
  border-radius: ($upload_button_height * 0.5) !important;
  flex: 0 0 $upload_button_height;
  position: relative;
  border-radius: $radius;
  cursor: pointer;
}

@mixin flow_grid {
  width: 100%;
  box-sizing: border-box;
  display: grid;

  grid-template-columns: repeat(auto-fit, minmax($cell - 5, 1fr));

  grid-auto-flow: row dense;
  grid-column-gap: $gap;
  grid-row-gap: $gap;
  grid-auto-rows: $cell;

  // 4 cells
  @media (max-width: $cell * 5 + $gap * 4 + 55) {
    grid-auto-rows: calc(25vw - 30px);
  }

  // 3 cells
  @media (max-width: $cell * 4 + $gap * 3 + 55) {
    grid-auto-rows: calc(33vw - 30px);
  }

  // 2 cells
  @media (max-width: $cell * 3 + $gap * 2 + 55) {
    grid-auto-rows: calc(50vw - 40px);
  }

  // < 870px
  @media (max-width: ($cell + 10) * 3) {
    grid-template-columns: repeat(auto-fill, minmax($fluid_cell - 20, 1fr));
    grid-template-rows: calc(50vw - 10px) $fluid_cell;
  }

  // < 776px
  @media (max-width: $cell_tablet) {
    grid-template-rows: calc(66vw - 10px) auto calc(50vw - 40px);
  }

  // < 520px
  @media (max-width: $cell_mobile) {
    grid-template-columns: repeat(auto-fill, minmax(calc(50vw - 20px), 1fr));
    grid-template-rows: calc(100vw - 10px) auto;
    grid-auto-rows: calc(50vw - 10px);
  }
}

@mixin appear {
  @keyframes __appear {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  animation: __appear 0.25s forwards;
}

@mixin container {
  max-width: $content_width + $gap * 8;
  width: 100%;

  padding-left: $gap * 4;
  padding-right: $gap * 4;

  @include tablet {
    padding-left: 0;
    padding-right: 0;
  }
}

@mixin hover_opacity($initial_opacity: 0.5) {
  opacity: $initial_opacity;
  transition: opacity 0.25s;

  &:hover {
    opacity: 1;
  }
}

@mixin popper_arrow {
  width: 0;
  height: 0;
  border-style: solid;
  position: absolute;

  [data-popper-placement*='bottom'] & {
    border-width: 0 10px 10px 10px;
    border-color: transparent transparent $content_bg_lightest transparent;
    top: -10px;
  }

  [data-popper-placement*='top'] & {
    border-width: 10px 10px 0 10px;
    border-color: $content_bg_lightest transparent transparent transparent;
    bottom: -10px;
  }

  [data-popper-placement*='right'] & {
    border-width: 10px 10px 10px 0;
    border-color: transparent $content_bg_lightest transparent transparent;
    left: -10px;
  }

  [data-popper-placement*='left'] & {
    border-width: 10px 0 10px 10px;
    border-color: transparent transparent transparent $content_bg_lightest;
    right: -10px;
  }
}
