//
//  LNIMChatEmojiCell.swift
//  Lanu
//
//  Created by OneeChan on 2025/12/17.
//

import Foundation
import UIKit
import SnapKit


class LNIMChatEmojiCell: UICollectionViewCell {
    private let imageView = UIImageView()
    private(set) var staticImage: UIImage?
    private(set) var gifImage: UIImage?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func update(_ data: LNEmojiData) {
        let image = LNIMEmojiManager.shared.getFaceFromCache(path: data.path)
        
        if image?.sd_imageFormat == .GIF {
            gifImage = image
            staticImage = image?.images?.first
        } else {
            staticImage = image
        }
        
        imageView.image = staticImage // 展示静态图
//        imageView.image = image // 展示动态图
    }
}

extension LNIMChatEmojiCell {
    private func setupViews() {
        contentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}
