//
//  SLMySpeedCell.m
//  SLAiELTS
//
//  Created by Gusont on 2023/5/31.
//

#import "SLMySpeedCell.h"

@interface SLMySpeedCell()

@end

@implementation SLMySpeedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    SLCustomSegment *segment = self.segmentView;
    CGRect frame = segment.frame;
    frame.size = CGSizeMake(kSCREEN_WIDTH - 24, frame.size.height);
    segment.frame = frame;
    segment.normalTitleFont = 13;
    segment.selectTitleFont = 13;
    segment.cornerRadius = 16.0f;
    segment.backgroundColor = [[UIColor colorFormString:@"#767680"] colorWithAlphaComponent:0.12];
    segment.tag = 110022;
    segment.normalBackgroundColor = [UIColor clearColor];
    segment.selectBackgroundColor = [UIColor whiteColor];
    segment.titleNormalColor = [UIColor colorFormString:@"#8E8E93"];
    segment.titleSelectColor = [UIColor blackColor];
}

- (void)confignCell:(SLPageModelDetail *)detail {
    self.titleLabel.text = detail.title;
    __block NSString *keyStr = @"";
    NSString *speechRate;
    NSInteger idx = 1;
    NSDictionary *dict = @{};
    if ([detail.title isEqualToString:NSLocalizedString(@"口音设置", nil)]) {
        speechRate = [SLGlobalInfo SharedInstance].roleModel.language;
        dict = [RoleModel roleLanuchModelDict];
    }
    if ([detail.title isEqualToString:NSLocalizedString(@"语速设置", nil)]) {
        speechRate = [SLGlobalInfo SharedInstance].roleModel.speechRate;
        dict = [RoleModel roleSpeedModelDict];
    }
    if (speechRate) {
        [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            if ([obj isEqualToString:speechRate]) {
                keyStr = key;
                *stop = YES;
            }
        }];
        idx = [detail.segments indexOfObject:keyStr];
    }
    [self.segmentView setTitlesWithArray:detail.segments];
    [self.segmentView updateWithSpacing:2 topHeight:2];
    self.segmentView.selectIndex = idx;
}

@end
