"use client";
import React from "react";
import TopHeader from "../components/topHeader/TopHeader";
import globalStyle from "../globalStyle.module.css";
import styles from "./styles.module.css";
import { useRouter } from "next/navigation";
import ViewIcon from "../components/icons/view";
import DeleteIcon from "../components/icons/delete";
import SuccessToast from "../components/toast/success/successToast";

const UsersPage = () => {
  const router = useRouter();

  const sampleData = [
    {
      id: 1,
      email: "nino.moonshot@gmail.com",
      fullName: "Nino Paul Cervantes",
      createdAt: "2024-10-21 08:01:31.474 +0000 UTC",
    },
    {
      id: 2,
      email: "nino.moonshot@gmail.com",
      fullName: "Nino Paul Cervantes",
      createdAt: "2024-10-21 08:01:31.474 +0000 UTC",
    },
    {
      id: 3,
      email: "nino.moonshot@gmail.com",
      fullName: "Nino Paul Cervantes",
      createdAt: "2024-10-21 08:01:31.474 +0000 UTC",
    },
  ];
  return (
    <div className={globalStyle.section}>
      <SuccessToast message="New User added successfully" />
      <div className={globalStyle.mainContainer}>
        <div className={globalStyle.container}>
          <TopHeader
            buttonText="Add User"
            topbarTitle="Users"
            requiredButtons={["title", "add", "search"]}
          />
          <div className={styles.tableContainer}>
            <table className={styles.table}>
              <thead className={styles.tableHeader}>
                <tr>
                  <th width="30%">Email</th>
                  <th width="30%">Full Name</th>
                  <th width="30%">Date Created</th>
                  <th></th>
                </tr>
              </thead>
              <tbody className={styles.tableBody}>
                {sampleData.map((user, index) => {
                  return (
                    <tr
                      key={user.id}
                      onClick={() => router.push(`/users/${user.id}`)}
                    >
                      <td>{user.email}</td>
                      <td>{user.fullName}</td>
                      <td>{user.createdAt}</td>
                      <td>
                        <div className={styles.tableActions}>
                          <button className={styles.viewBtn}>
                            <ViewIcon />
                          </button>
                          <button className={styles.deleteBtn}>
                            <DeleteIcon />
                          </button>
                        </div>
                      </td>
                    </tr>
                  );
                })}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  );
};

export default UsersPage;
