//
//  TSWallpaperPreviewVC.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/22.
//

class TSWallpaperPreviewVC: TSBaseVC {

    var image:UIImage
    var tintColor:UIColor
    init(image: UIImage, tintColor: UIColor) {
        self.image = image
        self.tintColor = tintColor
        super.init()
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        imageView.image = image
        return imageView
    }()
    
    lazy var previewImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        let originalImage = UIImage(named: "diy_preview")
        imageView.image = originalImage
        return imageView
    }()
    
    lazy var previewDataImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        let originalImage = UIImage(named: "diy_preview_date")
        let tintedImage = originalImage?.withRenderingMode(.alwaysTemplate)
        imageView.image = tintedImage
        imageView.tintColor = tintColor
        return imageView
    }()
    
    
    lazy var previewTimeImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        let originalImage = UIImage(named: "diy_preview_time")
        let tintedImage = originalImage?.withRenderingMode(.alwaysTemplate)
        imageView.image = tintedImage
        imageView.tintColor = tintColor
        return imageView
    }()

    override func createView() {
        setNavBarViewHidden(true)
        
        contentView.addSubview(imageView)
        contentView.addSubview(previewImageView)
        contentView.addSubview(previewDataImageView)
        contentView.addSubview(previewTimeImageView)
        
        imageView.snp.makeConstraints { make in
            make.leading.trailing.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
        previewImageView.snp.makeConstraints { make in
            make.leading.trailing.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
        previewDataImageView.snp.makeConstraints { make in
            make.top.equalTo(77)
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
        }
        
        previewTimeImageView.snp.makeConstraints { make in
            make.top.equalTo(101)
            make.centerX.equalToSuperview()
            make.height.equalTo(94)
        }
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(onPreviewButton))
        view.addGestureRecognizer(tap)

    }
    
    @objc func onPreviewButton() {
        pop()
    }
}
