/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/

'use client'

import { AbstractApi } from '@/app/api/abstract-api';
import { Website, WebsiteSerializer } from '@/app/lib/website';
import { useState, useEffect } from 'react';
import DOMPurify from "dompurify";
import { useParams } from 'next/navigation';

export default function Page() {
    const params = useParams<{ slug: string }>()
  
    useEffect(() => {
      if (typeof window !== 'undefined') {
        localStorage.setItem('slug', params.slug);
      }
    }, []);

  const [websiteContent, setWebsiteContent] = useState<string>("");

  const api = new AbstractApi<Website>();
  const serializer = new WebsiteSerializer();

  useEffect(() => {
    api.get(serializer, undefined, (loadedWebsite) => {
      setWebsiteContent(loadedWebsite.content || "");
    });
  }, []);

  return (
    <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(websiteContent) }} />
  );
}