<template>
  <div class="min-h-[calc(100vh-9rem)] h-fit container mx-auto py-12 px-2">
    <h1>{{ data?.title }}</h1>
    <p v-if="data?.date && data.date.includes('T')">
      {{
        new Date(data?.date ?? "").toLocaleString("de-DE", {
          day: "2-digit",
          month: "long",
          year: "numeric",
          minute: "2-digit",
          hour: "2-digit",
        })
      }}
    </p>
    <p v-else-if="data?.date">
      {{
        new Date(data?.date ?? "").toLocaleString("de-DE", {
          day: "2-digit",
          month: "long",
          year: "numeric",
        })
      }}
    </p>
    <br />
    <p>{{ data?.description }}</p>
    <br />
    <NuxtPicture
      v-if="data?.image"
      loading="lazy"
      class="max-sm:w-full h-full sm:h-[50vh] max-w-full object-cover object-center"
      :src="baseUrl + data.image.url"
      :imgAttrs="{ class: 'h-full sm:h-[50vh] object-cover object-center' }"
    />
    <br v-if="data?.image" />
    <div v-if="data?.content">
      <p>Bericht:</p>
      <FieldContent :data="data.content" />
    </div>
    <br />
    <div v-if="data?.attachment">
      <p>Anhang:</p>
      <div class="flex flex-col sm:flex-row flex-wrap gap-2 w-full min-h-fit">
        <NuxtPicture
          v-for="img in data.attachment"
          loading="lazy"
          class="max-sm:w-full sm:h-48 object-cover object-center"
          :src="baseUrl + img.url"
          :imgAttrs="{ class: 'max-sm:w-full sm:h-48 object-cover object-center' }"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { PropType } from "vue";
import type Article from "~~/types/collection/article";
import type Operation from "~~/types/collection/operation";
import type Event from "~~/types/collection/event";
import type Vehicle from "~~/types/collection/vehicle";

const runtimeConfig = useRuntimeConfig();
const baseUrl = runtimeConfig.public.strapi.url;

defineProps({
  data: Object as PropType<Article | Operation | Event | Vehicle>,
});
</script>
