//
//	GSFontViewController.h
//	Glyphs
//
//	Created by Georg Seifert.
//	Copyright 2023 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsApp/GSGlyphViewController.h>
#import <GlyphsApp/GlyphsToolEventProtocol.h>

#if TARGET_OS_IOS
#import <GlyphsApp/GSSteppingTextField.h>
#endif

typedef NS_ENUM(int, GSListViewMode) {
	GSListViewModeIcon = 0,
	GSListViewModeList = 1,
	GSListViewModeDetails = 2,
};

typedef NS_ENUM(int, GSGlyphFilterOptions) {
	GSGlyphFilterOptionsNegative = 1 << 1,
	GSGlyphFilterOptionsKeepSections = 1 << 2,
};

@class GSWindowController;
@class GSLayer;
@class GSGlyph;
@class MABGTimer;
#if !TARGET_OS_IOS
@class GSCollectionView;
@class GSFontViewSidebarController;
@class GSGlyphDetailViewController;
@class IKImageFlowView;
@class GSSplitView;
@class GSColorLabelViewController;
#endif
#ifndef GLYPHS_LITE
@class GSGlyphDetailDialog;
#endif

@class GSSidebarItem;

@interface GSFontViewController : GSGlyphViewController <NSMenuDelegate, GSContextMenuCallbackProtocol, NSTableViewDelegate>

@property (weak) GSWindowController *windowController;

@property (strong, nonatomic) NSSplitViewController *mainSplitViewController;
@property (nonatomic, weak) IBOutlet NSView *leftSideBarContainerView;
@property (nonatomic, weak) IBOutlet NSView *contentView;
#if !TARGET_OS_IOS
@property (unsafe_unretained, nonatomic) IBOutlet GSCollectionView *fontIconView;
@property (unsafe_unretained, nonatomic) IBOutlet GSCollectionView *fontGridDetailView;
#else
@property (unsafe_unretained, nonatomic) UICollectionView *fontIconView;
@property (unsafe_unretained, nonatomic) UICollectionView *fontGridDetailView;
#endif
@property (strong, nonatomic) NSIndexSet *selectedIndexes;
@property (unsafe_unretained, readonly, nonatomic) GSLayer *activeLayer;
@property (nonatomic, unsafe_unretained) IBOutlet NSSlider *iconSizeSlider;
#if !TARGET_OS_IOS
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *lSBField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *rSBField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *widthField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *topField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *bottomField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *vertWidthField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *vertOriginField;
#else
@property (nonatomic, unsafe_unretained) GSSteppingTextField *lSBField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *rSBField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *widthField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *topField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *bottomField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *vertWidthField;
@property (nonatomic, unsafe_unretained) GSSteppingTextField *vertOriginField;
#endif

@property (nonatomic, unsafe_unretained) IBOutlet NSMatrix *colorButtons;
@property (nonatomic, unsafe_unretained) IBOutlet NSMatrix *iconColorButtons;
@property (nonatomic, unsafe_unretained) IBOutlet NSTokenField *tagsField;

@property (nonatomic, weak) IBOutlet NSSearchField *glyphSearchField;
@property (nonatomic, weak) IBOutlet NSMenu *glyphSearchMenu;

@property (weak) IBOutlet NSTextField *productionField;
#if !TARGET_OS_IOS
@property (weak) IBOutlet NSComboBox *scriptsField;
@property (weak) IBOutlet NSComboBox *categoryField;
#endif
#ifndef GLYPHS_LITE
@property (nonatomic) NSUInteger masterIndex;
@property (unsafe_unretained, nonatomic) IBOutlet NSTabView *listViewModeTabview;
@property (nonatomic) GSListViewMode listViewMode;
#if !TARGET_OS_IOS
@property (unsafe_unretained, nonatomic) IBOutlet NSSplitView *listViewSplitView;
#endif
@property (unsafe_unretained, nonatomic) IBOutlet NSLayoutConstraint *listViewSplitViewTopConstraint;
@property (unsafe_unretained, nonatomic) IBOutlet NSTableView *listViewTableview;
#if !TARGET_OS_IOS
@property (unsafe_unretained, nonatomic) IBOutlet IKImageFlowView *coverFlowView;
#endif
@property (nonatomic, weak) IBOutlet NSMenu *listViewContextMenu;
#endif
@property (nonatomic, strong) NSLayoutConstraint *sidebarTopConstraint;
@property (nonatomic, strong) IBOutlet NSLayoutConstraint *detailViewHeightConstraint;

@property (unsafe_unretained, nonatomic) IBOutlet NSArrayController *glyphsArrayController;
@property (unsafe_unretained, nonatomic) IBOutlet NSView *sidebarDetailViewContainer;
@property (unsafe_unretained, nonatomic) IBOutlet NSStackView *sidebarDetailViewStack;
@property (unsafe_unretained, nonatomic) IBOutlet NSButton *sidebarDetailToggleButton;
@property (unsafe_unretained, nonatomic) IBOutlet NSButton *sidebarDetailSelectDetailsButton;
#if !TARGET_OS_IOS
@property (nonatomic, weak) IBOutlet NSTreeController *glyphsGroupTreeController;
@property (nonatomic, unsafe_unretained) IBOutlet GSFontViewSidebarController *glyphsGroupViewController;
@property (nonatomic, strong) GSGlyphDetailViewController *glyphInfoContextMenuViewController;
#endif
- (IBAction)leftMetricsAction:(id)sender;
- (IBAction)rightMetricsAction:(id)sender;
- (IBAction)widthMetricsAction:(id)sender;
#ifndef GLYPHS_LITE
- (IBAction)topMetricsAction:(id)sender;
- (IBAction)bottomMetricsAction:(id)sender;
- (IBAction)vertWidthMetricsAction:(id)sender;
- (IBAction)vertOriginMetricsAction:(id)sender;
#endif

@property (nonatomic, strong) NSString *leftMetricsKey;
@property (nonatomic, strong) NSString *rightMetricsKey;
@property (nonatomic, strong) NSString *widthMetricsKey;
#ifndef GLYPHS_LITE
@property (nonatomic, strong) NSString *topMetricsKey;
@property (nonatomic, strong) NSString *bottomMetricsKey;
@property (nonatomic, strong) NSString *vertWidthMetricsKey;
@property (nonatomic, strong) NSString *vertOriginMetricsKey;
#endif

@property (nonatomic, readonly) NSColor *leftMetricsColor;
@property (nonatomic, readonly) NSColor *rightMetricsColor;
@property (nonatomic, readonly) NSColor *widthMetricsColor;

#ifndef GLYPHS_LITE
@property (nonatomic, readonly) NSColor *topMetricsColor;
@property (nonatomic, readonly) NSColor *bottomMetricsColor;
@property (nonatomic, readonly) NSColor *vertWidthMetricsColor;
@property (nonatomic, readonly) NSColor *vertOriginMetricsColor;
#endif

- (id)plainValueForKey:(NSString *)key;

@property (nonatomic, strong) NSNumber *exportGlyphs;
@property (nonatomic, strong) NSString *leftKerningGroup;
@property (nonatomic, strong) NSString *rightKerningGroup;
#ifndef GLYPHS_LITE
@property (nonatomic, strong) NSString *topKerningGroup;
@property (nonatomic, strong) NSString *bottomKerningGroup;
@property (nonatomic, strong) NSString *production;
@property (nonatomic, strong) GSScriptID script;
@property (nonatomic, strong) NSString *category;
@property (nonatomic, strong) NSString *subCategory;
#endif

@property (nonatomic, strong) NSString *note;

#ifndef GLYPHS_LITE
@property (nonatomic, strong) GSGlyphDetailDialog *glyphDetailWindow;

@property (nonatomic, weak) IBOutlet NSView *gridDetailView;

// This for now, only used for the Kerning Panel.
@property (assign, nonatomic) GSWritingDirection writingDirection;
#endif

- (IBAction)doubleClick:(id)sender;

- (IBAction)setIconSize:(id)sender;

- (void)didGetSelected;

- (void)performTextFinderAction:(id)sender;

- (void)printDocument:(id)sender;

- (IBAction)filterGlyphs:(id)sender;

- (void)updateCoverage;

#ifndef GLYPHS_LITE

- (void)updateListViewMasterIndex;

#endif

- (void)redraw;

- (NSString *)displayString;

#ifndef GLYPHS_VIEWER

- (IBAction)duplicate:(id)sender;

- (IBAction)newGlyph:(id)sender;

- (IBAction)delete:(id)sender;

#endif

//- (IBAction)showGlyphInfoWindow:(id)sender;

- (void)selectAll:(id)sender;

- (void)deselectAll:(id)sender;

- (void)removeSidebarFilters;

- (void)selectGlyph:(GSGlyph *)glyph;

- (void)focusContentViewAndSelectFirst;

#ifndef GLYPHS_VIEWER

- (void)correctPathDirection:(id)sender;

- (void)cleanUpPaths:(id)sender;

- (void)addExtremes:(id)sender;

#endif

- (void)keyDown:(NSEvent *)theEvent;

- (void)resetTextInput:(NSTimer *)timer;

- (void)startTextInputTimer;

- (void)stopTextInputTimer;

- (void)openSelectedGlyphsInNewTab;

#ifndef GLYPHS_VIEWER

- (IBAction)roundCoordinates:(id)sender;

- (IBAction)resetColor:(id)sender;

#endif

- (IBAction)setColor:(id)sender;

#ifndef GLYPHS_LITE
#if 0
- (NSColor *)tableView:(NSTableView *)aTableView backgroundColorForRow:(NSInteger)rowIdx;
#endif
#endif

+ (NSPredicate *)predicateForNameList:(NSArray <GSGlyphInfo *> *)list options:(GSGlyphFilterOptions)options font:(GSFont *)font;

+ (NSPredicate *)predicateForCodes:(NSArray <NSNumber *> *)codes;

+ (NSPredicate *)filterForItem:(GSSidebarItem *)item sortDescriptors:(NSMutableArray *)sortDescriptors font:(GSFont *)font masterIndex:(NSInteger)masterIndex;

@end
