﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace JLGames.RocketDriver.Samples.i18nDemo
{
    [Serializable]
    public class I18NDemoFileInfo
    {
        public bool Default;
        public string FileKey;
        public string FileBasePath;

        public override string ToString()
        {
            return $"{{FileKey={FileKey}, FileBasePath={FileBasePath}, Default={Default}}}";
        }
    }

    public class I18NDemoFileNode : MonoBehaviour
    {
        public void UpdateView(I18NDemoFileInfo info)
        {
            var toggleDefault = transform.GetChild(0).GetComponent<Toggle>();
            toggleDefault.isOn = info.Default;
            var inputFileKey = transform.GetChild(1).GetComponent<InputField>();
            inputFileKey.text = info.FileKey;
            var inputFilePath = transform.GetChild(2).GetComponent<InputField>();
            inputFilePath.text = info.FileBasePath;
        }

        public I18NDemoFileInfo GetViewInfo()
        {
            var toggleDefault = transform.GetChild(0).GetComponent<Toggle>();
            var inputFileKey = transform.GetChild(1).GetComponent<InputField>();
            var inputFilePath = transform.GetChild(2).GetComponent<InputField>();
            return new I18NDemoFileInfo
            {
                Default = toggleDefault.isOn,
                FileKey = inputFileKey.text.Trim(),
                FileBasePath = inputFilePath.text.Trim()
            };
        }
    }
}