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

import UIKit
import Toast_Swift

protocol ReportUserAlertVCDelegate {
    func handleReportUserUpdateButtonTap(sender: UIButton, text: String)
}

class ReportUserAlertVC: UIViewController {
    
    // MARK: - IBOutlets
    
    @IBOutlet weak var updateButton: UIButton!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var textField: UITextField!
    
    // MARK: - Properties
    
    var delegate: ReportUserAlertVCDelegate?
    
    // MARK: - View Life Cycles
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.initialConfig()
    }
    
    // MARK: - Selectors
    
    // Cancel Button Action
    @IBAction func cancelButtonAction(_ sender: UIButton) {
        self.dismiss(animated: true, completion: nil)
    }
    
    // Update Button Action
    @IBAction func updateButtonAction(_ sender: UIButton) {
        if self.textField.text?.trimmingCharacters(in: .whitespaces).count == 0 {
            self.view.makeToast("Please enter some text")
            return
        }
        if let text = self.textField.text {
            self.dismiss(animated: true)
            self.delegate?.handleReportUserUpdateButtonTap(sender: sender, text: text)
        }
    }
    
    // MARK: - Helper Functions
    
    // Initial Config
    func initialConfig() {
        self.view.backgroundColor = .black.withAlphaComponent(0.4)
    }
    
}
