import { UsetButton } from "../ui/UserButton/UserButton";
import { TUserList } from "../../utils/types";

export const UserList: React.FC<TUserList> = ({
  users,
  audio,
  localUser,
  sendControlRequest,
  message,
  selected,
  setSelected,
  handleControl,
  handleReturnControl,
}) => {
  const handleAdmin = () => {
    const isAdmin = users.some(
      (i: any) => i.admin === true && i.id === localUser.id
    );
    return isAdmin;
  };

  console.log(users);

  return (
    <>
      {users.map((user: any) => (
        <UsetButton
          localUser={localUser}
          message={message}
          sendControlRequest={sendControlRequest}
          isAdmin={handleAdmin}
          audio={audio}
          user={user}
          key={user.id}
          setSelected={setSelected}
          selected={selected}
          handleControl={handleControl}
          handleReturnControl={handleReturnControl}
        ></UsetButton>
      ))}
    </>
  );
};
