//
//  TSPlogUploadPhotoVC+View.swift
//  KittensTravelNotes
//
//  Created by 100Years on 2025/7/7.
//

extension TSPlogUploadPhotoVC {
    
    func creatUploadImageView() -> UIImageView {
        let uploadImageView = UIImageView()
        return uploadImageView
    }
    
    func creatUploadImageBgView() -> UIView {
        let bgView = UIView()
        bgView.backgroundColor = .white
        bgView.cornerRadius = 16
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickBgView))
        tapGesture.cancelsTouchesInView = false
        bgView.addGestureRecognizer(tapGesture)
        
        
        let addImageView = UIImageView.createImageView(imageName: "add")
        bgView.addSubview(addImageView)
        addImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview().offset(-15)
            make.centerX.equalToSuperview()
            make.width.height.equalTo(24)
        }
        
        let textLabel = UILabel.createLabel(text: "Upload Your Cat Photo".localized,font: .font(size: 12),textColor: .secondaryText,textAlignment: .center,numberOfLines: 0)
        bgView.addSubview(textLabel)
        textLabel.snp.makeConstraints { make in
            make.top.equalTo(addImageView.snp.bottom).offset(16)
            make.leading.equalTo(18)
            make.trailing.equalTo(-18)
        }
        
        uploadImageView.contentMode = .scaleAspectFit
        bgView.addSubview(uploadImageView)
        uploadImageView.snp.makeConstraints { make in
            make.top.leading.equalTo(12)
            make.bottom.trailing.equalTo(-12)
        }

        return bgView
    }
    
    func creatPlacesView() -> TSPlogTravelPlacesView {
        let placesView = TSPlogTravelPlacesView()
        placesView.dataArray = [
            "🇫🇷Eiffel Tower",
            "🇨🇳Great Wall of China",
            "🇮🇹Colosseum",
            "🇪🇸Machu Picchu",
            "🇹🇭Taj Mahal",
            "🇦🇺Sydney Opera House",
            "🇧🇷Christ the Redeemer",
            "🇪🇬Pyramids of Giza",
            "🇺🇸Grand Canyon"
        ]
        placesView.changeBlock = { [weak self] string  in
            guard let self = self else { return }
            if let string = string {
                additionalPrompt = string
            }else{
                additionalPrompt = ""
            }
            
            checkBtnEnabled()
        }
        return placesView
    }
    
}

extension TSPlogUploadPhotoVC {
    
    func creatSubmitBtn() -> UIButton {
        let submitBtn = kCreateNormalSubmitBtn(title: "Travel Now".localized) { [weak self]  in
            guard let self = self else { return }
            generateImage()
        }
        return submitBtn
    }
    
    func creatDeleteBtn() -> UIButton {
        let deleteBtn = UIButton.createButton(backgroundImage: UIImage(named: "delete_redRound")) { [weak self]  in
            guard let self = self else { return }
            upLoadImage = nil
        }
        deleteBtn.isHidden = true
        return deleteBtn
    }
}


extension TSPlogUploadPhotoVC {
    func pickSinglePhoto(complete: @escaping (UIImage)->Void)  {
        photoPickerManager.pickCustomSinglePhoto() { [weak self] image, errorString in
            guard let self = self else { return }
            if let errorString = errorString {
                TSToastShared.showToast(text: errorString)
            }else if let image = image {
                complete(image)
            }else{
                dePrint("图片异常")
            }
            kMainShort {
                self.photoPickerManager.dismissPageVC()
            }
        }
    }
}
