//
//  AppUpdateView.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/21.
//

import Foundation
import DDControlsKit_Private
import SnapKit
import DDAutoUIKit_Private

open class AppUpdateView : DDView {
    private let radiusView : DDView
    private let scrollView : DDScrollView
    private let scrollContentView : DDView
    public let contentLabel : DDLabel
    public let horizontalLine : DDView
    public let verticalLine : DDView
    public let ignoreButton : DDButton
    public let updateButton : DDButton
    public override init(frame: CGRect) {
        radiusView = DDView.init()
        scrollView = DDScrollView()
        scrollContentView = DDView.init()
        contentLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(14)), textColor: .black.alpha(0.5))
        horizontalLine = DDView()
        verticalLine = DDView()
        ignoreButton = DDButton.dd_initCustom()
        updateButton = DDButton.dd_initCustom()
        super.init(frame: frame)
        radiusView.layer.cornerRadius = auto(10)
        radiusView.layer.masksToBounds = true
        addSubview(radiusView)
        radiusView.addSubview(scrollView)
        scrollView.addSubview(scrollContentView)
        contentLabel.numberOfLines = 0
        scrollContentView.addSubview(contentLabel)
        horizontalLine.backgroundColor = .hex("979797").alpha(0.35)
        radiusView.addSubview(horizontalLine)
        verticalLine.backgroundColor = .hex("979797").alpha(0.35)
        verticalLine.isHidden = true
        radiusView.addSubview(verticalLine)
        ignoreButton.setTitle("忽略", for: .normal)
        ignoreButton.titleLabel?.font = .mediumFont(auto(14))
        ignoreButton.backgroundColor = .white
        ignoreButton.setTitleColor(.black.alpha(0.3), for: .normal)
        radiusView.addSubview(ignoreButton)
        updateButton.setTitle("更新", for: .normal)
        updateButton.setTitleColor(.white, for: .normal)
        updateButton.titleLabel?.font = .mediumFont(auto(14))
        updateButton.backgroundColor = .hex("1C62D9")
        radiusView.addSubview(updateButton)
        
        radiusView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        scrollView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(horizontalLine.snp.top)
        }
        
        scrollContentView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalToSuperview()
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(auto(20))
            make.top.equalToSuperview().offset(auto(20))
            make.right.equalTo(-auto(20))
            make.bottom.equalTo(scrollContentView).offset(-auto(20))
        }
        
        horizontalLine.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-auto(40))
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        
        verticalLine.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(horizontalLine.snp.bottom)
            make.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
        
        ignoreButton.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.right.equalTo(verticalLine.snp.left)
            make.top.equalTo(horizontalLine.snp.bottom)
            make.bottom.equalToSuperview()
        }
        
        updateButton.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.right.equalToSuperview()
            make.top.equalTo(horizontalLine.snp.top)
            make.left.equalTo(verticalLine.snp.right)
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func isForce(isForce:Bool) {
        if isForce == true {
            updateButton.snp.remakeConstraints { make in
                make.bottom.equalToSuperview()
                make.right.equalToSuperview()
                make.top.equalTo(horizontalLine.snp.top)
                make.left.equalToSuperview()
            }
        }else{
            updateButton.snp.remakeConstraints { make in
                make.bottom.equalToSuperview()
                make.right.equalToSuperview()
                make.top.equalTo(horizontalLine.snp.top)
                make.left.equalTo(verticalLine.snp.right)
            }
        }
    }
}
