#ifndef Mtx_Pkg_Edit_INCLUDED
	#define Mtx_Pkg_Edit_INCLUDED

#include <bncs_script_helper.h>

#ifdef WIN32
	#ifdef DOEXPORT_SCRIPT
		#define EXPORT_SCRIPT __declspec(dllexport) 
	#else
		#define EXPORT_SCRIPT 
	#endif
#else 
	#define EXPORT_SCRIPT
#endif

class Mtx_Pkg_Edit : public bncs_script_helper
{
public:
	Mtx_Pkg_Edit( bncs_client_callback * parent, const char* path );
	virtual ~Mtx_Pkg_Edit();

	void buttonCallback( buttonNotify *b );
	int revertiveCallback( revertiveNotify * r );
	void databaseCallback( revertiveNotify * r );
	bncs_string parentCallback( parentNotify *p );
	void timerCallback( int );
	
private:
	bncs_string m_myParam;
	bncs_string m_instance;

	struct mtx_data {
		int pkgLevels;				// Number of levels switched by a package
		int driverIDs[5];			// Device IDs of drivers: [0]=package names, [1]= package crosspoints, [2]=video, [3]=audio1, [4]=audio2
		bncs_string areaname;		// Name of the area containing the matrix/matricies
		bncs_string driverType[5];	// Names of the levels in the driverIDs array.
	};

	enum LevelId {PkgName=0, PkgXpt, Video, Audio1, Audio2};

	// Module wide variables.
	bncs_string homePanel;			// Holds name of the home panel.
	bncs_string avNamePanel;			// Holds name of Name Editing panel
	bncs_string pkgNamePanel;		// Holds name of package name edit panel
	bncs_string pkgXptPanel;			// Holds name of crosspoint edit panel

	bncs_string myToken;			// A scratchpad for text transfers
	bncs_stringlist myList;
	bncs_string edit_name;			// Holds the source/destination name after editing.
	bncs_string preEditName;		// Package name before the edit
	bncs_string postEditName;		// Package name after the edit

	int num_areas;					// Holds a count of the number of active areas for name editing found by scanning the object settings file
	int selectedArea;				// Holds the current active button id for the area. A value of -1 means no area selected.
	int editType;					// Value indicates the selected edit type. 0=unselected, 1=matrix names, 2=package names, 3=package contents.
	int dataType;					// Value indicates data edit type. 0=unselected, 1=source names, 2=destination names, 3=Source package content, 4= Destination package content.
	int routerLevel;				// Holds the ID of the selected router level for name editing

	int matrix_id;					// Holds the current matrix id during an edit session
	int baseDatabase;				// Holds the current database, base value.
	int databaseOffset;				// Added to basedatabase to get curent working edit database. Value is either 0 or 2.
	int xptid;						// The crosspoint id being edited
	int mtxNameTimeOut;				// Holds the timeout count value for the Update/Cancel timer.
	int mtxNameIndex;				// Holds the index of the currently selected source or destination package
	int pkgNameTimeOut;				// Holds the timeout counter value for Package name edit timer.
	int pkgMatrixId;				// Holds the matrix ID of the package being edited
	int pkgBaseDatabase;			// Holds the database ID of either 0 (sources) or 1 (destinations)

	// Variables used by package content edit panel processing
	int namesDevID;					// Driver ID of the package names.
	int xptDevID;					// Driver ID of the package crosspoints.
	int curPkg;						// ID of the current package being edited.
	int numLevels;					// Number of levels for the current package set
	int currentLevel;				// Level currently being edited
	int xptVidNow;					// Initial Video crosspoint ID
	int xptAudNow;					// Initial Audio crosspoint ID
	int xptAESNow;					// Initial AES crosspoint ID (Studio C only)
	int xptVidNext;					// Updated Video crosspoint ID
	int xptAudNext;					// Updated AES crosspoint ID
	int xptAESNext;					// Updated AES crosspoint ID
	int xptBaseDatabase;			// Base database for the edit

	bool doEdit_enabled;			// True if the HOME panel DoEdit control is active.
	bool editWhat_enabled;			// True if at least one of the what data buttons is enabled.
	bool mtx_registered;			// Set true when a router is registered for revertives. Needed to get database updates!
	bool mtx_name_edit;				// Set true when the name edit functions (editType == 1) is true
	bool pkgXptEdit;				// Set true when a XPT level is being edited

	mtx_data matrixData[10];

	// Local methods/functions
	void processHomePanel(buttonNotify *b);		// Process button presses on the HOME panel.
	void processAVedit(buttonNotify *b);		// Process button presses on the Audio Video Element edit panel.
	void processPkgNameEdit(buttonNotify *b);	// Process button presses on the Package name edit panel.
	void processXptEdit(buttonNotify *b);		// Process button presses on the Package content edit panel.

	void enableSelectEdit(void);				// Routine to enable the valid edit type buttons on HOME panel when area selected
	void enableEditWhat(void);					// Routine to eneble the relevant Edit_What buttons once there is an area and a function selected

	void clearDoEdit(void);						// Switch off the DoEdit button if active.
	void clearRouter(void);						// Disable the router levels, setting the text field to empty
	void clearEditWhat(void);					// Disable the Edit_what_ buttons if enabled
	void clearEditType(void);					// Disable the Type_ buttons
	void configPkgSelect(int rl);				// Function to set up the database entries in the xpt select panel
	void configPkgClear(void);					// Function to clear down all of the values in the xpt select panel
	void disableNamesClear(void);				// Function to disable the name and clear level buttons on the PKG_XPT panel
	void enableNamesClear(void);				// Function to enable the name and clear level buttons on the PKG_XPT panel
	void clearPkgXptEdit(void);					// Function to clear the edit selector data and displays in the crosspoint editor
};


#endif // Mtx_Pkg_Edit_INCLUDED