#ifndef CREATEMEETINGDIALOG_H
#define CREATEMEETINGDIALOG_H

#include "framelessbase.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include <QDateTimeEdit>
#include <QCheckBox>
#include <QSpinBox>
#include <QComboBox>
#include <QGroupBox>
#include <QDateTime>

class QEventLoop;
class QCloseEvent;

struct MeetingInfo {
    QString meetingName;
    QString description;
    QDateTime startTime;
    int duration; // 分钟
    int maxParticipants;
    bool requirePassword;
    QString password;
    bool recordMeeting;
    QString meetingType;
    bool joinAsAdmin; // 是否以管理员身份加入
};

class CreateMeetingDialog : public TDialog
{
    Q_OBJECT

public:
    enum DialogCode { Rejected = TDialog::Rejected, Accepted = TDialog::Accepted };

    explicit CreateMeetingDialog(QWidget *parent = nullptr);
    ~CreateMeetingDialog();

    // 获取会议信息
    MeetingInfo getMeetingInfo() const;
    
    // 设置默认值
    void setDefaultValues();
    
    // 获取是否以管理员身份加入
    bool getJoinAsAdmin() const;

public slots:
    void accept() override;
    void reject() override;

private slots:
    void onPasswordCheckChanged(bool checked);
    void onMeetingNameChanged();
    void validateInput();
    void generateRandomPassword();

private:
    void setupUI();
    void applyStyles();
    bool isValidInput() const;
    
    // UI组件
    QVBoxLayout *m_mainLayout;
    QFormLayout *m_formLayout;
    
    // 基本信息组
    QGroupBox *m_basicGroup;
    QFormLayout *m_basicLayout;
    QLineEdit *m_meetingNameEdit;
    QTextEdit *m_descriptionEdit;
    QDateTimeEdit *m_startTimeEdit;
    QSpinBox *m_durationSpinBox;
    QSpinBox *m_maxParticipantsSpinBox;
    QComboBox *m_meetingTypeCombo;
    
    // 安全设置组
    QGroupBox *m_securityGroup;
    QVBoxLayout *m_securityLayout;
    QCheckBox *m_passwordCheckBox;
    QHBoxLayout *m_passwordLayout;
    QLineEdit *m_passwordEdit;
    QPushButton *m_generatePasswordButton;
    QCheckBox *m_recordCheckBox;
    
    // 角色选择
    QGroupBox *m_roleGroup;
    QVBoxLayout *m_roleLayout;
    QCheckBox *m_joinAsAdminCheckBox;
    
    // 按钮布局
    QHBoxLayout *m_buttonLayout;
    QPushButton *m_createButton;
    QPushButton *m_cancelButton;
    
    // 数据
    MeetingInfo m_meetingInfo;
};

#endif // CREATEMEETINGDIALOG_H