//
//  APICallsView.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 27/05/2024.
//

import SwiftUI
import LeStorage

struct APICallsListView: View {
    
    @State var collections: [String] = []
    
    var body: some View {
        
        List {
            ForEach(self.collections) { name in
                NavigationLink(name) {
                    APICallsView(name: name)
                }
            }
        }.onAppear {
            self.collections = Store.main.collectionNames()
        }
        
    }
}

struct APICallsView: View {
    
    var name: String
    @State var text: String = ""
    
    var body: some View {
        List {
            Text(self.text).lineLimit(nil)
        }.onAppear {
            self._load()
        }
    }
    
    @MainActor
    fileprivate func _load() {
        Task {
            self.text = await Store.main.apiCallsFileContent(resourceName: self.name)
        }
    }
    
}

//#Preview {
//    APICallsListView()
//}
