//
//  RibbonItemView.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/3.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

class RibbonItemView: UIView {
    
    var title:String? {
        didSet {
            self.label.text = title
        }
    }
    var imageName:String?{
        didSet {
            self.ribbonItemImageView.image = UIImage.init(named: imageName!)
        }
    }
    var biaojiNum:String?{
        didSet {
            if biaojiNum == nil || biaojiNum?.count == 0 || biaojiNum == "0"{
                baojiBtn.isHidden = true
            }else{
                baojiBtn.isHidden = false
                baojiBtn.setTitle(biaojiNum, for: .normal)
            }
        }
    }
    var block:selectBlock!
    
    var quickApplicationType:QuickApplicationType = .AddressBook
    
    lazy var label: UILabel = {
        let label = UILabel.init()
        label.font = UIFont.test_systemFont(ofSize: 11.33)
//        label.textColor = blackTitleColor
        label.textColor = UIColorFromRGB(rgbValue: 0x23262A)
        label.textAlignment = .center
        addSubview(label)
        return label
    }()
    
    lazy var ribbonItemImageView:UIImageView = {
        let ribbonItemImageView = UIImageView.init()
        self .addSubview(ribbonItemImageView)
        return ribbonItemImageView
    }()
    lazy var actionBtn : UIButton = {
        let actionBtn = UIButton.init(type: .custom)
        actionBtn.addTarget(self, action: #selector(actionBtnAction), for: .touchUpInside)
//        actionBtn.backgroundColor = UIColor.red
        self.addSubview(actionBtn)
        return actionBtn
    }()
    lazy var baojiBtn: UIButton = {
        let baojiBtn = UIButton.init(type: .custom)
        baojiBtn.setTitleColor(UIColor.white, for: .normal)
        baojiBtn.titleLabel?.font = UIFont.test_systemFont(ofSize: 10)
        baojiBtn.setBackgroundImage(UIImage.init(named: "biaoji_image"), for: .normal)
        baojiBtn.isHidden = true
        self.addSubview(baojiBtn)
        return baojiBtn
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.ribbonItemImageView.frame = CGRect(x:15, y: 0, width:33.33*WHIDTH_RATIO() , height:33.33*WHIDTH_RATIO() )
        self.ribbonItemImageView.centerX = frame.width/2
        self.label.frame = CGRect(x:0, y: self.ribbonItemImageView.height+8, width:frame.size.width , height:11 )
        let baojiBtnWidth:CGFloat = 21*WHIDTH_RATIO()
        baojiBtn.frame = CGRect(x:self.ribbonItemImageView.originX+self.ribbonItemImageView.width-10, y: self.ribbonItemImageView.originY/2-5, width:baojiBtnWidth , height:baojiBtnWidth)
        
//        self.actionBtn.frame = CGRect(x:0, y: 0, width:self.width , height:self.height )
        self.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(actionBtnAction)))
    }
    
    @objc func actionBtnAction() {
        self.block()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
