import Link from "next/link"; import { headers } from "next/headers"; import { notFound } from "next/navigation"; import FavoriteToggle from "../../components/FavoriteToggle"; import WorkHeroGallery from "../../components/WorkHeroGallery"; import WorkShareActions from "../../components/WorkShareActions"; import { serverFetch } from "../../lib/api"; function toText(value: unknown, fallback = "") { return typeof value === "string" && value ? value : fallback; } function asArray(value: unknown): string[] { return Array.isArray(value) ? value.map((item) => String(item)) : []; } function asRecords(value: unknown): Array> { return Array.isArray(value) ? value.filter((item): item is Record => Boolean(item) && typeof item === "object" && !Array.isArray(item)) : []; } function galleryFor(work: Record) { const images = [toText(work.image_url), ...asArray(work.gallery_urls)].filter(Boolean); return Array.from(new Set(images)); } function draftDataFor(work: Record) { return work.draft_data && typeof work.draft_data === "object" && !Array.isArray(work.draft_data) ? work.draft_data as Record : {}; } export default async function WorkPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; let work: Record; try { const data = await serverFetch<{ work: Record }>(`/works/${slug}`); work = data.work; } catch { notFound(); } const requestHeaders = await headers(); const gallery = galleryFor(work); const draftData = draftDataFor(work); const beforeImage = toText(draftData.beforeImageUrl); const afterImage = toText(draftData.afterImageUrl); const showBeforeAfter = Boolean(draftData.includeBeforeAfter && beforeImage && afterImage); const relatedWorks = asRecords(work.related_works); const title = toText(work.title, "Trabajo publicado"); const makerName = toText(work.maker_name, "Maker"); const host = requestHeaders.get("x-forwarded-host") || requestHeaders.get("host") || "dev.jazari.com.ar"; const protocol = requestHeaders.get("x-forwarded-proto") || (host.includes("localhost") ? "http" : "https"); const workUrl = `${protocol}://${host}/works/${slug}`; const contactHref = `/consultas/nueva?makerId=${encodeURIComponent(String(work.maker_id))}&sourceType=work&sourceId=${encodeURIComponent(String(work.id))}&makerName=${encodeURIComponent(makerName)}&contextTitle=${encodeURIComponent(title)}&returnTo=${encodeURIComponent(`/works/${slug}`)}`; return (

{title}

{toText(work.technology, "FDM")} {toText(work.material, "PLA")}
{makerName.slice(0, 2).toUpperCase()}
{makerName} * 4,9 | 128 opiniones | Aceptando trabajos
>

Que se hizo?

{toText(work.summary, "Se reprodujo una pieza a medida para resolver una necesidad real del cliente.")}

01Pieza funcional
02Resiste calor
031 unidad
0448 h fabricacion
{showBeforeAfter ? (

Antes / Resultado

Ver mas
Antes Antes
>
Resultado Resultado
) : null}

Historia del proyecto

{toText(work.story, "El cliente necesitaba recuperar una pieza o validar una solucion. Se tomo una referencia, se ajusto el diseno y se fabrico una version funcional lista para probar.")}

Detalles tecnicos
Tecnologia{toText(work.technology, "FDM")} Material{toText(work.material, "PETG")} AcabadoLijado y ajuste manual Resolucion0,16 mm capa Relleno40% Tiempo48 horas

Galeria

{gallery.length} fotos
{gallery.map((image, index) => ( {`${title} ))}
{relatedWorks.length ? (

Tambien puede interesarte

Ver todos
{relatedWorks.map((item) => ( {toText(item.title, {toText(item.title, "Trabajo sugerido")} {toText(item.technology, "FDM")} | {toText(item.material, "PETG")} ))}
) : null}

Compartir este trabajo

Comparte este enlace para mostrar la referencia o enviarla por WhatsApp.

); }