#ifndef GROUP_H
#define GROUP_H

#include <QWidget>
#include <QtWidgets/QComboBox>
#include "CameraMaterialGroupWnd/MaterialWindow/Wafer.h"
#include "CameraMaterialGroupWnd/MaterialWindow/Waffle.h"
#include "CameraMaterialGroupWnd/MaterialWindow/MaterialBox.h"
#include "CameraMaterialGroupWnd/MaterialWindow/Bond.h"
#include <CViewInterface.h>

namespace Ui {
class Group;
}

class Group : public QWidget
{
    Q_OBJECT

public:
    // 相机ID 实时图片 物料窗口类型 下拉框文本
    explicit Group(int groupId,const CameraInfo& cameraInfo, ns_module::CViewInterface *cViewInterface,QList<QPair<QString, QString>> fileList,QWidget* parent);
    ~Group();

    void initForm();
    bool eventFilter(QObject *obj, QEvent *event);
    void saveGroupSettings(int Id, int materialWndType);
    void saveBorderSettings();  // 新增:保存边框颜色信息
    void loadBorderSettings();  // 新增:加载边框颜色信息
    void recordBorderInfo(int groupId, const QString& side);
    QString getBlueBorderStyle();
    QString getRedBorderStyle();
    void setDatacomboBox(int index);
    void setEnableControls(bool enable);
    int getCurrentComboBoxIndex();
    void setCurrentCombox(const int index);
    void initBorderStyle(int index,int color);

signals:
    void send_button_Signal();
    void send_ComboBox_singal(int groupId,int index);
    void SendGroupSelectedSignals(Group* group, int index);
    void sendUpdateGroupState(int groupId,int index);

    /**当前选中了哪一个
     */
    void SetCurrentSelectSig(int groupId,int nIndex);
    /**相机图像转发
     */
    void SetUpDataImageShowSig(const QPixmap& imageData);

public slots:
    void Changedstyle();
    void onclickbutton();
    void on_DatacomboBox_currentIndexChanged(int comboxIndex);
    void GetGroupSelectedSlots(Group* group, int index);


    void UpDataImageShowSlots(const QPixmap& imageData);

protected:
    void showEvent(QShowEvent *event) override;
    void hideEvent(QHideEvent *event) override;
    void check_selected(int index);
    void WaferWidget(); // 圆晶
    void WaffleWidget(); // 华夫盒
    void MaterialBoxWidget(); // 料盒
    void BondWidget();

private:
    Ui::Group *ui;

    int             m_nCurrentGroupId;
    Wafer *         m_pWafer        =nullptr; // 声明Wafer指针
    Waffle *        m_pWaffle       = nullptr; // 声明Waffle指针
    MaterialBox *   m_pMaterialbox  = nullptr; // 声明materialbox指针
    Bond*           m_pBond         = nullptr;
    static Group*   m_pCurrentlySelectedGroup; // 当前选中(红色边框)的实例
    static Group*   m_pPreviouslySelectedBlueGroup; // 上一次选中且边框为蓝色的实例
    static Group*   m_pLastClickedGroup; // 上一次点击的实例
    static int      m_stnLastClickedIndex; // 上一次点击的索引
    static int      m_stnLastSavedIndex; // 上次保存的索引
    int      m_stnCurrentComboBoxIndex;

public:
    int             m_nGroupId;  // 新增:记录当前 Group 的 ID
    ns_module::CViewInterface* m_pCViewInterface;
};

#endif // GROUP_H