#pragma once

#include <QToolButton>
#include <functional>

/**
 * A toolbar button that opens a small popup grid of layout preview buttons.
 * Each cell draws a schematic of the grid it represents.
 *
 * The user clicks a cell → the popup closes → callback fires with the layout index.
 */
class LayoutPicker : public QToolButton {
    Q_OBJECT
public:
    explicit LayoutPicker(QWidget* parent = nullptr);

    /** 0-based index matching the Layout enum order:
     *  0=1×1  1=1×2  2=1×3  3=1×4  4=2×1  5=2×2  6=3×1  7=4×1 */
    void setCurrentLayout(int idx);
    int  currentLayout() const { return current_; }

signals:
    void layoutSelected(int idx);

private:
    void openPopup();

    int current_ = 0;

    struct LayoutDef {
        const char* label;   // e.g. "1×2"
        int rows, cols;
    };
    static const LayoutDef kLayouts[8];
};
