import React, { useRef, useState, useEffect } from 'react';
import Head from "next/head";
import Image from "next/image";
import Flipbook from "~/components/Flipbook";

export default function Home() {
  const mainRef = useRef<HTMLDivElement>(null);
  const [mainWidth, setMainWidth] = useState(350);  // default value

  useEffect(() => {
    if (mainRef.current) {
      setMainWidth(mainRef.current.offsetWidth/2.3);
    }
  }, []);

  return (
    <>
      <Head>
        <title>Create T3 App</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main className="" ref={mainRef}>
        <Flipbook className="" width={mainWidth} height={mainWidth*460/350}>
          <div className="bg-gray-300">
            <div className="flex justify-center items-center h-full">
              <a href="/download/GabrielDalle_Magazine.pdf" target="_blank" className="border-my-red border-[3px] p-4 rounded-full flex gap-2 cursor-pointer hover:border-black hover:bg-white font-mono font-bold text-sm tracking-wide">
                PDF DOWNLOAD
              </a>
            </div>
          </div>
          {Array.from(Array(24), (_, i) => (
            <div className="bg-white" key={i}>
              <Image key={i} alt="pdf page" height={468} width={mainWidth} src={`/projects/fizik/pdf/page${i + 1}.png`} />
            </div>
          ))}
          <div className="bg-gray-300" />
        </Flipbook>
      </main>
    </>
  );
}
