@keyframes center-spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(359deg);
  }
}

$upload-prefix: #{$prefix}-upload;
@mixin ne-upload {
  .#{$upload-prefix} {
    color: $component-default-color;
    &-list {
      overflow: hidden;
      margin-bottom: 6px;
    }

    &-list-item {
      display: flex;
      align-items: center;
      padding: 2px 0;
      border-radius: $global-radius;
      background-color: $white;
      transition: all $animation-duration-base;
      .#{$upload-prefix}-list-item-container {
        display: flex;
        align-items: center;
      }
      .#{$upload-prefix}-status {
        color: $icon-color;
      }
      &-loading {
        .#{$upload-prefix}-status {
          animation: spin 1s infinite linear;
        }
      }

      &-fail {
        .#{$upload-prefix}-file-name,
        .#{$upload-prefix}-status {
          color: $error-color;
        }
      }

      &:hover,
      &:focus {
        background-color: $upload-bg;
        .#{$upload-prefix}-mask {
          top: calc(100% - #{$upload-name-height});
          opacity: 1;
        }

        .#{$upload-prefix}-preview-btn {
          top: calc(100% - 70px);
          opacity: 1;
        }

        .#{$upload-prefix}-cropper-mask {
          top: calc(100% - #{$upload-name-height});
          opacity: 1;
        }

        .#{$upload-prefix}-delete {
          opacity: 1;
        }
        
      }
    }
    &-list-item-gallery,
    &-list-item-single,
    &-list-item-upload {
      position: relative;
      width: $upload-preview-size;
      height: $upload-preview-size;
      margin-right: $upload-list-item-margin;
      margin-bottom: $upload-name-height;
      padding: $upload-preview-padding;
      border: $global-border-width solid $global-border-color;
      border-radius: $global-radius;
      outline: none;
      .#{$upload-prefix}-list-item-container {
        display: block;
        position: relative;
        width: 100%;
        height: 100%;
      }
      &.#{$upload-prefix}-list-item-loading {
        .#{$upload-prefix}-status {
          animation: center-spin 1s infinite linear;
        }
      }

      .#{$upload-prefix}-file-name {
        position: absolute;
        top: 100%;
        left: 0;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: $upload-name-height;
        padding: 0;
        line-height: $upload-name-height;
        text-align: center;
      }

      .#{$upload-prefix}-delete {
        position: absolute;
        top: 0;
        right: 0;
      }
      &.#{$upload-prefix}-list-item-fail {
        .#{$upload-prefix}-status {
          color: $icon-color;
        }
      }
      .#{$upload-prefix}-status {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 28px;
        height: 28px;
        transform: translate(-50%, -50%);
      }

      .#{$upload-prefix}-status-fail {
        display: none;
      }
    }
    &-list-item-gallery {
      float: left;
      &:hover,
      &:focus {
        background-color: $white;
      }
    }
    &-list-item-single {
      overflow: hidden;
      &:hover,
      &:focus {
        background-color: $white;
      }
    }
    &-list-item-upload {
      justify-content: center;
      border-style: dashed;
      background-color: $upload-bg;
      cursor: pointer;
      &:hover,
      &:focus {
        border-color: $primary-color;
      }
    }
    &-preview {
      height: 100%;
    }

    &-file-name {
      overflow: hidden;
      flex: 1 1 auto;
      padding: 0 6px;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    &-delete {
      z-index: 3;
      min-width: 18px;
      padding: 0;
      border-radius: 2px;
      font-size: 16px;
      opacity: 0;
      &:hover,
      &:focus {
        background: none;
        opacity: 1;
      }
    }

    &-mask {
      display: flex;
      position: absolute;
      top: 100%;
      left: 50%;
      z-index: 2;
      align-items: center;
      justify-content: center;
      width: 50%;
      height: $upload-name-height;
      background: rgba(0, 0, 0, 0.7);
      color: $white;
      text-align: center;
      opacity: 0;
      transition: all $animation-duration-base;
      cursor: pointer;
    }

    &-preview-btn {
      display: flex;
      position: absolute;
      top: 100%;
      left: 25%;
      z-index: 2;
      align-items: center;
      justify-content: center;
      width: 50%;
      height: $upload-name-height;
      background: rgba(0, 0, 0, 0.7);
      color: $white;
      text-align: center;
      opacity: 0;
      transition: all $animation-duration-base;
      cursor: pointer;
    }

    &-cropper-mask {
      display: flex;
      position: absolute;
      top: 100%;
      left: 0;
      z-index: 2;
      align-items: center;
      justify-content: center;
      width: 50%;
      height: $upload-name-height;
      background: rgba(0, 0, 0, 0.7);
      color: $white;
      text-align: center;
      opacity: 0;
      transition: all $animation-duration-base;
      cursor: pointer;
      font-size: 12px;
    }
  }
}
