//
//  MenuVCCell.swift
//  SwiftProject
//
//  Created by aaa on 2024/4/12.
//

import Foundation
import UIKit
import Kingfisher
class MenuVCCell: UITableViewCell {
    //cell圆角类型
    enum MenuVCCellCornerRadiusType:Int {
        ///没有圆角
        case _none = 0
        ///上圆角
        case top = 1
        ///下圆角
        case bottom = 2
        ///全部圆角
        case all = 3
        ///对应切除范围
        var maskcorners:CACornerMask {
            switch self {
            case ._none:
                return []
            case .top:
                return [.layerMinXMinYCorner, .layerMaxXMinYCorner]
            case .bottom:
                return [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
            case .all:
                return [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
            }
        }
        ///对应圆角度数
        var corner:CGFloat{
            switch self {
            case ._none:
                return 0
            default:
                return 12
            }
        }
    }
    //当前cell的圆角
    var radiusType:MenuVCCellCornerRadiusType! {
        didSet{
            layer.maskedCorners = radiusType.maskcorners
            layer.cornerRadius = radiusType.corner
        }
    }
    //展示内容
    var data:[String:Any]!{
        didSet{
            if let image = data["image"] as? UIImage {
                //获取图片
                iconImageView.image = image
            }else {
                //是url
                let url = data["image"] as! URL
                iconImageView.kf.setImage(with: url, placeholder: UIImage(named: "menuvc_default"))
            }
//            //获取图片
//            iconImageView.image = data["image"] as? UIImage
            //设置标题
            titleLabel.text = data["title"] as? String
        }
    }
    
    //icon展示
    fileprivate lazy var iconImageView:UIImageView = {
        let imageView:UIImageView = .init()
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    //标题Label
    fileprivate lazy var titleLabel:UILabel = {
        let label = UILabel()
        label.textColor = .white
        label.font = .systemFont(ofSize: 14, weight: .medium)
        label.text = "Text"
        return label
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = UIColor(r: 29, g: 29, b: 29, a: 1)
        selectionStyle = .none
        //设置icon
        addSubview(iconImageView)
        iconImageView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(16)
        }
        //设置标题Label
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(iconImageView.snp.right).offset(12)
            make.right.equalToSuperview().offset(-16)
        }
        //设置超出范围切除
        layer.masksToBounds = true
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
