@import '../../style/themes/default';
@import '../../style/mixins/index';

@upload-prefix-cls: ~'@{c7n-prefix}-upload';
@upload-item: ~'@{c7n-prefix}-upload-list-item';

.@{upload-prefix-cls} {
  .reset-component;
  outline: 0;

  p {
    margin: 0;
  }

  &-btn {
    display: block;
    width: 100%;
    outline: none;
  }

  &.@{upload-prefix-cls}-disabled {
    cursor: not-allowed;
  }
  
  input[type='file'] {
    cursor: pointer;
  }

  &&-select {
    display: inline-block;
  }

  &&-select-picture-card {
    display: table;
    width: @upload-picture-card-size;
    height: @upload-picture-card-size;
    //margin-right: 0.08rem;
    //margin-bottom: 0.08rem;
    margin: 0.04rem;
    text-align: center;
    vertical-align: top;
    background-color: @background-color-light;
    border: @upload-picture-card-select-border;
    border-radius: @border-radius-base;
    cursor: pointer;
    transition: border-color @animation-duration-slow ease;

    > .@{upload-prefix-cls} {
      display: table-cell;
      width: 100%;
      height: 100%;
      padding: 0.08rem;
      text-align: center;
      vertical-align: middle;
    }

    &:not(.@{upload-prefix-cls}-disabled):hover {
      border-color: @primary-color;
    }
  }

  &&-drag-btn {
    display: inline-flex;

    > .@{upload-prefix-cls} {
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }
  }

  &&-drag {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 0.16rem 0;
    text-align: center;
    background: @background-color-light;
    border: @border-width-base dashed @border-color-base;
    border-radius: @border-radius-base;
    cursor: pointer;
    transition: border-color @animation-duration-slow;

    &.@{upload-prefix-cls}-drag-hover:not(.@{upload-prefix-cls}-disabled) {
      border: 0.02rem dashed @primary-5;
    }

    &.@{upload-prefix-cls}-disabled {
      cursor: not-allowed;
    }

    .@{upload-prefix-cls}-btn {
      display: table;
      height: 100%;
    }

    .@{upload-prefix-cls}-drag-container {
      display: table-cell;
      vertical-align: middle;
    }

    &:not(.@{upload-prefix-cls}-disabled):hover {
      border-color: @primary-5;
    }

    p.@{upload-prefix-cls}-drag-icon {
      .@{iconfont-css-prefix} {
        color: @upload-drag-icon-color;
        font-size: @upload-drag-icon-size;
      }

      margin: @upload-drag-icon-margin;
    }

    p.@{upload-prefix-cls}-text {
      margin: 0 0 0.04rem;
      color: @upload-drag-text-color;
      font-size: @upload-drag-text-font-size;
      line-height: @upload-drag-text-line-height;
    }

    p.@{upload-prefix-cls}-hint {
      color: @upload-drag-hint-color;
      font-size: @font-size-base;
    }

    .@{iconfont-css-prefix}-plus {
      color: @disabled-color;
      font-size: 0.3rem;
      transition: all @animation-duration-slow;

      &:hover {
        color: @text-color-secondary;
      }
    }

    &:hover .@{iconfont-css-prefix}-plus {
      color: @text-color-secondary;
    }
  }
}

.@{upload-prefix-cls}-list-drag {
  &::before {
    display: none !important;
  }
}

.@{upload-prefix-cls}-list {
  .reset-component;
  .clearfix;

  &-item {  
    margin-top: 0.08rem;
    font-size: @font-size-sm;

    &-name {
      display: inline-block;
      flex: auto;
      margin: auto 0;
      padding-right: 0.05rem;
      padding-left: 0.08rem;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      a& {
        color: @upload-list-item-name-link-color;
        &:hover {
          color: @upload-list-item-name-link-hover-color;
        }
      }
    }

    &-info {
      height: 100%;
      padding: 0 0.12rem 0 0.04rem;
      transition: background-color @animation-duration-slow;

      .@{upload-prefix-cls}-icon-file {
        flex: none;
        width: 0.2rem;
        height: 0.2rem;
      }

      &-filesize {
        flex: none;
        padding-right: 0.08rem;
        color: @text-color-secondary;
      }
    }

    .@{iconfont-css-prefix}-close {
      right: 0.04rem;
      flex: none;
      color: @upload-list-item-close-icon-color;
      font-size: 0.16rem;
      cursor: pointer;
      opacity: 0;
      transition: all @animation-duration-slow;

      &:hover {
        color: @upload-list-item-close-icon-hover-color;
      }
    }

    &:hover &-info {
      background-color: @item-hover-bg;
    }

    &:hover {
      .@{iconfont-css-prefix}-close,
      .@{upload-item}-reupload-text,
      .@{upload-item}-reupload-picture {
        opacity: 1;
      }
    }

    &-error,
    &-error &-info-filesize,
    &-error &-name,
    &-error &-name:hover {
      color: @error-color;
    }

    &-error {
      .@{iconfont-css-prefix}-close {
        color: @error-color !important;
        opacity: 1;
      }

      &.@{upload-item}-error-reupload {
        .@{upload-item}-reupload-text,
        .@{upload-item}-reupload-picture {
          opacity: 1;
        }
      }
    }

    &-progress {
      bottom: -0.12rem;
      width: 100%;
      padding-left: calc(@font-size-base + 0.12rem);
      font-size: @font-size-base;
      line-height: 0;
    }
  }

  &-text {
    .@{upload-item}-span {
      display: flex;
      align-items: center;
      height: 0.28rem;
    }

    .@{upload-item}-text {
      display: flex;
      flex: 1;
      overflow: hidden;
    }

    .@{upload-item}-reupload-text {
      padding-right: 0.08rem;
      color: @upload-reupload-color;
      cursor: pointer;
      opacity: 0;
      transition: all @animation-duration-slow;
    }
  }

  &-picture,
  &-picture-card {
    .@{upload-item} {
      position: relative;
      height: 0.66rem;
      padding: 0.08rem;
      background-color: #fff;
      border: @border-width-base @border-style-base @border-color-base;
      border-radius: @border-radius-base;

      &:hover {
        background: transparent;
      }

      &-error {
        border-color: @error-color;

        .@{upload-item}-name {
          padding-right: 0.24rem;
        }

        .@{upload-item}-actions-reupload-text {
          display: flex;
          flex-direction: column;
          align-items: flex-end;
          text-align: center;
        }
      }
    }

    .@{upload-item}-info {
      padding: 0;
    }

    .@{upload-item}:hover .@{upload-item}-info {
      background: transparent;
    }

    .@{upload-item}-uploading {
      border-style: dashed;
    }

    .@{upload-item}-thumbnail {
      position: absolute;
      top: 0.08rem;
      left: 0.08rem;
      width: 0.48rem;
      height: 0.48rem;
    }

    .@{upload-item}-icon {
      position: absolute;
      top: 50%;
      left: 50%;
      margin-top: -.18rem;
      margin-left: -.18rem;
      color: @disabled-color;
      font-size: .36rem;
    }

    .@{upload-item}-thumbnail img {
      display: block;
      width: 0.48rem;
      height: 0.48rem;
      overflow: hidden;
    }

    .@{upload-item}-thumbnail.@{iconfont-css-prefix}::before {
      color: @text-color-secondary;
      font-size: 0.24rem;
      line-height: 0.48rem;
    }

    .@{upload-item}-name {
      display: inline-block;
      box-sizing: border-box;
      max-width: 100%;
      margin: 0 0 0 0.08rem;
      padding-right: 0.2rem;
      padding-left: 0.48rem;
      overflow: hidden;
      line-height: 0.48rem;
      white-space: nowrap;
      text-overflow: ellipsis;
      transition: all @animation-duration-slow;
    }

    .@{upload-item}-error-reupload,
    .@{upload-item}-done-reupload {
      .@{upload-item}-name {
        padding-right: 0.8rem;
      }
    }

    .@{upload-item}-uploading .@{upload-item}-name {
      line-height: 0.28rem;
    }

    .@{upload-item}-progress {
      bottom: 0.14rem;
      width: ~'calc(100% - .24rem)';
      margin-top: 0;
      padding-left: 0.56rem;
    }

    .@{iconfont-css-prefix}-close {
      position: absolute;
      top: @upload-list-picture-close-icon-top;
      right: @upload-list-picture-close-icon-right;
      line-height: 1;
    }
  }

  &-picture {
    .@{upload-item}-uploading {
      .@{upload-item}-info {
        display: flex;
        flex-direction: column;
        justify-content: center;

        .@{upload-item}-span {
          display: flex;
          flex-direction: row;
          align-items: center;
        }

        .@{c7n-prefix}-progress-loading {
          padding-left: 14px;
          line-height: 28px;
        }

        .@{upload-item}-name {
          padding-left: 14px;
        }

        .@{upload-item}-text {
          display: flex;
          padding-right: 0.1rem;
          overflow: hidden;
        }
      }
    }

    .@{upload-item}-reupload-picture {
      position: absolute;
      top: 50%;
      right: 0.3rem;
      color: @upload-reupload-color;
      transform: translateY(-50%);
      cursor: pointer;
      opacity: 0;
      transition: all @animation-duration-slow;
    }
  }

  &-picture-card {
    display: inline;

    &.@{upload-prefix-cls}-list::after {
      display: none;
    }

    .@{upload-item} {
      float: left;
      width: @upload-picture-card-size;
      height: @upload-picture-card-size;
      //margin: 0 0.08rem 0.08rem 0;
      margin: 0.04rem;
    }

    .@{upload-item}-info {
      position: relative;
      height: 100%;
      overflow: hidden;
    }

    .@{upload-item}-picture-card {
      position: relative;
      display: block;
      height: .8rem;
      overflow: hidden;
      text-align: center;

      &::before {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
        width: 100%;
        height: .8rem;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        transition: all .3s;
        content: " ";
      }
    }

    .@{upload-item}-reupload-picture-card {
      display: inline-block;
      width: 0.8rem;
      color: #fff;
      text-align: center;
      cursor: pointer;
    }

    .@{upload-item}:hover .@{upload-item}-info .@{upload-item}-picture-card::before {
      opacity: 1;
    }

    .@{upload-item}-actions {
      position: absolute;
      top: 50%;
      left: 50%;
      z-index: 10;
      width: 100%;
      height: 100%;
      white-space: nowrap;
      transform: translate(-50%, -50%);
      opacity: 0;
      transition: all @animation-duration-slow;

      > span {
        text-align: center;
      }

      .c7n-upload-reupload-action {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }

      .c7n-upload-other-actions {
        position: absolute;
        bottom: 0;
        width: 100%;
      }

      .@{iconfont-css-prefix} {
        z-index: 10;
        width: 0.16rem;
        margin: 0 0.04rem 0.04rem;
        color: @text-color-dark;
        font-size: 0.16rem;
        cursor: pointer;
        transition: all @animation-duration-slow;
      }
    }

    .@{upload-item}-info:hover .@{upload-item}-actions,
    .@{upload-item}-actions:hover {
      opacity: 1;
    }

    .@{upload-item}-thumbnail,
    .@{upload-item}-thumbnail img {
      position: static;
      display: block;
      width: 100%;
      height: 100%;
    }

    .@{upload-item}-name {
      display: none;
      margin: 0.08rem 0 0;
      padding: 0;
      line-height: @line-height-base;
      text-align: center;
    }

    .anticon-picture + .@{upload-item}-name {
      display: block;
    }

    .@{upload-item}-uploading {
      &.@{upload-item} {
        background-color: @background-color-light;
      }

      .@{upload-item}-info {
        &::before,
        .@{iconfont-css-prefix}-visibility,
        .@{iconfont-css-prefix}-delete {
          display: none;
        }
      }

      &-text {
        margin: @upload-picture-card-uploading-text-margin;
        color: @text-color-secondary;
      }
    }

    .@{upload-item}-progress {
      bottom: 0.32rem;
      padding-left: 0;
    }
  }

  .@{upload-prefix-cls}-success-icon {
    color: @success-color;
    font-weight: bold;
  }

  .@{upload-prefix-cls}-animate-enter,
  .@{upload-prefix-cls}-animate-leave,
  .@{upload-prefix-cls}-animate-inline-enter,
  .@{upload-prefix-cls}-animate-inline-leave {
    animation-duration: @animation-duration-slow;
    animation-fill-mode: @ease-in-out-circ;
  }

  .@{upload-prefix-cls}-animate-enter {
    animation-name: uploadAnimateIn;
  }

  .@{upload-prefix-cls}-animate-leave {
    animation-name: uploadAnimateOut;
  }

  .@{upload-prefix-cls}-animate-inline-enter {
    animation-name: uploadAnimateInlineIn;
  }

  .@{upload-prefix-cls}-animate-inline-leave {
    animation-name: uploadAnimateInlineOut;
  }
}

@keyframes uploadAnimateIn {
  from {
    height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
  }
}

@keyframes uploadAnimateOut {
  to {
    height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
  }
}

@keyframes uploadAnimateInlineIn {
  from {
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
  }
}

@keyframes uploadAnimateInlineOut {
  to {
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
  }
}
