//
//  GroupChatSearchConversationOptionsVC.swift
//  WoWonder
//
//  Created by iMac on 29/05/24.
//  Copyright © 2024 ScriptSun. All rights reserved.
//

import UIKit

protocol GroupChatSearchConversationOptionsVCDelegate {
    func handleMessageOptionTap(index: Int, optionName: String, indexPath: IndexPath)
}

class GroupChatSearchConversationOptionsVC: UIViewController {
    
    // MARK: - IBOutlets
        
    @IBOutlet weak var copyView: UIControl!
    @IBOutlet weak var messageInfoView: UIControl!
    @IBOutlet weak var deleteMessageView: UIControl!
    @IBOutlet weak var forwardView: UIControl!
    
    // MARK: - Properties
    
    var delegate: GroupChatSearchConversationOptionsVCDelegate?
    var isCopy = false
    var indexPath = IndexPath()
    var isRightUser = false
    
    // 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.dismiss(animated: true)
    }
        
    // Copy Button Action
    @IBAction func copyButtonAction(_ sender: UIControl) {
        self.dismiss(animated: true) {
            self.delegate?.handleMessageOptionTap(index: 0, optionName: "Copy", indexPath: self.indexPath)
        }
    }
    
    // Message Button Action
    @IBAction func messageInfoButtonAction(_ sender: UIColor) {
        self.dismiss(animated: true) {
            self.delegate?.handleMessageOptionTap(index: 1, optionName: "Message Info", indexPath: self.indexPath)
        }
    }
    
    // Delete Message Button Action
    @IBAction func deleteMessaageButtonAction(_ sender: UIControl) {
        self.dismiss(animated: true) {
            self.delegate?.handleMessageOptionTap(index: 2, optionName: "Delete Message", indexPath: self.indexPath)
        }
    }
    
    // Forward Button Action
    @IBAction func forwardButtonAction(_ sender: UIControl) {
        self.dismiss(animated: true) {
            self.delegate?.handleMessageOptionTap(index: 3, optionName: "Forward", indexPath: self.indexPath)
        }
    }
    
    // MARK: - Helper Functions
    
    // Initial Config
    func initialConfig() {
        self.view.backgroundColor = .black.withAlphaComponent(0.4)
        self.setUpUI()
    }
    
    // SetUp UI
    func setUpUI() {
        self.copyView.isHidden = !self.isCopy
        self.messageInfoView.isHidden = !self.isRightUser
        self.deleteMessageView.isHidden = !self.isRightUser
    }
    
}
