#  Copyright (c) 2025  Jeffrey Hsu - JITToolBox
#  #
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#  #
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  #
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
from PySide6.QtWidgets import QHBoxLayout
from qfluentwidgets import PushButton, HyperlinkButton, SpinBox, LineEdit, PrimaryPushButton, FluentIcon, \
    GroupHeaderCardWidget

from ui.components.widget import MyGroupHeaderCardWidget


class ODModeSettings(MyGroupHeaderCardWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setTitle('输入选项')

        self.sBtn = PushButton('打开', self)
        self.sBtnTemplate = HyperlinkButton('', '模板下载')

        self.qBtn = PushButton('打开', self)
        self.bBtnTemplate = HyperlinkButton('', '模板下载')

        self.qNumber = SpinBox(self)
        self.qNumber.setRange(0, 999)

        self.defenseNameLineEdit = LineEdit(self)
        self.defenseNameLineEdit.setPlaceholderText('输入答辩名称')

        self.so = SpinBox(self)
        self.so.setRange(0, 999)

        self.sname = LineEdit(self)
        self.sname.setPlaceholderText('姓名')

        self.startBtn = PrimaryPushButton(FluentIcon.PLAY_SOLID, '开始')

        self.init_layout()

    def init_layout(self):
        self.sBtn.setFixedWidth(120)
        self.qBtn.setFixedWidth(120)
        self.defenseNameLineEdit.setFixedWidth(360)
        self.so.setFixedWidth(120)
        self.sname.setFixedWidth(120)
        self.qNumber.setFixedWidth(120)
        self.startBtn.setFixedWidth(120)

        hbox1 = QHBoxLayout(self)
        hbox1.addWidget(self.sBtnTemplate)
        hbox1.addWidget(self.sBtn)
        hbox2 = QHBoxLayout(self)
        hbox2.addWidget(self.bBtnTemplate)
        hbox2.addWidget(self.qBtn)

        self.stuGroup = self.addGroup(FluentIcon.DOCUMENT, '学生名单', '选择学生名单文件', hbox1)
        self.qGroup = self.addGroup(FluentIcon.DOCUMENT, '题库', '选择题库文件', hbox2)
        self.addGroup(FluentIcon.SETTING, '题目数量', '输入题目数量', self.qNumber)
        self.addGroup(FluentIcon.SETTING, '答辩名称', '输入答辩名称', self.defenseNameLineEdit)
        self.addGroup(FluentIcon.SETTING, '答辩序号', '输入答辩序号', self.so)
        self.addGroup(FluentIcon.SETTING, '学生姓名', '输入学生姓名', self.sname)


class ODModeExportSettings(GroupHeaderCardWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setTitle('导出选项')
        self.exportFilename = LineEdit(self)
        self.exportBtn = PrimaryPushButton(FluentIcon.PLAY_SOLID, '导出')

        self.init_layout()

    def init_layout(self):
        self.exportFilename.setPlaceholderText('输入导出的文件名')
        self.exportFilename.setFixedWidth(360)
        self.exportBtn.setFixedWidth(120)

        self.addGroup(FluentIcon.DOCUMENT, '导出文件名', '输入导出文件名', self.exportFilename)
