//
//  DayTimePrecipitationView.swift
//  1Weather
//
//  Created by Dmitry Stepanets on 18.03.2021.
//

import UIKit

class DayTimePrecipitationView: UIView {
    //Private
    private let dayTimeLabel = UILabel()
    private let precipitationView = PrecipitationView()
    private let valueLabel = UILabel()
    
    init(withSeparator:Bool = false) {
        super.init(frame: .zero)
        
        prepareView()
        prepareLabels()
        preparePrecipView()
        
        if withSeparator {
            prepareSeparator()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

private extension DayTimePrecipitationView {
    func prepareView() {
        self.snp.makeConstraints { (make) in
            make.width.equalTo(90)
        }
    }
    
    func prepareLabels() {
        dayTimeLabel.font = AppFont.SFPro.bold(size: 14)
        dayTimeLabel.textColor = ThemeManager.currentTheme.secondaryTextColor
        addSubview(dayTimeLabel)
        
        valueLabel.font = AppFont.SFPro.bold(size: 12)
        valueLabel.textColor = ThemeManager.currentTheme.secondaryTextColor
        addSubview(valueLabel)
        
        //Constraints
        dayTimeLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().inset(24)
            make.centerX.equalToSuperview()
        }
        
        valueLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().inset(18)
        }
    }
    
    func preparePrecipView() {
        addSubview(precipitationView)
        precipitationView.snp.makeConstraints { (make) in
            make.top.equalTo(dayTimeLabel.snp.bottom).offset(24).priority(.medium)
            make.bottom.equalTo(valueLabel.snp.top).offset(-20)
            make.width.equalTo(24)
            make.centerX.equalToSuperview()
            make.height.equalTo(130)
        }
    }
    
    func prepareSeparator() {
        let separatorView = UIView()
        separatorView.backgroundColor = UIColor(hex: 0xc2c9d6)
        separatorView.alpha = 0.5
        addSubview(separatorView)
        
        separatorView.snp.makeConstraints { (make) in
            make.top.equalTo(dayTimeLabel)
            make.bottom.equalTo(precipitationView)
            make.right.equalToSuperview()
            make.width.equalTo(1)
        }
    }
}
