import { ClipLoader } from 'react-spinners';
import LoanRepayment from './LoanRepayment.js';
import './PopoutPanel.css';
import { useState, useEffect } from 'react';
function PopoutPanel({
data = {},
userState = 'N/A', // Passed explicitly from Dashboard
loading = false,
error = null,
closePanel,
}) {
console.log('PopoutPanel Props:', { data, loading, error, userState });
const [isCalculated, setIsCalculated] = useState(false);
const [results, setResults] = useState([]); // Store loan repayment calculation results
const [loadingCalculation, setLoadingCalculation] = useState(false);
// ✅ Reset `results` when a new career is selected
useEffect(() => {
console.log(`Career changed to: ${data?.title}, clearing previous loan results.`);
setResults([]); // ✅ Clears results when a new career is selected
setIsCalculated(false); // ✅ Reset calculation state
}, [data]); // Runs whenever `data` changes (i.e., new career is selected)
// Handle loading state
if (loading) {
return (
Loading Career Details...
);
}
// Safely access nested data with fallbacks
const {
jobDescription = null, // Default to null if not provided
tasks = null, // Default to null if not provided
title = 'Career Details',
economicProjections = {},
salaryData = [],
schools = [],
} = data;
// Get program length for calculating tuition
const getProgramLength = (degreeType) => {
if (degreeType?.includes("Associate")) return 2;
if (degreeType?.includes("Bachelor")) return 4;
if (degreeType?.includes("Master")) return 6;
if (degreeType?.includes("Doctoral") || degreeType?.includes("First Professional")) return 8;
if (degreeType?.includes("Certificate")) return 1;
return 4; // Default to 4 years if unspecified
};
return (