//
//  TSMirrorVC.swift
//  Girly
//
//  Created by 100Years on 2025/1/7.
//



class TSMirrorVC: TSBaseVC{
    
    let kViewTop:CGFloat = k_Height_StatusBar+47
    
    lazy var brightnessNum:CGFloat =  {
        return 1.0
    }(){
        didSet{
            UIDevice.brightness(brightness: brightnessNum)
        }
    }
    
    lazy var cameraView: TSMirrorCameraView = {
        let cameraView = TSMirrorCameraView()
        return cameraView
    }()
    
    lazy var topView: UIView = {
        let view = UIView()

        view.addSubview(cameraView)
        cameraView.snp.makeConstraints { make in
            make.leading.equalTo(0)
            make.trailing.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
    
        return view
    }()
    
    lazy var toolView: TSMirrorToolView = {
        let toolView = TSMirrorToolView()
        
        toolView.changedBrightnessComplete = { [weak self] floatNum in
            guard let self = self else { return }
            UIDevice.brightness(brightness: floatNum)
        }
        
        toolView.selectedColorComplete = {[weak self] model in
            guard let self = self else { return }
            cameraView.imageNamed = model.shape
        }
        
        return toolView
    }()
    
    override func createView() {
        setNavBarViewHidden(true)
        edgesForExtendedLayout = [.top,.left,.right]
        contentView.addSubview(topView)
        contentView.addSubview(toolView)
        topView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(kViewTop)
            make.bottom.equalTo(-176.0)
        }
        toolView.snp.makeConstraints { make in
            make.leading.equalTo(0)
            make.trailing.equalTo(0)
            make.height.equalTo(116.0)
            make.bottom.equalTo(0)
        }

       
    }
    
    override func dealThings() {
        brightnessNum = 1.0
    }
    
    
    override func viewWillAppear(_ animated: Bool) {
        cameraView.startCapture()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        UIDevice.brightness(brightness: brightnessNum)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        cameraView.endCapture()
    }
}

