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

import UIKit

class SHInputAudioPlayView: UIView {

    // MARK: - property
    /// 播放/暂停按钮
    var playButton: UIButton!
    
    /// 时长
    var timeLabel: UILabel!
    
    /// 竖线
    var line: UIView!
    
    /// 播放速度按钮
    var speedButton: UIButton!
    
    
    // MARK - func
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor(r: 241, g: 241, b: 241)
        self.layer.masksToBounds = true
        self.layer.cornerRadius = 15
        
        self.addSubviews()
        
        self.setUpSubviewsLocation()
    }
    
    required init?(coder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MAKR: - UI
    func addSubviews()
    {
        // 播放/暂停按钮
        self.playButton = UIButton(type: .custom)
        self.playButton.setImage(UIImage(named: "input_audio_play"), for: .normal)
        self.addSubview(self.playButton)
        
        // 时长
        self.timeLabel = UILabel()
        self.timeLabel.textColor = UIColor(r: 65, g: 131, b: 244)
        self.timeLabel.font = UIFont(name: SHPingFangMedium, size: 14)
        self.addSubview(self.timeLabel)
        
        // 竖线
        self.line = UIView()
        self.line.backgroundColor = UIColor(r: 65, g: 131, b: 244)
        self.addSubview(self.line)
        
        // 播放速度按钮
        self.speedButton = UIButton(type: .system)
        self.speedButton.setTitle("x1", for: .normal)
        self.speedButton.setTitleColor(UIColor(r: 65, g: 131, b: 244), for: .normal)
        self.speedButton.titleLabel?.font = UIFont(name: SHPingFangMedium, size: 14)
        self.addSubview(self.speedButton)
    }
    
    // MARK: 控件位置
    func setUpSubviewsLocation()
    {
        self.playButton.mas_makeConstraints { (make) in
            
            make?.left.mas_equalTo()(9)
            make?.centerY.mas_equalTo()(self)
            make?.size.mas_equalTo()(CGSize(width: 27, height: 30))
            
        }
        
        self.timeLabel.mas_makeConstraints { (make) in
            
            make?.left.equalTo()(self.playButton.mas_right)
            make?.centerY.equalTo()(self)
            
        }
        
        self.line.mas_makeConstraints { (make) in
            
            make?.right.mas_equalTo()(-55)
            make?.centerY.equalTo()(self)
            make?.size.mas_equalTo()(CGSize(width: 1, height: 8))
            
        }
        
        self.speedButton.mas_makeConstraints { (make) in
            
            make?.left.equalTo()(self.line.mas_right)
            make?.right.mas_equalTo()(-9)
            make?.top.bottom()?.mas_equalTo()(0)
            
        }
    }
}
