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

type AllegatiProps = {
  userId: UsersId;
};

const AllegatiUser: NextPageWithLayout<AllegatiProps> = ({
  userId,
}: AllegatiProps) => {
  return (
    <div className="grow px-1">
      <AllegatiComp userId={userId} isAdmin />
    </div>
  );
};
export default AllegatiUser;

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" };
};

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