import { AreaRiservataLayoutUserView } from "~/components/Layout";
import type { NextPageWithLayout } from "~/pages/_app";
import type { GetStaticProps } from "next";
import type { UsersId } from "~/schemas/public/Users";
import { zUserId } from "~/server/utils/zod_types";
import { EmailAccordion } from "~/components/area-riservata/comunicazioni";

type ComunicazioniUserProps = {
  userId: UsersId;
};

const ComunicazioniUser: NextPageWithLayout<ComunicazioniUserProps> = ({
  userId,
}: ComunicazioniUserProps) => {
  return (
    <main className="flex flex-1 flex-col items-start gap-4 md:gap-8">
      <div className="grid w-full auto-rows-max items-start gap-2 md:gap-4">
        <div className="overflow-auto border-none">
          <h3 className="text-2xl font-bold">Comunicazioni</h3>

          <div className="w-full py-4">
            <EmailAccordion userId={userId} />
          </div>
        </div>
      </div>
    </main>
  );
};

export default ComunicazioniUser;
export const getStaticProps: GetStaticProps = (context) => {
  const userId = context.params?.userId;
  if (typeof userId !== "string") {
    return {
      notFound: true,
    };
  }

  const parsed = zUserId.safeParse(userId);

  if (!parsed.success) {
    {
      return {
        notFound: true,
      };
    }
  }

  return {
    props: {
      userId: parsed.data,
    },
  };
};

export const getStaticPaths = () => {
  return { paths: [], fallback: "blocking" };
};

ComunicazioniUser.getLayout = function getLayout(page) {
  return <AreaRiservataLayoutUserView>{page}</AreaRiservataLayoutUserView>;
};
