//
//  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 MVMCoreUITopAlertView;
@class MFViewController;
@class NavigationController;
@protocol TabBarProtocol;

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

@interface MVMCoreUISplitViewController : UIViewController

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

// For keeping
@property (nullable, strong, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *globalLeftPanel;
@property (nullable, strong, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *globalRightPanel;

// 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) NavigationController *navigationController;

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

// Reference to the status bar view
@property (nullable, weak, nonatomic) UIView *statusBarView;

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

/// Reference to the tabbar.
@property (nullable, weak, nonatomic) UIView <TabBarProtocol>*tabBar;

/// Tab bar index history. Contains either indices (0, 1, etc) or NSNull if there was no tab bar indice to set.
@property (nonnull, strong, nonatomic) NSMutableArray <NSNumber *>*tabBarIndices;

// Convenience getter
+ (nullable instancetype)mainSplitViewController;

/// Initializes the splitviewcontroller with the passed in panels.
- (nullable instancetype)initWithLeftPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)leftPanel rightPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)rightPanel;

// Returns a split controller with the mvm styling. Also sets the appropriate handlers.
+ (nullable instancetype)setup:(nullable UIViewController <MVMCoreUIPanelProtocol> *)leftPanel rightPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)rightPanel;

// Returns a split controller with the mvm styling. Also sets the appropriate handlers. Also sets up the default load screen
+ (nullable instancetype)setupAsMainController:(nullable UIViewController <MVMCoreUIPanelProtocol> *)leftPanel rightPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)rightPanel;

#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 updateNavigationButtons:(BOOL)updateNavigationButtons;

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

- (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;

/// Returns if the left panel is staying extended (usually do to screen size threshold)
- (BOOL)leftPanelStaysExtended;

/// Returns if the right panel is staying extended (usually do to screen size threshold)
- (BOOL)rightPanelStaysExtended;

#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;

// 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;

/// Returns true if a panel is showing.
- (BOOL)isAPanelShowing;

#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 change image of back button
- (nullable UIImage *)imageForBackButton;

// Can overide to provide other global buttons to be on the navigation bar.
- (nullable NSArray <UIBarButtonItem *>*)additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController;
- (nullable NSArray <UIBarButtonItem *>*)additionalRightButtonsForViewController:(nonnull UIViewController *)viewController;

// 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;

#pragma mark - TabBar

/// Called when split view is loaded to create the initial tabbar. Default is nil.
- (nullable UIView <TabBarProtocol>*)createTabBar;

/// Adds any tabbar at the bottom of the split view.
- (void)addTabBar:(nonnull UIView <TabBarProtocol>*)tabBar;

/// Updates if the tab bar is showing or not.
- (void)updateTabBarShowing:(BOOL)showing;

#pragma mark - Status Bar

/// Updates the status bar with the given style and background color
- (void)setStatusBarBackgroundColor:(nullable UIColor *)backgroundColor style:(UIStatusBarStyle)style;

/// Shows the view under the status bar.
- (void)expandStatusBarView;

/// Hides the view under the status bar.
- (void)collapseStatusBarView;

@end
