<template>
  <li
    :class="{ selected: selected }"
    @click="$emit('click')"
    @dblclick="$emit('dblclick')"
  >
    <div :class="`img-container ${loaded}`">
      <img
        :src="src"
        alt="thumbnail"
        @load="loaded = 'loaded'"
      >
    </div>
    <div :class="`asset-data ${classes}`">
      <div>{{ name }}</div>
      <div>
        <copy-to-clipboard :text="path" />
      </div>
    </div>
    <div :class="`modified-date ${classes}`">
      Modified: {{ formattedDate }}
    </div>
  </li>
</template>
<script>

import CopyToClipboard from 'Components/tools/CopyToClipboard.vue';

export default {
  components: {
    CopyToClipboard
  },
  props: {
    classes: {
      type: String,
      default: ''
    },
    date: {
      type: Number,
      default: null
    },
    selected: {
      type: Boolean
    },
    src: {
      type: String,
      required: true
    },
    name: {
      type: String,
      required: true
    },
    path: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      loaded: ''
    };
  },
  computed: {
    formattedDate() {
      return this.date ? new Date(this.date).toLocaleDateString() : null;
    }
  }
};
</script>
<style lang="scss" scoped>
  @import 'Styles/colors.scss';
  @import 'Styles/fonts.scss';

  $disable-color: rgba(0, 0, 0, 0.5);

  li {
    cursor: pointer;
    outline: 1px solid transparent;
    padding: 10px;
    position: relative;

    &:hover {
      box-shadow: 0 0 6px 1px $border-color;
    }

    &:hover,
    &.selected {
      outline-color: $item-selected;
    }
  }

  h4 {
    margin: 0 0 0.5em;
  }

  .img-container {
    background-color: #d8d8d8;
    height: 0;
    margin-bottom: 10px;
    padding-bottom: 100%;
    position: relative;
    width: 100%;

    &.loaded {
      background-color: transparent;
    }
  }

  img {
    height: 100%;
    position: absolute;
    width: 100%;
  }

  .asset-data {
    display: flex;
    font-weight: bold;

    &.picker-mode div {
      font-size: $small-font-size;
    }

    div {
      line-height: 1.17;

      &:first-of-type {
        flex: 1;
        word-break: break-all;
      }

      &:last-of-type {
        margin-left: 8px;
      }
    }
  }

  .asset-data,
  .modified-date {
    line-height: 1.17;

    &.picker-mode {
      font-size: $small-font-size;
    }
  }

  .select-enter-active,
  .select-leave-active {
    transition: opacity 0.3s, transform 0.3s;
  }
  .select-enter,
  .select-leave-to {
    opacity: 0;

    .ui-icon {
      transform: scale(1.3);
    }
  }
</style>
