import { Credential } from "@/common/types/auth"
import { Avatar, AvatarIcon, Card, CardBody } from '@nextui-org/react';
import { teamAliases } from '@/common/constants/team';
import styles from "./profile-card.module.css"
import Dropdown from './components/Dropdown';
import { cookies } from 'next/headers';

const ProfileCard = () => {
  const credentialStr = cookies().get('credential')?.value
  const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null

  return credential && (
    <Card shadow='sm'>
      <CardBody className={styles.cardBody}>
        <Avatar icon={<AvatarIcon />} size='sm' isBordered color='primary' classNames={{ icon: 'text-white' }} />
        <div>
          <div className={styles.name}>{credential.name}</div>
          <div className={styles.description}>
            <span>
              {credential.company.name}
            </span>
            &#183;
            <span>
              Tim {teamAliases[credential.team].name}
            </span>
          </div>
        </div>

        <div className="ml-auto">
          <Dropdown />
        </div>
      </CardBody>
    </Card>
  )
}

export default ProfileCard