#pragma once

#include <QDialog>
#include <QListWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QLabel>
#include <QLineEdit>
#include <QDialogButtonBox>
#include <QMessageBox>
#include "services/accountservice.h"

class SignatureEditorDialog : public QDialog
{
    Q_OBJECT

public:
    explicit SignatureEditorDialog(const QString& signatureHtml = QString(), QWidget *parent = nullptr);
    QString getSignatureHtml() const { return m_signatureHtml; }
    QString getSignatureName() const { return m_nameEdit->text().trimmed(); }
    void setSignatureName(const QString& name) { m_nameEdit->setText(name); }

signals:
    void signatureSaved(const QString& name, const QString& html);

private slots:
    void onAccept();

private:
    QString m_signatureHtml;
    QLineEdit* m_nameEdit;
    QTextEdit* m_editor;
    
    void setupUI();
};

class SignatureManagerDialog : public QDialog
{
    Q_OBJECT

public:
    explicit SignatureManagerDialog(AccountService* accountService, qint64 accountId = -1, QWidget *parent = nullptr);
    QString getSelectedSignature() const { return m_selectedSignatureHtml; }

signals:
    void signatureSelected(const QString& html);
    void signaturesChanged();

private slots:
    void onNewSignature();
    void onEditSignature(QListWidgetItem* item);
    void onDeleteSignature(QListWidgetItem* item);
    void onUseSignature(QListWidgetItem* item);
    void onSignatureSelected(QListWidgetItem* item);

private:
    AccountService* m_accountService;
    qint64 m_accountId;
    QString m_selectedSignatureHtml;
    QListWidget* m_list;
    QPushButton* m_btnNew;
    QPushButton* m_btnEdit;
    QPushButton* m_btnDelete;
    QPushButton* m_btnUse;
    QPushButton* m_btnClose;
    
    void setupUI();
    void loadSignatures();
    struct SignatureData { QString name; QString html; };
};