﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class TextFieldThreeDialog : MonoBehaviour
{
    public Action<string, string, string> action;

    public GameObject panel;

    public InputField inputField1;
    public InputField inputField2;
    public InputField inputField3;

    public static void Show(string placeHolder1, string placeHolder2, string placeHolder3, Action<string, string, string> action)
    {
        Present(placeHolder1,placeHolder2, placeHolder3, action);
    }

    public static void Present(string placeHolder1, string placeHolder2, string placeHolder3, Action<string, string, string> action)
    {
        GameObject textFieldThreeDialogPanel = GameObject.Find("TextFieldThreeDialogPanel");

        Image image = textFieldThreeDialogPanel.GetComponent<Image>();
        image.enabled = true;

        TextFieldThreeDialog textFieldThreeDialog = textFieldThreeDialogPanel.GetComponent<TextFieldThreeDialog>();
        textFieldThreeDialog.panel.SetActive(true);
        textFieldThreeDialog.action = action;

        textFieldThreeDialog.inputField1.placeholder.GetComponent<Text>().text = placeHolder1;
        textFieldThreeDialog.inputField2.placeholder.GetComponent<Text>().text = placeHolder2;
        textFieldThreeDialog.inputField3.placeholder.GetComponent<Text>().text = placeHolder3;
    }

    public static void Dismiss()
    {
        GameObject textFieldThreeDialogPanel = GameObject.Find("TextFieldThreeDialogPanel");

        Image image = textFieldThreeDialogPanel.GetComponent<Image>();
        image.enabled = false;

        TextFieldThreeDialog textFieldThreeDialog = textFieldThreeDialogPanel.GetComponent<TextFieldThreeDialog>();
        textFieldThreeDialog.panel.SetActive(false);
    }

    public void OnClick(int tag)
    {
        if (tag == 0)
        {
            action.Invoke(inputField1.text, inputField2.text, inputField3.text);
        }
        else
        {
            action.Invoke(null, null, null);
        }
        
        Dismiss();
    }
}
