using CommonUtil;

using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System;
using UnityEngine;
using UnityEditor;

public class YmlAutoGen : EditorWindow
{
    public static string repos_path = "./Assets/../repos/release/{0}_repos.yml";
    private string[] options = new string[] { "book", "practice", "say", "expand", "weekly", "monthly", "gushi_travel", "gushi_through", "gushi_say", "gushi_exercise", "gushi_sing" };
    private string[] options_type = new string[] { "book", "practice", "say", "expand", "weekly", "monthly", "gushi", "gushi", "gushi", "gushi", "gushi" };
    private int selectedIndex = 0;
    private string textFieldValue = "";


    [MenuItem("Tool/自动生成Yml")]
    public static void ShowWindow()
    {
        GetWindow<YmlAutoGen>("Yml Auto Gen");
    }

    private void OnGUI()
    {
        // 下拉框 (Popup)
        selectedIndex = EditorGUILayout.Popup("Select yml", selectedIndex, options);
         // 输入框 (Text Field)
        textFieldValue = EditorGUILayout.TextField("ID list", textFieldValue);
        // 显示输入的文本
        EditorGUILayout.LabelField("多个id以英文逗号隔开");

        if (GUILayout.Button("开始生成"))
        {
            string trunkPath = System.Environment.CurrentDirectory;
            string py_yml = Path.Combine(trunkPath, "Assets/app/Editor/tools/YmlAutoGen", "gen_yml.py");

            string ymlpath = string.Format(YmlAutoGen.repos_path, options_type[selectedIndex]);

            string args = $"{py_yml} {options[selectedIndex]} {ymlpath} {textFieldValue}";

            CmdResult result = CmdUtil.Cmd("python3", args);
            
            Debug.Log($"ret is:{result.stdOut.ToString()}");
            Debug.Log($"ret is:{result.stdErr.ToString()}");
        }
    }
}