<template>
  <div class="ws-state-images-item">
    <v-progress-circular
      v-if="loading"
      color="primary"
      indeterminate
    >{{percent}}</v-progress-circular>
    <v-img
      :max-width="maxWidth"
      v-else-if="url"
      :src="url"
    ></v-img>
    <!-- <template v-else>
      <a
        class="ws-state-images-item__link"
        :href="url"
        target="_blank"
      >{{$_getFileNameFromUrl(url)}}</a>
      <v-btn
        v-if="updatable"
        icon
        @click.stop="$_onRemoveClick()"
        class="ws-state-images-item__icon mr-3 textPrimary--text"
      >
        <v-icon>mdi-close-circle</v-icon>
      </v-btn>
    </template> -->
  </div>
</template>

<script>
export default {
  props: {
    maxWidth: {
      type: String,
      default: null
    },
    updatable: {
      type: Boolean,
      default: true
    },
    loading: {
      type: Boolean,
      default: false
    },
    percent: {
      type: Number,
      default: 0
    },
    url: {
      type: String,
      default: null
    }
  },
  methods: {
    $_onRemoveClick() {
      this.$emit("remove");
    },
    $_handleUploadProgress(progressEvent) {
      this.uploadPercent = Math.round(
        (progressEvent.loaded / progressEvent.total) * 100
      );
    },
    $_getFileNameFromUrl(url) {
      if (!url) {
        return null;
      }
      return decodeURIComponent(url)
        .split("?")[0]
        .split("/")
        .pop();
    }
  }
};
</script>