//
//  TsTGPPhotoStyleView.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/4.
//

import BetterSegmentedControl

class TSTGPPhotoStyleView: TSTGPTitleView {
    
    var selectedValueBlock:((Int)->Void)?
    
    let titles = ["Poster".localized,"Photo".localized]
    lazy var segmentedView: BetterSegmentedControl = {
        let segmentedView = BetterSegmentedControl(
            frame: .zero,
            segments:
                LabelSegment.segments(
                    withTitles: titles,
                    normalFont: .font(size: 14.0),
                    normalTextColor: .textDisable,
                    selectedFont: .font(size: 14.0),
                    selectedTextColor: .white),
            options:[.backgroundColor(.cardColor),
                     .indicatorViewBackgroundColor(.themeColor),
                     .indicatorViewInset(0),
                     .cornerRadius(8.0),
                     .animationSpringDamping(1.0)]
        )
        segmentedView.addTarget(self,action: #selector(segmentedControlValueChanged(_:)),for: .valueChanged)
        return segmentedView
    }()
    
    let moreInfoBtn = kCreateMoreInfoBtn()
    
    override func creatUI() {
        super.creatUI()
        titleLab.text = "Select type".localized
        
        contentView.addSubview(moreInfoBtn)
        moreInfoBtn.snp.makeConstraints { make in
            make.leading.equalTo(titleLab.snp.trailing).offset(8)
            make.width.height.equalTo(16)
            make.centerY.equalTo(titleLab)
        }
        
        contentView.addSubview(segmentedView)
        segmentedView.snp.makeConstraints { make in
            make.width.equalTo(144)
            make.height.equalTo(32)
            make.trailing.equalTo(-16)
            make.centerY.equalToSuperview()
        }
    }
    
    // MARK: - Action handlers
    @objc func segmentedControlValueChanged(_ sender: BetterSegmentedControl) {
        selectedValueBlock?(sender.index)
    }
}
