#ifndef WRITINGADDITEMDIALOG_H
#define WRITINGADDITEMDIALOG_H

#include <QDialog>
#include <QLabel>
#include <QList>
#include <QStack>
#include "global/kaglobal.h"
#include "documentlistview.h"
#include "documentitemdelegate.h"
#include "../writing/documentreader.h"
#include "docparsethread.h"
#include "kswitchbutton.h"

using namespace kdk;

namespace Ui {
class WritingAddItemDialog;
}

class WritingAddItemDialog : public QDialog
{
    Q_OBJECT
public:
    explicit WritingAddItemDialog(QWidget *parent = nullptr);
    ~WritingAddItemDialog();

signals:
    void sigDocItemAdd(DocTemplate info);

private slots:
    void on_toolButton_add_clicked();
    void onRecParseMsg(const QString message);
    void onRecParseError(const QString message);
    void on_pushButton_skip_clicked();
    void on_pushButton_filepage_next_clicked();
    void on_pushButton_step1_prev_clicked();
    void on_pushButton_step1_next_clicked();
    void on_pushButton_step2_prev_clicked();
    void on_pushButton_confirm_clicked();
    void on_lineEdit_article_parse_template_textChanged(const QString &arg1);
    void on_textEdit_article_parse_outline_textChanged();
    void on_closeButton_clicked();
    void onParseTimeout();

private:
    void initUI();
    void initConnect();
    void checkEmptyState();
    void onAddDocument(const QString &path);
    void onShowDeleteConfirm(const QString &filePath);
    void onSelectDocument();
    void checkDuplicateName(const QStringList &filePaths);
    bool onDeleteDocument(const QString &filePath);
    bool isTargetFile(const QString &documentPath);
    bool canEnableNextButton();
    void parsingDoc();
    void updateStep1NextButtonState();
    bool parseArticleResponse(QJsonDocument doc, QString& templateName, QString& title, QString& summary, QString& catalog, QString& toneStyle);
    QString cleanJsonMessage(const QString &rawMessage);

    void simulateAdvancedDocumentAnalysis(const QString& filePath);
    void generateDocumentReport(const QString& filePath, const QString& reportType);
    void batchProcessDocuments(const QStringList& filePaths, int processingMode);

private:
    Ui::WritingAddItemDialog *ui;
    DocumentItemDelegate *mDelegate = nullptr;
    DocumentListModel *mDocumentModel = nullptr;
    DocumentReader *mDocumentReader = nullptr;
    DocParseThread *mDocParseThread = nullptr;
    QString mRecvMsg;
    KSwitchButton* mSwitchBtnRefer = nullptr;
    KSwitchButton* mSwitchOutLine = nullptr;
    QTimer* mParseTimer = nullptr;
};

#endif // WRITINGADDITEMDIALOG_H
