import SwiftUI
import Bedrock

/// A generic action row with icon, title, optional subtitle, and chevron.
/// Used for share options, settings rows, and navigation items.
struct ActionRowView<Action: View>: View {
    let title: String
    let subtitle: String?
    let systemImage: String
    @ViewBuilder let action: () -> Action
    
    init(
        title: String,
        subtitle: String? = nil,
        systemImage: String,
        @ViewBuilder action: @escaping () -> Action
    ) {
        self.title = title
        self.subtitle = subtitle
        self.systemImage = systemImage
        self.action = action
    }
    
    var body: some View {
        action()
            .buttonStyle(.plain)
    }
}

/// Content layout for action rows - icon, text, chevron.
struct ActionRowContent: View {
    let title: String
    let subtitle: String?
    let systemImage: String
    
    init(title: String, subtitle: String? = nil, systemImage: String) {
        self.title = title
        self.subtitle = subtitle
        self.systemImage = systemImage
    }
    
    var body: some View {
        HStack(spacing: Design.Spacing.medium) {
            Image(systemName: systemImage)
                .foregroundStyle(Color.Accent.red)
                .frame(width: Design.CardSize.avatarSize, height: Design.CardSize.avatarSize)
                .background(Color.AppBackground.accent)
                .clipShape(.rect(cornerRadius: Design.CornerRadius.medium))
            
            VStack(alignment: .leading, spacing: Design.Spacing.xxSmall) {
                Text(title)
                    .font(.headline)
                    .foregroundStyle(Color.Text.primary)
                
                if let subtitle {
                    Text(subtitle)
                        .font(.subheadline)
                        .foregroundStyle(Color.Text.secondary)
                }
            }
            
            Spacer()
            
            Image(systemName: "chevron.right")
                .foregroundStyle(Color.Text.secondary)
        }
        .padding(Design.Spacing.large)
        .background(Color.AppBackground.elevated)
        .clipShape(.rect(cornerRadius: Design.CornerRadius.large))
    }
}

#Preview {
    VStack(spacing: Design.Spacing.medium) {
        ActionRowContent(
            title: "Share via NFC",
            subtitle: "Tap phones to share instantly",
            systemImage: "dot.radiowaves.left.and.right"
        )
        
        ActionRowContent(
            title: "Copy Link",
            systemImage: "link"
        )
    }
    .padding()
    .background(Color.AppBackground.base)
}
