#ifndef __FILELIST_H
#define __FILELIST_H

#ifdef __cplusplus
extern "C" {
#endif

#include <wiisprite.h>

#include "sound.h"
#include "widget.h"
#include "file.h"
#include "history.h"

typedef enum
{
	TYPE_BACK = 0,
	TYPE_FOLDER = 1,
	TYPE_SOUND = 2,
	TYPE_UNKNOWN = 3,
	TYPE_LASTSPRITE = 4
} IconType;

typedef struct
{
	DrawableImage *image;
	Sprite *sprite;
	Sprite *icon;
	
	IconType whichIcon;
	bool played;
	
	char fileName[MAXPATHLEN];
	FileType fType;
} FileListType;

class FileList : public Widget
{
	public:
		FileList();
		~FileList();
		
		void populate(const char *url);
		void getDir(char *url);
		void playFileRelative(int offset);
		
		void setRandomMode(bool mode);
		bool isRandomMode();
		
		virtual void resize(int width, int height);
		
		virtual void draw();
		
		virtual void cursorDown(int x, int y, Action a);
		virtual void cursorMove(int x, int y);
		virtual void cursorUp(int x, int y, Action a);
		virtual void cursorOut();
	private:
		void reskin();
		void fixScroll(int oldPos);
		
		int getRandomItem(int x);
		int getRandomCount();
		void resetRandom();
		
		FileListType *fList;
		int fListCount;
		Theme windowManager;
		Settings settingsManager;
		
		char currentDir[MAXPATHLEN];
		int textSize;
		
		TextRender text;
		Sound sound;
		
		// Crashes if i use preallocated memory for some reason
		DrawableImage *highlightImage;
		DrawableImage *selectImage;
		DrawableImage *bgImageSolid;
		Image *bgImagePicture;
		
		Image *scrollUpImage;
		Image *scrollDownImage;
		
		Sprite *highlightSprite;
		Sprite *selectSprite;
		Sprite *bgSprite;
		
		Sprite *scrollUp;
		Sprite *scrollDown;
		
		Image *icons[TYPE_LASTSPRITE];
		u32 iconWidth;
		
		int scrollPos;
		int selectPos;
		int highlightPos;
		
		int isDragging;
		int yDragPos;
		
		int animateCount;
		
		bool _random;
		History history;
};

#ifdef __cplusplus
}
#endif

#endif


