"use client";

import dynamic from "next/dynamic";
import { useSearchParams } from "next/navigation";

const ProjectsList = dynamic(() => import("@/app/projects/page"), { ssr: false });

function DetailsFrame({ src }: { src: string }) {
    return (
        <iframe
        key={src}
        src={src}
        className="w-full h-[70vh] rounded-md border"
        sandbox="allow-same-origin allow-scripts allow-forms allow-popups"
        />
    );
}

export default function ProjectsClient() {
    const search = useSearchParams();
    const id = search.get("id");

    return (
        <div className="space-y-4">
        <div className="rounded-lg border p-6">
        <h2 className="mb-4 text-xl font-semibold">Projects</h2>
        <ProjectsList />
        </div>

        {id && (
            <div className="rounded-lg border p-4">
            <div className="mb-2 text-sm opacity-70">Viewing project #{id}</div>
            <DetailsFrame src={`/projects/${id}`} />
            </div>
        )}
        </div>
    );
}
