#ifndef RECORDER_EXAMPLE_APP_H
#define RECORDER_EXAMPLE_APP_H

#include <QMainWindow>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QSlider>
#include <QProgressBar>
#include <QTextEdit>
#include <QGroupBox>
#include <QSplitter>
#include <QTimer>
#include <QStatusBar>
#include <QMenuBar>
#include <QToolBar>
#include <QAction>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QCloseEvent>
#include <QSystemTrayIcon>
#include <QMenu>

#include "recorder_main_widget.h"
#include "../recorder.h"

QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
class QSystemTrayIcon;
QT_END_NAMESPACE

/**
 * @brief 录制器示例应用程序
 * 
 * 这是一个完整的录制器应用程序示例，展示了如何使用重构后的录制器模块。
 * 提供了完整的用户界面和功能，包括：
 * - 录制控制（开始/停止/暂停/恢复）
 * - 实时预览
 * - 音频控制和电平显示
 * - 设置管理
 * - 状态监控
 * - 系统托盘支持
 * - 快捷键支持
 */
class RecorderExampleApp : public QMainWindow {
    Q_OBJECT

public:
    explicit RecorderExampleApp(QWidget* parent = nullptr);
    ~RecorderExampleApp();

protected:
    void closeEvent(QCloseEvent* event) override;
    void changeEvent(QEvent* event) override;
    bool eventFilter(QObject* obj, QEvent* event) override;

private slots:
    // 菜单和工具栏操作
    void onNewRecording();
    void onOpenRecording();
    void onSaveRecording();
    void onExportRecording();
    void onSettings();
    void onAbout();
    void onExit();
    
    // 录制控制
    void onStartRecording();
    void onStopRecording();
    void onPauseRecording();
    void onResumeRecording();
    void onStartPreview();
    void onStopPreview();
    
    // 系统托盘
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void onShowHide();
    
    // 录制器状态 (暂时保留，可能需要连接到RecorderMainWidget的信号)
    // void onRecorderStateChanged(RecorderState state);
    // void onRecorderError(const QString& error);
    // void onRecorderStatisticsUpdated(const Statistics& stats);
    
    // 定时器
    void updateStatusBar();
    void updateRecordingTime();
    void checkDiskSpace();
    
private:
    void initializeUI();
    void createMenuBar();
    void createToolBar();
    void createStatusBar();
    void createSystemTray();
    void setupShortcuts();
    void connectSignals();
    
    void loadSettings();
    void saveSettings();
    
    void updateUI();
    void updateActions();
    void updateWindowTitle();
    
    QString formatTime(qint64 seconds) const;
    QString formatFileSize(qint64 bytes) const;
    QString formatBitrate(qint64 bps) const;
    
    bool confirmExit();
    void showMessage(const QString& title, const QString& message, 
                    QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);

private:
    // 核心组件
    RecorderMainWidget* m_recorderWidget;
    // RecorderModule已移除，现在使用RecorderMainWidget内部的录制器
    
    // UI组件
    QWidget* m_centralWidget;
    QVBoxLayout* m_mainLayout;
    QSplitter* m_mainSplitter;
    
    // 菜单和工具栏
    QMenuBar* m_menuBar;
    QMenu* m_fileMenu;
    QMenu* m_recordMenu;
    QMenu* m_viewMenu;
    QMenu* m_helpMenu;
    
    QToolBar* m_mainToolBar;
    QToolBar* m_recordToolBar;
    
    // 动作
    QAction* m_newAction;
    QAction* m_openAction;
    QAction* m_saveAction;
    QAction* m_exportAction;
    QAction* m_settingsAction;
    QAction* m_exitAction;
    
    QAction* m_startRecordingAction;
    QAction* m_stopRecordingAction;
    QAction* m_pauseRecordingAction;
    QAction* m_resumeRecordingAction;
    QAction* m_startPreviewAction;
    QAction* m_stopPreviewAction;
    
    QAction* m_aboutAction;
    QAction* m_aboutQtAction;
    
    // 状态栏
    QStatusBar* m_statusBar;
    QLabel* m_statusLabel;
    QLabel* m_recordingTimeLabel;
    QLabel* m_fileSizeLabel;
    QLabel* m_bitrateLabel;
    QLabel* m_diskSpaceLabel;
    QProgressBar* m_recordingProgress;
    
    // 系统托盘
    QSystemTrayIcon* m_trayIcon;
    QMenu* m_trayMenu;
    QAction* m_showHideAction;
    QAction* m_trayExitAction;
    
    // 定时器
    QTimer* m_statusUpdateTimer;
    QTimer* m_recordingTimer;
    QTimer* m_diskSpaceTimer;
    
    // 状态
    bool m_isRecording;
    bool m_isPaused;
    bool m_isPreviewActive;
    qint64 m_recordingStartTime;
    qint64 m_recordingDuration;
    QString m_currentRecordingFile;
    
    // 设置
    QSettings* m_settings;
    bool m_minimizeToTray;
    bool m_closeToTray;
    bool m_autoStartPreview;
    bool m_showRecordingTime;
    bool m_showFileSize;
    bool m_showBitrate;
    bool m_showDiskSpace;
};

#endif // RECORDER_EXAMPLE_APP_H