//
//  EZStreamConfigSettingVC.m
//  EZOpenSDKDemo
//
//  Created by JuneCheng on 2026/3/12.
//  Copyright © 2026 hikvision. All rights reserved.
//

#import "EZStreamConfigSettingVC.h"

#define VideoQualityModes @[@"默认", @"性能优先", @"画质优先"]

@interface EZStreamConfigSettingVC () {
    NSArray *array;
}

@end

@implementation EZStreamConfigSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"取流特殊设置";
    
    // 预览/回放
    JCFormSwitchItem *item00 = [JCFormSwitchItem itemWithTitle:@"禁用播放器的P2P能力，非全局P2P开关" subTitle:nil];
    item00.status = [GlobalKit shareKit].isPlayerP2PDisable;
    item00.switchBlock = ^(BOOL on) {
        [GlobalKit shareKit].isPlayerP2PDisable = on;
    };
    JCFormSectionItem *section0 = [JCFormSectionItem sectionWithItems:@[item00] headerTitle:@"预览/回放" footerTitle:nil];
    [self.sections addObject:section0];
    
    // 预览
    JCFormItem *item10 = [JCFormArrowItem itemWithTitle:@"视频质量" subTitle:VideoQualityModes[(int)[GlobalKit shareKit].videoQuality] itemClick:^(NSIndexPath * _Nonnull indexPath) {
        [self showVideoQualityActionSheet:self.sections[indexPath.section].items[indexPath.row]];
    }];
    JCFormSectionItem *section1 = [JCFormSectionItem sectionWithItems:@[item10] headerTitle:@"预览" footerTitle:nil];
    [self.sections addObject:section1];
    
    // 回放
    JCFormSwitchItem *item20 = [JCFormSwitchItem itemWithTitle:@"纯音频播放（开启后取流时不会有画面）" subTitle:nil];
    item20.status = [GlobalKit shareKit].enablePureAudio;
    item20.switchBlock = ^(BOOL on) {
        [GlobalKit shareKit].enablePureAudio = on;
    };
    JCFormSectionItem *section2 = [JCFormSectionItem sectionWithItems:@[item20] headerTitle:@"回放" footerTitle:nil];
    [self.sections addObject:section2];
}

/** 画面质量模式选择框 */
- (void)showVideoQualityActionSheet:(JCFormItem *)item {
    [self showActionSheetWithTitle:@"请选择画面质量模式" message:nil appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
        for (int i = 0; i < VideoQualityModes.count; i ++) {
            alertMaker.addActionDefaultTitle(VideoQualityModes[i]);
        }
        alertMaker.addActionCancelTitle(NSLocalizedString(@"cancel", @"取消"));
    } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
        if (buttonIndex < VideoQualityModes.count) {
            [GlobalKit shareKit].videoQuality = (EZVideoQualityType)buttonIndex;
            item.subTitle = VideoQualityModes[buttonIndex];
            [self.tableView reloadData];
        }
    }];
}

@end
