import React from "react"; import { Accordion, AccordionDetails, AccordionSummary, Alert, Box, Button, Chip, LinearProgress, Typography } from "@mui/material"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import { useI18n } from "../../i18n/I18nProvider"; import { localizeCompletenessLabel } from "./careerCompletenessLabels"; import { PageSection } from "../../layout/PageLayout"; // Display-only slice of the Career Profile page: the completeness meter, the "missing" chips, and the // version-history accordion. Extracted from CareerProfilePage as the first step of the Phase 1 // component split. It owns no state and makes no API calls — the parent still holds `completeness` // and `versions` and performs the restore — so save/load behaviour is unchanged. export type CareerCompletenessView = { percent: number; missing: string[]; }; export type CareerVersionView = { version: number; source: string; createdAtUtc: string; isCurrent: boolean; }; export default function ProfileCompleteness({ completeness, versions, loading, onRestore, showSummary = true, versionsLoading = false, versionsError = null, onRetryVersions, restoreDisabled = false, restoreError = null, }: { completeness: CareerCompletenessView | null; versions: CareerVersionView[]; loading: boolean; onRestore: (version: number) => void; showSummary?: boolean; versionsLoading?: boolean; versionsError?: string | null; onRetryVersions?: () => void; restoreDisabled?: boolean; restoreError?: string | null; }) { const { language, t } = useI18n(); const restoreHelpId = React.useId(); const historyRef = React.useRef(null); const locale = language === "nb" ? "nb-NO" : "en"; const rows = versions.slice(0, 12).map((v) => ( v{v.version} · {v.source} · {new Date(v.createdAtUtc).toLocaleString(locale)}{v.isCurrent ? ` · ${t("profileCvVersionCurrent")}` : ""} {!v.isCurrent ? ( ) : null} )); return ( {showSummary && completeness ? ( <> {t("profileCvCompletenessTitle")} {completeness.percent}% = 80 ? "success" : completeness.percent >= 40 ? "primary" : "warning"} sx={{ height: 8, borderRadius: 999 }} /> {completeness.missing.length > 0 ? ( {t("profileCvCompletenessMissing")} {completeness.missing.map((label) => ( ))} ) : ( {t("profileCvCompletenessComplete")} )} ) : null} {versionsLoading ? : null} {versionsError !== null ? { historyRef.current?.focus(); onRetryVersions(); }}>{t("retry")} : undefined}> {t("careerHistoryLoadFailed")} {versionsError ? {versionsError} : null} : null} {restoreError !== null ? {t("careerRestoreFailed")} {restoreError ? {restoreError} : null} : null} {restoreDisabled ? {t("careerSaveBeforeRestore")} : null} {versions.length > 1 ? ( } sx={{ px: 0, minHeight: 0 }}> {t("profileCvVersionHistory", { count: versions.length })} {rows} ) : rows} {versions.length === 0 && !versionsLoading && versionsError === null ? {t("careerHistoryEmpty")} : null} ); }