MovieCard.vue 1.46 KB
<script lang="ts" setup>
import type { MovieInterface } from "~/interfaces/movie";
// #region --Props--.
import { useDateFormat } from "@vueuse/core";
import { FilmIcon } from "lucide-vue-next";
// #endregion

// #region --Props--.
/** Typescript typage */
defineProps<{
  movie: MovieInterface;
}>();
// #endregion
</script>

<template>
  <section
    class="bg-gray-800 rounded-lg overflow-hidden shadow-lg transition-transform duration-300 hover:scale-105 cursor-pointer"
    @click="navigateTo(`/movies/${movie.id}`)"
  >
    <div class="relative pb-[150%]">
      <img
        v-if="movie.poster_path"
        :alt="movie.title"
        :src="`https://image.tmdb.org/t/p/w500${movie.poster_path}`"
        class="absolute inset-0 w-full h-full object-cover"
      >
      <div
        v-else
        class="absolute inset-0 w-full h-full bg-gray-700 flex items-center justify-center"
      >
        <FilmIcon
          :size="48"
          class="text-gray-500"
        />
      </div>
      <div
        class="absolute top-2 right-2 bg-primary text-white rounded-full w-10 h-10 flex items-center justify-center font-bold"
      >
        {{ movie.vote_average.toFixed(1) }}
      </div>
    </div>
    <div class="p-4">
      <h2 class="text-lg font-bold mb-1 line-clamp-1">
        {{ movie.title }}
      </h2>
      <p class="text-sm text-gray-400">
        {{ useDateFormat(movie.release_date, "DD-MM-YYYY") }}
      </p>
    </div>
  </section>
</template>

<style scoped></style>