//
//  MessageAlertVC.swift
//  WoWonder
//
//  Created by iMac on 02/08/23.
//  Copyright © 2023 ScriptSun. All rights reserved.
//

import UIKit

protocol MessageAlertVCDelegate {
    func messageAlertConfirmButtonPressed(_ sender: UIButton)
    func messageAlertCloseButtonPressed(_ sender: UIButton)
}

class MessageAlertVC: UIViewController {
    
    // MARK: - IBOutlets
    
    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet weak var confirmButton: UIButton!
    @IBOutlet weak var closeButton: UIButton!
    
    // MARK: - Properties
    
    var delegate: MessageAlertVCDelegate?
    var messageText: String?
    var confirmText: String?
    var closeText: String?
    
    // MARK: - View Life Cycles

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.initialConfig()
    }
    
    // MARK: - Selectors
    
    // Close Button Action
    @IBAction func closeButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true) {
            self.delegate?.messageAlertCloseButtonPressed(sender)
        }
    }
    
    // Confirm Button Action
    @IBAction func confirmButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true) {
            self.delegate?.messageAlertConfirmButtonPressed(sender)
        }
    }
    
    // MARK: - Helper Functions
    
    // Initial Config
    func initialConfig() {
        self.view.backgroundColor = .black.withAlphaComponent(0.4)
        self.setTitleAndMessage()
    }
    
    func setTitleAndMessage() {
        self.messageLabel.text = messageText ?? "N/A"
        self.confirmButton.setTitle((confirmText ?? "CONFIRM"), for: .normal)
        self.closeButton.setTitle((closeText ?? "CLOSE"), for: .normal)
    }

}

extension MessageAlertVCDelegate {
    
    func messageAlertCloseButtonPressed(_ sender: UIButton) {
        
    }
    
}
