import SwiftUI

struct CreateFooter: View {
    let isVisible: Bool
    let showTrashButton: Bool
    let isKeyboardVisible: Bool
    let createButtonTitle: String
    let createButtonIcon: String
    let onTrash: () -> Void
    let onCreate: () -> Void
    
    init(
        isVisible: Bool,
        showTrashButton: Bool = false,
        isKeyboardVisible: Bool = false,
        createButtonTitle: String = "Create",
        createButtonIcon: String = "Icon/create",
        onTrash: @escaping () -> Void = {},
        onCreate: @escaping () -> Void
    ) {
        self.isVisible = isVisible
        self.showTrashButton = showTrashButton
        self.isKeyboardVisible = isKeyboardVisible
        self.createButtonTitle = createButtonTitle
        self.createButtonIcon = createButtonIcon
        self.onTrash = onTrash
        self.onCreate = onCreate
    }
    
    var body: some View {
        if isVisible {
            VStack {
                Spacer()
                
                VStack(spacing: 0) {
                    // Gradient overlay that fades content above (from Figma)
                    LinearGradient(
                        colors: [
                            Constants.Colors.Background.Gradient.end,   // Fully transparent
                            Constants.Colors.Background.Gradient.start  // Semi-transparent
                        ],
                        startPoint: .top,
                        endPoint: .bottom
                    )
                    .frame(height: 80)
                }
                .overlay(
                    // Buttons positioned over the gradient
                    VStack {
                        Spacer()
                        
                        HStack(spacing: 12) {
                            // Trash button (conditionally shown)
                            if showTrashButton {
                                LargeButton.iconOnlySecondary("Icon/trash") {
                                    onTrash()
                                }
                            }
                            
                            // Create button
                            LargeButton.aura(createButtonTitle, iconName: createButtonIcon) {
                                onCreate()
                            }
                        }
                        .padding(.horizontal, 16)
                        .padding(.bottom, isKeyboardVisible ? 16 : 50)
                    }
                )
            }
        }
    }
}

// MARK: - Preview
#Preview {
    ZStack {
        // Background content
        VStack {
            Spacer()
            Text("Background Content")
                .foregroundColor(.white)
            Spacer()
        }
        .background(Constants.Colors.Background.primary)
        
        // Floating footer
        CreateFooter(
            isVisible: true,
            showTrashButton: true,
            isKeyboardVisible: false,
            createButtonTitle: "Create",
            createButtonIcon: "Icon/create",
            onTrash: {
                print("Trash tapped")
            },
            onCreate: {
                print("Create tapped")
            }
        )
        .ignoresSafeArea(.container, edges: .bottom)
    }
}