//
//  CustomTools.m
//  SMSuperMap
//
//  Created by Shanglong Yang on 2022/3/7.
//

#import "SUserDefine.h"
#import "SARMap.h"

@implementation SUserDefine
RCT_EXPORT_MODULE();

static ARMapControl * m_arMapControl = nil;
static UILabel* text = nil;

#pragma mark 添加Callout
RCT_REMAP_METHOD(addMapCallout, addMapCallout:(NSString*)info resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){
    
    if([SARMap getInstance]!= nil){
        dispatch_async(dispatch_get_main_queue(), ^{
            @try {
                if(text == nil){
                    CGRect bounds = UIScreen.mainScreen.bounds;
                    text = [[UILabel alloc]initWithFrame:CGRectMake(bounds.size.width/2.0-80, bounds.size.height/2.0-15, 160, 30)];
                    text.backgroundColor = [UIColor redColor];
                    text.textColor = [UIColor whiteColor];
                    text.textAlignment = NSTextAlignmentCenter;
                    text.text = info;
                    text.layer.masksToBounds = YES;
                    text.layer.cornerRadius = 10;
                }
                [[SARMap getInstance] addSubview:text];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [text removeFromSuperview];
                });
                resolve(@(YES));
            } @catch (NSException *exception) {
                resolve(@(FALSE));
            }
        });
    }
}



@end
