cache: "no-store";

import { ReactNode } from "react";
import EntityManagementTable from "@/components/client/EntityManagementTable";
import PostTable from "@/components/client/admin/PostTable";
import {
	deletePost,
	getPostsWithBucketsAndProject,
	updatePost,
} from "@/app/lib/actions/entitymanagement/post/postActions";
import { getProjects } from "@/app/lib/actions/entitymanagement/post/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
import { Attributes } from "@sequelize/core";
import * as util from "util";

type Props = {
	children?: ReactNode;
};

async function getHeadings() {
	let headings: string[] = [];
	for (const key in Project.getAttributes()) {
		headings.push(key);
	}
	return headings;
}

export async function ProjectView(props: Props) {
	const sync = await dbSync;

	const actions = {
	    deletePost: deletePost,
	    getProjects:getProjects,
	    savePost:updatePost,
	    // uploadAttachment:tryCreateAttachment
	};
	const projects: Project[] = await Project.findAll().then((projects) =>
		projects.map((e) => JSON.parse(JSON.stringify(e)))
	);
	return (
		<>
			<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
				<div className="w-[100%] m-auto">
					<EntityManagementTable
                        entityName="Project"
                        headings={[
                            '#',
                            'Title',
                            'Content',
                            'Project',
                            'Date Created',
                            'Date Modified',
                            'Edit',
                            'Delete',
                        ]}>
                            {""}
					</EntityManagementTable>
					{/* <PostTable  data={posts} 
                            projects={projects} 
                            headings={headings} 
                            actions={actions}>
                </PostTable> */}
				</div>
			</div>
		</>
	);
}
