<template>
  <div
    class="c-card u-pointer"
    @click="onClick"
    @dblclick="onDblclick"
  >
    <auto-image
      class="c-card__image"
      :placeholder="source.icon"
      :src="source.thumbnailUrl"
    />
    <div class="c-card__name u-ellipsis">{{ source.name }}</div>
    <slot />
  </div>
</template>

<script>
export default {
  name: 'MediaCard',
  props: {
    source: {
      type: Object,
      required: true
    }
  },
  methods: {
    onClick () {
      this.$emit('click', this.source)
    },
    onDblclick () {
      this.$emit('dblclick', this.source)
    }
  }
}
</script>

<style lang="scss" scoped>
.c-card {
  display: inline-block;
  position: relative;
  padding-top: 60%;
  color: $info;
  background-color: rgba(0, 0, 0, 0.8);

  &__name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 4px 6px;
    font-size: 14px;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.6);
  }

  &__image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-size: 20px;
  }
}
</style>
