//
//  LNAdBannerImageCell.swift
//  Lanu
//
//  Created by Codex on 2026/4/8.
//

import Foundation
import UIKit
import SnapKit

final class LNAdBannerImageCell: UICollectionViewCell {
    private let imageView = UIImageView()
    private var curItem: LNBannerInfoVO?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }

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

    override func prepareForReuse() {
        super.prepareForReuse()
        curItem = nil
        imageView.image = nil
    }

    func update(_ item: LNBannerInfoVO) {
        curItem = item
        imageView.sd_setImage(with: URL(string: item.img))
    }
}

private extension LNAdBannerImageCell {
    func setupViews() {
        contentView.layer.masksToBounds = true
        contentView.layer.cornerRadius = 16

        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 16
        imageView.contentMode = .scaleAspectFill

        contentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}
