//
//  KKVideoViewController.m
//  Open
//
//  Created by 雷俊博 on 2021/2/20.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "KKVideoViewController.h"

#if TARGET_IPHONE_SIMULATOR

#else

//#import <JUnion/JUnion.h>
    
#endif

#import "KKTabBarViewController.h"
#import <WXApi.h>

@interface KKVideoViewController ()
#if TARGET_IPHONE_SIMULATOR

#else

//<JUVideoDelegate>
    
#endif
{
    CGFloat statusBarHeight;
    UIEdgeInsets gSafeAreaInsets;
}

#if TARGET_IPHONE_SIMULATOR

#else

//@property (nonatomic, strong)JULittleVideoListController *littleVc;
    
#endif



@end

@implementation KKVideoViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
    [tabVC pausmeAnimation];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //init
    if ([UIScreen mainScreen].bounds.size.height > 811) {
        statusBarHeight = 44;
        gSafeAreaInsets = UIEdgeInsetsMake(44, 0, 34, 0);
    }else{
        statusBarHeight = 20;
        gSafeAreaInsets = UIEdgeInsetsMake(20, 0, 0, 0);
    }
    
    
#if TARGET_IPHONE_SIMULATOR

#else

//    //UI界面配置类
//    JUUIConfig.littleCommentType = JULittleCommentTypeReadWrite;//// 评论展示类型(默认不显示)
//    JUUIConfig.playerContentMode = JULittlePlayerContentModeResizeAspectFill;//// 播放器填充类型(默认resizeAspect)
//    JUUIConfig.littleShowShare = YES;
//
//
//    //添加rootController
//
//    self.littleVc = [JUService getLittleListVideoViewControllerWithDelegate:self];
//    self.littleVc.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
//    [self.view addSubview:self.littleVc.view];
//    [self addChildViewController:self.littleVc];
//
//    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
//        NSString *photoUrlString = [UserDefault objectForKey:@"ImageHJT"];
//        [JUService loginWithNickname:[getPeopleID Peopletitle] avatar:photoUrlString phone:[getPeopleID PeopleIphoneNmber] userid:[NSString stringWithFormat:@"%@",@([getPeopleID PeopleID])] callback:^(BOOL State, NSString * _Nonnull error) {
//            NSLog(@">>>>state:%d   >>>>error:%@",State,error);
//        }];
//    }
    
#endif
    
    
   
    

    
    
    //导航栏配置
    [self navConfig];
    
    
    
    
    NSLog(@"微信当前版本号:%@",[WXApi getApiVersion]);
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:navView];
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake( 10 * WIDTHRADIU, cl_kStatusBarHeight + 9.5, 50, 25);
    backBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    
    
    
    
    //title
    UILabel* lb_title = [[UILabel alloc]init];
    lb_title.textColor = [UIColor whiteColor];
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    lb_title.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:lb_title];
    
    lb_title.text = self.title;
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navView);
        make.height.offset(25);
        make.top.offset(cl_kStatusBarHeight + 9.5);
    }];
    
    
}

#if TARGET_IPHONE_SIMULATOR

#else

//#pragma mark - JUVideoDelegate
///// 首个视频开始播放(isAD: 是否是广告)
//- (void)firstPlayerStartWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isAD:(BOOL)isAD {
//    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
//
//    if (tabVC.isStart) {
//        [tabVC resumeAnimation];
//    }else{
//        [tabVC startAnimation];
//    }
//
//    //[[NSNotificationCenter defaultCenter]postNotificationName:KKSBVideoPlayNotificationName object:nil userInfo:nil];
//
//}
///// 视频开始播放
//- (void)playerStartWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isAD:(BOOL)isAD {
//    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
//
//    if (![tabVC.videoIdArray containsObject:videoInfo.video_id] && (![Tools isBlankString:videoInfo.video_id])) {
//        [tabVC resumeAnimation];
//
//        [tabVC addVideoId:videoInfo.video_id];
//    }
//}
///// 视频播放暂停状态变化
//- (void)playerPauseWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isPause:(BOOL)isPause isAD:(BOOL)isAD {
//    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
//
//    if ([tabVC.videoIdArray containsObject:videoInfo.video_id] && ![tabVC.endvideoIdArray containsObject:videoInfo.video_id] && (![Tools isBlankString:videoInfo.video_id])) {
//        if (isPause) {
//            [tabVC pausmeAnimation];
//            //[[NSNotificationCenter defaultCenter]postNotificationName:KKSBVideoPauseNotificationName object:nil userInfo:nil];
//        }else{
//            //[[NSNotificationCenter defaultCenter]postNotificationName:KKSBVideoResumeNotificationName object:nil userInfo:nil];
//            [tabVC resumeAnimation];
//        }
//    }
//}
///// 视频播放结束
//- (void)playerEndWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isAD:(BOOL)isAD {
//    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
//
//    if (![Tools isBlankString:videoInfo.video_id]) {
//        if (![tabVC.endvideoIdArray containsObject:videoInfo.video_id]) {
//            [tabVC pausmeAnimation];
//        }
//
//        [tabVC addEndVideoId:videoInfo.video_id];
//    }
//
//    //[tabVC pausmeAnimation];
//}
///// 视频播放失败
//- (void)playerErrorWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo error:(NSError * _Nullable)error isAD:(BOOL)isAD {
//
//}
///// 广告信息获取成功
//- (void)ylADInfoLoadSuccessWithAdID:(NSString * _Nonnull)adID {
//
//}
///// 广告信息获取失败
//- (void)ylADInfoLoadFailWithAdID:(NSString * _Nonnull)adID error:(NSError * _Nullable)error {
//
//}
///// 点击分享按钮(isMain: 竖版视频用来标记是否是首页，仅首页支持负反馈功能)
//- (void)clickShareBtnWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isMain:(BOOL)isMain {
//
//    [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession info:videoInfo];
//    NSLog(@">>>>>131414");
//}
///// 点赞(isPraise：true - 点赞，false - 取消点赞)
//- (void)clickPraiseBtnWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo isPraise:(BOOL)isPraise isAD:(BOOL)isAD {
////    [self.logData addObject:isPraise ? @"点赞" :@"取消点赞" ];
////    [self.logTableView reloadData];
//}
///// 进入CP页
//- (void)gotoCPPageWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo {
//    NSLog(@"进入CP页");
////    [self.logData addObject:@"进入CP页" ];
////    [self.logTableView reloadData];
////    [[UIApplication sharedApplication].windows.lastObject addSubview:self.logTableView];
//}
///// 进入播放页
//- (void)gotoPlayerPageWithVideoInfo:(JUFeedVideoData * _Nonnull)videoInfo {
//    NSLog(@"进入播放页");
//
////    [self.logData addObject:@"进入播放页" ];
////    [self.logTableView reloadData];
////    [[UIApplication sharedApplication].windows.lastObject addSubview:self.logTableView];
//}
///// 进入Feed页
//- (void)gotoFeedPageWithChannelID:(NSString * _Nonnull)channelID {
//    NSLog(@"进入feed页");
////    [self.logData addObject:[NSString stringWithFormat:@"进入feed页: %@",channelID]];
////    [self.logTableView reloadData];
//    //[[NSNotificationCenter defaultCenter]postNotificationName:KKSBVideoPauseNotificationName object:nil userInfo:nil];
//}
///// YLLittleVideoListController列表滑动
//- (void)yl_scrollViewDidScroll:(UIScrollView * _Nonnull)scrollView {
//
//}
///// 广告展现
//- (void)adShowWithYlID:(NSString * _Nonnull)ylID reqId:(NSString * _Nonnull)reqId type:(NSInteger)type {
//
//}
///// 广告点击
//- (void)adClickWithYlID:(NSString * _Nonnull)ylID reqId:(NSString * _Nonnull)reqId type:(NSInteger)type {
//
//}
    
#endif



#pragma mark - event response
- (void)backClick {
    
    KKTabBarViewController* tabVC = (KKTabBarViewController *)self.navigationController.tabBarController;
    
    [tabVC pausmeAnimation];
    
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
}

#if TARGET_IPHONE_SIMULATOR

#else

//#pragma mark - 分享
//- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType info:(JUFeedVideoData *)videoInfo
//{
//
//    if (![WXApi isWXAppInstalled]) {
//        [Tools showMessage:@"请先安装微信!!!"];
//        return;
//    }
//
//    WeakSelf
//    //创建分享消息对象
//    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//
//
//    //创建网页内容对象
//    NSString* thumbURL =  UMS_THUMB_IMAGE;
//   UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"看看生活" descr:videoInfo.title thumImage:videoInfo.image];
//    //设置网页地址
//    NSString *url = @"https://a.app.qq.com/o/simple.jsp?pkgname=com.weface.kksocialsecurity";//外网
//
//    shareObject.webpageUrl = url;
//
//    //分享消息对象设置分享内容对象
//    messageObject.shareObject = shareObject;
//
//    //调用分享接口
//    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
//        if (error) {
//            UMSocialLogInfo(@"************Share fail with error %@*********",error);
//        }else{
//            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
//                UMSocialShareResponse *resp = data;
//                //分享结果消息
//                UMSocialLogInfo(@"response message is %@",resp.message);
//                //第三方原始返回的数据
//                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
//
//            }else{
//                UMSocialLogInfo(@"response data is %@",data);
//            }
//
//
//        }
//
//    }];
//}

    
#endif



#pragma mark - getters and setters


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
