import SwiftUI
import ComponentLibrary

typealias ChatAudioErrorState = ChatAudio.ChatAudioErrorState

struct ChatBar: View {
    @Binding var text: String
    let suggestions: [String]
    let onPlusTap: () -> Void
    let onUploadTap: () -> Void
    let onRecordTap: () -> Void
    let onLibraryTap: () -> Void
    let onMicrophoneTap: () -> Void
    let onSendTap: () -> Void
    let onSuggestionTap: (String) -> Void
    let placeholder: String
    let scrollToBeginning: Bool
    @Binding var isChatBarFocused: Bool
    let audioFileName: String?
    let uploadProgress: Double
    let isUploading: Bool
    let uploadCompleted: Bool
    let onCloseAudio: () -> Void
    let errorState: ChatAudioErrorState?
    let onRetryUpload: () -> Void
    let onPlayPauseSelected: () -> Void
    let currentlyPlayingSongTitle: String?
    let currentArtworkGradient: LinearGradient?
    let isSelectedSongPlaying: Bool
    let onDeselectSong: () -> Void
    let hideTextInput: Bool
    let showCreateView: Bool
    let showSendButton: Bool

    // CreateView parameters
    @Binding var lyricsDescription: String
    @Binding var styleDescription: String
    let selectedModel: String
    let currentlyPlayingSong: Song?
    let currentlyPlayingSongId: String?
    let onSongPlayPause: ((String) -> Void)?
    let lyricsFocusMode: Bool
    let audioManager: AudioManager?
    let onModelVersionChange: ((String) -> Void)?

    // Advanced options bindings
    @Binding var weirdnessValue: Double
    @Binding var styleInfluenceValue: Double
    @Binding var audioInfluenceValue: Double
    @Binding var vocalGender: String

    @FocusState private var isTextFieldFocused: Bool
    @State private var forceMultilineLayout: Bool = false
    @State private var showActionMenu: Bool = false

    private var showAudioFile: Bool {
        audioFileName != nil || isUploading || uploadCompleted || errorState != nil
    }

    init(
        text: Binding<String>,
        suggestions: [String] = [],
        onPlusTap: @escaping () -> Void = {},
        onUploadTap: @escaping () -> Void = {},
        onRecordTap: @escaping () -> Void = {},
        onLibraryTap: @escaping () -> Void = {},
        onMicrophoneTap: @escaping () -> Void = {},
        onSendTap: @escaping () -> Void = {},
        onSuggestionTap: @escaping (String) -> Void = { _ in },
        placeholder: String = "What do you want to make?",
        scrollToBeginning: Bool = false,
        isChatBarFocused: Binding<Bool>,
        audioFileName: String? = nil,
        uploadProgress: Double = 0.0,
        isUploading: Bool = false,
        uploadCompleted: Bool = false,
        onCloseAudio: @escaping () -> Void = {},
        errorState: ChatAudioErrorState? = nil,
        onRetryUpload: @escaping () -> Void = {},
        onPlayPauseSelected: @escaping () -> Void = {},
        currentlyPlayingSongTitle: String? = nil,
        currentArtworkGradient: LinearGradient? = nil,
        isSelectedSongPlaying: Bool = false,
        onDeselectSong: @escaping () -> Void = {},
        hideTextInput: Bool = false,
        showCreateView: Bool = false,
        showSendButton: Bool = false,
        lyricsDescription: Binding<String> = .constant(""),
        styleDescription: Binding<String> = .constant(""),
        selectedModel: String = "v4.5",
        currentlyPlayingSong: Song? = nil,
        currentlyPlayingSongId: String? = nil,
        onSongPlayPause: ((String) -> Void)? = nil,
        lyricsFocusMode: Bool = false,
        audioManager: AudioManager? = nil,
        onModelVersionChange: ((String) -> Void)? = nil,
        weirdnessValue: Binding<Double> = .constant(0.5),
        styleInfluenceValue: Binding<Double> = .constant(0.5),
        audioInfluenceValue: Binding<Double> = .constant(0.5),
        vocalGender: Binding<String> = .constant("Female")
    ) {
        self._text = text
        self.suggestions = suggestions
        self.onPlusTap = onPlusTap
        self.onUploadTap = onUploadTap
        self.onRecordTap = onRecordTap
        self.onLibraryTap = onLibraryTap
        self.onMicrophoneTap = onMicrophoneTap
        self.onSendTap = onSendTap
        self.onSuggestionTap = onSuggestionTap
        self.placeholder = placeholder
        self.scrollToBeginning = scrollToBeginning
        self._isChatBarFocused = isChatBarFocused
        self.audioFileName = audioFileName
        self.uploadProgress = uploadProgress
        self.isUploading = isUploading
        self.uploadCompleted = uploadCompleted
        self.onCloseAudio = onCloseAudio
        self.errorState = errorState
        self.onRetryUpload = onRetryUpload
        self.onPlayPauseSelected = onPlayPauseSelected
        self.currentlyPlayingSongTitle = currentlyPlayingSongTitle
        self.currentArtworkGradient = currentArtworkGradient
        self.isSelectedSongPlaying = isSelectedSongPlaying
        self.onDeselectSong = onDeselectSong
        self.hideTextInput = hideTextInput
        self.showCreateView = showCreateView
        self.showSendButton = showSendButton
        self._lyricsDescription = lyricsDescription
        self._styleDescription = styleDescription
        self.selectedModel = selectedModel
        self.currentlyPlayingSong = currentlyPlayingSong
        self.currentlyPlayingSongId = currentlyPlayingSongId
        self.onSongPlayPause = onSongPlayPause
        self.lyricsFocusMode = lyricsFocusMode
        self.audioManager = audioManager
        self.onModelVersionChange = onModelVersionChange
        self._weirdnessValue = weirdnessValue
        self._styleInfluenceValue = styleInfluenceValue
        self._audioInfluenceValue = audioInfluenceValue
        self._vocalGender = vocalGender
    }

    var body: some View {
        VStack(spacing: 0) {
            // Referenced song (if available) - only show when not in CreateView mode
            if let songTitle = currentlyPlayingSongTitle, let gradient = currentArtworkGradient, !showCreateView {
                ReferencedSong(
                    songTitle: songTitle,
                    artworkGradient: gradient,
                    isPlaying: isSelectedSongPlaying,
                    onPlayPause: onPlayPauseSelected,
                    onClose: onDeselectSong
                )
            }

            if !suggestions.isEmpty && !showCreateView {
                suggestionsView
            }

            // Audio file display (when present)
            if showAudioFile {
                if let errorState = errorState {
                    errorAudioFileView(errorState: errorState)
                } else {
                    normalAudioFileView
                }
            }

            // Text input and buttons (hide text input if hideTextInput is true)
            if !hideTextInput {
                textInputField
            }

            buttonsRow

            // CreateView content (shown when in .full mode)
            if showCreateView {
                createViewContent
            }
        }
        .contentShape(Rectangle())
        .onTapGesture {
            // Dismiss keyboard when tapping outside text fields (only in create view mode)
            if showCreateView {
                UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
            }
        }
    }

    private var textInputField: some View {
        TextField(placeholder, text: $text, axis: .vertical)
            .figmaMCPTypography(TypographyV1.FigmaMCP.mediumTitle)
            .foregroundColor(ChatConstants.Colors.Foreground.primary)
            .tint(ChatConstants.Colors.Accent.brand)
            .textFieldStyle(PlainTextFieldStyle())
            .focused($isTextFieldFocused)
            .lineLimit(1...8)
            .padding(.horizontal, 16)
            .padding(.vertical, 12)
            .onChange(of: text) { oldValue, newValue in
                // Only auto-focus when user is actively typing (text increased)
                if !newValue.isEmpty && newValue.count > oldValue.count {
                    isTextFieldFocused = true
                }

                // Force multiline if user added a newline
                if newValue.contains("\n") && !forceMultilineLayout {
                    forceMultilineLayout = true
                }

                // Reset force multiline if text is empty or becomes short again
                if newValue.isEmpty || (newValue.count <= 32 && !newValue.contains("\n")) {
                    forceMultilineLayout = false
                }
            }
            .onChange(of: isTextFieldFocused) { _, isFocused in
                isChatBarFocused = isFocused
            }
    }

    private var buttonsRow: some View {
        HStack(spacing: 0) {
            // Plus button on left
            if audioFileName == nil && errorState == nil {
                integratedPlusButton
            }

            Spacer()

            // Model version and credits in middle (only in .full mode)
            if showCreateView {
                VStack(spacing: 0) {
                    Menu {
                        Button {
                            onModelVersionChange?("v4")
                        } label: {
                            HStack {
                                Text("v4")
                                if selectedModel == "v4" {
                                    Image(systemName: "checkmark")
                                }
                            }
                        }

                        Button {
                            onModelVersionChange?("v4.5")
                        } label: {
                            HStack {
                                Text("v4.5")
                                if selectedModel == "v4.5" {
                                    Image(systemName: "checkmark")
                                }
                            }
                        }

                        Button {
                            onModelVersionChange?("v5")
                        } label: {
                            HStack {
                                Text("v5")
                                if selectedModel == "v5" {
                                    Image(systemName: "checkmark")
                                }
                            }
                        }
                    } label: {
                        HStack(spacing: 2) {
                            Text("Suno \(selectedModel)")
                                .figmaMCPTypography(TypographyV1.FigmaMCP.mediumTitle)
                                .foregroundColor(ChatConstants.Colors.Foreground.primary)
                                .tracking(0.24)

                            Image.FigmaMCP.triangleDown
                                .resizable()
                                .renderingMode(.template)
                                .aspectRatio(contentMode: .fit)
                                .frame(width: 16, height: 16)
                                .foregroundColor(ChatConstants.Colors.Foreground.secondary)
                        }
                    }
                    .buttonStyle(PlainButtonStyle())

                    // Credits display would go here - using billingInfo from store
                    // For now, we'll skip it as it requires access to billingInfo
                }
            }

            Spacer()

            // Mic or Send button on right
            rightButton
        }
        .padding(.horizontal, 16)
        .padding(.bottom, 16)
    }

    private var integratedInputBar: some View {
        let shouldUseMultilineLayout = text.count > 32 || forceMultilineLayout
        let cornerRadius: CGFloat = shouldUseMultilineLayout ? 24 : 100
        let minHeight: CGFloat = 56

        return HStack(alignment: shouldUseMultilineLayout ? .bottom : .center, spacing: 16) {

            // Always show plus button when no audio file present
            if audioFileName == nil && errorState == nil {
                integratedPlusButton
            }

            if audioFileName != nil {
                Spacer()
                    .frame(width: 0.1)
            }

            // Text Input
            adaptiveTextInput

            rightButton
        }
        .padding(.horizontal, shouldUseMultilineLayout ? 8 : 8)
        .padding(.vertical, shouldUseMultilineLayout ? 8 : 8)
        .frame(minHeight: minHeight)
        .background(
            RoundedRectangle(cornerRadius: cornerRadius)
                .stroke(ChatConstants.Colors.Border.primary, lineWidth: 1)
        )
        .clipShape(RoundedRectangle(cornerRadius: cornerRadius))
        .animation(.easeInOut(duration: 0.2), value: shouldUseMultilineLayout)
    }

    private var adaptiveTextInput: some View {
        let shouldUseMultilineLayout = text.count > 32 || forceMultilineLayout
        let alignment: Alignment = shouldUseMultilineLayout ? .topLeading : .leading

        return ZStack(alignment: alignment) {
            if text.isEmpty {
                Text(placeholder)
                    .figmaMCPTypography(TypographyV1.FigmaMCP.mediumTitle)
                    .foregroundColor(ChatConstants.Palette.white.opacity(0.3))
                    .padding(.top, shouldUseMultilineLayout ? 4 : 0)
            }

            TextField("", text: $text, axis: .vertical)
                .figmaMCPTypography(TypographyV1.FigmaMCP.mediumTitle)
                .foregroundColor(ChatConstants.Colors.Foreground.primary)
                .tint(ChatConstants.Colors.Accent.brand)
                .textFieldStyle(PlainTextFieldStyle())
                .focused($isTextFieldFocused)
                .lineLimit(shouldUseMultilineLayout ? 1...4 : 1...1)
                .onChange(of: text) { _, newValue in
                    // Only focus when text is being added, not when cleared
                    if !newValue.isEmpty {
                        isTextFieldFocused = true
                    }

                    // Reset force multiline if text is empty or becomes short again
                    if newValue.isEmpty || (newValue.count <= 32 && !newValue.contains("\n")) {
                        forceMultilineLayout = false
                    }

                    // Force multiline if user added a newline
                    if newValue.contains("\n") && !forceMultilineLayout {
                        forceMultilineLayout = true
                    }
                }
                .onChange(of: isTextFieldFocused) { _, isFocused in
                    isChatBarFocused = isFocused
                }
        }
        .frame(minHeight: 24)
    }

    private var normalAudioFileView: some View {
        HStack(spacing: 16) {
            HStack(spacing: 8) {
                ZStack {
                    RoundedRectangle(cornerRadius: 8)
                        .fill(ChatConstants.Colors.Background.Fog.thin)
                        .frame(width: 28, height: 28)

                    Image.FigmaMCP.audioFile
                        .resizable()
                        .renderingMode(.template)
                        .frame(width: 16, height: 16)
                        .foregroundColor(ChatConstants.Colors.Foreground.primary)
                }

                Text(audioFileName?.uppercased() ?? "")
                    .typographyV1(TypographyV1.FigmaMCP.timecode.kerning(0.2))
                    .foregroundColor(ChatConstants.Colors.Foreground.primary)
                    .frame(maxWidth: UIScreen.main.bounds.width * 0.3)
                    .lineLimit(1)
                    .truncationMode(.tail)
            }

            // Progress bar
            if isUploading || uploadCompleted {
                GeometryReader { geometry in
                    ZStack(alignment: .leading) {
                        RoundedRectangle(cornerRadius: 100)
                            .fill(ChatConstants.Colors.Background.Fog.thin)
                            .frame(height: 12)

                        RoundedRectangle(cornerRadius: 100)
                            .fill(uploadCompleted ? ChatConstants.Colors.Accent.green : ChatConstants.Colors.Accent.brand)
                            .frame(width: geometry.size.width * CGFloat(uploadProgress), height: 12)
                            .animation(.spring(response: 0.4, dampingFraction: 0.8), value: uploadProgress)
                            .animation(uploadCompleted ? .spring(response: 0.3, dampingFraction: 0.9) : .spring(response: 0.4, dampingFraction: 0.8), value: uploadCompleted)
                    }
                }
                .frame(height: 12)
                .opacity((isUploading || uploadCompleted) ? 1 : 0)
                .animation(.spring(response: 0.5, dampingFraction: 0.85), value: isUploading)
                .animation(.spring(response: 0.5, dampingFraction: 0.85), value: uploadCompleted)
                .transition(.opacity)
            } else {
                Spacer()
            }

            Button {
                onCloseAudio()
            } label: {
                Image.FigmaMCP.close
                    .resizable()
                    .renderingMode(.template)
                    .frame(width: 8.0, height: 8.0)
                    .padding(4.0)
                    .foregroundColor(ChatConstants.Colors.Foreground.tertiary)
            }
            .buttonStyle(PlainButtonStyle())
        }
        .padding(.horizontal, 8)
        .padding(.vertical, 8)
        .background(ChatConstants.Colors.Background.Fog.thin)
        .cornerRadius(12)
        .padding(.horizontal, 16)
        .padding(.vertical, 0)
    }

    @ViewBuilder
    private func errorAudioFileView(errorState: ChatAudioErrorState) -> some View {
        HStack(spacing: 16) {
            HStack(spacing: 8) {
                // Retry button (if retryable) or headphones icon
                if errorState.isRetryable {
                    Button {
                        onRetryUpload()
                    } label: {
                        ZStack {
                            Circle()
                                .fill(ChatConstants.Colors.Background.Fog.thin)
                                .frame(width: 32, height: 32)

                            Image.FigmaMCP.rotateRight
                                .resizable()
                                .renderingMode(.template)
                                .frame(width: 16, height: 16)
                                .foregroundColor(ChatConstants.Colors.Foreground.primary)
                        }
                    }
                    .buttonStyle(PlainButtonStyle())
                } else {
                    ZStack {
                        RoundedRectangle(cornerRadius: 8)
                            .fill(ChatConstants.Colors.Background.Fog.thin)
                            .frame(width: 28, height: 28)

                        Image.FigmaMCP.audioFile
                            .resizable()
                            .renderingMode(.template)
                            .frame(width: 16, height: 16)
                            .foregroundColor(ChatConstants.Colors.Foreground.primary)
                    }
                }

                VStack(alignment: .leading, spacing: 2.0) {
                    Text(audioFileName?.uppercased() ?? "AUDIO")
                        .typographyV1(TypographyV1.FigmaMCP.timecode.kerning(0.2))
                        .foregroundColor(ChatConstants.Colors.Foreground.primary)
                        .frame(maxWidth: UIScreen.main.bounds.width * 0.3)
                        .lineLimit(1)
                        .truncationMode(.tail)

                    Text(errorState.errorMessage.uppercased())
                        .typographyV1(TypographyV1.FigmaMCP.timecode.kerning(0.2))
                        .foregroundColor(ChatConstants.Colors.Accent.error)
                }
            }

            Spacer()

            Button {
                onCloseAudio()
            } label: {
                Image.FigmaMCP.close
                    .resizable()
                    .renderingMode(.template)
                    .frame(width: 8.0, height: 8.0)
                    .padding(4.0)
                    .foregroundColor(ChatConstants.Colors.Foreground.tertiary)
            }
            .buttonStyle(PlainButtonStyle())
        }
        .padding(.horizontal, 8)
        .padding(.vertical, 8)
        .background(ChatConstants.Colors.Background.Fog.thin)
        .cornerRadius(12)
        .padding(.horizontal, 16)
        .padding(.vertical, 0)
    }

    private var integratedPlusButton: some View {
        Button {
            showActionMenu = true
        } label: {
            ZStack {
                Circle()
                    .fill(ChatConstants.Colors.Background.Fog.thin)
                    .frame(width: 40, height: 40)

                Image.FigmaMCP.plus
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 16, height: 16)
                    .foregroundColor(ChatConstants.Colors.Foreground.primary)
            }
        }
        .buttonStyle(PlainButtonStyle())
        .sheet(isPresented: $showActionMenu) {
            ActionMenuSheet(
                currentModel: selectedModel,
                onModelSelect: { model in
                    onModelVersionChange?(model)
                },
                onUploadTap: onUploadTap,
                onRecordTap: onRecordTap,
                onLibraryTap: onLibraryTap
            )
        }
    }

    @ViewBuilder
    private var rightButton: some View {
        if showSendButton || !text.isEmpty {
            // Send Button - using animated aura background (matches swift-vibes pattern)
            Button(action: onSendTap) {
                ZStack {
                    // Animated aura background (matches Create button style)
                    #if targetEnvironment(simulator)
                        Color.orange
                    #else
                        AuraShaderView(
                            id: "send-button-aura",
                            appPreset: .pinkYellowOrange,
                            morphSpeed: 0.05,
                            scale: 0.2,
                            seed: 0
                        )
                    #endif

                    // Icon - using arrowUp from FigmaMCP
                    Image.FigmaMCP.arrowUp
                        .resizable()
                        .renderingMode(.template)
                        .frame(width: 16, height: 16)
                        .foregroundColor(ChatConstants.Colors.Foreground.primary)
                }
                .frame(width: 40, height: 40)
                .clipShape(Circle())
            }
            .buttonStyle(PlainButtonStyle())
        } else {
            // Microphone Icon
            Button {
                onMicrophoneTap()
            } label: {
                Image.FigmaMCP.microphone
                    .resizable()
                    .renderingMode(.template)
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 24, height: 24)
                    .foregroundColor(ChatConstants.Palette.Dumbo._200.opacity(0.6))
                    .padding(.trailing, 8)
            }
            .buttonStyle(PlainButtonStyle())
        }
    }

    private var suggestionsView: some View {
        ScrollViewReader { proxy in
            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 8) {
                    // Suggestion pills
                    ForEach(Array(suggestions.prefix(5).enumerated()), id: \.offset) { index, suggestion in
                        Button(action: {
                            onSuggestionTap(suggestion)
                        }) {
                            Text(suggestion.uppercased())
                                .figmaMCPTypography(TypographyV1.FigmaMCP.timecode)
                                .foregroundColor(colorForSuggestion(suggestion, index: index))
                                .lineLimit(1)
                                .padding(.horizontal, 10)
                                .padding(.vertical, 8)
                                .background(
                                    RoundedRectangle(cornerRadius: 100)
                                        .fill(ChatConstants.Colors.Background.Fog.thin)
                                )
                        }
                        .buttonStyle(PlainButtonStyle())
                        .id(index == 0 ? "first" : "suggestion_\(index)")
                    }
                }
                .padding(.horizontal, 16)
                .padding(.bottom, 12)
            }
            .onChange(of: scrollToBeginning) { _, shouldScroll in
                if shouldScroll {
                    withAnimation(.easeInOut(duration: 0.3)) {
                        proxy.scrollTo("first", anchor: .leading)
                    }
                }
            }
        }
    }

    private func colorForSuggestion(_ suggestion: String, index: Int) -> Color {
        // Check if this is an additive suggestion (starts with +)
        if suggestion.hasPrefix("+") {
            // Additive suggestions use foreground.inactive (matches swift-vibes)
            return ChatConstants.Colors.Foreground.tertiary
        } else {
            // Regular suggestions use foreground.primary
            return ChatConstants.Colors.Foreground.primary
        }
    }

    private var createViewContent: some View {
        ScrollViewWithSheetSupport {
            VStack(spacing: 16) {
                // Audio Player (when there's a selected song)
                if let selectedSong = currentlyPlayingSong {
                    CreateAudioPlayer(
                        songTitle: selectedSong.title,
                        artworkGradient: createGradientForSong(selectedSong),
                        isPlaying: currentlyPlayingSongId == selectedSong.id,
                        onPlayPause: {
                            onSongPlayPause?(selectedSong.id)
                        },
                        audioManager: audioManager
                    )
                }

                // Lyrics Description Component
                LyricsDescription(
                    lyricsText: $lyricsDescription,
                    startExpanded: true,
                    placeholderText: "Write lyrics or prompt",
                    onSaveLyrics: { currentLyricsText in
                        print("Save lyrics: \(currentLyricsText)")
                    },
                    showOnlyUndo: false,
                    hideFooterControls: false,
                    customHeight: lyricsFocusMode ? 340 : nil
                )

                // Style Description Component
                StyleDescription(
                    styleText: $styleDescription,
                    modelVersion: selectedModel,
                    startExpanded: !lyricsFocusMode
                ) { currentStyleText in
                    print("Save style: \(currentStyleText)")
                }

                // Advanced Options Component
                AdvancedOptions(
                    weirdnessValue: $weirdnessValue,
                    styleInfluenceValue: $styleInfluenceValue,
                    audioInfluenceValue: $audioInfluenceValue,
                    vocalGender: $vocalGender
                )
            }
            .padding(16)
        }
    }

    private func createGradientForSong(_ song: Song) -> LinearGradient {
        guard let artwork = song.artwork else {
            // Default gradient
            return LinearGradient(
                colors: [
                    ChatConstants.Colors.Accent.purple,
                    ChatConstants.Colors.Accent.pink
                ],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        }

        // Create consistent gradient based on artwork string hash
        let hash = artwork.hashValue
        let seed1 = abs(hash % 1000)
        let seed2 = abs((hash / 1000) % 1000)

        return LinearGradient(
            colors: [
                Color(
                    red: 0.3 + (Double(seed1 % 600) / 1000.0),
                    green: 0.3 + (Double((seed1 + 200) % 600) / 1000.0),
                    blue: 0.3 + (Double((seed1 + 400) % 600) / 1000.0)
                ),
                Color(
                    red: 0.3 + (Double(seed2 % 600) / 1000.0),
                    green: 0.3 + (Double((seed2 + 200) % 600) / 1000.0),
                    blue: 0.3 + (Double((seed2 + 400) % 600) / 1000.0)
                )
            ],
            startPoint: .topLeading,
            endPoint: .bottomTrailing
        )
    }
}

#Preview {
    VStack(spacing: 20) {
        // Empty State
        ChatBar(
            text: .constant(""),
            onPlusTap: { print("Plus tapped") },
            onMicrophoneTap: { print("Microphone tapped") },
            onSendTap: { print("Send tapped") },
            onSuggestionTap: { suggestion in print("Suggestion tapped: \(suggestion)") },
            isChatBarFocused: .constant(false)
        )

        // With Regular Suggestions State
        ChatBar(
            text: .constant(""),
            suggestions: ["EXTEND", "EDIT LYRICS", "REPLACE SECTION", "CHANGE GENRE", "MAKE SLOWER"],
            onPlusTap: { print("Plus tapped") },
            onMicrophoneTap: { print("Microphone tapped") },
            onSendTap: { print("Send tapped") },
            onSuggestionTap: { suggestion in print("Suggestion tapped: \(suggestion)") },
            isChatBarFocused: .constant(false),
            onPlayPauseSelected: { print("Play/Pause selected song") },
            currentlyPlayingSongTitle: "Song Title (#1)",
            currentArtworkGradient: LinearGradient(
                colors: [Color.blue, Color.purple],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            ),
            isSelectedSongPlaying: true
        )

        Spacer()
    }
    .background(ChatConstants.Colors.Background.primary)
}
