//
//  BrandingPreviewView.swift
//  CasinoKit
//
//  Development view for previewing and exporting app icons and launch screens.
//  Access this during development to generate icon assets.
//

import SwiftUI

/// Preview view for app branding assets.
/// Use this during development to preview icons and launch screens.
public struct BrandingPreviewView: View {
    let iconConfig: AppIconConfig
    let launchConfig: LaunchScreenConfig
    let appName: String
    
    // Development view: fixed sizes acceptable
    private let largePreviewSize: CGFloat = 300
    private let iconCornerRadiusRatio: CGFloat = 0.22
    
    /// Creates a branding preview view.
    /// - Parameters:
    ///   - iconConfig: The app icon configuration for this game.
    ///   - launchConfig: The launch screen configuration for this game.
    ///   - appName: The app name for display purposes.
    public init(
        iconConfig: AppIconConfig,
        launchConfig: LaunchScreenConfig,
        appName: String
    ) {
        self.iconConfig = iconConfig
        self.launchConfig = launchConfig
        self.appName = appName
    }
    
    public var body: some View {
        TabView {
            // App Icon Preview
            ScrollView {
                VStack(spacing: 32) {
                    Text("App Icon")
                        .font(.largeTitle.bold())
                    
                    AppIconView(config: iconConfig, size: largePreviewSize)
                        .clipShape(.rect(cornerRadius: largePreviewSize * iconCornerRadiusRatio))
                        .shadow(radius: 20)
                    
                    Text("1024 × 1024px")
                        .font(.caption)
                        .foregroundStyle(.secondary)
                    
                    instructionsSection
                }
                .padding()
            }
            .tabItem {
                Label("Icon", systemImage: "app.fill")
            }
            
            // Launch Screen Preview
            LaunchScreenView(config: launchConfig)
                .tabItem {
                    Label("Launch", systemImage: "rectangle.portrait.fill")
                }
        }
    }
    
    private var instructionsSection: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("To Export")
                .font(.headline)
            
            Text("Use the Icon Generator in Settings → DEBUG to save the 1024px icon to the Files app, then add it to Xcode's Assets.xcassets/AppIcon.")
                .font(.callout)
        }
        .foregroundStyle(.secondary)
        .frame(maxWidth: .infinity, alignment: .leading)
        .padding()
        .background(Color.gray.opacity(0.1))
        .clipShape(.rect(cornerRadius: 12))
    }
}

#Preview {
    BrandingPreviewView(
        iconConfig: .example,
        launchConfig: .example,
        appName: "Casino"
    )
}
