//
//  ChannelHeaderView.swift
//  SYMobilePortal
//
//  Created by xiejiangbo on 2018/5/8.
//  Copyright © 2018年 yin chen. All rights reserved.
//

import UIKit

class ChannelHeaderView: UICollectionReusableView {
    
    var text: String? {
        didSet {
            label.text = text
//            if text == "我的常用" || text == "我的应用" {
//                print(indexPath!)
//                label.frame = CGRect(x:10, y: 0, width:getTexWidth(textStr: text!, font: UIFont.systemFont(ofSize: 16), height: self.height) , height:self.height )
//                backgroundColor = moreClassColor
//                lineView.isHidden = true
//            }else{
//                addSubview(lineView)
//                lineView.isHidden = false
//                lineView.frame = CGRect(x:label.originX+label.width, y: 0, width:self.width-label.originX+label.width , height:0.5 )
//                lineView.centerY = self.height/2
//            }
//            print(text)
            if self.lineViewShowType {
                label.frame = CGRect(x:10, y: 0, width:getTexWidth(textStr: text!, font: UIFont.test_systemFont(ofSize: 16), height: self.height) , height:self.height )
                backgroundColor = moreClassColor
//                lineView.isHidden = true
            }else{
//                addSubview(lineView)
//                lineView.isHidden = false
                
                label.frame = CGRect(x:10, y: 0, width:getTexWidth(textStr: text!, font: UIFont.test_systemFont(ofSize: 16), height: self.height) , height:self.height )
                retractBtn.frame = CGRect(x:label.originX+label.width + 5, y: 0, width:40 , height:self.height )
//                retractBtn.backgroundColor = UIColor.red
                upDownView.center = retractBtn.center
                lineView.frame = CGRect(x:label.originX+label.width, y: 0, width:self.width-label.originX+label.width , height:0.5 )
                lineView.centerY = self.height/2
            }
        }
    }
    
    var lineViewShowType: Bool!
    var retractUnfoldBlack:passParameterBlock!
    
    var retractUnfoldType:RetractUnfoldType = .Retractype {
        didSet {
            if retractUnfoldType == .Retractype {
//                retractBtn.setTitle("收回", for: .normal)
                upDownView.image = UIImage.init(named: "unfold_image")
            } else {
//                retractBtn.setTitle("展开", for: .normal)
                upDownView.image = UIImage.init(named: "takeBack_image")
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    private func setupUI() {
        addSubview(label)
        addSubview(upDownView)
        addSubview(retractBtn)
        upDownView.center = retractBtn.center
//        self.backgroundColor = UIColor.yellow
        //backgroundColor = UIColor.groupTableViewBackground
        //
    }
    private lazy var lineView: UIImageView = {
        let lineView = UIImageView.init()
        lineView.backgroundColor = blackTitleColor
        lineView.alpha = 0.4
        lineView.isHidden = true
        return lineView
    }()
    private lazy var upDownView: UIImageView = {
        let upDownView = UIImageView.init()
        upDownView.frame = CGRect(x:50, y: 0, width:10 , height:6 )
        upDownView.contentMode = .scaleAspectFit
        upDownView.image = UIImage.init(named: "unfold_image")
        return upDownView
    }()
    private lazy var retractBtn: UIButton = {
        let retractBtn = UIButton.init()
        retractBtn.frame = CGRect(x:50, y: 0, width:40 , height:self.height )
//        retractBtn.backgroundColor = statusBarColor
        retractBtn.setTitleColor(UIColor.white, for: .normal)
        retractBtn.addTarget(self, action: #selector(retractUnfoldBlackActioin), for: .touchUpInside)
        return retractBtn
    }()
    @objc func retractUnfoldBlackActioin() {
        self.retractUnfoldBlack(self.retractUnfoldType)
    }
    private lazy var label: UILabel = {
        let label = UILabel(frame: CGRect(x:10, y: 0, width:45 , height:self.height ))
        //label.frame.origin.x = 20
        label.textColor = UIColorFromRGB(rgbValue: 0x9DA2A9)
        label.font = UIFont.test_systemFont(ofSize: 14.93)
//        label.font = UIFont.boldSystemFont(ofSize: 13)
        //label.font = UIFont.init(name: "Arial Rounded MT Bold", size: 13)
        return label
    }()
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
