import type { TerminalLine } from '$lib/components/tui/types';
import { researchItems } from '$lib/config';
import { projectNavLinks } from './projectNav';
import { tagColor } from './palette';

const researchSections: TerminalLine[] = researchItems.flatMap(item => {
    const infoChildren: TerminalLine[] = [
        {
            type: 'output' as const,
            content: `(&icon, mdi:microscope, 32) (&bg-cyan,black) RESEARCH (&)`
        },
        ...(item.organization
            ? [{ type: 'info' as const, content: `(&primary)${item.organization}(&)` }]
            : []),
        ...(item.period
            ? [{ type: 'output' as const, content: `(&muted)${item.period}(&)` }]
            : []),
        ...(item.description
            ? [{ type: 'output' as const, content: `(&text)${item.description}(&)` }]
            : []),
        ...(item.tech?.length
            ? [{ type: 'output' as const, content: item.tech.map((tech, i) => `(&bg-${tagColor(i)},black) ${tech} (&)`).join(' ') }]
            : []),
        ...(item.link
            ? [{
                type: 'group' as const,
                content: '',
                groupDirection: 'row' as const,
                groupGap: '0.75rem',
                groupExpand: true,
                children: [
                    { type: 'button' as const, content: 'View', href: item.link, icon: 'mdi:open-in-new', style: 'primary' as const, flex: true }
                ]
            }]
            : [])
    ];

    return [
        { type: 'divider' as const, content: item.title.toUpperCase() },
        { type: 'group' as const, content: '', groupDirection: 'column' as const, groupAlign: 'stretch' as const, children: infoChildren },
        { type: 'blank' as const, content: '' }
    ];
});

export const lines: TerminalLine[] = [
    { type: 'command' as const, content: 'ls ~/projects/research' },
    projectNavLinks,
    { type: 'blank' as const, content: '', height: '2rem' },
    { type: 'header' as const, content: 'Research' },
    { type: 'output' as const, content: `(&muted)Research roles, projects, and publications.(&)` },
    { type: 'blank' as const, content: '' },
    ...researchSections
];
