"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 RolesPage = () => {
  const router = useRouter();

  const sampleData = [
    {
      id: 1,
      name: "organization-owner",
      orgId: "67160a5ae69144ff19aafb86",
      permissions: "35 Permissions",
    },
    {
      id: 2,
      name: "organization-owner",
      orgId: "67160a5ae69144ff19aafb86",
      permissions: "35 Permissions",
    },
    {
      id: 3,
      name: "organization-owner",
      orgId: "67160a5ae69144ff19aafb86",
      permissions: "35 Permissions",
    },
    {
      id: 4,
      name: "organization-owner",
      orgId: "67160a5ae69144ff19aafb86",
      permissions: "35 Permissions",
    },
    {
      id: 5,
      name: "organization-owner",
      orgId: "67160a5ae69144ff19aafb86",
      permissions: "35 Permissions",
    },
  ];
  return (
    <div className={globalStyle.section}>
      <SuccessToast message="New Role added successfully!" />
      <div className={globalStyle.mainContainer}>
        <div className={globalStyle.container}>
          <TopHeader
            buttonText="Add Role"
            topbarTitle="Roles"
            requiredButtons={["title", "add", "search"]}
          />
          {/* Users Table */}
          <div className={styles.tableContainer}>
            <table className={styles.table}>
              <thead className={styles.tableHeader}>
                <tr>
                  <th width="30%">Name</th>
                  <th width="30%">Organization ID</th>
                  <th width="30%">Permissions</th>
                  <th></th>
                </tr>
              </thead>
              <tbody className={styles.tableBody}>
                {sampleData.map((role, index) => {
                  //role or user?
                  return (
                    <tr
                      key={role.id}
                      onClick={() => router.push(`/roles/${role.id}`)}
                    >
                      <td>{role.name}</td>
                      <td>{role.orgId}</td>
                      <td>{role.permissions}</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 RolesPage;
