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

public class HasilJawaban : MonoBehaviour, IDataPresistence
{
    public int gameKe;
    public Sprite uiLocked;
    public Image hasilJawaban1;
    public Image hasilJawaban2;
    public Image hasilJawaban3;

    public Sprite jawabanBenar;
    public Sprite jawabanSalah;

    public string thisGameIndex;

    public Image thisImage;
    public Button thisButton;

    private int dataHasilJawaban1;
    private int dataHasilJawaban2;
    private int dataHasilJawaban3;

    private bool game1;
    private bool game2;
    private bool game3;
    private bool game4;
    private bool game5;

    public void LoadData(GameData data)
    {
        if (gameKe == 1)
        {
            dataHasilJawaban1 = data.jawaban1Game1;
            dataHasilJawaban2 = data.jawaban2Game1;
            dataHasilJawaban3 = data.jawaban3Game1;
            game1 = data.game1;
        }
        else if (gameKe == 2)
        {
            dataHasilJawaban1 = data.jawaban1Game2;
            dataHasilJawaban2 = data.jawaban2Game2;
            dataHasilJawaban3 = data.jawaban3Game2;
            game2 = data.game2;
        }
        else if (gameKe == 3)
        {
            dataHasilJawaban1 = data.jawaban1Game3;
            dataHasilJawaban2 = data.jawaban2Game3;
            dataHasilJawaban3 = data.jawaban3Game3;
            game3 = data.game3;
        }
        else if (gameKe == 4)
        {
            dataHasilJawaban1 = data.jawaban1Game4;
            dataHasilJawaban2 = data.jawaban2Game4;
            dataHasilJawaban3 = data.jawaban3Game4;
            game4 = data.game4;
        }
        else if (gameKe == 5)
        {
            dataHasilJawaban1 = data.jawaban1Game5;
            dataHasilJawaban2 = data.jawaban2Game5;
            dataHasilJawaban3 = data.jawaban3Game5;
            game5 = data.game5;
        }

        InitializeUI();
    }

    public void SaveData(ref GameData data) {}

    public void InitializeUI()
    {
        if (thisGameIndex == "game1" && game1 != true)
        {
            thisImage.sprite = uiLocked;
            hasilJawaban1.gameObject.SetActive(false);
            hasilJawaban2.gameObject.SetActive(false);
            hasilJawaban3.gameObject.SetActive(false);
            thisButton.interactable = false;
        }

        if (thisGameIndex == "game2" && game2 != true)
        {
            thisImage.sprite = uiLocked;
            hasilJawaban1.gameObject.SetActive(false);
            hasilJawaban2.gameObject.SetActive(false);
            hasilJawaban3.gameObject.SetActive(false);
            thisButton.interactable = false;
        }

        if (thisGameIndex == "game3" && game3 != true)
        {
            thisImage.sprite = uiLocked;
            hasilJawaban1.gameObject.SetActive(false);
            hasilJawaban2.gameObject.SetActive(false);
            hasilJawaban3.gameObject.SetActive(false);
            thisButton.interactable = false;
        }

        if (thisGameIndex == "game4" && game4 != true)
        {
            thisImage.sprite = uiLocked;
            hasilJawaban1.gameObject.SetActive(false);
            hasilJawaban2.gameObject.SetActive(false);
            hasilJawaban3.gameObject.SetActive(false);
            thisButton.interactable = false;
        }

        if (thisGameIndex == "game5" && game5 != true)
        {
            thisImage.sprite = uiLocked;
            hasilJawaban1.gameObject.SetActive(false);
            hasilJawaban2.gameObject.SetActive(false);
            hasilJawaban3.gameObject.SetActive(false);
            thisButton.interactable = false;
        }

        if (dataHasilJawaban1 == 1)
        {
            hasilJawaban1.sprite = jawabanBenar;
        }
        else if (dataHasilJawaban1 == 2)
        {
            hasilJawaban1.sprite = jawabanSalah;
        }

        if (dataHasilJawaban2 == 1)
        {
            hasilJawaban2.sprite = jawabanBenar;
        }
        else if (dataHasilJawaban2 == 2)
        {
            hasilJawaban2.sprite = jawabanSalah;
        }

        if (dataHasilJawaban3 == 1)
        {
            hasilJawaban3.sprite = jawabanBenar;
        }
        else if (dataHasilJawaban3 == 2)
        {
            hasilJawaban3.sprite = jawabanSalah;
        }
    }
}
