//
//  EPIconFlagView.swift

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

import UIKit
import SnapKit

class EPIconFlagView: UIImageView {
    
    // MARK: - Properties
    
    private let icon: UIImageView
    
    // MARK: - Initialization
    
    override init(frame: CGRect) {
        icon = UIImageView()
        super.init(frame: frame)
        
        // Setup constraints using SnapKit
        snp.makeConstraints { make in
            make.height.equalTo(24)
        }
        
        addSubview(icon)
        icon.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 12, height: 12))
            make.left.equalTo(6)
            make.right.equalTo(-6)
            make.centerY.equalToSuperview()
        }
        
        contentMode = .scaleToFill
    }
    
    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Public Methods
    
    func setupRightTopLockStyle() {
        configIconLocked(true)
        layer.cornerRadius = 4
        layer.masksToBounds = true
        // Right-top and left-bottom corners rounded
        // layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMaxYCorner]
    }
    
    func configIconLocked(_ lock: Bool) {
        if lock {
            icon.image = MWIconFont.image(fromIcon: .iconPrivate, size: .init(width: 16, height: 16), color: .text)
            backgroundColor = .c.csedn
            image = nil
        } else {
            
            icon.image = MWIconFont.image(fromIcon: .iconPublic, size: .init(width: 16, height: 16), color: .text)
            let gradient = CLSystemToken.gradient(token: .cpgn)
            image = gradient.toImage(size: CGSize(width: 40, height: 32))
        }
    }
}
