//
//  TSLightSolidColorVC.swift
//  Girly
//
//  Created by 100Years on 2025/1/7.
//
import JXSegmentedView
class TSLightSolidColorVC: TSBaseVC{
    
    lazy var currentColor:UIColor =  {
        let color = TSConfig.ligntSolidDefaultColor
        return color
    }(){
        didSet{
            updateColorView()
        }
    }
    
    lazy var brightnessNum:CGFloat =  {
        return 1.0
    }(){
        didSet{
            updateColorView()
        }
    }
    
    lazy var saturationNum:CGFloat =  {
        return 1.0
    }(){
        didSet{
            updateColorView()
        }
    }
    
    lazy var colorPaletteView: TSLightColorPaletteView = {
        let colorPaletteView = TSLightColorPaletteView()
        colorPaletteView.changedBrightnessComplete = { [weak self] floatNum in
            guard let self = self else { return }
            brightnessNum = floatNum
        }
        
        colorPaletteView.changedSaturationComplete = { [weak self] floatNum in
            guard let self = self else { return }
            saturationNum = floatNum
        }
        
        return colorPaletteView
    }()
    
    lazy var topView: UIView = {
        let view = UIView()
        view.backgroundColor = currentColor
        view.cornerRadius = 22.0
        
        view.addSubview(colorPaletteView)
        colorPaletteView.snp.makeConstraints { make in
            make.leading.equalTo(12)
            make.trailing.equalTo(-12)
            make.height.equalTo(100.0)
            make.bottom.equalTo(-12)
        }

        let fullScreenBtn = UIButton.createButton(image: UIImage(named: "fullScreen"),backgroundColor: UIColor.fromHex("000000", alpha: 0.2),corner: 8.0) { [weak self]  in
            guard let self = self else { return }
            kPresentModalVC(target: self, modelVC: TSFullScreenVC.creatSolidColorVC(color: topView.backgroundColor ?? .white),transitionStyle: .crossDissolve)
        }
        view.addSubview(fullScreenBtn)
        fullScreenBtn.snp.makeConstraints { make in
            make.top.equalTo(16)
            make.trailing.equalTo(-12)
            make.width.height.equalTo(36)
        }
 
        return view
    }()
    
    lazy var toolView: TSLightSolidColorToolView = {
        let toolView = TSLightSolidColorToolView()
        toolView.changedColorComplete = {[weak self] color in
            guard let self = self else { return }
            
            currentColor = color
            
        }
        return toolView
    }()

    override func createView() {
        setNavBarViewHidden(true)
        contentView.addSubview(topView)
        contentView.addSubview(toolView)
        topView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(kLightTop)
            make.bottom.equalTo(-172.0)
        }
        toolView.snp.makeConstraints { make in
            make.leading.equalTo(0)
            make.trailing.equalTo(0)
            make.height.equalTo(128.0)
            make.bottom.equalTo(0)
        }
    }
    
    
    func updateColorView(){
        topView.backgroundColor = currentColor.adjusted(brightness: brightnessNum,saturation: saturationNum)
    }
}

extension TSLightSolidColorVC: JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}
