@import "mixins/mixins";
@import "mixins/utils";
@import "common/var";

@include b(upload-box){
  position: relative;
}

@include b(upload) {
  display: inline-block;
  text-align: center;
  cursor: pointer;
  outline: none;
  @include e(input) {
    display: none;
  }

  @include e(tip) {
    font-size: $--font-size-base;
    color: $--upload-tip-color;
    margin-top: 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  iframe {
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    opacity: 0;
    filter: alpha(opacity=0);
  }
}

@mixin drag() {
  background-color: #fff;
  border: 1px dashed #DBDBDB;
  box-sizing: border-box;
  width: $--upload-drag-width;
  height: $--upload-drag-height;
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  .xb_icon_upload {
    font-size: 92px;
    color: $--upload-drag-icon-color;
    margin: 40px 0 24px;
    line-height: 50px;
  }
}

@include b(upload-dragger) {
  @include drag;

  &:hover{
    border:1px dashed #FCB3A4;
    @include upload-drag-hover-border-color;
  }

  .xb-upload__tip {
    color:#8C8C8C;
    font-size: $--font-size-base;
    padding: 0 20px;
    text-align: left;
  }

  ~ .xb-upload__files {
    border-top: $--border-base;
    margin-top: 7px;
    padding-top: 5px;
  }

  .xb-upload__text {
    color: $--color-text-title;
    font-size: $--font-size-base;
    padding: 0 20px;
    line-height: 1.6em;
  }

  @include when(dragover) {
    background-color: rgba(32, 159, 255, .06);
  }
}

@include b(upload-list) {
  margin: 0;
  padding: 0;
  list-style: none;

  @include e(item) {
    transition: all .5s cubic-bezier(.55,0,.1,1);
    font-size: 14px;
    color: $--color-black-65;
    line-height: 1.6;
    margin-top: 5px;
    position: relative;
    box-sizing: border-box;
    border-radius: $--border-radius-base;
    width: 100%;
    outline: none;

    .xb-progress__text{
      float: right;
      margin-right:5px;
      .xb_icon_close_facet{
        display: none;
      }
    }

    & .xb-icon-upload-success {
      color: $--progress-success-icon-color;
    }

    [class*="xb_icon_"]{
      font-size: 16px;
      vertical-align: middle;
    }
    .xb_icon_refresh{
      margin-left: 5px;
      line-height: 1.6;
    }
    .xb_icon_delete {
      display: none;
      position: absolute;
      top: 5px;
      right: 5px;
      cursor: pointer;
      color: $--upload-delete-icon-color;
      font-size: $--font-size-base;
    }

    & .xb-icon-close-tip {
      display: none;
      position: absolute;
      top: 5px;
      right: 5px;
      font-size: 12px;
      cursor: pointer;
      opacity: 1;
      color: red;
    }

    .xb-progress-bar{
      padding-left:25px;
      @include e(inner) {
        @include progress-error;
      }
    }

    @include when(success) {
      
      .xb-upload-list__item-status-label {
        display: block;
      }

      .xb-upload-list__item-name:hover, .xb-upload-list__item-name:focus {
        color: $--color-black-65;
        cursor: pointer;
        outline: none;
      }

      &:focus:not(:hover) {  /* 键盘focus */
        .xb-icon-close-tip {
          display: inline-block;
        }
      }

      &:not(.focusing):focus, &:active { /* click时 */
        outline-width: 0;
        .xb-icon-close-tip {
          display: none;
        }
      }

      &:hover, &:focus {
        .xb-upload-list__item-status-label {
          display: none;
        }
      }

      &:hover {
        background-color: $--upload-list-item-hover-bg-color;
  
        .xb_icon_delete {
          display: inline-block;
        }
  
        .xb-progress__text {
          display: none;
        }
      }
    }

    @include when(fail) {
      .xb_icon_delete {
        display: block;
        top: auto;
        bottom: 0;
        z-index: 1;
        color: $--upload-delete-icon-color;
        font-size: $--font-size-base;
      }

      .xb-upload-list__item-name{
        color: $--color-black-45;
      }

      .xb-upload-list__item-name:hover, .xb-upload-list__item-name:focus {
        color: $--color-black-65;
        cursor: pointer;
        outline: none;
      }
    }
  }

  @include when(disabled) {
    .xb-upload-list__item:hover .xb-upload-list__item-status-label {
      display: block;
    }
  }

  @include e(item-name) {
    color: $--color-text-regular;
    display: flex;
    margin-right: 40px;
    overflow: hidden;
    padding-left: 4px;
    text-overflow: ellipsis;
    transition: color .3s;
    white-space: nowrap;
    .xb_icon_pin{
      margin-right: 4px;
    }
    [class^="xb-icon"] {
      height: 100%;
      margin-right: 7px;
      color: $--upload-delete-icon-color;
      line-height: inherit;
    }
    span{
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  @include e(item-status-label) {
    position: absolute;
    right: 5px;
    top: 0;
    line-height: inherit;
    display: none;
  }

  @include e(item-delete) {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 12px;
    color: $--color-text-regular;
    display: none;

    &:hover {
      color: red;
    }
  }

  @include m(picture-card) {
    margin: 0;
    display: inline;
    vertical-align: top;

    .xb-upload-list__item {
      overflow: hidden;
      background-color: #fff;
      border: 1px solid #c0ccda;
      border-radius: 6px;
      box-sizing: border-box;
      width: 148px;
      height: 148px;
      margin: 0 8px 8px 0;
      display: inline-block;

      .xb-icon-check,
      .xb-icon-circle-check {
        color: $--color-white;
      }

      .xb_icon_delete {
        display: none;
      }
      &:hover {
        .xb-upload-list__item-status-label {
          display: none;
        }

        .xb-progress__text {
          display: block;
        }
      }
    }

    .xb-upload-list__item-name {
      display: none;
    }

    .xb-upload-list__item-thumbnail {
      width: 100%;
      height: 100%;
    }

    .xb-upload-list__item-status-label {
      position: absolute;
      right: -15px;
      top: -6px;
      width: 40px;
      height: 24px;
      background: #13ce66;
      text-align: center;
      transform: rotate(45deg);
      box-shadow: 0 0 1pc 1px rgba(0,0,0,0.2);

      i {
        font-size: 12px;
        margin-top: 11px;
        transform: rotate(-45deg);
      }
    }

    .xb-upload-list__item-actions {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      cursor: default;
      text-align: center;
      color: #fff;
      opacity: 0;
      font-size: 20px;
      background-color: rgba(0, 0, 0, .5);
      transition: opacity .3s;
      &::after {
        display: inline-block;
        content: "";
        height: 100%;
        vertical-align: middle
      }

      span {
        display: none;
        cursor: pointer;
      }

      span + span {
        margin-left: 15px;
      }

      .xb-upload-list__item-delete {
        position: static;
        font-size: inherit;
        color: inherit;
      }

      &:hover {
        opacity: 1;
        span {
          display: inline-block;
        }
      }
    }

    .xb-progress {
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      bottom: auto;
      width: 126px;

      .xb-progress__text {
        top: 50%;
      }
    }
  }

  @include m(picture) {
    .xb-upload-list__item {
      overflow: hidden;
      z-index: 0;
      background-color: #fff;
      border: 1px solid #c0ccda;
      border-radius: 6px;
      box-sizing: border-box;
      margin-top: 10px;
      padding: 10px 10px 10px 90px;
      height: 92px;

      .xb-icon-check,
      .xb-icon-circle-check {
        color: $--color-white;
      }

      &:hover {
        .xb-upload-list__item-status-label {
          background: transparent;
          box-shadow: none;
          top: -2px;
          right: -12px;
        }

        .xb-progress__text {
          display: block;
        }
      }

      &.is-success {
        .xb-upload-list__item-name {
          line-height: 70px;
          margin-top: 0;
          i {
            display: none;
          }
        }
      }
    }

    .xb-upload-list__item-thumbnail {
      vertical-align: middle;
      display: inline-block;
      width: 70px;
      height: 70px;
      position: relative;
      z-index: 1;
      margin-left: -80px;
      background-color: $--color-white
    }

    .xb-upload-list__item-name {
      display: block;
      margin-top: 20px;

      i {
        font-size: 70px;
        line-height: 1;
        position: absolute;
        left: 9px;
        top: 10px;
      }
    }

    .xb-upload-list__item-status-label {
      position: absolute;
      right: -17px;
      top: -7px;
      width: 46px;
      height: 26px;
      background: #13ce66;
      text-align: center;
      transform: rotate(45deg);
      box-shadow: 0 1px 1px #ccc;

      i {
        font-size: 12px;
        margin-top: 12px;
        transform: rotate(-45deg);
      }
    }

    .xb-progress {
      position: relative;
      top: -7px;
    }
  }

  @include when(drag) {
    position: absolute;
    top: 0;
    left: 0;
    height: $--upload-drag-height;
    overflow: hidden;
    .xb-upload-list__item{
      &:hover{
        border: 1px dashed #FCB3A4;
        @include upload-drag-hover-border-color;
      }
      .xb-progress--line{
        width: 95%;
      }
      .xb-progress-bar{
        padding-left: 22px;
      }
      .xb-progress__text{
        width:25px;
        margin-left: 2px;
      }
      @include when(fail){
        .xb_icon_delete{
          bottom: auto;
          margin-top: 0;
        }
      }
      @include when(success) {
        .xb-upload-list__item-name{
          &:hover{
            // TODO:
            background: #F5F7FA;
            @include upload-success-bg-color;
          }
        }
      }
      @include drag;
      margin-top: 0;
      .xb-icon-drag{
        color:$--upload-drag-icon-color;
        font-size: 94px;
        margin-top: 46px;
        line-height: 76px;
      }
      .xb-upload-list__item-name{
        margin:0 12px;
        margin-top: 20px;
        display: flex;
        align-items: center;
        border-radius: $--border-radius-base;
        padding-left: 0;
        span{
          max-width: 80%;
          text-align: left;
        }
      }
      .xb-upload-list__item-status-label{
        top:auto;
        margin-top: -22px;
        right:12px;
      }
      .xb_icon_delete{
        top:auto;
        margin-top: -18px;
        right:12px;
      }
    }
  }
}

@include b(upload-cover) {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 10;
  cursor: default;
  @include utils-vertical-center;

  img {
    display: block;
    width: 100%;
    height: 100%;
  }

  @include e(label) {
    position: absolute;
    right: -15px;
    top: -6px;
    width: 40px;
    height: 24px;
    background: #13ce66;
    text-align: center;
    transform: rotate(45deg);
    box-shadow: 0 0 1pc 1px rgba(0,0,0,0.2);

    i {
      font-size: 12px;
      margin-top: 11px;
      transform: rotate(-45deg);
      color: #fff;
    }
  }

  @include e(progress) {
    display: inline-block;
    vertical-align: middle;
    position: static;
    width: 243px;

    + .xb-upload__inner {
      opacity: 0;
    }
  }

  @include e(content) {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  @include e(interact) {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(#000, .72);
    text-align: center;

    .btn {
      display: inline-block;
      color: $--color-white;
      font-size: 14px;
      cursor: pointer;
      vertical-align: middle;
      transition: $--md-fade-transition;
      margin-top: 60px;

      i {
        margin-top: 0;
      }

      span {
        opacity: 0;
        transition: opacity .15s linear;
      }

      &:not(:first-child) {
        margin-left: 35px;
      }

      &:hover {
        transform: translateY(-13px);

        span {
          opacity: 1;
        }
      }

      i {
        color: $--color-white;
        display: block;
        font-size: 24px;
        line-height: inherit;
        margin: 0 auto 5px;
      }
    }
  }

  @include e(title) {
    position: absolute;
    bottom: 0;
    left: 0;
    background-color: $--color-white;
    height: 36px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: normal;
    text-align: left;
    padding: 0 10px;
    margin: 0;
    line-height: 36px;
    font-size: 14px;
    color: $--color-text-primary;
  }

  + .xb-upload__inner {
    opacity: 0;
    position: relative;
    z-index: 1;
  }
}

.avatar-uploader{
  .xb-upload{
    overflow: hidden;
    width:104px;
    height:104px;
    overflow: hidden;
    background:rgba(0,0,0,0.02);
    border-radius:$--border-radius-base;
    border:1px dashed rgba(0,0,0,0.15);
    text-align: center;
    padding: 8px;
    align-items: center;
    justify-content: center;
    display: flex;
    &:hover{
      border:1px dashed rgba(242,121,121,1);
    }
    .avatar{
      max-width: 100%;
      max-height: 100%;
    }
    &>div{
      text-align: center;
      width: 100%;
    }
  }
  &.avatar-success{
    .xb-upload{
      border:1px solid rgba(0,0,0,0.15);
      background: $--color-white;
    }
    .xb-upload__tip{
      display: none;
    }
  }
  &.avatar-error{
    .xb-upload{
      border:1px dashed $--upload-avatar-error-color;
    }
    .xb-upload__tip{
      color:$--upload-avatar-error-color;
      display: block;
    }
  }
  .avatar-uploader-icon{
    font-size: 24px;
    & + span{
      display: block;
      font-size: $--font-size-base;
      margin-top: 14px;
      color: $--color-black-65;
    }
  }
  .xb-upload-list{
    display: none;
  }
}