//
//  TopTabbar.h
//  myverizon
//
//  Created by Chris Yang on 1/14/16.
//  Copyright © 2016 Verizon Wireless. All rights reserved.
//
//************************************************************************************************
//*  Please use datasource and delegate to populate the bar as well as set the action for each tab
//
//*  if it is created programatically, please use pinHeight method to pin the height constraint
//
//*  might add methods to set up the bar without protocol if needed
//
//*  alternately you can subclass TopTabbarViewController
//************************************************************************************************

#import <UIKit/UIKit.h>
#import <MVMCoreUI/MFView.h>
@protocol TopTabbarDataSource;
@protocol TopTabbarDelegate;

@interface TopTabbar : MFView 

@property (nullable, weak, nonatomic) UICollectionView *collectionView;
@property (nullable, weak, nonatomic) id <TopTabbarDataSource> datasource;
@property (nullable, weak, nonatomic) id <TopTabbarDelegate> delegate;
@property (nullable, strong, nonatomic) NSLayoutConstraint *heightConstraint;
@property (assign, nonatomic) CGFloat maxHeight;

@property (nonatomic, readonly) NSInteger selectedIndex;

//method to set the height
- (void)pinHeight:(CGFloat)height;

// use this to programatically select and index. should be useful when page loads
// default way to programatically select index
- (void)selectIndex:(NSInteger)index animated:(BOOL)animate;

// an alternative way to animate the selection.
// It should be used as a passive tab selection. For example, using pan gesture to paginate the views which leading a tab selection change.
// tab selection is finished(changing label color and call delegate functions if necessary) by passing the percentage as 0 or 1.
- (void)progressFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex withProgressPercentage:(CGFloat)percentage;

- (void)reloadData;

@end


@protocol TopTabbarDataSource <NSObject>

//protocol to set number of items in the tabbar
- (NSInteger)numberOfTopTabbarItems:(nonnull TopTabbar *)topTabbar;

//protocol to set the title show on the tabbar for each item
- (nullable NSString *)topTabbar: (nonnull TopTabbar *)topTabbar titleForItemAtIndex:(NSInteger)index;

@end


@protocol TopTabbarDelegate <NSObject>

//protocall to set the action for the tab
- (void)topTabbar:(nonnull TopTabbar *)topTabbar didSelectItemAtIndex:(NSInteger)index;

@optional

// Asks if we should select the item. default is YES.
- (BOOL)shouldSelectItemAtIndex:(NSInteger)index topTabbar:(nonnull TopTabbar *)topTabbar;

@end
