//
//  MFMailComposeViewControllerDelegateImpl.m
//  Project
//
//  Created by 杨殷杭 on 2018/8/22.
//

#import "MFMailComposeViewControllerDelegateImpl.h"
#import "SDK.h"
#import "CocoaUtils.h"

@implementation MFMailComposeViewControllerDelegateImpl

+ (instancetype)sharedInstance {
	static dispatch_once_t onceToken;
	static MFMailComposeViewControllerDelegateImpl *instance;
	dispatch_once(&onceToken, ^{
		instance = [[self alloc] init];
	});
	return instance;
}

#pragma mark - Mail compose delegate

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
	UIViewController *this = controller.presentingViewController;
	if (result == MFMailComposeResultCancelled || result == MFMailComposeResultSaved) {
		[this dismissViewControllerAnimated:YES completion:nil];
	} else if (result == MFMailComposeResultSent) {
		[CocoaUtils showAlertWithTitle:IMLocalizedString(@"Information") message:IMLocalizedString(@"Send Success") dismissalHandler:^{
			[this dismissViewControllerAnimated:YES completion:nil];
		}];
	} else if (result == MFMailComposeResultFailed) {
		[CocoaUtils showAlertWithTitle:IMLocalizedString(@"Error") message:IMLocalizedString(@"Send Failed") dismissalHandler:^{
			[this dismissViewControllerAnimated:YES completion:nil];
		}];
	}
}

@end
