import SwiftUI
import NucleicProtocol

/// Pretty rendering of an `ExitPlanMode` tool call — the phone echo of the Mac's `ExitPlanModeCard`.
/// The agent calls `ExitPlanMode` to present the plan it wrote on its way out of plan mode; the raw
/// tool card reads as escaped JSON with an unrendered Markdown blob, so instead we render the plan
/// body as formatted Markdown under a "Plan" header. The plan is on the call input, so the card
/// shows the moment the call arrives — before, and regardless of, the user's approval. Mirrors
/// `AskUserQuestionResultCard`'s accent-tinted card so a presented plan reads as a first-class moment.
struct ExitPlanModeCard: View {
    let plan: ExitPlanMode.Plan

    private var accent: Color { Palette.accent }

    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            HStack(spacing: 8) {
                Image(systemName: "list.bullet.clipboard")
                    .font(.caption).foregroundStyle(accent).frame(width: 15)
                Text("Plan")
                    .font(.callout.weight(.medium))
                Spacer(minLength: 0)
            }
            MarkdownText(markdown: plan.markdown)
                .textSelection(.enabled)
        }
        .padding(.horizontal, 12).padding(.vertical, 10)
        .frame(maxWidth: .infinity, alignment: .leading)
        .background(accent.opacity(0.06))
        .overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(accent.opacity(0.16), lineWidth: 1))
        .clipShape(RoundedRectangle(cornerRadius: 8))
    }
}
