//
//  PQStuckPointMusicTagsContentCell.swift
//  PQSpeed
//
//  Created by SanW on 2021/4/29.
//  Copyright © 2021 BytesFlow. All rights reserved.
//

import BFCommonKit
import BFMediaKit
import UIKit

class PQStuckPointMusicTagsContentCell: UICollectionViewCell {
    lazy var titleLab: UILabel = {
        let titleLab = UILabel()
        titleLab.font = UIFont.systemFont(ofSize: 12)
        titleLab.textColor = UIColor.hexColor(hexadecimal: "#959595")
        titleLab.textAlignment = .center
        titleLab.backgroundColor = BFConfig.shared.styleBackGroundColor
        titleLab.addCorner(corner: 4)
        return titleLab
    }()

    @objc class func stuckPointMusicTagsContentCell(collectionView: UICollectionView, indexPath: IndexPath) -> PQStuckPointMusicTagsContentCell {
        let cell: PQStuckPointMusicTagsContentCell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PQStuckPointMusicTagsContentCell.self), for: indexPath) as! PQStuckPointMusicTagsContentCell
        return cell
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(titleLab)
    }

    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    var tagData: PQStuckPointMusicTagsModel? {
        didSet {
            addData()
            addLayout()
        }
    }

    func addData() {
        titleLab.text = "\(tagData?.tagName ?? "")"
        if tagData?.isSelected ?? false {
            titleLab.textColor = UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue)
            titleLab.layer.borderWidth = 0.5
            titleLab.layer.borderColor = UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue).cgColor
        } else {
            titleLab.textColor = UIColor.hexColor(hexadecimal: "#959595")
            titleLab.layer.borderWidth = 0.5
            titleLab.layer.borderColor = UIColor.hexColor(hexadecimal: "#E9E9E9").cgColor
        }
    }

    func addLayout() {
        titleLab.snp.makeConstraints { make in
            make.size.equalToSuperview()
        }
    }
}
