package header import ( "fmt" "path/filepath" "time" "github.com/charmbracelet/lipgloss" "playback/internal/ui" ) // Model represents the header component type Model struct { AudioPath string TranscriptPath string IsTemp bool Width int } // New creates a new header model func New() Model { return Model{} } // SetPaths sets the file paths func (m *Model) SetPaths(audioPath, transcriptPath string, isTemp bool) { m.AudioPath = audioPath m.TranscriptPath = transcriptPath m.IsTemp = isTemp } // SetWidth sets the header width func (m *Model) SetWidth(width int) { m.Width = width } // formatDuration formats a duration as MM:SS func formatDuration(d time.Duration) string { d = d.Round(time.Second) m := d / time.Minute s := (d % time.Minute) / time.Second return fmt.Sprintf("%02d:%02d", m, s) } // View renders the header func (m Model) View(position, duration time.Duration, playing bool) string { // Title title := ui.HeaderStyle.Render("♪ Playback") // File info audioName := filepath.Base(m.AudioPath) transcriptName := filepath.Base(m.TranscriptPath) if m.IsTemp { transcriptName += " (temp)" } fileInfo := ui.FilePathStyle.Render( fmt.Sprintf("Audio: %s | Transcript: %s", audioName, transcriptName), ) // Playback status status := "⏸ Paused" if playing { status = "▶ Playing" } timeInfo := fmt.Sprintf("%s / %s", formatDuration(position), formatDuration(duration)) statusStyle := lipgloss.NewStyle().Foreground(ui.ColorSecondary) if !playing { statusStyle = lipgloss.NewStyle().Foreground(ui.ColorMuted) } rightSide := lipgloss.JoinHorizontal( lipgloss.Center, statusStyle.Render(status), " ", ui.BaseStyle.Render(timeInfo), ) // Layout leftWidth := lipgloss.Width(title) + lipgloss.Width(fileInfo) + 2 rightWidth := lipgloss.Width(rightSide) spacerWidth := m.Width - leftWidth - rightWidth - 4 if spacerWidth < 1 { spacerWidth = 1 } return lipgloss.JoinHorizontal( lipgloss.Center, title, " ", fileInfo, lipgloss.NewStyle().Width(spacerWidth).Render(""), rightSide, ) }