import { useState, useMemo } from 'react' import { Container, Title, Text, SimpleGrid, Card, Badge, Group, Stack, Checkbox, Drawer, ActionIcon, Loader, Center, Anchor, Box, Popover, } from '@pikku/mantine/core' import { useDisclosure } from '@mantine/hooks' import { IconAward, IconBriefcase, IconCalendar, IconFilter, IconInfoCircle, IconLanguage, IconSchool, } from '@tabler/icons-react' import { useI18n } from '@/context/i18n-provider' import { asI18n } from '@pikku/react' import { useGetCompanyCandidates } from '@/hooks/company/useGetCompanyCandidates' import { useGetCountries } from '@/hooks/useGetCountries' import { useParams } from '@tanstack/react-router' import { SUPPORTED_COUNTRIES } from '@heygermany/sdk/config' import { LanguageLevels, NurseRecognitionGermanyValues, RecognitionLikelihoodValues, type LanguageLevel, } from '@heygermany/sdk' import { CandidateProfileAvatar } from '@/components/company/CandidateProfileAvatar' const LANGUAGE_LEVEL_SORT_RANK: Record = { [LanguageLevels.NONE]: 0, [LanguageLevels.A_ONE]: 1, [LanguageLevels.A_TWO]: 2, [LanguageLevels.B_ONE]: 3, [LanguageLevels.B_TWO]: 4, [LanguageLevels.C_ONE]: 5, [LanguageLevels.C_TWO]: 6, } const getLanguageLevelSortRank = ( level: LanguageLevel | null | undefined ): number => { if (!level) return -1 return LANGUAGE_LEVEL_SORT_RANK[level] ?? -1 } const getCreatedAtTimestamp = ( createdAt: string | Date | null | undefined ): number => { if (!createdAt) return 0 return new Date(createdAt).getTime() } export default function CompanyCandidates() { const { isLoading, data: response } = useGetCompanyCandidates() const candidates = response?.data || [] const t = useI18n() const { lang } = useParams({ strict: false }) const { data: countriesData, getCountryNameFromAbbreviation } = useGetCountries() const [drawerOpened, { open: openDrawer, close: closeDrawer }] = useDisclosure(false) const [selectedProfessions, setSelectedProfessions] = useState([]) const [selectedLanguageLevels, setSelectedLanguageLevels] = useState< string[] >([]) const [selectedCountries, setSelectedCountries] = useState([]) const [selectedResidency, setSelectedResidency] = useState([]) const candidateSourceCountries = SUPPORTED_COUNTRIES.filter( (code) => code !== 'DEU' ) const allCountries = useMemo(() => { if (!countriesData) return [] return candidateSourceCountries .map((code) => ({ code, name: countriesData[code] || code, })) .sort((a, b) => a.name.localeCompare(b.name)) }, [countriesData]) const filteredCandidates = useMemo(() => { return candidates .filter((candidate: any) => { if ( selectedProfessions.length > 0 && !selectedProfessions.includes( candidate.qualificationStatusGermany || '' ) ) { return false } if ( selectedLanguageLevels.length > 0 && !selectedLanguageLevels.includes( candidate.languageSelfAssessmentLevel || '' ) ) { return false } if ( selectedCountries.length > 0 && !selectedCountries.includes(candidate.countryEducation || '') ) { return false } if (selectedResidency.length > 0) { const isInGermany = candidate.livingInGermany ? 'in-germany' : 'not-in-germany' if (!selectedResidency.includes(isInGermany)) { return false } } return true }) .sort((a: any, b: any) => { const languageLevelDifference = getLanguageLevelSortRank(b.languageSelfAssessmentLevel) - getLanguageLevelSortRank(a.languageSelfAssessmentLevel) if (languageLevelDifference !== 0) { return languageLevelDifference } return ( getCreatedAtTimestamp(b.createdAt) - getCreatedAtTimestamp(a.createdAt) ) }) }, [ candidates, selectedProfessions, selectedLanguageLevels, selectedCountries, selectedResidency, ]) const languageLevelOptions = useMemo( () => t.getEnumOptions(LanguageLevels, 'languagelevel'), [t] ) const professionOptions = useMemo( () => t.getEnumOptions(NurseRecognitionGermanyValues, 'nurserecognitiongermany'), [t] ) const formatLanguageLevel = (level: string | null) => { if (!level) return t('enums.languagelevel.none' as any) const option = languageLevelOptions.find((opt) => opt.value === level) return option?.label || level } const formatProfession = (profession: string | null) => { if (!profession) return t('company.candidates.profession.na' as any) const option = professionOptions.find((opt) => opt.value === profession) return option?.label || profession } const formatEducationSummary = (program: string | null | undefined) => program || t('common.na') const formatTotalExperienceDuration = ( totalExperienceMonths: number | null | undefined ) => { if (!totalExperienceMonths) return t('common.na') const years = Math.floor(totalExperienceMonths / 12) const months = totalExperienceMonths % 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.length === 0) { parts.push( `${months} ${t( months === 1 ? 'company.candidates.duration.month' : 'company.candidates.duration.months' )}` ) } return parts.join(' ') } const getRecognitionLikelihoodBadge = (likelihood: string | null) => { if (!likelihood) return null const colorMap: Record = { [RecognitionLikelihoodValues.HIGH]: 'green', [RecognitionLikelihoodValues.MEDIUM]: 'yellow', [RecognitionLikelihoodValues.LOW]: 'red', } return { color: colorMap[likelihood] || 'gray', label: t(`enums.recognitionlikelihood.${likelihood}` as any), } } const FilterContent = () => (
{t('company.candidates.filters.profession')} {t('company.candidates.filters.profession.tooltip' as any)} {professionOptions.map((option) => ( ))}
{t('company.candidates.filters.language')} {languageLevelOptions.map((option) => ( ))}
{t('company.candidates.filters.country')} {allCountries.map(({ code, name }) => ( ))}
{t('company.candidates.filters.residency')}
) const filterPanelScrollStyle = { minHeight: 0, overflowY: 'auto' as const, paddingRight: 4, } if (isLoading) { return (
) } return ( <> {t('company.candidates.filters.title')} } padding="lg" size="sm" hiddenFrom="lg" > {t('company.candidates.filters.title')} {t('company.candidates.candidatesfound' as any, { count: filteredCandidates.length, })} {filteredCandidates.map((candidate: any) => { const recognitionBadge = getRecognitionLikelihoodBadge( candidate.recognitionLikelihood ) return ( {candidate.livingInGermany && ( {t('company.candidates.card.in_germany')} )} {candidate.name} {asI18n(getCountryNameFromAbbreviation( candidate.countryEducation ) || t('common.na'))} {asI18n(formatProfession( candidate.qualificationStatusGermany ))} {asI18n(formatEducationSummary( candidate.education?.program ))} {asI18n(`${t('company.candidates.card.germanlevel' as any)}: ${formatLanguageLevel(candidate.languageSelfAssessmentLevel)}`)} {asI18n(`${t('company.candidates.card.totalexperience')}: ${formatTotalExperienceDuration(candidate.totalExperienceMonths)}`)} {recognitionBadge ? ( {asI18n(`${t('company.candidates.card.recognitionlikelihood' as any)}:`)} {asI18n(recognitionBadge.label)} ) : null} ) })} {filteredCandidates.length === 0 && (
{t('company.candidates.nocandidates')}
)}
) }