import React, { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
// --- Helper Component for Tag Inputs ---
const TagInput = ({ name, value, onChange, placeholder, isEditing }) => {
const [inputValue, setInputValue] = useState("");
// Convert string "A, B, C" to array ["A", "B", "C"]
const tags = value ? value.split(',').map(s => s.trim()).filter(Boolean) : [];
const handleAddParam = (val) => {
const trimmed = val.trim();
if (trimmed && !tags.includes(trimmed)) {
const newTags = [...tags, trimmed];
onChange({ target: { name, value: newTags.join(', ') } });
}
setInputValue("");
};
const handleKeyDown = (e) => {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
handleAddParam(inputValue);
} else if (e.key === 'Backspace' && !inputValue && tags.length > 0) {
handleRemoveTag(tags.length - 1);
}
};
const handleRemoveTag = (index) => {
const newTags = tags.filter((_, i) => i !== index);
onChange({ target: { name, value: newTags.join(', ') } });
};
return (
{tags.map((tag, index) => (
{tag}
{isEditing && (
)}
))}
{isEditing && (
setInputValue(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={() => handleAddParam(inputValue)} // Add on blur too
placeholder={tags.length === 0 ? placeholder : ""}
style={{
background: 'transparent', border: 'none', color: 'white',
outline: 'none', flex: 1, minWidth: '100px'
}}
/>
)}
{!isEditing && tags.length === 0 && Not set}
);
};
const ProfileTab = ({
profileData,
isEditing,
handleProfileChange,
handleExperienceChange,
handleAddExperience,
handleAddEducation,
handleEducationChange,
showFullProfile,
}) => {
if (!profileData) return null;
const inputStyles = {
width: '100%', padding: '0.75rem', borderRadius: '0.5rem',
border: '1px solid rgba(251, 191, 36, 0.3)',
backgroundColor: 'rgba(255,255,255,0.1)', color: 'white'
};
const labelStyles = { display: 'block', marginBottom: '0.5rem', color: '#d1d5db' };
const checkboxLabelStyles = { display: 'flex', alignItems: 'center', gap: '0.5rem', color: '#d1d5db' };
const checkboxStyles = { width: '1.15em', height: '1.15em', accentColor: '#FBBF24' };
return (
{/* Basic Info */}
{isEditing ? (
) : (
{profileData?.full_name || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.headline || 'Not set'}
)}
{/* Summary */}
{isEditing ? (
) : (
{profileData?.summary || 'Not set'}
)}
{/* Extended Profile Fields */}
{showFullProfile && (
{isEditing ? (
) : (
{profileData?.email || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.phone || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.address || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.current_position || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.experience_years || 'Not set'}
)}
{isEditing ? (
) : (
{profileData?.desired_salary || 'Not set'}
)}
{/* TAG INPUTS */}
{isEditing ? (
) : (
{profileData?.willing_to_relocate ? 'Willing to relocate' : 'Not willing to relocate'}
)}
{isEditing ? (
) : (
{profileData?.available_remote ? 'Available for remote' : 'Not available for remote'}
)}
)}
{/* Work Experience Section */}
Work Experience
{isEditing ? (
<>
{(profileData?.work_experience || []).map((exp, index) => (
handleExperienceChange(index, e)} placeholder="Company" style={inputStyles} />
handleExperienceChange(index, e)} placeholder="Role" style={inputStyles} />
handleExperienceChange(index, e)} placeholder="Years" style={inputStyles} />
))}
>
) : (
{profileData?.work_experience && profileData.work_experience.length > 0 ? (
profileData.work_experience.map((exp, index) => (
{exp.role}
{exp.company} • {exp.years} years
))
) : (
No work experience added.
)}
)}
{/* Education Section */}
Education
{isEditing ? (
<>
{(profileData?.education || []).map((edu, index) => (
handleEducationChange(index, e)} placeholder="Course/Degree" style={inputStyles} />
handleEducationChange(index, e)} placeholder="Institution" style={inputStyles} />
handleEducationChange(index, e)} placeholder="Year" style={inputStyles} />
))}
>
) : (
{profileData?.education && profileData.education.length > 0 ? (
profileData.education.map((edu, index) => (
{edu.course}
{edu.institution} • {edu.year}
))
) : (
No education added.
)}
)}
{/* Projects Section */}
Projects
{isEditing ? (
<>
{(profileData?.projects || []).map((proj, index) => (
))}
>
) : (
{profileData?.projects && profileData.projects.length > 0 ? (
profileData.projects.map((proj, index) => (
{proj.title}
{Array.isArray(proj.technologies_used) ? proj.technologies_used.join(', ') : proj.technologies_used}
{proj.description}
))
) : (
No projects added.
)}
)}
);
};
export default ProfileTab;