//
//  TSFlashVC.swift
//  Girly
//
//  Created by 100Years on 2025/1/7.
//
class TSFlashVC: TSBaseVC{
    
    lazy var navBarView: TSBaseNavContentBarView = {
        let navBarView = TSBaseNavContentBarView()
        let titleImageView = UIImageView.createImageView(imageName: "nav_title_flash",contentMode: .scaleToFill)
        
        navBarView.barView.addSubview(titleImageView)
        titleImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(16)
        }
        return navBarView
    }()
    
    lazy var simpleTableView:TSSimpleTableView = {
        let simpleTableView = TSSimpleTableView()
        simpleTableView.tableView.contentInset =  UIEdgeInsets( top: 0,left: 0,bottom: 0,right: 0)
        simpleTableView.reuseClass = ["TSFlashCell"]
        simpleTableView.dataArray = dataArray
        return simpleTableView
    }()
    
    lazy var dataArray:[TSBasicSectionModel] = {
        let cellH:CGFloat = 164.0*kDesignScale
        var dataArray = [TSBasicSectionModel]()
        let sectionModel = TSBasicSectionModel()
        dataArray.append(sectionModel)
        
        sectionModel.addSubItemModel(
            createItemModel(
            leftImageName: "light_warning",
            height: cellH,
            rectCorner:.allCorners,
            tapBlock: {[weak self] itemModel, index, view  in
                guard let self = self else { return }
                kPushVC(target: self,modelVC:TSWarningLightVC())
            }))
        
        sectionModel.addSubItemModel(
            createItemModel(
            leftImageName: "light_night",
            height: cellH,
            rectCorner:.allCorners,
            tapBlock: {[weak self] itemModel, index, view  in
                guard let self = self else { return }
                kPushVC(target: self,modelVC:TSNightLightVC())
            }))
        
        sectionModel.addSubItemModel(
            createItemModel(
            leftImageName: "light_disco",
            height: cellH,
            rectCorner:.allCorners,
            tapBlock: {[weak self] itemModel, index, view  in
                guard let self = self else { return }
                kPushVC(target: self,modelVC:TSDiscoLightVC())
            }))
        
//        sectionModel.addSubItemModel(
//            createItemModel(
//            leftImageName: "light_flash",
//            height: cellH,
//            rectCorner:.allCorners,
//            tapBlock: {[weak self] itemModel, index, view  in
//                guard let self = self else { return }
//                kPushVC(target: self,modelVC:TSFlashLightVC())
//            }))
        
        sectionModel.addSubItemModel(
            createItemModel(
            leftImageName: "light_sos",
            height: cellH,
            rectCorner:.allCorners,
            tapBlock: {[weak self] itemModel, index, view  in
                guard let self = self else { return }
                kPushVC(target: self,modelVC:TSSOSLigntVC())
            }))
        
        return dataArray
        
        
        
        
    }()
    
    override func createView() {
        edgesForExtendedLayout = [.top,.left,.right]
        navBarContentView.addSubview(navBarView)
        navBarView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        contentView.addSubview(simpleTableView.tableView)
        simpleTableView.tableView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.equalTo(12)
            make.bottom.equalTo(0)
        }
    }
    
    func createItemModel(leftImageName: String,
                            height: CGFloat,
                        rectCorner: UIRectCorner,
                          tapBlock: @escaping ((TSBasicItemModel, Int, Any?) -> Void)) -> TSBasicItemModel {
        let model = TSBasicItemModel()
        model.leftImageName = leftImageName
        model.height = height
        model.rectCorner = rectCorner
        model.tapBlock = tapBlock
        return model
    }
}



class TSFlashCell: TSSimpleTableViewCell {

    override var itemModel: TSBasicItemModel{
        didSet{
            if let leftImageName  = itemModel.leftImageName {
                bgImageView.image = UIImage(named: leftImageName)
            }
        }
    }
    
    let bgImageView = UIImageView()
    
    override func creatUI() {
    
        bgContentView.snp.updateConstraints { make in
            make.bottom.equalTo(-24)
        }
        bgImageView.contentMode = .scaleToFill
        bgContentView.addSubview(bgImageView)
        bgImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}
