# -*- coding: utf-8 -*-
from __future__ import annotations
import sys, os, io, csv, time, datetime
from typing import Callable, Optional

# PyQt5
from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QTimer, QSize
from PyQt5.QtGui import QImage, QPixmap, QKeySequence
from PyQt5.QtWidgets import (
    QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
    QLabel, QPushButton, QComboBox, QTextEdit, QFileDialog, QMessageBox,
    QGroupBox, QGridLayout, QDialog, QFormLayout, QSpinBox, QCheckBox,
    QLineEdit, QTableWidget, QTableWidgetItem,QDialogButtonBox,QShortcut
)

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import cv2
from PIL import Image
import serial
import serial.tools.list_ports

# ---------- 协议导入----------
from Shared_CODE.FaceRecognitionProtocol import (
    build_reset, build_uvc_view, build_face_view, build_verify,
    build_enroll_itg_single, build_delete_all, build_get_all_userid,build_delete_user,
    MID_REPLY, MID_NOTE, CMD_ENROLL, CMD_ENROLL_ITG,
    parse_reply, parse_note
)

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
ui_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../Shared_UI'))

enrill_ui_file_path = os.path.join(ui_path, "enroll.ui")

class EnrollItgSingleDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
    
        uic.loadUi(enrill_ui_file_path, self)
        self.cb_admin.setCurrentIndex(0)
        self.btn_ok.clicked.connect(self.accept)

    def values(self):
        admin_val = self.cb_admin.currentIndex()
        uname = self.le_name.text().strip()[:32]
        face_dir = 0
        if self.chk_mid.isChecked(): face_dir |= 0x01
        if self.chk_right.isChecked(): face_dir |= 0x02
        if self.chk_left.isChecked(): face_dir |= 0x04
        if self.chk_down.isChecked(): face_dir |= 0x08
        if self.chk_up.isChecked(): face_dir |= 0x10
        if face_dir == 0: face_dir = 0x01
        timeout_val = self.sb_timeout.value()
        try:
            itg_val = int(self.le_itg.text().strip(), 0)
        except ValueError:
            itg_val = 0
        return admin_val, uname, face_dir, timeout_val, itg_val

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = EnrollItgSingleDialog()
    dialog.exec()
    sys.exit(0)
