import SwiftUI

struct ContentView: View {
    @StateObject var model = NFCViewModel()
    
    var body: some View {
        NavigationStack {
            Form {
                Section(header: Text("Info")) {
                    TextField("ID", text: $model.deviceId)
                        .textInputAutocapitalization(.never)
                    TextField("RSSI", text: $model.deviceRssi)
                        .textInputAutocapitalization(.never)
                }
                
                Section(header: Text("Password")) {
                    TextField("请输入密码", text: $model.devicePassword)
                        .textInputAutocapitalization(.never)
                }
                
                Section(header: Text("Operation")) {
                    Button("开锁") {
                        model.deviceId = ""
                        model.deviceRssi = ""
                        model.mUnlock()
                    }
                    
                    Button("关锁") {
                        model.deviceId = ""
                        model.deviceRssi = ""
                        model.mLock()
                    }
                    
                    Button("设置密码") {
                        model.deviceId = ""
                        model.deviceRssi = ""
                        model.mSetKey(sKey: "123456")
                    }
                    
                    Button("写自定义数据") {
                        model.deviceId = ""
                        model.deviceRssi = ""
                        model.mWriteCustomData(data: Data(repeating: 0x80, count: 56))
                    }
                    
                    Button("读自定义数据") {
                        model.deviceId = ""
                        model.deviceRssi = ""
                        model.mReadCustomData()
                    }
                }
            }
        }
    }
}
