//
//  CODDatePickerHelper.h
//  Shared
//
//  Created by Robinson on 23.05.2014.
//  Copyright (c) 2014 Coding Turtle. All rights reserved.
//

#import <Foundation/Foundation.h>


extern NSString *const kCODDatePickerHelperDatePickerDidFadeOutNotification;


//Each individual date text field (CODDateTextField)---there can be lots of them in the app!---will create/remove an instance of this class as needed.
//The text fields should not just willy-nilly create these instances without them being required though; that would waste memory.

@interface CODDatePickerHelper : NSObject <NSAnimationDelegate>

//The following “show” method should only be called once.
//Subsequently, the following “fade out” method should only be called once.
//We should then use the “did fade out” notification to get rid of this instance.
//Safety mechanism: We can also get rid of this instance without calling the “fade out” method.

//Note: Below, we talk about time being (possibly) included in the local time zone date.
//This is fine. The point is just to have the date picker display the correct date. The time doesn’t matter.
//However, we will have to deal with the time elsewhere (in the text field), where we convert the date to and from a timeless GMT date.

//This class relies on the view we pass into the “show” method.
//But this class retains neither this view nor its window; it keeps weak references to them.
//Safety mechanism: However, even if this view, its superview, or window disappear, this class continues working gracefully (by doing nothing at all, where applicable).

//Worth noting: We should think about this class as being very self-contained. We should think about
//it as being independent from the date text field (CODDateTextField) class. When an instance of this
//class is alive, it’s alive, and its by-products (including the attached window) are alive. When
//the instance goes away (gets deallocated) it goes away with its by-products.
//In this context, remember again what we said above: We can get rid of this instance in two ways:
// (1) Calling “fade out” and get rid of the instance upon kCODDatePickerHelperDatePickerDidFadeOutNotification.
// (2) Getting rid of this instance directly, without calling “fade out.”

//Even if this class is a separate beast, it’s worth nothing this: If we do things correctly in the CODDateTextField,
//when a CODDateTextField goes away, the corresponding CODDatePickerHelper object(s) should go away with it as well.

//date should be in *local time zone* (so we can get the blue color on the correct date).
//Remember: 1) the date formatter is the GMT guy. 2) this date picker is the local time zone guy. 3) the text field mediates between the two.
//To start with the current date (in local time zone, possibly with time in it), pass nil to date.
//Note: when this initial date (or nil date) is being set, the delegate does *not* get notified about this change (i.e., it gets temporarily disconnected).
- (void)showDatePickerForView:(NSView *)view withDate:(NSDate *)date andSetDatePickerDelegate:(id)delegate beginOffScreen:(BOOL)beginOffScreen;

- (void)fadeOutAttachedWindowAfterDisconnectingDatePickerDelegate;

- (void)setDatePickerDateToCurrentDateTemporarilyDisconnectingDelegate; //the current date will be set in local time zone (possibly with time in it)
- (void)setDatePickerDateToDateThatIsAssumedToBeNonNilTemporarilyDisconnectingDelegate:(NSDate *)date; //provide a date in the local time zone (time can be included if we wish)

- (NSDate *)datePickerDate; //the date of the date picker in local time zone

- (void)updateAttachedWindowPosition; //safety: if the view provided in the “show” method no longer exists, or it no longer has a superview, or it no longer has a window, this method simply does nothing
- (void)moveAttachedWindowOffScreen;

@end
