/*

 Owner: Michael Ehrmann	<michael@boinx.com>
 Company: Boinx Software Ltd., Germany

 Abstract: Controller for all Assistants. Handles loading, ordering and presentation of assistant panes.

 Related:	BXAssistantPaneProtocol.h
			BXAssistantPaneProviderProtocol.h

 Documentation: Documentation/assistants.html

 */


#import "BXAssistantPaneProtocol.h"

//#define DEBUG_METHOD_CALLS
//#define DEBUG_BX_ASSISTANT_CONTOLLER

@class BXGradientView, CTGradient, BXSubmissionController;

@interface BXAssistantController : NSWindowController
{
	IBOutlet NSButton* goBackButton;
	IBOutlet NSButton* continueButton;
	
	IBOutlet NSButton* logoButton;
	
	IBOutlet NSTextField* assistantTitle;
	
	IBOutlet NSView* content;
	IBOutlet NSView* contentBox;
	
	IBOutlet BXGradientView* _backgroundGradient;
	IBOutlet NSImageView* _ibBackgroundImage;
	
	IBOutlet NSView* customButtonView;
	
	IBOutlet NSMatrix* stepMatrix;
	
	/*Sheet*/
	IBOutlet NSButton *quitSheetButton;
	IBOutlet NSButton *continueSheetButton;
	
	IBOutlet NSWindow *cantCloseSheet;
	
	IBOutlet NSTextField *closeAssistantTitle;
	IBOutlet NSTextField *closeAssistantMessage;
	IBOutlet NSButton *closeAssistantContinueButton;
	IBOutlet NSButton *closeAssistantCloseButton;
	
@private
	id _delegate;
	id _session;
	
	NSMutableDictionary* _assistantPanes;
	id <BXAssistantPaneProtocol> _currentAssistantPane;
	
	NSArray* _assistants;
	unsigned _selectedAssistantIndex;
	
	NSArray* _assistantPaneOrder;
	unsigned _selectedAssistantPaneOrderIndex;
	
	int _modalSession;
	
	NSImage *dotInactive;
	NSImage *dotInactiveDisabled;
	NSImage *dotActive;
	NSImage *dotActiveDisabled;
	
	BOOL _active;
	
	NSString *_assistantID;
	
	NSMutableSet *_submissionController;
}

+ (void)localize;
		
- (void)updateButtons;
- (void)updateWindow;

- (void)loadAssistentPanes;
- (void)loadAssistantPaneWithPath:(NSString *)path;

- (void)loadAssistants;
- (NSArray *)allAssistantIDs;
- (BOOL)loadAssistantWithID:(NSString *)assistantID;

- (void)loadAssistantPaneOrder;

- (void)displayAssistantPane:(id <BXAssistantPaneProtocol>)assistantPane;
- (void)displayAssistantPaneWithName:(NSString *)assistantPaneName;
- (void)displayAssistantPaneWithID:(NSString *)assistantPaneID;

- (IBAction)displayFirstAssistantPane:(id)sender;
- (IBAction)displayNextAssistantPane:(id)sender;
- (IBAction)displayPreviousAssistantPane:(id)sender;

- (void)displayAssistantPaneAtIndex:(unsigned)index;

- (void)resizeWindowForAssistantPane:(id <BXAssistantPaneProtocol>)assistantPane;

#pragma mark ACTIONS

- (IBAction)terminate:(id)sender;
- (IBAction)nextStep:(id)sender;
- (IBAction)previousStep:(id)sender;

- (void)showAssistantWithPaneAtIndex:(int)inIndex;
- (IBAction)showAssistant:(id)sender;
- (void) switchToAssistantWithID:(NSString *)inAssistantID;
- (IBAction)closeAssistant:(id)sender;
- (void) abortAssistant;

- (IBAction)showCantCloseSheet:(id)sender;
- (IBAction)quitAssistantAndCloseSheet:(id)sender;
- (IBAction)continueAssistantAndCloseSheet:(id)sender;

#pragma mark STATE

- (BOOL)canCloseWindow;
- (id <BXAssistantPaneProtocol>)firstAssistantPaneProbitingWindowClose;

- (BOOL)hasNextStep;
- (BOOL)hasPreviousStep;

- (BOOL)isActive;
- (void)setActive:(BOOL)flag;

#pragma mark SUBMISSON

- (void)addSubmissionController:(BXSubmissionController *)inSubmissionController;
- (void)removeSubmissionController:(BXSubmissionController *)inSubmissionController;

#pragma mark DELEGATE

- (id)delegate;
- (void)setDelegate:(id)newDelegate;

#pragma mark WINDOW_DELEGATION

- (BOOL)windowShouldClose:(id)sender;

#pragma mark ACCESSOR_METHODS

- (NSWindow *)assistantWindow;

- (NSArray *)assistantPaneOrder;
- (void)setAssistantPaneOrder:(NSArray *)newAssistantPaneOrder;

- (NSArray *)assistants;
- (void)setAssistants:(NSArray *)newAssistants;

- (id)currentAssistantPane;
- (void)setCurrentAssistantPane:(id)newCurrentAssistantPane;

- (int)selectedAssistantPaneIndex;

- (NSString *)assistantID;
- (void)setAssistantID:(NSString *)inAssistantID;

- (void) setBackgroundGradient:(CTGradient *)newGradient;
- (void) setBackgroundImageScaling:(NSImageScaling)newScaling;
- (void) setBackgroundImage:(NSImage*)inImage;

- (id)session;
- (void)setSession:(id)inSession;

- (void)feedSession:(id)inSession;

- (NSMutableSet *)submissionController;

- (void)setLogoImage:(NSImage *)inLogo;

@end
