//
//  XVCategoryTitleView.m
//  fastservice
//
//  Created by xuning on 2/4/24.
//  Copyright © 2024 FastService. All rights reserved.
//

#import "XVCategoryTitleView.h"

@implementation XVCategoryTitleView


- (void)initializeData {
    [super initializeData];

}

//返回自定义的cell class
- (Class)preferredCellClass {
    return [XVCategoryTitleCell class];
}

- (void)refreshDataSource {
    NSMutableArray *tempArray = [NSMutableArray array];
    for (int i = 0; i < self.titles.count; i++) {
        XVCategoryTitleCellModel *cellModel = [[XVCategoryTitleCellModel alloc] init];
        [tempArray addObject:cellModel];
    }
    self.dataSource = tempArray;
}

- (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
    [super refreshCellModel:cellModel index:index];

    XVCategoryTitleCellModel *myModel = (XVCategoryTitleCellModel *)cellModel;
    myModel.uiType = (XVCategoryTitleUIType)(self.uiTypes[@(index)].integerValue);
    myModel.imageLocation = (XVCategoryTitleImageLocation)(self.imageLocations[@(index)].integerValue);
    myModel.singleImage = self.singleImages[@(index)];
}

- (CGFloat)preferredCellWidthAtIndex:(NSInteger)index {
    CGFloat cellWidth = [super preferredCellWidthAtIndex:index];
    XVCategoryTitleUIType uiType = (XVCategoryTitleUIType)(self.uiTypes[@(index)].integerValue);
    if (uiType == XVCategoryTitleUIType_None) {
        return cellWidth;
    }
    return cellWidth + 3 + 10;
}

@end
