//
//  MonthYearPickerViewManager.m
//  react-native-month-year-picker
//
//  Created by Kien Tran on 11/04/2023.
//

#import "MonthYearPickerViewManager.h"
#import "RNMonthYearPicker.h"

@implementation MonthYearPickerViewManager
RCT_EXPORT_MODULE(MonthYearPickerView)

- (UIView *)view {
    return [RNMonthYearPicker new];
}

RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(value, NSDate)
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)


RCT_CUSTOM_VIEW_PROPERTY(locale, NSString, RNMonthYearPicker) {
    NSString *defaultLocale = [[NSLocale preferredLanguages] objectAtIndex:0];
    if ([json length] != 0) {
        defaultLocale = [RCTConvert NSString:json];
    }
    NSLocale *useLocale = [[NSLocale alloc] initWithLocaleIdentifier:defaultLocale];
    [view setLocale:useLocale];
}

RCT_CUSTOM_VIEW_PROPERTY(textColor, NSString, RNMonthYearPicker)
{
  NSString *colorStr = (json && json != (id)kCFNull) ? [RCTConvert NSString:json] : nil;
  view.textColor = colorStr ? [RNMonthYearPicker colorFromString:colorStr] : nil;
  [view reloadAllComponents];
}
@end
