#ifndef XTREEWIDGET_H
#define XTREEWIDGET_H

#include "d3dbsp_structs.h"
#include "ddsfile.h"
#include "iwifile.h"
#include "fastfile.h"
#include "xloadedsound.h"
#include "xtreewidgetitem.h"
#include "zonefile.h"
#include "xrawfile.h"
#include "xgfximage.h"
#include "xstringtable.h"
#include "xmenudef.h"

#include <QTreeWidget>
#include <QFileDialog>

class XTreeWidget : public QTreeWidget
{
    Q_OBJECT
public:
    explicit XTreeWidget(QWidget *parent = nullptr);
    ~XTreeWidget();

    void AddFastFile(FastFile* aFastFile);
    void AddZoneFile(const ZoneFile *aZoneFile, XTreeWidgetItem *aParentItem = nullptr);
    void AddIWIFile(IWIFile* aIWIFile);
    void AddDDSFile(DDSFile* aDDSFile);

    const ZoneFile *FindZoneFile(const QString aStem);
    const FastFile* FindFastFile(const QString aStem);

    bool HasZoneFile(const QString aStem);
    bool HasFastFile(const QString aStem);

    void CloseFastFile(const QString aFFName);
signals:
    void DDSFileSelected(const DDSFile* aDDSFile, const QString aParentName);
    void IWIFileSelected(const IWIFile* aIWIFile, const QString aParentName);
    void FastFileSelected(const FastFile* aFastFile, const QString aParentName);
    void ZoneFileSelected(const ZoneFile* aZoneFile, const QString aParentName);
    void LocalStringSelected(const ZoneFile* aZoneFile, const QString aParentName);
    void RawFileSelected(const XRawFile* aRawFile, const QString aParentName);
    void ImageSelected(const XGfxImage* aImage, const QString aParentName);
    void TechSetSelected(const XMaterialTechniqueSet* aZoneFile, const QString aParentName);
    void StrTableSelected(const XStringTable* aStrTable, const QString aParentName);
    void MenuSelected(const XMenuDef* aMenu, const QString aParentName);
    void SoundSelected(const XLoadedSound* aSound, const QString aParentName);
    void MaterialSelected(const XMaterial* aMaterial, const QString aParentName);
    void ItemSelected(const QString itemText);

    void ItemClosed(const QString itemText);
    void Cleared();

protected:
    void ItemSelectionChanged();
    void PrepareContextMenu(const QPoint &pos);

private:
    QMap<QString, const FastFile*> mFastFiles;
    QMap<QString, const ZoneFile*> mZoneFiles;
    QMap<QString, const DDSFile*> mDDSFiles;
    QMap<QString, const IWIFile*> mIWIFiles;
};

#endif // XTREEWIDGET_H
