/* stylelint-disable selector-class-pattern */

// Query to kick us into "mobile" mode with larger drag handles/bars.
// See: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer
@mobile-media-query: '(pointer: coarse)';

// SASS variables for normal drag handle and bar size.
// Override in your scss file by setting these variables FIRST, then including this file.
@drag-handle-width: 10px;
@drag-handle-height: 10px;
@drag-bar-size: 6px;

// Mobile handle/bar sizes.  Override as above.
@drag-handle-mobile-width: 24px;
@drag-handle-mobile-height: 24px;

// Handle color/border.

@drag-handle-background-colour: rgba(0, 0, 0, 0.2);
@drag-handle-border: 1px solid rgba(255, 255, 255, 0.7);
@drag-handle-active-border-color: blue;
@drag-handle-active-bg-color: #2dbfff;

@half-drag-handle-height: @drag-handle-height / 2;
@half-drag-handle-width: @drag-handle-width / 2;
@half-drag-bar-size: @drag-bar-size / 2;

.ReactCrop {
  position: relative;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  cursor: crosshair;

  & *,
  & *::before,
  & *::after {
    box-sizing: border-box;
  }

  &--disabled,
  &--locked {
    cursor: inherit;
  }

  &__child-wrapper {
    max-height: inherit;

    & > img,
    & > video {
      display: block;
      max-width: 100%;
      max-height: inherit;
      touch-action: none;
    }
  }

  &__crop-selection {
    position: absolute;
    top: 0;
    left: 0;
    border: 1px dashed white;
    box-shadow: 0 0 0 9999em rgba(0, 0, 0, 0.5);
    transform: translate3d(0, 0, 0);
    cursor: move;
    touch-action: none;

    .ReactCrop--disabled & {
      cursor: inherit;
    }

    .ReactCrop--circular-crop & {
      border-radius: 50%;
      box-shadow: 0 0 1px 1px white, 0 0 0 9999em rgba(0, 0, 0, 0.5);
    }

    &:focus {
      border-color: @drag-handle-active-border-color;
      border-style: solid;
      outline: none;
    }
  }

  &--invisible-crop &__crop-selection {
    display: none;
  }

  &__rule-of-thirds-vt::before,
  &__rule-of-thirds-vt::after,
  &__rule-of-thirds-hz::before,
  &__rule-of-thirds-hz::after {
    position: absolute;
    display: block;
    content: '';
  }

  &__rule-of-thirds-vt {
    &::before,
    &::after {
      width: 1px;
      height: 100%;
      border-left: 1px dashed #fff;
    }

    &::before {
      left: 33.3333%;
      left: calc(100% / 3);
    }

    &::after {
      left: 66.6666%;
      left: calc(100% / 3 * 2);
    }
  }

  &__rule-of-thirds-hz {
    &::before,
    &::after {
      width: 100%;
      height: 1px;
      border-top: 1px dashed #fff;
    }

    &::before {
      top: 33.3333%;
      top: calc(100% / 3);
    }

    &::after {
      top: 66.6666%;
      top: calc(100% / 3 * 2);
    }
  }

  &__drag-handle {
    position: absolute;

    &::after {
      position: absolute;
      display: block;
      width: @drag-handle-width;
      height: @drag-handle-height;
      background-color: @drag-handle-background-colour;
      border: @drag-handle-border;

      // This stops the borders disappearing when keyboard
      // nudging.
      outline: 1px solid transparent;
      content: '';
    }

    &:focus {
      &::after {
        background: @drag-handle-active-bg-color;
        border-color: @drag-handle-active-border-color;
      }
    }
  }

  .ord-nw {
    top: 0;
    left: 0;
    margin-top: -(@half-drag-handle-height);
    margin-left: -(@half-drag-handle-width);
    cursor: nw-resize;

    &::after {
      top: 0;
      left: 0;
    }
  }

  .ord-n {
    top: 0;
    left: 50%;
    margin-top: -(@half-drag-handle-height);
    margin-left: -(@half-drag-handle-width);
    cursor: n-resize;

    &::after {
      top: 0;
    }
  }

  .ord-ne {
    top: 0;
    right: 0;
    margin-top: -(@half-drag-handle-height);
    margin-right: -(@half-drag-handle-width);
    cursor: ne-resize;

    &::after {
      top: 0;
      right: 0;
    }
  }

  .ord-e {
    top: 50%;
    right: 0;
    margin-top: -(@half-drag-handle-height);
    margin-right: -(@half-drag-handle-width);
    cursor: e-resize;

    &::after {
      right: 0;
    }
  }

  .ord-se {
    right: 0;
    bottom: 0;
    margin-right: -(@half-drag-handle-width);
    margin-bottom: -(@half-drag-handle-height);
    cursor: se-resize;

    &::after {
      right: 0;
      bottom: 0;
    }
  }

  .ord-s {
    bottom: 0;
    left: 50%;
    margin-bottom: -(@half-drag-handle-height);
    margin-left: -(@half-drag-handle-width);
    cursor: s-resize;

    &::after {
      bottom: 0;
    }
  }

  .ord-sw {
    bottom: 0;
    left: 0;
    margin-bottom: -(@half-drag-handle-height);
    margin-left: -(@half-drag-handle-width);
    cursor: sw-resize;

    &::after {
      bottom: 0;
      left: 0;
    }
  }

  .ord-w {
    top: 50%;
    left: 0;
    margin-top: -(@half-drag-handle-height);
    margin-left: -(@half-drag-handle-width);
    cursor: w-resize;

    &::after {
      left: 0;
    }
  }

  // Use the same specificity as the ords above but just
  // come after.
  &__disabled &__drag-handle {
    cursor: inherit;
  }

  &__drag-bar {
    position: absolute;

    &.ord-n {
      top: 0;
      left: 0;
      width: 100%;
      height: @drag-bar-size;
      margin-top: -(@half-drag-bar-size);
    }

    &.ord-e {
      top: 0;
      right: 0;
      width: @drag-bar-size;
      height: 100%;
      margin-right: -(@half-drag-bar-size);
    }

    &.ord-s {
      bottom: 0;
      left: 0;
      width: 100%;
      height: @drag-bar-size;
      margin-bottom: -(@half-drag-bar-size);
    }

    &.ord-w {
      top: 0;
      left: 0;
      width: @drag-bar-size;
      height: 100%;
      margin-left: -(@half-drag-bar-size);
    }
  }

  &--new-crop &__drag-bar,
  &--new-crop &__drag-handle,
  &--fixed-aspect &__drag-bar {
    display: none;
  }

  &--fixed-aspect &__drag-handle.ord-n,
  &--fixed-aspect &__drag-handle.ord-e,
  &--fixed-aspect &__drag-handle.ord-s,
  &--fixed-aspect &__drag-handle.ord-w {
    display: none;
  }

  @media @mobile-media-query {
    .ord-n,
    .ord-e,
    .ord-s,
    .ord-w {
      display: none;
    }

    &__drag-handle {
      width: @drag-handle-mobile-width;
      height: @drag-handle-mobile-height;
    }
  }
}

/* stylelint-disable-next-line max-line-length */
@bixi-crop-bg: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAAXNSR0IArs4c6QAAAExJREFUKBVjfPP6zX8GNMDIyMggKCTIAKLRARO6ACH+INTAgs1jILH//zHCAuw9xn///mHIgBR//PARqyasNoCMAmnCZssgDCWSnQQAxO0Z3Gl6s4YAAAAASUVORK5CYII=';

.bixi-image-crop-container {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: url(@bixi-crop-bg) repeat;

  .bixi-image-crop-image {
    position: relative;
    z-index: -1;
    max-width: none;
    max-height: none;
    user-select: none;
  }
}
