"use server";

import React from "react";
import styles from "@/app/(Admin)/dashboard/(Users)/users/users.module.css";
import Link from "next/link";
import { BsArrowLeft } from "react-icons/bs";
import UsersData from "@/components/administrator/UserData/user.data";
import { getAllUserExcept } from "@/services/users";
import { cookies } from "next/headers";
import { JWT } from "@/utils/jwt";

const UsersPage = async () => {
  const jwt = new JWT();
  const cookie = await cookies();
  const accessToken = cookie.get("accessToken")?.value;
  const detail = jwt.decodeToken(accessToken);
  const users = await getAllUserExcept([detail._id]);

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

export default UsersPage;
