//
//  CloudView.swift
//  MemoryTree
//
//  Created by Work on 2023-02-05.
//

import Boutique
import SwiftUI

struct CloudView: View {
//    @Stored(in: .entriesStore) var entries
    @Binding var entries: [Entry]

    @Environment(\.dismiss) var dismiss

    var body: some View {
        VStack {
            ForEach(entries) { entry in
                Text(entry.text)
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .edgesIgnoringSafeArea(.bottom)
        .background(Color.blue)
        .foregroundColor(.white)
        .toolbar {
            ToolbarItem(placement: .destructiveAction) {
                Button {
//                    Task {
//                        try await $entries.removeAll()
//                    }
                    entries.removeAll()
                    dismiss()
                } label: {
                    Image(systemName: "flame")
                }
            }
        }
    }
}

struct CloudView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            NavigationStack {
                CloudView(entries: .constant([]))

                CloudView(entries: .constant([Entry(text: "Coffee"), Entry(text: "Trees")]))
            }
        }
        .tint(.white)
    }
}
