
import type { TerminalLine } from '$lib/components/tui/types';
import { user, skills, openSourceProjects, experience } from '$lib/config';

const experienceElements: TerminalLine[] = [];

experience.forEach(exp => {
    experienceElements.push(
        { type: 'header', content: `(&orange,bold)${exp.role}(&)` },
        { type: 'output', content: `(&primary)${exp.organization}(&)` + (exp.employmentType ? ` (&muted)· ${exp.employmentType}(&)` : '') },
        { type: 'output', content: `(&muted)${exp.period}(&)` + (exp.location ? ` (&muted)· ${exp.location}(&)` : '') },
        ...(exp.description ? [{ type: 'output' as const, content: `(&muted)${exp.description}(&)` }] : []),
        ...(exp.tech ? [{ type: 'output' as const, content: '  ' + exp.tech.map(t => `(&blue)${t}(&)`).join(' (&muted)•(&) ') }] : []),
        ...(exp.awards ? exp.awards.map(award => ({ type: 'success' as const, content: `(&success)${award}(&)` })) : []),
        { type: 'blank', content: '' }
    );
});

const openSourceElements:TerminalLine[] = [];

openSourceProjects.forEach(project => {
    openSourceElements.push(
        {
            type: 'output',
            content: `(&orange,bold)▸ ${project.name}(&) - ${project.description}`
        },
        {
            type: 'output',
            content: `  ${project.tech.map(tech => `(&blue)${tech}(&)`).join(' (&muted)•(&) ')}`
        },
        { type: 'blank', content: '' }
    );
});

export const lines: TerminalLine[] = [
    // Header command
    { type: 'command', content: 'cat ~/portfolio.md' },
    { type: 'blank', content: '' },

    // Avatar image
    { type: 'image', content: '', image: user.avatar, imageAlt: user.name, imageWidth: 180, inline: true },

    {
        type: 'group',
        content: '',
        groupDirection: 'column',
        groupAlign: 'start',
        inline: true,
        children: [
            // User info
            { type: 'header', content: `(&bold)${user.name}(&)` },
            { type: 'info', content: `(&accent)B.S. Computer Science Student(&)` },
            { type: 'output', content: `(&white)Location:(&) (&primary)${user.location}(&)` },
            { type: 'output', content: `(&muted)My passion is using Computer Science with practical Engineering to enhance technology for the future.(&)` },
        ]
    },

    { type: 'blank', content: '' },
    { type: 'blank', content: '' },
    {
        type: 'group', content: '', groupAlign: 'start', groupGap: '1rem',
        children: [
            { type: 'output', content: `(&primary, bold)Links >(&)`, inline: true },
            { type: 'link', href: "/portfolio#contact", content: `(&bg-blue,black)Contact(&)`, inline: true },
            { type: 'link', href: "/portfolio#experience", content: `(&bg-magenta,black)Experience(&)`, inline: true },
            { type: 'link', href: "/portfolio#skills", content: `(&bg-orange,black)Skills(&)`, inline: true },
            { type: 'link', href: "/portfolio#projects", content: `(&bg-green,black)Projects(&)`, inline: true },
        ]
    },
    { type: 'divider', content: 'CONTACT', id: 'contact' },
    // Contact buttons - dynamically generated from socials array
    ...user.socials.map(social => ({
        type: 'button' as const,
        content: `${social.name}`,
        icon: social.icon,
        style: 'primary' as const,
        href: social.link,
        inline: true
    })),

    { type: 'divider', content: 'EXPERIENCE', id: 'experience' },

    ...experienceElements,

    { type: 'divider', content: 'SKILLS', id: 'skills' },

    // Skills as TUI sections

    // Languages
    { type: 'info', content: '(&blue,bold)▸ Languages(&)' },
    { type: 'output', content: '  ' + skills.languages.map(s => `(&cyan)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Frameworks
    { type: 'info', content: '(&magenta,bold)▸ Frameworks(&)' },
    { type: 'output', content: '  ' + skills.frameworks.map(s => `(&pink)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Applications
    { type: 'info', content: '(&green,bold)▸ Tools(&)' },
    { type: 'output', content: '  ' + skills.tools.map(s => `(&green)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Platforms
    { type: 'info', content: '(&yellow,bold)▸ Platforms(&)' },
    { type: 'output', content: '  ' + skills.platforms.map(s => `(&yellow)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Applications
    { type: 'info', content: '(&purple,bold)▸ Applications(&)' },
    { type: 'output', content: '  ' + skills.applications.map(s => `(&purple)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Databases
    { type: 'info', content: '(&cyan,bold)▸ Databases(&)' },
    { type: 'output', content: '  ' + skills.databases.map(s => `(&cyan)${s}(&)`).join(' (&muted)•(&) ') },
    { type: 'blank', content: '' },

    // Interests
    { type: 'info', content: '(&accent,bold)▸ Interests(&)' },
    { type: 'output', content: '  ' + skills.interests.map(s => `(&muted)${s}(&)`).join(' (&muted)•(&) ') },

    { type: 'divider', content: 'PROJECTS', id: 'projects' },

    ...openSourceElements,

    // End
    { type: 'success', content: `(&success)Portfolio loaded successfully!(&)` }
];