<script setup lang="ts">
import type { FeedItem } from '@/feed'
import { RouterLink } from 'vue-router'
import MediaInfo from './MediaInfo.vue'

const props = defineProps<{
  item: FeedItem
}>()
</script>

<template>
  <div class="scroller-item">
    <div class="scroller-item-img">
      <div class="poster-tag" v-if="props.item.tag !== '' && props.item.tag !== undefined">
        <div class="text-tag" v-if="props.item.tag !== '0'">{{ props.item.tag }}</div>
        <div class="icon-tag" v-else>
          <font-awesome-icon icon="fa-solid fa-check" size="md" class="clickable" />
        </div>
      </div>
      <div class="poster-img">
        <RouterLink :to="`/play/${item.itemId}`">
          <font-awesome-icon icon="fa-solid fa-play" class="play-icon"
        /></RouterLink>
        <RouterLink :to="`/item/${item.itemId}`">
          <img
            :src="props.item.image"
            alt=""
            :style="{
              width: `${160}px`,
              height: `${160 * (3 / 2)}px`,
            }"
        /></RouterLink>
      </div>
      <div class="info-box">
        <div class="info-box-content">
          <div class="info-box-header">
            <RouterLink
              class="info-box-title clamp-2"
              :to="`/item/${props.item.itemId}`"
              :key="props.item.itemId"
              >{{ props.item.title }}
              <div class="info-box-subtext clamp" v-show="item.infoSubtext !== ''">
                {{ item.infoSubtext }}
              </div></RouterLink
            >
          </div>
          <div class="info-box-summary clamp-8">{{ props.item.summary }}</div>
          <MediaInfo :itemId="item.itemId" size="sm" />
        </div>
      </div>
    </div>
    <div class="scroller-item-title clamp-2" :style="{ maxWidth: `${160 - 5}px` }">
      {{ props.item.title }}
    </div>
    <div class="scroller-item-subtext clamp" :style="{ maxWidth: `${160 - 5}px` }">
      {{ props.item.subtext }}
    </div>
  </div>
</template>

<style scoped>
.scroller-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 12px;
}
.play-icon {
  position: absolute;
  top: 85px;
  left: 45px;
  width: 35px;
  height: 35px;
  cursor: pointer;
  z-index: 2;
  opacity: 0%;
  padding: 0.75em;
  background: rgba(0, 0, 0, 0.2);
  color: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: background 10ms linear 0ms;
}
.play-icon:hover {
  background: rgba(122, 122, 122, 0.2);
}
.scroller-item-img:hover .play-icon {
  top: 53%;
  left: 49%;
  opacity: 100%;
  transition:
    all var(--hover-animation-speed) ease var(--hover-animation-delay),
    z-index 1ms,
    background 10ms linear 0ms;
  z-index: 5;
  visibility: visible;
}
.scroller-item-img {
  position: relative;
}
.scroller-item-img img {
  position: relative;
  background-size: cover;
  z-index: 1;
  transition-duration: 0.3s;
}
.scroller-item-img:hover img {
  transform: scale(1.3) translateX(19px) translateY(28px);
  cursor: pointer;
  transition:
    all var(--hover-animation-speed) ease,
    z-index 1ms;
  transition-delay: var(--hover-animation-delay);
  position: relative;
  z-index: 4;
}
.poster-tag {
  position: absolute;
  right: 0px;
  top: 6px;
  z-index: 2;
  font-weight: 500;
  font-size: 13px;
  width: 36px;
  background: rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 1);
  border-radius: 16px 0px 0px 16px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(2.6px);
  -webkit-backdrop-filter: blur(2.6px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-right: none;
  text-align: center;
  transition: all var(--hover-animation-speed) ease 0.2s;
  opacity: 100%;
}
.scroller-item-img:hover .poster-tag {
  opacity: 0%;
  transition: all var(--hover-animation-speed) ease 0.2s;
  /* transition-delay: var(--hover-animation-delay); */
  /* transform: translateX(10px); */
}
.scroller-item-title {
  text-align: center;
}
.scroller-item-subtext {
  color: var(--color-text-faded);
  max-width: 245px;
  text-align: center;
}
.info-box {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  width: 160px;
  height: 240px;
  visibility: hidden;
  background-color: var(--color-background-grey);
  transition-duration: 0.3s;
}
.scroller-item-img:hover .info-box {
  visibility: visible;
  transform: translateX(208px);
  width: 240px;
  height: 312px;
  z-index: 3;
  transition:
    all var(--hover-animation-speed) ease var(--hover-animation-delay),
    z-index 1ms var(--hover-animation-delay);
}
.info-box-content {
  margin: 0 auto;
  padding: 1.5em;
  max-height: 180px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: baseline;
  justify-content: space-between;
  min-height: 100%;
  font-size: 13px;
}
.scroller-item-img:hover .info-box-content {
  max-height: 240px;
  transition-delay: 0.05s;
}
.info-box-title {
  font-weight: 600;
  font-size: 18px;
  color: var(--color-text);
  text-decoration: none;
}
.info-box-title:hover {
  text-decoration: underline;
}
.info-box-subtext {
  color: var(--color-text-faded);
  font-size: 12px;
}
.info-box-misc-info {
  display: flex;
  justify-content: space-between;
  min-width: 95%;
}
</style>
