//
//  StyleButtonExt.swift

//
//  Created by Leon on 2025/8/26.
//

extension StyleButton{
    /// Coin : price * 100
    static func getUnlockAttributeTitleByCoin(coin: Int, string: String = "") -> NSAttributedString {
        let coin = Coin(cents: coin)
        
        let text = " \(coin.thousandthsFormatted) \(string)"
        let attributedString = NSMutableAttributedString()
        if let iconImage = UIImage(named: "icon_32_diamond") { // 替换为你的图标名称
            let attachment = NSTextAttachment()
            attachment.image = iconImage

            let iconSize = CGSize(width: 24, height: 24) // 调整为你需要的大小
            attachment.bounds = CGRect(origin: .init(x: 0, y: -4), size: iconSize)

            let iconAttributedString = NSAttributedString(attachment: attachment)
            attributedString.append(iconAttributedString)
        }

        // 添加文字并设置样式
        let textAttributedString = text.withAttributes([
            .font(.t.tll), // 设置字体
            .textColor(.white),
        ])
        attributedString.append(textAttributedString)
        return attributedString
    }
    
    /// 黑色vip + 文字 AttributeString
    static func getVIPBlackTitleByWords(words: String) -> NSAttributedString {
        
//        let text = " \(words)"
//        let attributedString = NSMutableAttributedString()
//        if let iconImage = MWIconFont.image(fromIcon: .iconVip, size: CGSize(width: 24, height: 24), color: .black) { // 替换为你的图标名称
//            let attachment = NSTextAttachment()
//            attachment.image = iconImage
//
//            let iconSize = CGSize(width: 24, height: 24) // 调整为你需要的大小
//            attachment.bounds = CGRect(origin: .init(x: 0, y: -4), size: iconSize)
//
//            let iconAttributedString = NSAttributedString(attachment: attachment)
//            attributedString.append(iconAttributedString)
//        }
//
//        // 添加文字并设置样式
//        let textAttributedString = text.withAttributes([
//            .font(.t.tbsl), // 设置字体
//            .textColor(.black),
//        ])
//        attributedString.append(textAttributedString)
//        return attributedString
        return NSAttributedString.getIconTitleAttributeByWords(words: words, icon:.iconVip, textFont: .t.tll)
    }
}
