import type { ReactNode } from 'react' import { useParams } from '@tanstack/react-router' import { Container, Title, Text, Card, Badge, Group, Stack, Button, Box, Grid, Loader, Center, Alert, } from '@pikku/mantine/core' import { IconMapPin, IconLanguage, IconCalendar, IconBriefcase, IconAward, IconMail, IconInfoCircle, IconSchool, IconCheck, } from '@tabler/icons-react' import { useI18n } from '@/context/i18n-provider' import { asI18n } from '@pikku/react' import { useGetCompanyCandidate } from '@/hooks/company/useGetCompanyCandidate' import { useGetCountries } from '@/hooks/useGetCountries' import { CandidateProfileAvatar } from '@/components/company/CandidateProfileAvatar' function SectionHeader({ icon, title, meta, titleOrder = 3, }: { icon: ReactNode title: string meta?: ReactNode titleOrder?: 3 | 4 }) { return ( {icon} {asI18n(title)} {meta} ) } export default function CandidateDetailPage() { const params = useParams({ strict: false }) const candidateId = params.candidateId as string const t = useI18n() const { getCountryNameFromAbbreviation } = useGetCountries() const { isLoading, data: candidate } = useGetCompanyCandidate(candidateId) const locale = t.locale || 'en' // Format language level for display const formatLanguageLevel = (level: string | null) => { if (!level) return t('enums.languagelevel.none' as any) return t(`enums.languagelevel.${level.toLowerCase()}` as any) } // Format profession for display const formatProfession = (profession: string | null) => { if (!profession) return t('common.na') return t(`enums.nurserecognitiongermany.${profession.toLowerCase()}` as any) } const getRecognitionLikelihoodColor = ( likelihood: string | null | undefined ) => { if (likelihood === 'high') return 'green' if (likelihood === 'medium') return 'yellow' if (likelihood === 'low') return 'red' return 'gray' } const formatExperienceDate = (date: Date | string | null | undefined) => { if (!date) return null const parsedDate = new Date(date) if (Number.isNaN(parsedDate.getTime())) return null return new Intl.DateTimeFormat(locale, { month: 'short', year: 'numeric', }).format(parsedDate) } const getExperienceMonthIndex = ( date: Date | string | null | undefined ): number | null => { if (!date) return null const parsedDate = new Date(date) if (Number.isNaN(parsedDate.getTime())) return null return parsedDate.getUTCFullYear() * 12 + parsedDate.getUTCMonth() } const getExperienceDurationMonths = ( startDate: Date | string | null | undefined, endDate: Date | string | null | undefined ): number | null => { const startMonth = getExperienceMonthIndex(startDate) const endMonth = getExperienceMonthIndex(endDate || new Date()) if ( startMonth === null || endMonth === null || endMonth < startMonth ) { return null } return endMonth - startMonth + 1 } const formatExperienceDuration = ( startDate: Date | string | null | undefined, endDate: Date | string | null | undefined ) => { const totalMonths = getExperienceDurationMonths(startDate, endDate) if (totalMonths === null) return null const years = Math.floor(totalMonths / 12) const months = totalMonths % 12 const parts: string[] = [] if (years > 0) { parts.push( `${years} ${t( years === 1 ? 'company.candidates.duration.year' : 'company.candidates.duration.years' )}` ) } if (months > 0) { parts.push( `${months} ${t( months === 1 ? 'company.candidates.duration.month' : 'company.candidates.duration.months' )}` ) } return parts.length > 0 ? parts.join(' ') : null } const formatExperienceTimeline = ( startDate: Date | string | null | undefined, endDate: Date | string | null | undefined ) => { const start = formatExperienceDate(startDate) const end = endDate ? formatExperienceDate(endDate) : start ? t('company.candidate.experience.present' as any) : null if (start && end) return `${start} - ${end}` return start || end || t('common.na') } const formatExperiencePeriod = ( startDate: Date | string | null | undefined, endDate: Date | string | null | undefined ) => { const timeline = formatExperienceTimeline(startDate, endDate) const duration = formatExperienceDuration(startDate, endDate) return duration ? `${timeline} · ${duration}` : timeline } const formatFacilityType = (facilityType: string | null | undefined) => { if (!facilityType) return t('common.na') return facilityType .split('_') .filter(Boolean) .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)) .join(' ') } const getExperienceLocation = ( city: string | null | undefined, country: string | null | undefined ) => { const locationParts = [ city, country ? getCountryNameFromAbbreviation(country) || country : null, ].filter(Boolean) return locationParts.length > 0 ? locationParts.join(', ') : null } const formatExperienceSummary = ( city: string | null | undefined, country: string | null | undefined, facilityType: string | null | undefined ) => { const parts = [ getExperienceLocation(city, country), facilityType ? formatFacilityType(facilityType) : null, ].filter(Boolean) return parts.length > 0 ? parts.join(' · ') : t('common.na') } const formatExperienceDepartments = ( department: string | null | undefined ) => { if (!department) return null const departments = department .split(',') .map((entry) => entry.trim()) .filter(Boolean) .slice(0, 3) return departments.length > 0 ? departments.join(', ') : null } const formatHomeCountryQualification = (qualification: string | null) => { if (!qualification) return t('common.na') return t( `enums.nurserecognitionhomecountry.${qualification.toLowerCase()}` as any ) } const formatEducationSummary = ( program: string | null | undefined, institution: string | null | undefined ) => { const educationParts = [program, institution].filter(Boolean) return educationParts.length > 0 ? educationParts.join(' · ') : t('common.na') } const formatEducationCountry = (country: string | null | undefined) => country ? getCountryNameFromAbbreviation(country) || country : t('common.na') if (isLoading) { return (
) } if (!candidate) { return ( {t('company.candidate.notfound.message')} ) } const experiences = candidate.experience.filter((experience: any) => Boolean( experience.roleTitle || experience.employerName || experience.department || experience.country || experience.city || experience.facilityType || experience.startDate || experience.endDate ) ) const education = candidate.education const hasExperienceDetails = experiences.length > 0 const hasEducationDetails = Boolean( candidate.qualificationStatusHomeCountry || education?.program || education?.institution || education?.country || typeof education?.nursingRelatedDegree === 'boolean' ) const sectionCardStyle = { borderColor: 'var(--mantine-color-gray-2)', } const contactEmailHref = `mailto:info@hey-germany.com?subject=${encodeURIComponent( `${t('company.candidate.contact.emailsubject')}: ${candidate.name} (${candidate.candidateId})` )}&body=${encodeURIComponent( `${t('company.candidate.contact.emailbody')}\n\n${t('company.candidates.candidate')}: ${candidate.name}\n${t('company.candidate.contact.emailcandidateid')}: ${candidate.candidateId}\n` )}` return ( {/* Profile Header Card */} {/* Info */} {asI18n(candidate.name)} {formatProfession(candidate.qualificationStatusGermany)} {candidate.recognitionLikelihood && ( {asI18n(`${t( `enums.recognitionlikelihood.${candidate.recognitionLikelihood}` as any )} ${t('company.candidate.badge.recognitionlikelihood')}`)} )} {asI18n(`${getCountryNameFromAbbreviation( candidate.countryEducation ) || t('common.na')}${candidate.livingInGermany ? ` (${t('company.candidates.badge.ingermany')})` : ''}`)} {asI18n(education?.program || t('common.na'))} {asI18n(`${t('company.candidates.german')} ${formatLanguageLevel( candidate.languageSelfAssessmentLevel )}`)} {candidate.age ? asI18n(`${candidate.age} ${t('company.candidate.yearsold')}`) : t('common.na')} {/* Main Content Grid */} {/* Left Column */} {/* Education Card */} } title={t('company.candidate.section.education')} /> {hasEducationDetails ? (
{t('company.candidate.field.qualificationlevel')} {asI18n(formatHomeCountryQualification( candidate.qualificationStatusHomeCountry ))}
{t('company.candidate.field.educationdegree')} {asI18n(formatEducationSummary( education?.program, education?.institution ))}
{t('company.candidate.field.countryofeducation')} {asI18n(formatEducationCountry( education?.country || candidate.countryEducation ))}
{t('company.candidate.field.nursinglicense')} {candidate.hasVerifiedLicense ? ( {t('company.candidate.license.verified')} ) : ( {t('company.candidate.license.notprovided')} )}
) : ( {t('company.candidate.education.nodetails')} )}
{/* Languages Card */} } title={t('company.candidate.section.languages')} /> {candidate.languagesSpoken && candidate.languagesSpoken.length > 0 && ( {candidate.languagesSpoken.map((lang: any, index: number) => ( {t(`enums.languagecode.${lang.toLowerCase()}` as any)} ))} )}
{t('company.candidate.field.germanlevel')} {asI18n(formatLanguageLevel( candidate.languageSelfAssessmentLevel ))}
{t('company.candidate.field.assessmenttype')} {candidate.languageCertificateProvided ? t('company.candidate.assessmenttype.certificate') : t('company.candidate.assessmenttype.selfassessment')}
} title={t('company.candidate.section.workexperience')} /> {hasExperienceDetails ? ( {experiences.map((experience: any, index: number) => ( {asI18n(experience.roleTitle || t('common.na'))} {experience.employerName ? ( {asI18n(experience.employerName)} ) : null} {experience.department ? ( {asI18n(formatExperienceDepartments( experience.department ) || t('common.na'))} ) : null} {asI18n(formatExperiencePeriod( experience.startDate, experience.endDate ) || t('common.na'))} {asI18n(formatExperienceSummary( experience.city, experience.country, experience.facilityType ) || t('common.na'))} ))} ) : ( {t('company.candidate.experience.nodetails' as any)} )} {/* Recognition Status Card */} } title={t('company.candidate.section.recognitionstatus')} />
{t('company.candidate.field.referenceprofession')} {asI18n(formatProfession(candidate.qualificationStatusGermany))}
{t('company.candidate.field.recognitionlikelihood')} {candidate.recognitionLikelihood ? ( {t( `enums.recognitionlikelihood.${candidate.recognitionLikelihood}` as any )} ) : ( {t('common.na')} )}
{/* Right Column */} {/* Personal Information Card */} } title={t('company.candidate.section.personalinformation')} titleOrder={4} />
{t('company.candidate.field.nationality')} {asI18n(getCountryNameFromAbbreviation( candidate.nationality || candidate.countryEducation ) || t('common.na'))}
{t('company.candidate.field.countryofresidence')} {asI18n(getCountryNameFromAbbreviation( candidate.currentResidence ) || t('common.na'))}
{candidate.stateWorkPreference && candidate.stateWorkPreference.length > 0 && (
{t('company.candidate.field.preferredlocations')} {candidate.stateWorkPreference.map((state: any, index: number) => ( {t( `enums.germanstate.${state.toLowerCase().replace(/_/g, '-')}` as any )} ))}
)}
{/* Contact Information Card */} } title={t('company.candidate.section.contactinformation')} titleOrder={4} /> {t('company.candidate.contact.emaildescription')}
) }