#import "RCTPlayspacePlayer.h"
#import "connatix_player_sdk_react_native-Swift.h"
@import ConnatixPlayerSDKObjc;

@implementation RCTPlayspacePlayer

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    self.playspacePlayer = [[CNPlayspacePlayer alloc] initWithFrame:CGRectZero delegate:nil];
    
    CNPlayspacePlayer * __weak weakSelf = self;
    self.playspacePlayer.onPlayerEvent = ^(CNPlayerEvent * _Nonnull event) {
        NSString* key = [ObjcHelper getEventKey:event];
        if (event.payload) {
            weakSelf.onPlayerEvent(@{key: event.payload});
        } else {
            weakSelf.onPlayerEvent(@{key: [NSNull null]});
        }
    };
    
    self.playspacePlayer.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:self.playspacePlayer];
    
    [NSLayoutConstraint activateConstraints:[NSArray arrayWithObjects:[self.playspacePlayer.topAnchor constraintEqualToAnchor:self.topAnchor], [self.playspacePlayer.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], [self.playspacePlayer.leftAnchor constraintEqualToAnchor:self.leftAnchor], [self.playspacePlayer.rightAnchor constraintEqualToAnchor:self.rightAnchor], nil]];
    return self;
}

@end
