//
//  JXSegmentedTagStyle.swift

//
//  Created by Leon on 2025/9/9.
//
import JXSegmentedView
class JXSegmentedTagStyleDataSource : JXSegmentedTitleDataSource {
    var normalBackgroundColor: UIColor = .c.csen
    var normalBorderColor: UIColor =  .c.csen
    var selectBackgroundColor: UIColor = .c.cpn
    var selectBorderColor:UIColor = .c.con
    
    var borderLineWidth:CGFloat = 1
    var backgroundCornerRadius :CGFloat = 16 // 32*0.5
    var backgroundWidth : CGFloat = 60
    var backgroundHeight : CGFloat = 32
    
    override init() {
        super.init()
        
        isItemSpacingAverageEnabled = false
        itemSpacing = 12
        titleNormalColor = .c.ctpn
        titleSelectedColor = .c.ctpn
        titleNormalFont = .t.tlm
        titleSelectedFont = .t.tlm
        
        itemWidthIncrement = 32
    }
    
    open override func preferredItemModelInstance() -> JXSegmentedBaseItemModel {
        return JXSegmentedTagStyleItemModel()
    }
    
    open override func preferredRefreshItemModel(_ itemModel: JXSegmentedBaseItemModel, at index: Int, selectedIndex: Int) {
        super.preferredRefreshItemModel(itemModel, at: index, selectedIndex: selectedIndex)
        
        guard let itemModel = itemModel as? JXSegmentedTagStyleItemModel else {
            return
        }
        
        itemModel.normalBackgroundColor = normalBackgroundColor
        itemModel.normalBorderColor = normalBorderColor
        itemModel.selectBackgroundColor = selectBackgroundColor
        itemModel.selectBorderColor = selectBorderColor
        itemModel.borderLineWidth = borderLineWidth
        
        itemModel.backgroundWidth = backgroundWidth
        itemModel.backgroundHeight = backgroundHeight
        itemModel.backgroundCornerRadius = backgroundHeight * 0.5//backgroundCornerRadius

        
        // ...
    }
    
    //MARK: - JXSegmentedViewDataSource
    open override func registerCellClass(in segmentedView: JXSegmentedView) {
        segmentedView.collectionView.register(JXSegmentedTagStyleCell.self, forCellWithReuseIdentifier: "cell")
    }

    open override func segmentedView(_ segmentedView: JXSegmentedView, cellForItemAt index: Int) -> JXSegmentedBaseCell {
        let cell = segmentedView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
        return cell
    }
}

extension JXSegmentedTagStyleDataSource{
    func standardTagStyle(){
        
    }
}
