//
//  RCTVideoManager.m
//  RCTOMPlayer
//
//  Created by lcg on 2017/7/13.
//  Copyright © 2017年 Anren. All rights reserved.
//

#import "RCTVideoManager.h"
#import "RCTVideo.h"

@implementation RCTVideoManager

RCT_EXPORT_MODULE(RCTOMVideoView)

@synthesize bridge = _bridge;

- (UIView *)view
{
    return [[RCTVideo alloc] init];
}

RCT_EXPORT_VIEW_PROPERTY(controls, BOOL);
RCT_CUSTOM_VIEW_PROPERTY(fullscreen, BOOL, RCTVideo) {
    BOOL fullscreen = [RCTConvert BOOL:json];
    [view setFullscreen: fullscreen];
    if (fullscreen) {
        [view expand];
    }
}

RCT_CUSTOM_VIEW_PROPERTY(src, NSString*, RCTVideo)
{
    view.player.src = [RCTConvert NSString:json];
    [view seekTo: 0.0f];
}
RCT_CUSTOM_VIEW_PROPERTY(cookie, NSString*, RCTVideo)
{
    view.player.cookie = [RCTConvert NSString:json];
}
RCT_CUSTOM_VIEW_PROPERTY(displayText, NSString*, RCTVideo)
{
    view.player.displayText = [RCTConvert NSString:json];
}


RCT_CUSTOM_VIEW_PROPERTY(repeat, BOOL, RCTVideo)
{
    view.player.repeat = [RCTConvert BOOL:json];
}

RCT_CUSTOM_VIEW_PROPERTY(paused, BOOL, RCTVideo)
{
    view.player.paused = [RCTConvert BOOL:json];
}

RCT_CUSTOM_VIEW_PROPERTY(muted, BOOL, RCTVideo)
{
    view.player.muted = [RCTConvert BOOL:json];
}

RCT_CUSTOM_VIEW_PROPERTY(volume, float, RCTVideo)
{
    view.player.volume = [RCTConvert float:json];
}
RCT_CUSTOM_VIEW_PROPERTY(displayTextSize, float, RCTVideo)
{
    view.player.displayTextSize = [RCTConvert float:json];
}
RCT_CUSTOM_VIEW_PROPERTY(displayDelay, float, RCTVideo)
{
    view.player.displayDelay = [RCTConvert float:json];
}
RCT_CUSTOM_VIEW_PROPERTY(rate, float, RCTVideo)
{
    
    view.player.rate = [RCTConvert float:json];
    [view setRateBtnState];
}

RCT_CUSTOM_VIEW_PROPERTY(orientation, NSString*, RCTVideo)
{
    
    [view setFullscreenDirectionAuto: [RCTConvert NSString:json]];
}

RCT_CUSTOM_VIEW_PROPERTY(currentTime, float, RCTVideo)
{
    view.player.currentTime = [RCTConvert float:json];
}

RCT_EXPORT_VIEW_PROPERTY(onOMVideoLoadStart, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoLoad, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoLoadStalled, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoLoadResume, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoError, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoProgress, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoSeek, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoEnd, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoFullscreenPlayerDidDismiss, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMVideoFullscreenOrientationChange, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMReadyForDisplay, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMPlaybackStalled, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMPlaybackResume, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onOMPlaybackRateChange, RCTBubblingEventBlock);

@end
