//
//  MVMCoreUISplitViewController.h
//  myverizon
//
//  Created by Scott Pfeil on 1/13/14.
//  Copyright (c) 2014 Verizon Wireless. All rights reserved.
//
//  The main splitview controller. Handles the hamburger menu and other content. Used because at the time, apple's UISplitViewController wasn't robust enough to satisfy our needs.

#import <UIKit/UIKit.h>
@import MVMCore.MVMCoreActionDelegateProtocol;
#import <MVMCoreUI/MVMCoreUIPanelProtocol.h>
#import <MVMCoreUI/MVMCoreUIPanelButtonProtocol.h>

@class MVMCoreUINavigationController;
@class MVMCoreUITopAlertView;
@class MFViewController;

typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
    MFNoDrawer = 0,
    MFOneDrawer,
    MFTwoDrawer
};

@interface MVMCoreUISplitViewController : UIViewController

// Reference to the panels.
@property (nullable, weak, nonatomic, readonly) UIViewController <MVMCoreUIPanelProtocol> *leftPanel;
@property (nullable, weak, nonatomic, readonly) UIViewController <MVMCoreUIPanelProtocol> *rightPanel;

// Can be of protocol MVMCoreUIPanelButtonProtocol
@property (nullable, strong, nonatomic) UIBarButtonItem *leftPanelButton;
@property (nullable, strong, nonatomic) UIBarButtonItem *rightPanelButton;

@property (nullable, strong, nonatomic) UIBarButtonItem *backButton;

@property (nullable, weak, nonatomic, readonly) MVMCoreUINavigationController *navigationController;

// Reference to the top alert view
@property (nullable, weak, nonatomic) MVMCoreUITopAlertView *topAlertView;

// References to the current navigation item settings.
@property (nonatomic, readonly) BOOL leftPanelIsAccessible;
@property (nonatomic, readonly) BOOL rightPanelIsAccessible;
@property (nullable, weak, nonatomic, readonly) UIViewController *navigationItemViewController;

// Convenience getter
+ (nullable instancetype)mainSplitViewController;

// Returns a split controller with the mvm styling. Also sets the appropriate handlers.
+ (nullable instancetype)setup;

// Returns a split controller with the mvm styling. Also sets the appropriate handlers. Also sets up the default load screen
+ (nullable instancetype)setupAsMainController;

#pragma mark - Panel Functions

// Sets if the left panel accessible for the view controller. Will show or hide the button.
- (void)setLeftPanelIsAccessible:(BOOL)leftPanelIsAccessible forViewController:(nonnull UIViewController *)viewController;

// Sets if the right panel accessible for the view controller. Will show or hide the button.
- (void)setRightPanelIsAccessible:(BOOL)rightPanelIsAccessible forViewController:(nonnull UIViewController *)viewController;

- (void)hideLeftPanelIfNeededAnimated:(BOOL)animated;
- (void)showLeftPanelAnimated:(BOOL)animated;

- (void)hideRightPanelIfNeededAnimated:(BOOL)animated;
- (void)showRightPanelAnimated:(BOOL)animated;

// Setters for the navigation items
- (void)setLeftNavigationItemForViewController:(UIViewController * _Nonnull)viewController accessible:(BOOL)accessible extended:(BOOL)extended;
- (void)setRightNavigationItemForViewController:(UIViewController * _Nonnull)viewController accessible:(BOOL)accessible extended:(BOOL)extended;

// Force hides both drawers. Does not animate or open always extended drawers on ipad either.
- (void)forceHideBothDrawers;

// reset drawers
- (void)resetDrawers;

// contains speicaly logic to set the icon color
- (void)setNavigationIconColor:(nullable UIColor *)color;

/// Updates the panels that are used.
- (void)setupPanels;

#pragma mark - Bottom Progress Bar

- (void)setBottomProgressBarProgress:(float)progress;

#pragma mark - Getters

// Returns the topmost visible view controller. This can also be the top level presented view controller.
- (nullable UIViewController *)getCurrentVisibleController;

// Returns the current detail view controller (taking into account tab bar page control).
- (nullable UIViewController *)getCurrentDetailViewController;

// Returns the current detail view controller only if it is an MFViewController.
- (nullable MFViewController *)getCurrentDetailMFViewController;

// Provides the width of the detail view.
+ (CGFloat)getDetailViewWidth;

// Provides the height of the detail view.
+ (CGFloat)getDetailViewHeight;

// Provides the width of the main application view.
+ (CGFloat)getApplicationViewWidth;
+ (CGFloat)getApplicationViewMaxSize;

// return subviewcontrollers' prefer status bar style
- (UIStatusBarStyle)getDefaultStatusBarStyle;
- (nullable UIColor *)getDefaultStatusBarBackgroundColor;

#pragma mark - Main Subclassables

// Can subclass to set threshold for when the drawers are permanently extended. Default is 1000 for the left panel and 2000 for both.
- (MFNumberOfDrawers)numberOfDrawersShouldShow:(nullable NSNumber *)forWidth;

// subclass to return default global panels. kept alive after creation.
- (nullable UIViewController <MVMCoreUIPanelProtocol> *)createLeftPanelViewController;
- (nullable UIViewController <MVMCoreUIPanelProtocol> *)createRightPanelViewController;

// subclass to change image of back button
- (nullable UIImage *)imageForBackButton;

// Can overide to provide other global buttons to be on the navigation bar.
- (nullable NSArray <UIBarButtonItem *>*)additionalLeftButtons;
- (nullable NSArray <UIBarButtonItem *>*)additionalRightButtons;

// The width of the panel when it is permanently extended. Default 320.
- (CGFloat)leftPanelExtendedWidth;
- (CGFloat)rightPanelExtendedWidth;

// The maximum width of the panel. It will never grow past these sizes. Otherwise it is the size of the main view.
- (CGFloat)leftPanelMaxWidth; // Default 415
- (CGFloat)rightPanelMaxWidth; // Default 500

#pragma mark - Button Presses

- (IBAction)leftPanelButtonPressed:(nullable id)sender;
- (IBAction)backButtonPressed:(nullable id)sender;
- (IBAction)rightPanelButtonPressed:(nullable id)sender;

@end
