import React from 'react'; import { RiArrowDownSLine, RiCheckLine, RiLoader4Line, RiGitBranchLine, RiBriefcaseLine, RiHomeLine, RiGraduationCapLine, RiCodeLine, RiHeartLine, RiHistoryLine, RiUser3Line, } from '@remixicon/react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { BranchSelector } from './BranchSelector'; import { WorktreeBranchDisplay } from './WorktreeBranchDisplay'; import { SyncActions } from './SyncActions'; import type { GitStatus, GitIdentityProfile, GitRemote } from '@/lib/api/types'; import { useI18n } from '@/lib/i18n'; type SyncAction = 'fetch' | 'pull' | 'push' | null; interface GitHeaderProps { status: GitStatus | null; localBranches: string[]; remoteBranches: string[]; branchInfo: Record | undefined; syncAction: SyncAction; remotes: GitRemote[]; onFetch: (remote: GitRemote) => void; onPull: (remote: GitRemote) => void; onPush: () => void; onRemoveRemote: (remote: GitRemote) => void; removingRemoteName: string | null; onCheckoutBranch: (branch: string) => void; onCreateBranch: (name: string, remote?: GitRemote) => Promise; onRenameBranch?: (oldName: string, newName: string) => Promise; activeIdentityProfile: GitIdentityProfile | null; availableIdentities: GitIdentityProfile[]; onSelectIdentity: (profile: GitIdentityProfile) => void; isApplyingIdentity: boolean; isWorktreeMode: boolean; onOpenHistory?: () => void; } const IDENTITY_ICON_MAP: Record< string, React.ComponentType> > = { branch: RiGitBranchLine, briefcase: RiBriefcaseLine, house: RiHomeLine, graduation: RiGraduationCapLine, code: RiCodeLine, heart: RiHeartLine, user: RiUser3Line, }; const IDENTITY_COLOR_MAP: Record = { keyword: 'var(--syntax-keyword)', error: 'var(--status-error)', string: 'var(--syntax-string)', function: 'var(--syntax-function)', type: 'var(--syntax-type)', success: 'var(--status-success)', info: 'var(--status-info)', warning: 'var(--status-warning)', }; function getIdentityColor(token?: string | null) { if (!token) { return 'var(--primary)'; } return IDENTITY_COLOR_MAP[token] || 'var(--primary)'; } interface IdentityIconProps { icon?: string | null; className?: string; colorToken?: string | null; } const IdentityIcon: React.FC = ({ icon, className, colorToken }) => { const IconComponent = IDENTITY_ICON_MAP[icon ?? 'branch'] ?? RiUser3Line; return ( ); }; interface IdentityDropdownProps { activeProfile: GitIdentityProfile | null; identities: GitIdentityProfile[]; onSelect: (profile: GitIdentityProfile) => void; isApplying: boolean; iconOnly?: boolean; } const IdentityDropdown: React.FC = ({ activeProfile, identities, onSelect, isApplying, iconOnly = false, }) => { const { t } = useI18n(); const isDisabled = isApplying || identities.length === 0; return ( {t('gitView.header.identityTooltip')} {identities.length === 0 ? (

{t('gitView.header.noProfiles')}

) : ( identities.map((profile) => { const isSelected = activeProfile?.id === profile.id; return ( onSelect(profile)}> {profile.name} {profile.userEmail} {isSelected ? ( ) : null} ); }) )}
); }; export const GitHeader: React.FC = ({ status, localBranches, remoteBranches, branchInfo, syncAction, remotes, onFetch, onPull, onPush, onRemoveRemote, removingRemoteName, onCheckoutBranch, onCreateBranch, onRenameBranch, activeIdentityProfile, availableIdentities, onSelectIdentity, isApplyingIdentity, isWorktreeMode, onOpenHistory, }) => { const { t } = useI18n(); if (!status) { return null; } const managementButtons = (
{onOpenHistory ? ( {t('gitView.history.title')} ) : null}
); const syncButtons = ( ); const identityControl = ( ); return (
{isWorktreeMode ? ( ) : ( )}
{syncButtons} {managementButtons}
{identityControl}
); };