#pragma once
#include "CustomIconGridItemView.h"
#include "CustomAppBarView.h"
#include "CustomFileInfoView.h"
#include "../IRomBrowserViewFactory.h"
#include "CustomBannerListItemView.h"
#include "romBrowser/views/CoverFlowRecyclerView.h"
#include "romBrowser/viewModels/RomBrowserViewModel.h"
#include "romBrowser/DisplayMode/CoverFlowFileRecyclerAdapter.h"

class MaterialColorScheme;
class ITheme;
class VramContext;
class IFontRepository;

class CustomRomBrowserViewFactory : public IRomBrowserViewFactory
{
public:
    CustomRomBrowserViewFactory(const MaterialColorScheme* materialColorScheme,
        const IFontRepository* fontRepository)
        : _materialColorScheme(materialColorScheme), _fontRepository(fontRepository) { }

    IconGridItemView* CreateIconGridItemView() const override
    {
        return new CustomIconGridItemView(_gridCellTexVramOffset, _gridCellPlttVramOffset,
            _gridCellSelectedTexVramOffset, _gridCellSelectedPlttVramOffset);
    }

    BannerListItemView* CreateBannerListItemView(VBlankTextureLoader* vblankTextureLoader) const override
    {
        return new CustomBannerListItemView(_materialColorScheme, _fontRepository,
            _bannerListCellTexVramOffset, _bannerListCellPlttVramOffset,
            _bannerListCellSelectedTexVramOffset, _bannerListCellSelectedPlttVramOffset, vblankTextureLoader);
    }

    BannerListItemView::VramToken UploadBannerListItemViewGraphics(const VramContext& vramContext) const override
    {
        return BannerListItemView::VramToken(0);
    }

    std::unique_ptr<AppBarView> CreateAppBarView(int x, int y, AppBarView::Orientation orientation,
        int startButtonCount, int endButtonCount) const override
    {
        return std::make_unique<CustomAppBarView>(x, y, orientation, startButtonCount, endButtonCount, _materialColorScheme,
            _scrimTexVramOffset, _scrimPlttVramOffset);
    }

    std::unique_ptr<BannerView> CreateFileInfoView() const override
    {
        return std::make_unique<CustomFileInfoView>(_fontRepository);
    }

    std::unique_ptr<RecyclerViewBase> CreateCoverFlowRecyclerView() const override
    {
        return std::make_unique<CoverFlowRecyclerView>();
    }

    FileRecyclerAdapter* CreateCoverFlowRecyclerAdapter(
        RomBrowserViewModel* viewModel, const IThemeFileIconFactory* themeFileIconFactory,
        VBlankTextureLoader* vblankTextureLoader) const override
    {
        return new CoverFlowFileRecyclerAdapter(
            &viewModel->GetFileInfoManager(), viewModel->GetIoTaskQueue(),
            themeFileIconFactory, this, vblankTextureLoader, &viewModel->GetCoverRepository());
    }

    void LoadResources(const ITheme& theme, const VramContext& mainVramContext);

private:
    u32 _gridCellTexVramOffset;
    u32 _gridCellPlttVramOffset;
    u32 _gridCellSelectedTexVramOffset;
    u32 _gridCellSelectedPlttVramOffset;
    u32 _bannerListCellTexVramOffset;
    u32 _bannerListCellPlttVramOffset;
    u32 _bannerListCellSelectedTexVramOffset;
    u32 _bannerListCellSelectedPlttVramOffset;
    u32 _scrimTexVramOffset;
    u32 _scrimPlttVramOffset;
    const MaterialColorScheme* _materialColorScheme;
    const IFontRepository* _fontRepository;
};
