"use server";

import React from "react";
import styles from "@/app/(Admin)/dashboard/(Posts Zone)/posts/posts.module.css";
import Link from "next/link";
import { BsArrowLeft } from "react-icons/bs";
import { getPosts } from "@/services/posts";
import PostsData from "@/components/administrator/PostData/posts.data";
import PostLock from "@/providers/post.lock";
import { getAllLockPost } from "@/models/posts.model";

const PostsPage = async ({ searchParams }) => {
  const querySearch = await searchParams;
  const page = querySearch?.page || 1;
  const limit = 50;
  const posts = await getPosts({ page: parseInt(page), limit });

  // lock post data
  const lockPostData = await getAllLockPost();

  /*
   * title, subtitle, description, content, slug, status, categories, tags, image, author
   */
  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <Link
          className={styles.back}
          href="/dashboard">
          <BsArrowLeft /> back
        </Link>
      </div>
      <div className={styles.body}>
        <PostLock>
          <PostsData
            initialData={posts}
            limit={limit}
            lockPostData={lockPostData}
          />
        </PostLock>
      </div>
    </div>
  );
};

export default PostsPage;
