//
//  VehicleMonitoringConfigView.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/12/27.
//

import Foundation
import DDControlsKit_Private
import DDAutoUIKit_Private
import SnapKit

open class VehicleMonitoringConfigView : DDView {
    public var optionsRadiusView : DDView
    public var vehicleLogoutItem : VMCItemView
    public var vehicleVideoItem : VMCItemView
    public var cancelView : VMCCancelView
    public var logoutGes = UITapGestureRecognizer()
    public var videoGes = UITapGestureRecognizer()
    public var cancelGes = UITapGestureRecognizer()

    public override init(frame: CGRect) {
        optionsRadiusView = DDView()
        vehicleLogoutItem = VMCItemView()
        vehicleVideoItem = VMCItemView()
        cancelView = VMCCancelView()
        super.init(frame: frame)
        
        optionsRadiusView.layer.cornerRadius = auto(10)
        optionsRadiusView.layer.masksToBounds = true
        optionsRadiusView.backgroundColor = .white
        addSubview(optionsRadiusView)
        vehicleLogoutItem.titleLabel.text = "车辆退出"
        vehicleLogoutItem.icon.image = UIImage(named: "vehicleMonitor_logout_icon")
        vehicleLogoutItem.addGestureRecognizer(logoutGes)
        optionsRadiusView.addSubview(vehicleLogoutItem)
        vehicleVideoItem.titleLabel.text = "车辆监控"
        vehicleVideoItem.icon.image = UIImage(named: "vehicleMonitor_video_icon")
        vehicleVideoItem.addGestureRecognizer(videoGes)
        optionsRadiusView.addSubview(vehicleVideoItem)
    
        cancelView.layer.cornerRadius = auto(10)
        cancelView.backgroundColor = .white
        cancelView.titleLabel.text = "取消"
        cancelView.addGestureRecognizer(cancelGes)
        addSubview(cancelView)
        
        cancelView.snp.makeConstraints { make in
            make.bottom.equalTo(-auto(20))
            make.left.right.equalToSuperview().inset(auto(10))
            make.height.equalTo(auto(60))
        }
        
        optionsRadiusView.snp.makeConstraints { make in
            make.bottom.equalTo(cancelView.snp.top).offset(-auto(10))
            make.left.right.equalTo(cancelView)
            make.height.equalTo(auto(120))
        }
        
        vehicleLogoutItem.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(auto(60))
        }
        
        vehicleVideoItem.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(auto(60))
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func showMonitoring(_ isShow: Bool) {
        if isShow == true {
            optionsRadiusView.snp.updateConstraints { make in
                make.height.equalTo(auto(120))
            }
            
            vehicleLogoutItem.snp.updateConstraints { make in
                make.height.equalTo(auto(60))
            }
            
            vehicleVideoItem.isHidden = false
            vehicleVideoItem.snp.updateConstraints { make in
                make.height.equalTo(auto(60))
            }
        }else{
            optionsRadiusView.snp.updateConstraints { make in
                make.height.equalTo(auto(60))
            }
            
            vehicleLogoutItem.snp.updateConstraints { make in
                make.height.equalTo(auto(60))
            }
            
            vehicleVideoItem.isHidden = true
            vehicleVideoItem.snp.updateConstraints { make in
                make.height.equalTo(0)
            }
        }
    }
}
 
open class VMCItemView : DDView {
    public let titleLabel : DDLabel
    public let icon : DDImageView
    public let line : DDView
    public override init(frame: CGRect) {
        titleLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(16)), textColor: .hex("0B0B0B"))
        icon = DDImageView()
        line = DDView()
        super.init(frame: frame)
        addSubview(titleLabel)
        addSubview(icon)
        line.backgroundColor = .hex("F1F2F5")
        addSubview(line)
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(auto(20))
        }
        
        icon.snp.makeConstraints { make in
            make.right.equalTo(-auto(20))
            make.centerY.equalToSuperview()
        }
        
        line.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview().inset(auto(10))
            make.height.equalTo(1)
        }
    }
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

open class VMCCancelView : DDView {
    public let titleLabel : DDLabel
    public override init(frame: CGRect) {
        titleLabel = DDLabel.dd_init(withText: "取消", font: .mediumFont(auto(18)), textColor: .hex("0B0B0B"))
        super.init(frame: frame)
        addSubview(titleLabel)
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.centerY.equalToSuperview()
        }
    }
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
