/*
   SPDX-FileCopyrightText: 2025-2026 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "textautogenerateattachmentdelegatehelperbase.h"

#include <QObject>
#include <QStyleOptionViewItem>
class QPainter;
namespace TextAutoGenerateText
{
class TextAutoGenerateAttachment;
class TextAutoGenerateAttachmentDelegateHelperImage : public TextAutoGenerateAttachmentDelegateHelperBase
{
    Q_OBJECT
public:
    explicit TextAutoGenerateAttachmentDelegateHelperImage(TextAutoGenerateText::TextAutoGenerateManager *manager, QObject *parent = nullptr);
    ~TextAutoGenerateAttachmentDelegateHelperImage() override;

    void draw(const TextAutoGenerateText::TextAutoGenerateAttachment &msgAttach,
              QPainter *painter,
              QRect attachmentsRect,
              const QModelIndex &index,
              const QStyleOptionViewItem &option) const override;
    [[nodiscard]] QSize sizeHint(const TextAutoGenerateText::TextAutoGenerateAttachment &msgAttach,
                                 const QModelIndex &index,
                                 int maxWidth,
                                 const QStyleOptionViewItem &option) const override;

    [[nodiscard]] bool handleMouseEvent(const TextAutoGenerateText::TextAutoGenerateAttachment &msgAttach,
                                        QMouseEvent *mouseEvent,
                                        QRect attachmentsRect,
                                        const QStyleOptionViewItem &option,
                                        const QModelIndex &index) override;

protected:
    [[nodiscard]] QPoint adaptMousePosition(const QPoint &pos,
                                            const TextAutoGenerateText::TextAutoGenerateAttachment &msgAttach,
                                            QRect attachmentsRect,
                                            const QStyleOptionViewItem &option) override;

private:
    struct ImageLayout {
        QPixmap pixmap;
        QSize imageSize;
        QString name;
        QSize nameSize;
        QByteArray mimetype;
        bool showImage = false;
    };
    [[nodiscard]] TextAutoGenerateAttachmentDelegateHelperImage::ImageLayout layoutImage(const TextAutoGenerateText::TextAutoGenerateAttachment &msgAttach,
                                                                                         const QStyleOptionViewItem &option,
                                                                                         int attachmentsWidth,
                                                                                         int attachmentsHeight) const;
};
}
