//
//  AddNewCardView.swift
//  OnCue
//
//  Created by Pradyun Setti on 22/06/2024.
//

import SwiftUI

struct AddNewCardView: View {
    @State private var newCardText = ""
    @Environment(\.dismiss) var dismiss
    
    let completionHandler: (String) -> Void
    
    var body: some View {
        NavigationView {
            Form {
                TextEditor(text: $newCardText)
                    .frame(minHeight: 500)
            }
            .navigationTitle("Add New Card")
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .topBarLeading) {
                    Button("Cancel", role: .cancel) { dismiss() }
                        .foregroundStyle(.red)
                }
                ToolbarItem(placement: .topBarTrailing) {
                    Button("Done") {
                        completionHandler(newCardText)
                        dismiss()
                    }
                }
            }
        }
    }
}

#Preview {
    AddNewCardView(completionHandler: {_ in})
}
