//
//  TagLabel.swift

//
//  Created by Leon on 2025/7/22.
//

import UIKit

enum RoleTagStyle{
    case `default`
    case purple
    case theme
    case blurPurple
    case blurTheme
}

/// 角色的Character Code、设定展示用
class RoleTag: UIView{

    var label:UILabel!

    var title: String = ""{
        didSet{
            refreshViews()
        }
    }

    var style: RoleTagStyle = .purple{
        didSet{
            refreshViews()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews(){
        layer.cornerRadius = 4
        layer.masksToBounds = true

        self.snp.makeConstraints { make in
            make.height.equalTo(24)
        }

        label = {
            let view = UILabel()
            view.font = .t.tls
            view.textColor = .c.ctpn
            addSubview(view)
            view.snp.makeConstraints { make in
                make.centerY.equalToSuperview()
                make.leading.equalToSuperview().offset(6)
                make.trailing.equalToSuperview().offset(-6)
            }
            return view
        }()
    }

    private func refreshViews(){
        label.text = title
        switch style{
        case .default:
            backgroundColor = .c.csen
        case .purple:
            backgroundColor = UIColor(red: 0.48, green: 0.28, blue: 1, alpha: 1)
        case .theme:
            backgroundColor = UIColor(red: 0.82, green: 0.12, blue: 0.47, alpha: 1)
        case .blurPurple:
            backgroundColor = UIColor(red: 0.48, green: 0.28, blue: 1, alpha: 0.45)
        case .blurTheme:
            backgroundColor = UIColor(red: 0.82, green: 0.12, blue: 0.47, alpha: 0.45)
        }
    }
    
    
}
