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

import UIKit

class RibbonView: UIView {

    lazy var backgroundView:UIImageView = {
        let backgroundView = UIImageView.init()
        backgroundView.image = UIImage.init(named: "ribbon_image")
        backgroundView.contentMode = .scaleToFill
        backgroundView.isUserInteractionEnabled = true
        self .addSubview(backgroundView)
        return backgroundView
    }()
    /// 通讯录
    lazy var addressBookView:RibbonItemView = {
        let addressBookView = RibbonItemView.init(frame: CGRect(x:22, y:30, width:rubbonItemViewW , height:frame.height))
        addressBookView.quickApplicationType = .AddressBook
        self .addSubview(addressBookView)
        return addressBookView
    }()
    /// 我的新闻
    lazy var newsView:RibbonItemView = {
        let newsView = RibbonItemView.init(frame: CGRect(x:22+rubbonItemViewW, y:30, width:rubbonItemViewW , height:frame.height))
        newsView.quickApplicationType = .MyNews
        self .addSubview(newsView)
        return newsView
    }()
    /// 我的待办
    lazy var todoView:RibbonItemView = {
        let todoView = RibbonItemView.init(frame: CGRect(x:22+rubbonItemViewW*2, y:30, width:rubbonItemViewW , height:frame.height))
        todoView.quickApplicationType = .MyToDo
        self .addSubview(todoView)
        return todoView
    }()
    /// 我的已办
    lazy var doneView:RibbonItemView = {
        let doneView = RibbonItemView.init(frame: CGRect(x:22+rubbonItemViewW*3, y:30, width:rubbonItemViewW , height:frame.height))
        doneView.quickApplicationType = .MyDone
        self .addSubview(doneView)
        return doneView
    }()
    let rubbonItemViewW:CGFloat = (SCREEN_WHIDTH()-44)/4
    override init(frame: CGRect) {
        super.init(frame: frame)
//        self.backgroundColor = UIColor.red
        self.backgroundView.frame = CGRect(x:0, y:0, width:SCREEN_WHIDTH() , height:frame.height)
    }
    func updatePageData(modelArray:NSMutableArray){
        for index in 0..<modelArray.count {
            let itemModel = modelArray[index] as! MineHeadTableViewCellRibbonModel
            if itemModel.quickApplicationType == .AddressBook {
                self.updateRibbonItemView(itemModel: itemModel, rubbonItemView: addressBookView)
            } else if itemModel.quickApplicationType == .MyDone {
                self.updateRibbonItemView(itemModel: itemModel, rubbonItemView: doneView)
            } else if itemModel.quickApplicationType == .MyToDo {
                self.updateRibbonItemView(itemModel: itemModel, rubbonItemView: todoView)
            } else if itemModel.quickApplicationType == .MyNews {
                self.updateRibbonItemView(itemModel: itemModel, rubbonItemView: newsView)
            }
        }
    }
    func updateRibbonItemView(itemModel:MineHeadTableViewCellRibbonModel,rubbonItemView:RibbonItemView) {
        rubbonItemView.title = itemModel.titleStr
        rubbonItemView.imageName = itemModel.imageName
        rubbonItemView.biaojiNum = itemModel.biaojiNum
        rubbonItemView.block = itemModel.block
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
