//
//  GSDocument.h
//  GlyphsApp
//
//  Created by Florian Pircher on 28.04.26.
//  Copyright © 2026 schriftgestaltung.de. All rights reserved.
//

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

#if TARGET_OS_IOS
#import <GlyphsApp/GSDocumentGo.h>
#else

NS_ASSUME_NONNULL_BEGIN

/**
 UTI of the glyphs files
 */
typedef NSString *GSDocumentType NS_TYPED_EXTENSIBLE_ENUM;
extern GSDocumentType const GSDocumentTypeNative;
extern GSDocumentType const GSDocumentTypeNativePackage;
extern GSDocumentType const GSDocumentTypeNativeArchive;
extern GSDocumentType const GSDocumentTypeProject;
extern GSDocumentType const GSDocumentTypeIconSet;
extern GSDocumentType const GSDocumentTypeUFO NS_SWIFT_NAME(ufo);

typedef NSString *GSDocumentExtension NS_TYPED_EXTENSIBLE_ENUM;
extern GSDocumentExtension const GSDocumentExtensionNative;
extern GSDocumentExtension const GSDocumentExtensionNativePackage;
extern GSDocumentExtension const GSDocumentExtensionNativeArchive;
extern GSDocumentExtension const GSDocumentExtensionProject;
extern GSDocumentExtension const GSDocumentExtensionIconSet;

@class GSPathObservation;

@interface GSDocument : NSDocument {
	GSFont *_font;
	NSStoryboard *_windowStoryboard;
	NSKeyedUnarchiver *_displayState;
	NSArray *_displayStrings;
	NSString *_importedVersion;
	NSDate *startTime;
	BOOL _restoring;
#if !(defined(GLYPHS_LITE) || defined(GLYPHS_VIEWER))
	GSGlyphsInfo *_localGlyphInfo;
#endif
#ifndef GLYPHS_LITE
	GSPathObservation *_featuresDirectoryObservation;
	NSDictionary<NSString *, NSDate *> *_featuresFileModificationDates;
#ifndef TESTING
	/// GSValidateFontsResultsWindowController
	NSWindowController *_validateFontsResultsWindowController;
	NSArray *_validateFontsResults;
#endif
#endif
	NSDate *_openDate;
}

@property (strong, nonatomic) GSFont *font;

@property (readonly, nonatomic, nullable) GSWindowController *windowController;

@property (readonly, nonatomic, nullable) GSFontMaster *selectedFontMaster;

- (GSGlyphsInfo *)glyphsInfo;

+ (nullable GSDocumentType)documentTypeFromExtension:(GSDocumentExtension)extension;

@property (strong, nonatomic, nullable) NSDictionary *userSettings;

- (void)addDefaultContent;

@property (assign) NSTimeInterval lastAutosaveInterval;

@property (strong, nullable) NSURL *saveToURL;

- (nullable NSUndoManager *)undoManagerCheck;

- (nullable GSEditViewController *)addTabWithLayers:(NSArray<GSLayer *> *)layers;

- (nullable GSEditViewController *)addTabWithGlyphs:(NSArray<GSGlyph *> *)glyphs;

- (nullable GSEditViewController *)addTabWithGlyphNames:(NSArray<NSString *> *)glyphs;

@property (assign) BOOL isAutosaving;
@property (nonatomic) BOOL closing;
@property (assign) BOOL isSaving; // Tracks if saving is in progress
@property (assign) BOOL saveRequestedDuringAsyncSave; // Tracks if another save is requested
@property (strong) NSDate *lastSaveTimestamp;

@end

NS_ASSUME_NONNULL_END

#endif
