//
//  SHInputBottomView.swift
//  ShorthandMaster
//
//  Created by 张哲 on 2020/9/24.
//  Copyright © 2020 明津李. All rights reserved.
//

import UIKit

class SHInputBottomView: UIView {
    
    // MARK: - property
    /// 背景
    var bgView : UIView!
    /// 选择图片按钮
    var imageButton : UIButton!
    
    
    /// 录音按钮背景
    var audioBgView : UIView!
    
    /// 录制时间背景
    var audioTimeBgView : UIView!
    /// 录制时间小红点
    var audioTimePointView : UIView!
    /// 录制时间
    var audioTimeLabel : UIView!
    
    /// 添加录音按钮
    var addAudioButton : SHInputAudioButton!
    /// 暂停录音按钮
    var pauseAudioButton : SHInputAudioButton!
    /// 继续录音按钮
    var goOnAudioButton : SHInputAudioButton!
    /// 结束录音按钮
    var stopAudioButton : SHInputAudioButton!
    
    
    /// 键盘按钮
    var keyboardButton : UIButton!
    /// 箭头图片
    var directionImageView : UIImageView!
    

    // MARK: - func
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        
        self.addSubviews()
        
        self.setUpSubviewsLocation()
    }
    
    required init?(coder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MAKR: - UI
    func addSubviews()
    {
        // 背景
        self.bgView = UIView()
        self.bgView.backgroundColor = UIColor(r: 249, g: 249, b: 249)
        self.addSubview(self.bgView)
        
        // 选择图片按钮
        self.imageButton = UIButton(type: UIButton.ButtonType.custom)
        self.imageButton.setImage(UIImage(named: "input_image"), for: UIControl.State.normal)
        self.bgView.addSubview(self.imageButton)
        
        // 录音按钮背景
        self.audioBgView = UIView()
        self.bgView.addSubview(self.audioBgView)
        
        // 录制时间背景
        self.audioTimeBgView = UIView()
        self.audioTimeBgView.backgroundColor = UIColor(r: 241, g: 241, b: 241)
        self.audioTimeBgView.layer.masksToBounds = true
        self.bgView.addSubview(self.audioTimeBgView)
        
        // 录制时间小红点
        // 录制时间
        
        // 添加录音按钮
        self.addAudioButton = SHInputAudioButton(type: UIButton.ButtonType.custom)
        self.addAudioButton.layer.cornerRadius = 15
        self.addAudioButton.backgroundColor = UIColor(r: 250, g: 219, b: 219)
        self.addAudioButton.leftImageView.image = UIImage(named: "input_addAudio")
        self.addAudioButton.rightLabel.text = "添加录音"
        self.addAudioButton.rightLabel.textColor = UIColor(r: 244, g: 65, b: 65)
        self.audioBgView.addSubview(self.addAudioButton)
        
        // 暂停录音按钮
        self.pauseAudioButton = SHInputAudioButton(type: UIButton.ButtonType.custom)
        self.pauseAudioButton.layer.cornerRadius = 15
        self.pauseAudioButton.backgroundColor = UIColor(r: 219, g: 231, b: 250)
        self.pauseAudioButton.leftImageView.image = UIImage(named: "input_pause")
        self.pauseAudioButton.rightLabel.text = "暂停"
        self.pauseAudioButton.rightLabel.textColor = UIColor(r: 65, g: 131, b: 244)
        self.audioBgView.addSubview(self.pauseAudioButton)
        self.pauseAudioButton.isHidden = true
        
        // 继续录音按钮
        self.goOnAudioButton = SHInputAudioButton(type: UIButton.ButtonType.custom)
        self.goOnAudioButton.layer.cornerRadius = 15
        self.goOnAudioButton.backgroundColor = UIColor(r: 250, g: 234, b: 219)
        self.goOnAudioButton.leftImageView.image = UIImage(named: "input_goOn")
        self.goOnAudioButton.rightLabel.text = "继续"
        self.goOnAudioButton.rightLabel.textColor = UIColor(r: 244, g: 119, b: 65)
        self.audioBgView.addSubview(self.goOnAudioButton)
        self.goOnAudioButton.isHidden = true
        
        // 结束录音按钮
        self.stopAudioButton = SHInputAudioButton(type: UIButton.ButtonType.custom)
        self.stopAudioButton.layer.cornerRadius = 15
        self.stopAudioButton.backgroundColor = UIColor(r: 250, g: 219, b: 219)
        self.stopAudioButton.leftImageView.image = UIImage(named: "input_stop")
        self.stopAudioButton.rightLabel.text = "结束录制"
        self.stopAudioButton.rightLabel.textColor = UIColor(r: 244, g: 65, b: 65)
        self.audioBgView.addSubview(self.stopAudioButton)
        self.stopAudioButton.isHidden = true
        
        // 键盘按钮
        self.keyboardButton = UIButton(type: UIButton.ButtonType.custom)
        self.keyboardButton.setImage(UIImage(named: "input_keyboard"), for: UIControl.State.normal)
        self.bgView.addSubview(self.keyboardButton)
        
        // 箭头图片
        self.directionImageView = UIImageView()
        self.directionImageView.image = UIImage(named: "input_down")
        self.bgView.addSubview(self.directionImageView)
    }
    
    // MARK: 控件位置
    func setUpSubviewsLocation()
    {
        self.bgView.mas_makeConstraints { (make) in
            
            make?.top.left()?.right()?.mas_equalTo()(0)
            make?.bottom.mas_equalTo()(-SafeAreaBottomHeight())
            
        }
        
        self.imageButton.mas_makeConstraints { (make) in
            
            make?.top.bottom()?.mas_equalTo()(0)
            make?.left.mas_equalTo()(39 - 11)
            make?.width.height()?.mas_equalTo()(self.bgView.mas_height)
            
        }
        
        self.audioBgView.mas_makeConstraints { (make) in
            
            make?.center.equalTo()(self.bgView)
            make?.size.mas_equalTo()(CGSize(width: 72 + 18 + 100, height: 50))
            
        }
        
        self.addAudioButton.mas_makeConstraints { (make) in
            
            make?.center.equalTo()(self.audioBgView)
            make?.size.mas_equalTo()(CGSize(width: 100, height: 30))
            
        }
        
        self.pauseAudioButton.mas_makeConstraints { (make) in
            
            make?.left.mas_equalTo()(0)
            make?.centerY.equalTo()(self.audioBgView)
            make?.size.mas_equalTo()(CGSize(width: 72, height: 30))
            
        }
        
        self.goOnAudioButton.mas_makeConstraints { (make) in
            
            make?.top.left()?.bottom()?.right()?.equalTo()(self.pauseAudioButton)
            
        }
        
        self.stopAudioButton.mas_makeConstraints { (make) in
            
            make?.left.equalTo()(self.pauseAudioButton.mas_right)?.offset()(18)
            make?.right.mas_equalTo()(0)
            make?.centerY.equalTo()(self.audioBgView)
            make?.size.mas_equalTo()(CGSize(width: 100, height: 30))
            
        }
        
        self.keyboardButton.mas_makeConstraints { (make) in
            
            make?.top.bottom()?.mas_equalTo()(0)
            make?.right.mas_equalTo()(11 - 40)
            make?.size.equalTo()(self.imageButton)
            
        }
        
        self.directionImageView.mas_makeConstraints { (make) in
            
            make?.centerY.equalTo()(self.bgView)
            make?.width.height()?.mas_equalTo()(16)
            make?.right.mas_equalTo()(-20)
            
        }
    }
}
