//
//  GSExportSettingsViewController.h
//  GlyphsCore
//
//  Created by Georg Seifert on 01.06.21.
//  Copyright © 2021 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsApp/GlyphsFileFormatProtocol.h>
#import <GlyphsCore/GSBase.h>

@class GSInstance;
@class GSMenuButton;

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, GSExportOKButtonMode) {
	///OK button shows “Next…”
	GSExportOKButtonModeContinue = 0,
	/// OK button shows “Export”
	GSExportOKButtonModeExport = 1,
};

@interface GSExportSettingsViewController : NSViewController <GlyphsProgressDelegate>

@property (strong) id taskToken;

@property (weak) IBOutlet NSButton *otfButton;
@property (weak) IBOutlet NSButton *ttfButton;
@property (weak) IBOutlet NSButton *plainButton;

@property (weak) IBOutlet GSMenuButton *recentExportPathsButton;
@property (weak) IBOutlet NSPathControl *exportPathControl;
@property (nonatomic, weak) NSView *exportSettingsView;

@property (strong) NSMutableDictionary *results;
@property (strong, nullable) NSDate *time;
@property GSOutlineFormat outlineFormat;

@property (strong) NSURL *destinationURL;

@property (nonatomic, weak) GSFont *font;

@property (assign) BOOL testInstall;

- (IBAction)openDoc:(id)sender;

/// Reads `exportUseExportPathKey` from user defaults and calls `setOKButtonMode:` accordingly.
///
/// Subclasses may override this to apply custom logic.
- (void)updateOKButtonMode;

/// Update the OK button mode on the enclosing GSExportSettingsWindowController.
///
/// Call this whenever the export destination changes (e.g. from a path control checkbox).
- (void)setOKButtonMode:(GSExportOKButtonMode)mode;

- (NSString *)exportPathKey;

- (NSString *)exportRecentExportPathsKey;

- (void)showProgress;

- (void)hideProgress;

- (NSURL *)exportURL;

- (void)exportFont:(GSFont *)font;

- (BOOL)exportToURL:(NSURL *)destinationURL error:(out NSError **)error;

- (BOOL)exportInstances:(NSArray *)instances
				  toURL:(NSURL *)destinationURL
				options:(NSDictionary *)options
				  error:(NSError **)error;

- (void)generalOptions:(NSMutableDictionary *)options;

- (BOOL)instance:(GSInstance *)instance options:(NSMutableDictionary *)options error:(NSError **)error;

- (BOOL)applyNameTokens:(GSInstance *)instance error:(NSError **)error;

- (BOOL)instance:(GSInstance *)currInstance outlineFormat:(GSOutlineFormat)outlineFormat activeInstances:(NSMutableArray *)activeInstances seenInstanceNames:(NSMutableSet *)seenInstanceNames duplicateNames:(NSMutableArray *)duplicateNames instanceCount:(NSUInteger *)instanceCount error:(NSError **)error;

- (nullable NSString *)fileNameFor:(GSInstance *)currInstance outlineFormat:(GSOutlineFormat)outlineFormat error:(NSError **)error;

#pragma mark - Deprecated (Glyphs 3 compatibility)

/// Internal helper. Exposed for Glyphs 3 source compatibility; still implemented but not intended as public API.
- (void)setupRecentExportPathsButton;

@end

NS_ASSUME_NONNULL_END
