"use client"; /** * TEE OFF DETAIL VIEW - COMPLETE v3.7 (STABLE) * --------------------------------------------------------------------------- * REGEL 1: Garanterer parsing av JSON-data (courses, amenities, greenfee osv). * REGEL 2: Beholder 22/78 layout og alle visuelle seksjoner (Kart, Video, Priser). * REGEL 3: Viser KUN bilder fra klubbens eget galleri i slideren. * REGEL 4: Bruker monokrome ikoner (#11280f) og oransje lenker (#ff5722). * --------------------------------------------------------------------------- */ import { useState, useEffect } from 'react'; import { STATUS_MAP, FALLBACK_IMAGE } from "@/config/constants"; import Link from 'next/link'; import CourseDisplay from './CourseDisplay'; // --- MONOKROME SVG IKONER --- const Icon = ({ children, className = "w-5 h-5" }: { children: React.ReactNode, className?: string }) => ( {children} ); const ICONS = { web: <>, phone: , mail: <>, map: <>, booking: <>, trophy: <>, guide: <>, camera: <>, webcam: <>, weather: , facebook: , instagram: <> }; export default function FacilityDetailView({ facility }: { facility: any }) { const [showBackToTop, setShowBackToTop] = useState(false); const [currentSlide, setCurrentSlide] = useState(0); // --- DATA RECOVERY LOGIKK (Fikser krasj fra API-strenger) --- const parseJson = (val: any, fallback: any) => { if (!val) return fallback; if (typeof val === 'object') return val; try { return JSON.parse(val); } catch (e) { return fallback; } }; const rawCourses = parseJson(facility.courses, []); const activeCourses = Array.isArray(rawCourses) ? rawCourses.filter((c: any) => c.holes && (typeof c.holes === 'string' || c.holes.length > 0)) : []; const amenities = parseJson(facility.amenities, {}); const gallery = parseJson(facility.gallery, [facility.image_url || FALLBACK_IMAGE]); const greenfee = parseJson(facility.greenfee, []); const shotzoom = parseJson(facility.shotzoom, []); const linkClass = "text-orange-600 hover:underline transition-colors font-bold"; useEffect(() => { if (gallery.length <= 1) return; const timer = setInterval(() => setCurrentSlide((p) => (p + 1) % gallery.length), 5000); return () => clearInterval(timer); }, [gallery.length]); useEffect(() => { const handleScroll = () => setShowBackToTop(window.scrollY > 500); window.addEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll); }, []); const scrollTo = (id: string) => { const el = document.getElementById(id); if (el) window.scrollTo({ top: el.getBoundingClientRect().top + window.pageYOffset - 80, behavior: 'smooth' }); }; const formatDate = (d: string) => d ? new Date(d).toLocaleDateString('nb-NO', { day: 'numeric', month: 'long', year: 'numeric' }) : null; const weatherImg = facility.weather_url?.replace("/graf/dag/", "/innhold/").replace(/\/$/, "") + "/meteogram.svg"; return (
{/* GALLERI SLIDER */}
{gallery.map((img: string, i: number) => ( ))}
{/* BANESTATUS BADGES */}
{activeCourses.map((c: any) => ( {STATUS_MAP[c.status] || c.status} ))}
{facility.status_updated_at && Sist oppdatert: {formatDate(facility.status_updated_at)}}
{/* HURTIGKNAPPER */}
{facility.website_url && } {facility.golfbox_booking_url && } {facility.golfbox_tournament_url && } {facility.weather_url && }
{facility.logo_url &&
}

{facility.name}

{facility.county} • {facility.city}

{/* NAVIGASJON */}
{/* INTRO SEKSJON */}
{facility.footnote &&
{facility.footnote}
}
{/* VÆR SEKSJON */}

Vær for {facility.name}

{facility.weather_url ? ( Vær ) :

Værvarsel ikke tilgjengelig

}
{/* DETALJER SEKSJON */}

Ressurser

{facility.golfbox_booking_url && Book Starttid} {facility.baneguide_url && Baneguide} {shotzoom.map((sz: any, i: number) => ( 📊 Statistikk: {sz.shotzoom_beskrivelse?.replace(' ', ' ')} ))}

Banen

Hull:{amenities.antall_hull || '--'}
Banetype:{facility.banetype || 'Park/Skog'}
Arkitekt:{facility.architect || '--'}

Fasiliteter

Drivingrange:{amenities.drivingrange || 'Nei'}
Proshop:Ja`) : 'Nei' }} />
Simulator:Ja`) : 'Nei' }} />
{/* KART SEKSJON */}

Kart