//
//  PhotoEditorWarningAlertVC.swift
//  WoWonder
//
//  Created by iMac on 05/06/25.
//  Copyright © 2025 ScriptSun. All rights reserved.
//

import UIKit

protocol PhotoEditorWarningAlertVCDelegate {
    func photoEditorWarningAlertSAVEButtonPressed(_ sender: UIButton)
    func photoEditorWarningAlertDISCARDButtonPressed(_ sender: UIButton)
}

class PhotoEditorWarningAlertVC: UIViewController {
    
    // MARK: - IBOutlets
    
    @IBOutlet weak var okButton: UIButton!
    @IBOutlet weak var cancelButton: UIButton!
    
    // MARK: - Properties
    
    var delegate: PhotoEditorWarningAlertVCDelegate?
    var titleText: String?
    var messageText: String?
    var okText: String?
    var cancelText: String?
    
    // MARK: - View Life Cycles

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.initialConfig()
    }
    
    // MARK: - Selectors
    
    // Save Button Action
    @IBAction func saveButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true) {
            self.delegate?.photoEditorWarningAlertSAVEButtonPressed(sender)
        }
    }
    
    // Cancel Button Action
    @IBAction func cancelButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true, completion: nil)
    }
    
    // Discard Button Action
    @IBAction func discardButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true) {
            self.delegate?.photoEditorWarningAlertDISCARDButtonPressed(sender)
        }
    }
    

    // MARK: - Helper Functions
    
    // Initial Config
    func initialConfig() {
        self.view.backgroundColor = .black.withAlphaComponent(0.4)
        if let objColor = UserDefaults.standard.value(forKey: "ColorTheme") as? String, objColor != "" {
            self.okButton.setTitleColor(UIColor(hex: objColor), for: .normal)
            self.cancelButton.setTitleColor(UIColor(hex: objColor), for: .normal)
        }
    }

}
