import React from "react";
import styles from "@/app//(Admin)/dashboard/(Posts Zone)/tags/tags.module.css";
import Link from "next/link";
import { BsArrowLeft } from "react-icons/bs";
import TagsData from "@/components/administrator/TagData/tag.data";
import { getTagsPagination } from "@/models/term";

const TagsPage = async ({ searchParams }) => {
  const query = await searchParams;
  const sort = query?.sort ? JSON.parse(query.sort) : { name: 1 };
  let page = parseInt(query?.page) || 1;
  const search = query?.search || null;
  const limit = 100;

  if (search) page = 1;

  const tags = await getTagsPagination({ page, limit }, sort, search);

  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <Link
          className={styles.back}
          href="/dashboard">
          <BsArrowLeft /> back
        </Link>
      </div>
      <div className={styles.body}>
        <TagsData
          initialData={tags}
          limit={limit}
          sort={sort}
        />
      </div>
    </div>
  );
};

export default TagsPage;
