<template>
  <div class="upload-status" :class="[status, inline && 'inline']">
    <div
      class="spinner"
      :class="[
        status === 'success' && successIcon,
        status === 'error' && errorIcon,
      ]"
      :style="{
        '--line-width': `${lineWidth || 4}px`,
        '--spinner-width': `${size || 60}px`,
        '--spinner-height': `${size || 60}px`,
        '--font-size': `${labelSize || 18}px`,
        '--success-label-color': successLabelColor || '#04967d',
      }"
    >
      <div class="spinner-bg" />
    </div>
    <p class="label" v-if="label && !reverseLabelsOrder">{{ label }}</p>
    <span class="file-name" v-if="fileName">{{ fileName }}</span>
    <p class="label" v-if="label && reverseLabelsOrder">{{ label }}</p>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component
export default class UploadStatus extends Vue {
  @Prop() public status: 'pending' | 'success' | 'error' | '';
  @Prop() public label: string;
  @Prop() public inline: boolean;
  @Prop() public reverseLabelsOrder: boolean;
  @Prop() public fileName: string;
  @Prop({ default: 16 }) public labelSize: number;
  @Prop({ default: 60 }) public size: number;
  @Prop({ default: 4 }) public lineWidth: number;
  @Prop({ default: 'pgs-check' }) public successIcon: string;
  @Prop({ default: 'pgs-close' }) public errorIcon: string;
  @Prop({ default: '#04967d' }) public successLabelColor: string;
}
</script>

<style lang="scss" scoped>
@keyframes border-segments-anim {
  0% {
    border-bottom-color: #eceef8;
    border-top-color: #eceef8;
    border-right-color: #eceef8;
    border-left-color: #1491cf;
  }
  25% {
    border-bottom-color: #eceef8;
    border-right-color: #eceef8;
    border-left-color: #eceef8;
    border-top-color: #1491cf;
  }
  50% {
    border-left-color: #eceef8;
    border-bottom-color: #eceef8;
    border-top-color: #eceef8;
    border-right-color: #1491cf;
  }
  75% {
    border-top-color: #eceef8;
    border-left-color: #eceef8;
    border-right-color: #eceef8;
    border-bottom-color: #1491cf;
  }
  100% {
    border-bottom-color: #eceef8;
    border-top-color: #eceef8;
    border-right-color: #eceef8;
    border-left-color: #1491cf;
  }
}
.upload-status {
  font-family: 'Golos Text';
  font-style: normal;
  text-align: center;
  align-items: center;
  display: flex;
  gap: 6px;
  flex-direction: column;
  justify-content: center;
  font-weight: 500;
  font-size: var(--font-size);
  background-color: white;
  color: black;
  z-index: 10;
  line-height: 20px;
  letter-spacing: -0.015em;

  &.inline {
    flex-direction: row;
    gap: 12px;
    .label {
      font-weight: 400;
      white-space: nowrap;
      margin-top: 0;
    }
  }

  &:not(.inline) {
    .spinner {
      margin-bottom: 8px;
    }
  }

  .label {
    margin-top: 4px;
    margin-bottom: 0;
  }

  .file-name + .label {
    margin-top: 0;
  }

  .file-name {
    color: rgba(#020C12, 0.58);
    font-weight: 400;
    font-size: 14px;
    line-height: 20px;
    letter-spacing: 0;
  }

  .spinner {
    box-sizing: border-box;
    border: 2px solid transparent;
    border-radius: 50%;
    font-family: 'pgs';
    text-align: center;
    width: var(--spinner-width);
    height: var(--spinner-height);
    line-height: calc(var(--spinner-width) - var(--line-width));
    position: relative;
    background-color: inherit;

    .spinner-bg {
      position: absolute;
      background-color: inherit;
      display: none;
      z-index: 10;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      border-radius: 50%;
    }

    &:before {
      font-size: calc(var(--spinner-width) / 1.5);
    }
  }

  &.success {
    color: var(--success-label-color);
    .spinner {
      background-color: #e3fefa;
      color: #04967d;
    }
  }

  &.error .spinner {
    background-color: rgba(#cf5f14, 0.15);
    color: #cf5f14;
  }
  &.pending .spinner {
    background-color: inherit;
    color: rgb(16, 122, 188);
    transform: rotate(40deg);
    border: var(--line-width) solid #eceef8;
    animation: border-segments-anim 0.8s linear infinite;

    .spinner-bg {
      display: block;
    }

    &:before,
    &:after {
      content: '';
      z-index: 5;
      position: absolute;
      top: 50%;
      left: calc(var(--line-width) * -1);
      right: calc(var(--line-width) * -1);
      height: var(--line-width);
      background: inherit;
      transform: translateY(-50%) rotate(-45deg);
    }
    &:after {
      top: calc(var(--line-width) * -1);
      bottom: calc(var(--line-width) * -1);
      left: 50%;
      right: unset;
      height: unset;
      transform: translateX(-50%) rotate(-45deg);
      width: var(--line-width);
    }
  }
}
</style>
