//
//  TSPlogBootImageVC.swift
//  KittensTravelNotes
//
//  Created by 100Years on 2025/7/9.
//

class TSPlogBootImageVC: TSBaseVC {
    var itemModel:TSAIDataItemModel
    init(itemModel:TSAIDataItemModel) {
        self.itemModel = itemModel
        super.init()
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var uploadImageView: UIImageView = UIImageView.createImageView(contentMode: .scaleAspectFit)
    lazy var submitBtn: UIButton = {
        let submitBtn = kCreateNormalSubmitBtn(title: "Let my cat go".localized) { [weak self]  in
            guard let self = self else { return }
            generateImage()
        }
        return submitBtn
    }()

    override func createView() {

        setPageTitle(itemModel.generateModel?.inputText ?? "")
        view.insertSubview(uploadImageView, at: 0)
        uploadImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        contentView.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(250*kDesignScale)
            make.height.equalTo(56)
            make.bottom.equalTo(-k_Height_safeAreaInsetsBottom())
        }

        uploadImageView.setAsyncImage(urlString: itemModel.viewModel.imageURLString)
    }

    override func dealThings() {

    }
    
    func generateImage() {
        TSPlogVC.enterSelectPhotos(target: self,style: .ptp) { [weak self] image in
            guard let self = self else { return }
            kPushVC(target: self, modelVC: TSPlogUploadPhotoVC(upLoadImage:image, generatorStyle: self.itemModel.style,dataModel: self.itemModel.generateModel))
        }
    }
}
