//
//  DebugSettingsView.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 28/05/2024.
//

import SwiftUI
import LeStorage

struct DebugSettingsView: View {
    var body: some View {
        List {
            
            Section("Status") {
                LabeledContent("Has Websocket Manager", value: self._hasWebSocketManager)
                LabeledContent("Websocket ping", value: self._wsPingStatus)
                LabeledContent("Websocket failure", value: self._wsFailure)
                LabeledContent("Last sync date", value: self._lastSyncDate)
            }
            
            Section("Settings") {
                LabeledContent("UUID", value: self._userId)
                LabeledContent("User Name", value: self._userName)
                LabeledContent("Token", value: self._token)
                LabeledContent("Server", value: self._apiURL)
                LabeledContent("Synchronized", value: self._synchronized)
            }
        }
    }
    
    fileprivate var _userId: String {
        return StoreCenter.main.userId ?? ""
    }
    
    fileprivate var _userName: String {
        return StoreCenter.main.userName ?? ""
    }
    
    fileprivate var _token: String {
        let token = try? StoreCenter.main.token()
        return token ?? ""
    }
    
    fileprivate var _apiURL: String {
        return StoreCenter.main.apiURL ?? "not configured"
    }
    
    fileprivate var _synchronized: String {
        if let synchronized = PListReader.readBool(plist: "local", key: "synchronized") {
            return "\(synchronized)"
        } else {
            return "not specified"
        }
    }
    
    fileprivate var _wsPingStatus: String {
        return "\(StoreCenter.main.websocketPingStatus)"
    }
    fileprivate var _wsFailure: String {
        return "\(StoreCenter.main.websocketFailure)"
    }
    fileprivate var _hasWebSocketManager: String {
        return "\(StoreCenter.main.hasWebSocketManager)"
    }
    fileprivate var _lastSyncDate: String {
        return "\(StoreCenter.main.lastSyncDate)"
    }
}

//#Preview {
//    DebugSettingsView()
//}
