//
//  GMFaceSkinFrontView.swift
//  Gengmei
//
//  Created by 刘鹿杰 on 2019/11/8.
//  Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//

import Foundation

import GMBaseSwift

class GMFaceSkinFrontView : GMView {
    
    let margin = (Constant.screenHeight - (OCNavigationBar.barHeight + UIView.safeAreaInsetsBottom + Constant.screenWidth + 235)) / 2
    let viewMaxHeight = Constant.screenHeight - 167 - 120 - OCNavigationBar.barHeight + UIView.safeAreaInsetsBottom
    override func setup() {
        super.setup()
        self.backgroundColor = UIColor.clear
       
        let hudView = GMView()
        hudView.backgroundColor = UIColor.clear
        self.addSubview(hudView)
        hudView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        // 添加顶部View
        self.addSubview(topView)
        topView.snp.makeConstraints { (make) in
            make.top.equalTo(OCNavigationBar.barHeight + 10)
            make.right.equalTo(-16)
            make.left.equalTo(16)
            make.height.equalTo(30)
        }
        self.addSubview(noticeLabel)
        noticeLabel.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 300, height: 35))
            make.bottom.equalToSuperview().offset(-187 - UIView.safeAreaInsetsBottom)
            make.centerX.equalTo(self)
        }
         let minMargin = margin < 10 ? 10 : margin
        // 添加图片
        let lefticon = UIImageView(image: UIImage(named: "face_skin_front_lefticon"))
        self.addSubview(lefticon)
        lefticon.snp.makeConstraints { (make) in
            make.top.equalTo(topView.snp.bottom).offset(minMargin)
            make.left.equalTo(16)
            make.height.equalTo(67)
        }
        
        let righticon = UIImageView(image: UIImage(named: "face_skin_front_righticon"))
        self.addSubview(righticon)
        righticon.snp.makeConstraints { (make) in
            make.height.equalTo(77)
            make.right.equalTo(-16)
            make.bottom.equalTo(noticeLabel.snp.top).offset(-minMargin)
        }
        let frontImage = UIImageView(image: UIImage(named: "face_skin_front_image"))
        self.addSubview(frontImage)
        let frontImageHeight = (viewMaxHeight < Constant.screenWidth - 32 ) ? viewMaxHeight : Constant.screenWidth - 32
        frontImage.snp.makeConstraints { (make) in
            make.top.equalTo(topView.snp.bottom).offset(minMargin)
            make.width.height.equalTo(frontImageHeight)
            make.centerX.equalToSuperview()
        }
        
        self.addSubview(closeEyeLabel)
        closeEyeLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(frontImage.snp.centerX)
            make.centerY.equalTo(frontImage.snp.centerY).offset(-60)
        }
    }
    
    lazy var flashLaber : GMLabel = {
        let flashLaber = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: UIColor(hex: 0xD8D8D8).alpha(1.0), fontSize: 12)
        flashLaber.text = "闪光灯【已开启】"
        flashLaber.layer.shadowColor = UIColor.black.cgColor
        flashLaber.layer.shadowOpacity = 0.1
        flashLaber.layer.shadowRadius = 5
        return flashLaber
    }()
    
    lazy var middleLabel : GMLabel = {
        let middleLabel = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: UIColor(hex: 0xD8D8D8).alpha(1.0), fontSize: 12)
        middleLabel.text = "直视摄像头"
        middleLabel.layer.shadowColor = UIColor.black.cgColor
        middleLabel.layer.shadowOpacity = 0.1
        middleLabel.layer.shadowRadius = 5
        return middleLabel
    }()
    
    lazy var facePlaceLabel : GMLabel = {
        let facePlaceLabel = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: UIColor(hex: 0xD8D8D8), fontSize: 12)
        facePlaceLabel.text = "脸部位置"
        facePlaceLabel.layer.shadowColor = UIColor.black.cgColor
        facePlaceLabel.layer.shadowOpacity = 0.1
        facePlaceLabel.layer.shadowRadius = 5
        return facePlaceLabel
    }()
    
    lazy var tipsLaber : GMLabel = {
        let tipsLaber = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: UIColor(hex: 0xD8D8D8), fontSize: 12)
        tipsLaber.text = "【近一点】"
        tipsLaber.layer.shadowColor = UIColor.black.cgColor
        tipsLaber.layer.shadowOpacity = 0.1
        tipsLaber.layer.shadowRadius = 5
        return tipsLaber
    }()
    
    lazy var closeEyeLabel : GMLabel = {
        let closeEyeLabel = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: UIColor(hex: 0xD8D8D8), fontSize: 18)
        closeEyeLabel.text = "请闭眼"
        closeEyeLabel.isHidden = true
        closeEyeLabel.layer.shadowColor = UIColor(hex: 0x50D7E7).cgColor
        closeEyeLabel.layer.shadowOpacity = 0.1
        closeEyeLabel.layer.shadowRadius = 5
        return closeEyeLabel
    }()
    
    lazy var topView: GMView = {
        let topView = GMView()
        topView.backgroundColor = UIColor.clear
        topView.addSubview(flashLaber)  // 闪光灯
        topView.addSubview(middleLabel) // 直视摄像头
        topView.addSubview(tipsLaber)  // 【近一点】【远一点】【良好】
        topView.addSubview(facePlaceLabel) // 脸部位置
        flashLaber.snp.makeConstraints({ (make) in
            make.centerY.equalTo(topView.snp.centerY)
            make.left.equalTo(0)
        });
        middleLabel.snp.makeConstraints({ (make) in
            make.centerY.equalTo(topView.snp.centerY)
            make.centerX.equalTo(topView.snp.centerX)
        });
        tipsLaber.snp.makeConstraints({ (make) in
            make.centerY.equalTo(topView.snp.centerY)
            make.right.equalTo(0)
            make.width.equalTo(75)
        });
        facePlaceLabel.snp.makeConstraints({ (make) in
            make.centerY.equalTo(topView.snp.centerY)
            make.right.equalTo(-75)
        });
        return topView
    }()

    // 懒加载 懒加载说明文字
    lazy var noticeLabel: GMLabel = {
        let noticeLabel = GMLabel(textAlignment: .left, backgroundColor: .clear, textColor: .white, fontSize: 14)
        let text = "   · 摘下眼镜，平视摄像头，寻找合适的距离\n"
        let attributedStr = NSMutableAttributedString(string: text)
        let style = NSMutableParagraphStyle()
        style.lineSpacing = 1
        attributedStr.addAttribute(NSAttributedString.Key.paragraphStyle, value: style, range: NSMakeRange(0, attributedStr.length))
        noticeLabel.attributedText = attributedStr
        noticeLabel.verticalAlignment = .middle
        noticeLabel.layer.shadowColor = UIColor.black.cgColor
        noticeLabel.layer.shadowOpacity = 0.1
        noticeLabel.layer.shadowRadius = 5
        noticeLabel.layer.cornerRadius = 4;
        noticeLabel.layer.masksToBounds = true
        noticeLabel.numberOfLines = 0;
        noticeLabel.backgroundColor = UIColor(hex: 0, alpha: 0.25)
        return noticeLabel
    }()
    
}
