#ifndef CUSTOMCOMBOBOX_H
#define CUSTOMCOMBOBOX_H

#include <QWidget>
#include <QLabel>
#include <QToolButton>
#include <QListWidget>
#include <QVBoxLayout>
#include <QMouseEvent>

class CustomComboBox : public QWidget
{
    Q_OBJECT
public:
    explicit CustomComboBox(QWidget *parent = nullptr);

    void addItem(const QString &text);
    void clear();
    QString currentText() const;
    void setCurrentIndex(int index = 0);
    int currentIndex() const;
    int findText(const QString& text);

signals:
    void currentIndexChanged(int index);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void extracted(QWidget *&widget);
    bool eventFilter(QObject *obj, QEvent *event) override;
    
private slots:
    void onItemClicked(QListWidgetItem *item);

private:
    QLabel *displayLabel;
    QToolButton *arrowBtn;
    QListWidget *listWidget;
    QWidget *popupWidget;
    bool isDisplay = false;
    int m_currentIndex = -1;
};

#endif // CUSTOMCOMBOBOX_H
