import { SimpleGrid, Text, Box } from '@mantine/core';
import dayjs from 'dayjs';
import type { Employee } from '../../../api/types';

const font = "'Montserrat', Arial, sans-serif";
const charcoal = '#58595b';

const MARITAL_LABELS: Record<string, string> = {
  casatorit: 'Căsătorit',
  necasatorit: 'Necăsătorit',
  divortat: 'Divorțat',
  vaduv: 'Văduv',
};

const SCIENTIFIC_LABELS: Record<string, string> = {
  doctor: 'Doctor',
  doctor_habilitat: 'Doctor habilitat',
};

function Field({ label, value }: { label: string; value?: string | null }) {
  return (
    <Box>
      <Text
        size="xs"
        style={{
          fontFamily: font,
          fontWeight: 600,
          textTransform: 'uppercase',
          letterSpacing: '0.06em',
          color: '#adb5bd',
          marginBottom: 2,
        }}
      >
        {label}
      </Text>
      <Text
        size="sm"
        style={{ fontFamily: font, fontWeight: value ? 400 : 300, color: value ? charcoal : '#ced4da' }}
      >
        {value ?? '—'}
      </Text>
    </Box>
  );
}

interface Props {
  employee: Employee;
}

export function PersonalTab({ employee }: Props) {
  return (
    <SimpleGrid cols={2} spacing={24}>
      <Field label="IDNP" value={employee.idnp} />
      <Field label="Data nașterii" value={employee.dataNasterii ? dayjs(employee.dataNasterii).format('DD.MM.YYYY') : null} />
      <Field label="Sex" value={employee.sex === 'F' ? 'Feminin' : 'Masculin'} />
      <Field label="Stare civilă" value={employee.stareCivila ? MARITAL_LABELS[employee.stareCivila] : null} />
      <Field label="Domiciliu" value={employee.domiciliu} />
      <Field label="Adresă reală" value={employee.adresaReala} />
      <Field label="Telefon personal" value={employee.telefonPersonal} />
      <Field label="Telefon serviciu" value={employee.telefonServiciu} />
      <Field label="Email personal" value={employee.emailPersonal} />
      <Field label="Email corporativ" value={employee.emailCorporativ} />
      <Field label="Cod CPAS" value={employee.codCpas} />
      <Field label="Grad dizabilitate" value={employee.gradDizabilitate?.name} />
      <Field label="Titlu științific" value={employee.titluStiintific ? SCIENTIFIC_LABELS[employee.titluStiintific] : null} />
      <Field label="Titlu universitar" value={employee.titluUniversitar} />
      {employee.numeAnterior && <Field label="Nume anterior" value={employee.numeAnterior} />}
      {employee.recomandareInterna && (
        <Field
          label="Recomandare internă"
          value={`${employee.recomandareInterna.nume} ${employee.recomandareInterna.prenume}`}
        />
      )}
    </SimpleGrid>
  );
}
