import Layout from "@/layouts/main";
import Main from "@/components/pages/blog";
import { GetStaticProps } from "next";
import datasquirel from "@moduletrace/datasquirel";
import { DSQL_TBENME_BLOG_POSTS, PagePropsType } from "@/types";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";

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

export const getStaticProps: GetStaticProps<PagePropsType> = async (ctx) => {
    const blogPosts: APIResponseObject<DSQL_TBENME_BLOG_POSTS[]> =
        await datasquirel.crud<DSQL_TBENME_BLOG_POSTS>({
            action: "get",
            table: "blog_posts",
            query: {
                order: {
                    field: "id",
                    strategy: "DESC",
                },
            },
        });

    return {
        props: {
            blogPosts: blogPosts.payload || null,
        },
    };
};
