//
//  PrinterInformationView.swift
//  SIIMpaPrinterSample
//

import SwiftUI

struct PrinterInformationView: View {
    @ObservedObject var printerViewModel: PrinterViewModel
    @State var alertTitle: String = ""
    @State var alertStr: String? = String()
    @State var isShowAlert: Bool = false
    var body: some View {
        VStack {
            List {
                ForEach(PRINTER_INFO_TABLE, id:\.self) { key in
                    Button(key) {
                        PrinterManager.getDispatchQueue().async {
                            printerViewModel.showIndicator(true)
                            alertTitle = key
                            alertStr = PrinterManager.getPrinterInformation(key: key)
                            isShowAlert = true
                            printerViewModel.showIndicator(false)
                        }
                    }
                    .alert(alertTitle, isPresented: $isShowAlert, actions: {}, message: {
                        Text(alertStr!)
                    })
                }
            }
            .listStyle(.plain)
        }
        .navigationTitle("Select PrinterInformation")
    }
}
