import Main from "@/src/components/pages/admin/users";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import defaultAdminProps from "@/src/functions/pages/admin/default-admin-props";
import Layout from "@/src/layouts/admin";
import NSQLite from "@moduletrace/nsqlite";
import { GetServerSideProps } from "next";

export default function AdminDeploymentUsers() {
    return (
        <Layout>
            <Main />
        </Layout>
    );
}

export const getServerSideProps: GetServerSideProps = async (ctx) => {
    return await defaultAdminProps({
        ctx,
        async propsFn({ user, props }) {
            if (!user.super_admin) {
                return `/admin`;
            }

            const users_res = await NSQLite.select<NSQLITE_TURBOCI_ADMIN_USERS>(
                {
                    table: "users",
                },
            );

            return {
                deployment_users: users_res.payload,
            };
        },
    });
};
