//
//  CustomMessageAlertVC.swift
//  WoWonder
//
//  Created by iMac on 30/09/23.
//  Copyright © 2023 ScriptSun. All rights reserved.
//

import UIKit

import Toast_Swift

protocol CustomMessageAlertVCDelegate {
    func handleCustomMessageSendButtonTap(sender: UIButton, text: String)
}

class CustomMessageAlertVC: UIViewController {
    
    // MARK: - IBOutlets
    
    @IBOutlet weak var messageTextField: UITextField!
    
    // MARK: - Properties
    
    var delegate: CustomMessageAlertVCDelegate?
    
    // MARK: - View Life Cycles

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.initialConfig()
    }
    
    // MARK: - Selectors
    
    // Cancel Button Action
    @IBAction func cancelButtonAction(_ sender: UIButton) {
        self.view.endEditing(true)
        self.dismiss(animated: true, completion: nil)
    }
    
    // Send Button Action
    @IBAction func sendButtonAction(_ sender: UIButton) {
        if self.messageTextField.text?.trimmingCharacters(in: .whitespaces).count == 0 {
            self.view.makeToast("Please write your message")
            return
        }
        if let text = self.messageTextField.text {
            self.dismiss(animated: true) {
                self.delegate?.handleCustomMessageSendButtonTap(sender: sender, text: text)
            }            
        }
    }
    
    // MARK: - Helper Functions
    
    // Initial Config
    func initialConfig() {
        self.view.backgroundColor = .black.withAlphaComponent(0.4)
    }

}
