//
//  DebugSection.swift
//  CasinoKit
//
//  Reusable debug section for settings views.
//  Only visible in DEBUG builds.
//

import SwiftUI

/// A debug row that navigates to a destination view.
public struct DebugNavigationRow<Destination: View>: View {
    let title: String
    let icon: String
    let destination: () -> Destination
    
    public init(
        title: String,
        icon: String,
        @ViewBuilder destination: @escaping () -> Destination
    ) {
        self.title = title
        self.icon = icon
        self.destination = destination
    }
    
    public var body: some View {
        NavigationLink {
            destination()
        } label: {
            HStack {
                Text(title)
                    .font(.system(size: CasinoDesign.BaseFontSize.body, weight: .medium))
                    .foregroundStyle(.orange)
                Spacer()
                Image(systemName: icon)
                    .font(.system(size: CasinoDesign.BaseFontSize.large))
                    .foregroundStyle(.orange)
            }
            .frame(minHeight: CasinoDesign.Size.actionRowMinHeight)
        }
    }
}

/// A debug row that performs an action.
public struct DebugActionRow: View {
    let title: String
    let icon: String
    let action: () -> Void
    
    public init(
        title: String,
        icon: String,
        action: @escaping () -> Void
    ) {
        self.title = title
        self.icon = icon
        self.action = action
    }
    
    public var body: some View {
        Button(action: action) {
            HStack {
                Text(title)
                    .font(.system(size: CasinoDesign.BaseFontSize.body, weight: .medium))
                    .foregroundStyle(.orange)
                Spacer()
                Image(systemName: icon)
                    .font(.system(size: CasinoDesign.BaseFontSize.large))
                    .foregroundStyle(.orange)
            }
            .frame(minHeight: CasinoDesign.Size.actionRowMinHeight)
        }
    }
}

/// Branding debug rows for icon generation and preview.
/// Use these in your app's debug section.
public struct BrandingDebugRows: View {
    let iconConfig: AppIconConfig
    let launchConfig: LaunchScreenConfig
    let appName: String
    
    public init(
        iconConfig: AppIconConfig,
        launchConfig: LaunchScreenConfig,
        appName: String
    ) {
        self.iconConfig = iconConfig
        self.launchConfig = launchConfig
        self.appName = appName
    }
    
    public var body: some View {
        DebugNavigationRow(
            title: "Icon Generator",
            icon: "app.badge.fill"
        ) {
            IconGeneratorView(config: iconConfig, appName: appName)
        }
        
        Divider()
            .background(Color.orange.opacity(0.3))
        
        DebugNavigationRow(
            title: "Branding Preview",
            icon: "paintpalette.fill"
        ) {
            BrandingPreviewView(
                iconConfig: iconConfig,
                launchConfig: launchConfig,
                appName: appName
            )
        }
    }
}

#Preview {
    NavigationStack {
        List {
            Section("Debug") {
                BrandingDebugRows(
                    iconConfig: .example,
                    launchConfig: .example,
                    appName: "Casino"
                )
            }
        }
    }
}
