import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from '@/components/ui/breadcrumb'; import { Button } from '@/components/ui/button'; import { toast } from '@/hooks/use-toast'; import { StartESILogin, ESILoggedIn, ListCharacters, ToggleCharacterWaypointEnabled } from 'wailsjs/go/main/App'; import { main } from 'wailsjs/go/models'; interface HeaderProps { title: string; breadcrumbs?: Array<{ label: string; path?: string; }>; } export const Header = ({ title, breadcrumbs = [] }: HeaderProps) => { const navigate = useNavigate(); const [chars, setChars] = useState([]); const refreshState = async () => { try { const list = await ListCharacters(); setChars(list); } catch { } }; useEffect(() => { refreshState(); }, []); const handleLogin = async () => { try { await StartESILogin(); toast({ title: 'EVE Login', description: 'Complete login in your browser.' }); for (let i = 0; i < 20; i++) { const ok = await ESILoggedIn(); if (ok) { await refreshState(); break; } await new Promise(r => setTimeout(r, 500)); } } catch (e: any) { toast({ title: 'Login failed', description: String(e), variant: 'destructive' }); } }; const handleCharacterClick = async (character: main.CharacterInfo) => { try { await ToggleCharacterWaypointEnabled(character.character_id); await refreshState(); const newStatus = character.waypoint_enabled ? 'disabled' : 'enabled'; toast({ title: 'Waypoint Status', description: `${character.character_name} waypoints ${newStatus}` }); } catch (e: any) { toast({ title: 'Toggle failed', description: String(e), variant: 'destructive' }); } }; return (
{breadcrumbs.length > 0 && (
{breadcrumbs.map((crumb, index) => ( {index > 0 && } {crumb.path ? ( navigate(crumb.path!)} className="text-purple-200 hover:text-white cursor-pointer" > {crumb.label} ) : ( {crumb.label} )} ))}
)}

{title}

{chars.length > 0 && (
{chars.map((c) => ( handleCharacterClick(c)} className={`px-3 py-1 text-xs cursor-pointer transition-colors text-center overflow-hidden text-ellipsis ${ c.waypoint_enabled ? 'bg-purple-500/20 text-purple-200 border border-purple-400/40 hover:bg-purple-500/30' : 'bg-gray-500/20 text-gray-400 border border-gray-400/40 hover:bg-gray-500/30' }`} title={`Click to ${c.waypoint_enabled ? 'disable' : 'enable'} waypoints for ${c.character_name}`} > {c.character_name} ))}
)}
); };