import dayjs from "dayjs"; export interface ItemObject { id: string; date: number; slug: string; type: string; place: string; city: string; state: string; country: string; thumbnail: string; } export interface FilesObject { youtube?: string; video?: string; audio?: string; booklet?: string; simple?: string; } export function formatFiles(files: FilesObject) { const { $i18n } = useNuxtApp(); const t = $i18n.t; let items = []; if (files) { if (files.youtube) { items.push({ to: files.youtube, target: "_blank", label: "Youtube", icon: "ph:youtube-logo-thin", labelClass: "text-xs", }); } if (files.video) { items.push({ to: files.video, target: "_blank", label: t("Activities.video"), icon: "ph:file-video-thin", labelClass: "text-xs", }); } if (files.audio) { items.push({ to: `https://actividadeswp.carpa.com/wp-content/uploads/${files.audio}`, target: "_blank", label: t("Activities.audio"), icon: "ph:file-audio-thin", labelClass: "text-xs", }); } if (files.booklet) { items.push({ to: files.booklet, target: "_blank", label: t("Activities.book"), icon: "ph:notebook-thin", labelClass: "text-xs", }); } if (files.simple) { items.push({ to: files.simple, target: "_blank", label: t("Activities.simple"), icon: "ph:note-thin", labelClass: "text-xs", }); } } return items; } export function formatDate(d: number) { if (!d) { return } const { $i18n } = useNuxtApp() const locale = $i18n.locale const date = new Date(d * 1000) const dateString = date.toLocaleString(locale.value, { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long', timeZone: 'UTC' }) return capitalizeFirstLetter(dateString) } export function formatLocation(i: ItemObject) { if (!i) { return } const { $i18n } = useNuxtApp() const locale = $i18n.locale const regionNames = new Intl.DisplayNames([locale.value], { type: 'region' }) const locationParts = [] locationParts.push(i?.place) locationParts.push(i?.city) locationParts.push(i?.state) if (i.country) { locationParts.push(regionNames.of(i.country)) } return locationParts.filter(Boolean).join(', ') } export function formatSignature(i: ItemObject) { const date = formatDate(i?.timestamp) const location = formatLocation(i) if (date === undefined || location === undefined) { return } const val = `${date} - ${location}` if (!val) { return } return val } export function getDay(d: number) { const { $i18n } = useNuxtApp(); const locale = $i18n.locale; let date = new Date(d * 1000); return date.toLocaleString(locale.value, { weekday: "long", timeZone: "utc", }); } export function getDayDate(d: number) { const { $i18n } = useNuxtApp(); const locale = $i18n.locale; let date = new Date(d * 1000); return date.toLocaleString(locale.value, { day: "numeric", timeZone: "utc" }); } export function getMonth(d: number) { const { $i18n } = useNuxtApp(); const locale = $i18n.locale; let date = new Date(d * 1000); return date.toLocaleString(locale.value, { month: "long", timeZone: "utc" }); } export function setUrl(item: ItemObject, isSearch: boolean) { const { $i18n } = useNuxtApp(); const locale = $i18n.locale; const date = dayjs(item.date * 1000); const month = (date.month() + 1).toString(); const slug = item.slug || item.slug === "undefined" ? item.slug : item.id; if (isSearch) { return false; } else { return `/${locale.value}/${item.type}/${date.year()}/${month.padStart(2, "0")}/${slug}`; } } export function getThumbnail(item: ItemObject) { console.log("ITEM", item); let path = item.thumbnail; if (!path) { return "https://images.carpa.com/tr:w-900,f-auto/youtube_thumbnail_46396.png"; } else { return `https://images.carpa.com/${item.type}/${path}?tr=w-900`; } } export function getAuthor(type: string) { let author = ""; switch (type) { case "activities": author = "Dr. José Benjamín Pérez Matos"; break; case "conferences": author = "Dr. William Soto Santiago"; break; case "sermons": author = "William Marrion Branham"; break; } return author; } // removed: openItem relied on a Pinia store that is not installed in this app. // Detail navigation is now handled directly inside the search pages.