//mobile

//input file/button
.upload,
.upload-avatar {
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}

//input file
.upload {
  //button styling
  &[type='file'] + label {
    max-width: 80%;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-block;
    overflow: hidden;
    padding: 7px 24px;
    border-radius: $border-radius;
    color: $white;
    background-color: $primary;
    transition: background-color 0.15s;

    &:hover {
      background-color: shade-color($primary, 10%);
    }

    //icon
    svg {
      fill: $white;
      margin-right: 10px;
    }
  }
}

//pictures wall version
.upload-pictures-wall {
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  //grid list element
  & > li {
    list-style-type: none;
    margin-right: $v-gap;
    margin-bottom: $v-gap;

    &:last-child {
      margin-right: 0;
    }
  }

  //input file
  .upload {
    //button styling
    &[type='file'] + label {
      font-weight: 600;
      height: 128px;
      width: 128px;
      border-radius: 0;
      padding: 0;
      border: 2px dashed $primary-a1;
      background-color: tint-color($primary-a1, 10%);
      color: $primary-a7;
      text-align: center;
      display: table-cell;
      vertical-align: middle;
      transition: border-color 0.2s;

      .icon {
        display: block;
        fill: $primary;
        margin: 0 auto;
        width: 48px;
        height: 48px;
        flex-shrink: 0;
      }

      &:hover {
        border: 2px dashed $primary;
      }
    }

    &:focus,
    &:active {
      &[type='file'] + label {
        border: 2px dashed $primary-a3;
      }
    }
  }

  //image
  .upload-image {
    flex-shrink: 0;
    width: 128px;
    height: 128px;

    img {
      object-fit: cover;
      width: 100%;
      height: 100%;
    }
  }
}

//files list
.upload-file-list {
  margin-top: 5px;
  padding: 0;
  //image version
  &.upload-file-list-image {
    .progress {
      left: 52px;
    }
  }

  .upload-file {
    list-style-type: none;
    display: flex;
    align-items: center;
    max-width: 375px;
    margin-bottom: 16px;
    position: relative;
    //states
    &.uploading {
      .icon {
        fill: $neutral-1-a7;
      }

      p {
        color: $neutral-1-a7;
      }
    }

    &.success {
      svg {
        fill: $primary;
      }

      p {
        color: $primary;

        .upload-file-weight {
          display: inline-block;
        }
      }
    }

    &.error {
      svg {
        fill: $danger;
      }

      p {
        color: $danger;
      }
    }

    //left icon
    svg {
      flex-shrink: 0;
    }

    //left image
    .upload-image {
      flex-shrink: 0;
      width: 40px;
      height: 40px;

      img {
        object-fit: cover;
        width: 100%;
        height: 100%;
      }
    }

    //file name
    p {
      margin: 0;
      font-size: 0.875rem;
      font-weight: 600;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-left: 12px;
      overflow: hidden;
      .upload-file-weight {
        color: $neutral-1-a7;
        // font-size: 0.75em;
        margin-left: 10px;
        display: none;
      }
    }

    //action button / upload ok
    button {
      background: transparent;
      border: 0;
      padding: 0px;
      margin-left: auto;

      &:hover {
        cursor: pointer;

        svg {
          fill: $primary;
        }
      }
    }
  }

  //file upload progress
  .progress {
    position: absolute;
    bottom: -10px;
    left: 36px;
    width: calc(100% - 45px);
    height: 4px;
    background-color: $lightgrey-a1;
    box-shadow: none;

    &.progress-image {
      width: calc(100% - 60px);
    }
  }
}

//avatar version -------------------------------- START
.upload-avatar-container {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;

  .upload-avatar {
    &[type='file'] + label {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;

      svg {
        display: none;
      }

      span {
        display: none;
      }
    }
  }
}

.avatar-upload-wrapper {
  position: relative;
  display: inline-block;
  //avatar version
  .avatar {
    &.avatar-upload {
      position: relative;
    }
  }

  .avatar-upload-icon {
    position: absolute;
    bottom: 16px;
    right: 4px;
    width: 26px;
    height: 26px;
    background: $neutral-1-a1;
    border-radius: 50%;
    border: 2px solid $white;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;

    & > svg {
      width: 16px;
      height: 16px;
    }
  }

  &.size-sm {
    .avatar {
      width: $avatar-base-size * 10;
      height: $avatar-base-size * 10;
    }

    .avatar-upload-icon {
      bottom: 6px;
      right: 4px;
      width: 18px;
      height: 18px;

      & > svg {
        width: 12px;
        height: 12px;
      }
    }
  }
}

//avatar version -------------------------------- END

//drag/drop version ----------------------------- START
.upload-dragdrop {
  display: inline-flex;
  align-items: center;

  &.dragover,
  &.loading {
    .upload-dragdrop-image {
      img {
        transform: translateX(-50%) translateY(-50%) scale(0.85);
      }
    }
  }

  &.loading {
    p:not(.upload-dragdrop-weight) {
      font-style: italic;
    }

    .upload-dragdrop-loading {
      opacity: 1;
    }
  }

  &.loading,
  &.success {
    .upload-dragdrop-text {
      .upload-dragdrop-weight {
        visibility: visible;
      }
    }
  }

  &.success {
    .upload-dragdrop-success {
      opacity: 1;
      transform: scale(1);
    }
  }
}

//drag and drop text
.upload-dragdrop-text {
  p {
    margin: 0;
    font-size: 0.875rem;
    color: $secondary;

    &.upload-dragdrop-weight {
      color: $neutral-1-a7;
      font-size: 0.75rem;
      visibility: hidden;

      svg {
        fill: $neutral-1-a7;
      }
    }
  }

  h5 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.75rem;
    color: $neutral-1;
  }
}

.upload-dragdrop-input {
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  z-index: -1;

  &[type='file'] + label {
    text-decoration: underline;
    color: $primary;
    cursor: pointer;
  }

  &:focus {
    &[type='file'] + label {
      outline: auto 5px -webkit-focus-ring-color;
    }
  }
}

.upload-dragdrop-loading {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 128px;
  height: 128px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
  border-radius: 50%;
  .progress-donut {
    position: relative;
    .progressbar-text {
      color: #000 !important;
      font-weight: 700;
    }
    svg {
      position: relative;
      path:first-child {
        display: none;
      }
    }
    &:before {
      content: '';
      background: #fff;
      width: 67px;
      height: 67px;
      left: 50%;
      top: 50%;
      transform: translateX(-50%) translateY(-50%);
      position: absolute;
      border-radius: 50%;
      z-index: 0;
    }
  }
}

.upload-dragdrop-image {
  width: 128px;
  height: 128px;
  flex-shrink: 0;
  position: relative;
  margin-right: 16px;

  img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    position: absolute;
    transform-origin: center center;
    top: 50%;
    left: 50%;
    transition: transform 0.4s cubic-bezier(0.33, 1.07, 0.54, 1);
    transform: translateX(-50%) translateY(-50%);
  }

  .upload-dragdrop-success {
    width: 36px;
    height: 36px;
    position: absolute;
    top: calc(50% - 18px);
    left: 20px;
    background: $primary;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transform: scale(0.6);
    transition:
      opacity 0.2s,
      transform 0.5s cubic-bezier(0.75, -0.5, 0, 1.75);

    svg {
      fill: $white;
      width: 30px;
      height: 30px;
    }
  }
}

//drag/drop version ----------------------------- END

//small - tablet
@include media-breakpoint-up(sm) {
  //input file
  .upload {
    &[type='file'] + label {
      font-size: 0.875rem;
    }
  }
}

//Tablet vertical
@include media-breakpoint-up(md) {
  //drag and drop version
  .upload-dragdrop-image {
    width: 180px;
    height: 180px;
    margin-right: 32px;

    .upload-dragdrop-success {
      left: 28px;
    }
  }

  .upload-dragdrop-loading {
    width: 180px;
    height: 180px;
    .progress-donut {
      &:before {
        content: '';
        width: 94px;
        height: 94px;
      }
    }
  }
}

//Desktop
@include media-breakpoint-up(xl) {
  //avatar version -------------------------------- START
  .avatar-upload:hover,
  .avatar-upload:focus-within {
    .upload-avatar-container {
      opacity: 1;
      //fade in speed
      transition: opacity 0.25s;
    }
  }

  .upload-avatar-container {
    bottom: -10%;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: 60%;
    background-color: rgba(0, 0, 0, 0.6);
    //fade out speed
    transition: opacity 0.15s;
    opacity: 0;

    .upload-avatar {
      &[type='file'] + label {
        margin: 0;
        padding-top: 10px;
        color: $white;
        text-align: center;
        width: 100%;
        height: 100%;
        font-size: 0.75rem;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        flex-direction: column;
        cursor: pointer;

        span {
          display: block;
        }

        svg {
          display: block;
          fill: $white;
          width: 20px;
          height: 20px;
        }
      }

      &:focus:not([data-focus-mouse='true']) {
        &[type='file'] + label {
          outline: auto 5px -webkit-focus-ring-color;
        }
      }
    }
  }

  .avatar-upload-wrapper {
    //hide icon
    .avatar-upload-icon {
      display: none;
    }

    &.size-sm {
      .upload-avatar {
        &[type='file'] + label {
          span {
            display: none;
          }
        }
      }
    }
  }
  //avatar version -------------------------------- END
}
