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

#import "JCFormItem.h"

@implementation JCFormItem

+ (instancetype)itemWithTitle:(NSString *)title subTitle:(nullable NSString *)subTitle {
    JCFormItem *item = [[self alloc] init];
    item.subTitle = subTitle;
    item.title = title;
    
    return item;
}

+ (instancetype)itemWithTitle:(NSString *)title subTitle:(nullable NSString *)subTitle itemClick:(void(^)(NSIndexPath *indexPath))itemClick {
    JCFormItem *item = [self itemWithTitle:title subTitle:subTitle];
    item.itemClick = itemClick;
    
    return item;
}

- (instancetype)init {
    if (self = [super init]) {
        _titleColor = [UIColor blackColor];
        _subTitleColor = [UIColor blackColor];
//        _cellHeight = AdaptedWidth(44);
        _titleFont = AdaptedFontSize(14);
        _subTitleFont = AdaptedFontSize(14);
    }
    
    return self;
}

- (CGFloat)cellHeight {
    if (!_cellHeight) {
        _cellHeight += 20;
        NSString *totalString = [NSString stringWithFormat:@"%@%@", self.title, self.subTitle];
        _cellHeight += [totalString boundingRectWithSize:CGSizeMake(kScreenWidth - 20, MAXFLOAT) options:0 attributes:@{NSFontAttributeName : self.subTitleFont} context:nil].size.height;
        _cellHeight = MAX(_cellHeight, 44);
        _cellHeight = AdaptedWidth(_cellHeight);
    }
    return _cellHeight;
}

- (void)setSubTitle:(NSString *)subTitle {
    _subTitle = subTitle;
}

@end
