import SwiftUI

/// A disclosure that reveals the literal shell command beneath a structured command card —
/// so a command rendered as a GUI element (a commit card, an `rm`/`git` step list) never
/// hides what's actually being run, and an approval still lets the user verify exactly what
/// they are granting. Shared by ``GitBlockCard`` and ``CommandStepsCard``.
struct CommandDisclosure: View {
    /// The literal command to reveal.
    let command: String
    /// The card's accent, applied to the toggle and the revealed block.
    let accent: Color

    @State private var showCommand = false

    var body: some View {
        VStack(alignment: .leading, spacing: 6) {
            Button {
                withAnimation(.easeInOut(duration: 0.15)) { showCommand.toggle() }
            } label: {
                HStack(spacing: 5) {
                    Image(systemName: "chevron.right")
                        .font(.caption2.weight(.semibold))
                        .rotationEffect(.degrees(showCommand ? 90 : 0))
                    Text(showCommand ? "Hide command" : "Show command")
                        .font(.caption.weight(.medium))
                }
                .foregroundStyle(accent)
                .contentShape(Rectangle())
            }
            .buttonStyle(.plain)
            if showCommand {
                Text(command)
                    .font(.system(.caption, design: .monospaced))
                    .foregroundStyle(.secondary)
                    .textSelection(.enabled)
                    .multilineTextAlignment(.leading)
                    .frame(maxWidth: .infinity, alignment: .leading)
                    .padding(8)
                    .background(accent.opacity(0.05), in: .rect(cornerRadius: 6))
            }
        }
    }
}
