private IT_SearchPanel _searchPane;                 //
    #endregion

    /// <summary>
    /// Initializes the variables used by the identity manager tab
    /// </summary>
    /// <param name="skin">GUISkin for custom Editor display</param>
    public IdentitiesTab(GUISkin skin)
    {
        _skin = skin;

        _controller = new IdentitiesTabController();

        _listPane       = new IT_ListPane();
        _createEditPane = new IT_CreateEditPane();
        //_optionsPane = new IT_OptionsPanel();
        _searchPane = new IT_SearchPanel();

        _controller.RefreshLists();
    }
    public void DrawSearchPane(IdentitiesTabController controller, GUISkin skin)
    {
        GUILayout.BeginArea(new Rect(5, 10, 912, 100), skin.GetStyle("TopBackground"));
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(new GUIContent("SEARCH IDENTITIES"), skin.GetStyle("MainTitle"), GUILayout.Width(165));
        EditorGUILayout.BeginVertical();
        GUILayout.Space(12);
        EditorGUILayout.LabelField(new GUIContent("ID, User ID, Link Code, Eth Address"), skin.GetStyle("ContentDark"));
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(20);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(16);
        controller.SearchText = EditorGUILayout.TextField(controller.SearchText, skin.textField, GUILayout.Height(30));

        if (GUILayout.Button(new GUIContent("Search"), GUILayout.Height(32), GUILayout.Width(100)))
        {
            controller.IdentitiesList.Clear();
            controller.FieldsFoldout.Clear();
            Identity[] sResults = Enjin.SearchIdentities(controller.SearchText);

            if (sResults != null)
            {
                controller.IdentitiesList = new List <Identity>(sResults);
            }

            for (int i = 0; i < controller.IdentitiesList.Count; i++)
            {
                controller.FieldsFoldout.Add(false);
            }

            controller.IsInSearchMode   = true;
            controller.HasRefreshedList = false;
        }

        if (controller.SearchText == "" && !controller.HasRefreshedList)
        {
            controller.RefreshLists();
            controller.IsInSearchMode   = false;
            controller.HasRefreshedList = true;
            controller.SelectedIndex    = 0;
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
    public void DrawOptionsPanel(IdentitiesTabController controller, GUISkin skin)
    {
        #region Identity Options Panel
        GUILayout.BeginArea(new Rect(5, 10, 230, 100), skin.GetStyle("TopBackground"));
        EditorGUILayout.LabelField(new GUIContent("ADD IDENTITY"), skin.GetStyle("MainTitle"));
        GUILayout.Space(20);
        EditorGUILayout.BeginHorizontal(GUILayout.Width(100));
        GUILayout.Space(14);

        //if (GUILayout.Button(new GUIContent("Create Identity"), GUILayout.Height(36), GUILayout.Width(100)))
        //{
        //    controller.CurrentIdentity = new Identity();
        //    controller.SetUserIDList();
        //    controller.State = IdentitiesTabController.IdentityState.CREATE;
        //}

        EditorGUILayout.EndHorizontal();
        GUILayout.EndArea();
        #endregion
    }
    public void DrawListPane(IdentitiesTabController controller, GUISkin skin)
    {
        GUILayout.BeginArea(new Rect(5, 126, 912, 490), skin.GetStyle("TopBackground"));
        GUILayout.Space(10);
        EditorGUILayout.BeginHorizontal();

        if (controller.HasRefreshedList)
        {
            EditorGUILayout.LabelField(new GUIContent("TEAM LIST"), skin.GetStyle("MainTitle"));
        }
        else
        {
            EditorGUILayout.LabelField(new GUIContent("IDENTITIES (" + EnjinEditor.CurrentAppName + ")"), skin.GetStyle("MainTitle"));
        }

        EditorGUILayout.EndHorizontal();

        GUILayout.Space(20);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(16);
        EditorGUILayout.LabelField(new GUIContent("ID"), skin.GetStyle("Subtitle"), GUILayout.Width(96));
        EditorGUILayout.LabelField(new GUIContent("USER ID"), skin.GetStyle("Subtitle"), GUILayout.Width(124));
        EditorGUILayout.LabelField(new GUIContent("USERNAME"), skin.GetStyle("Subtitle"), GUILayout.Width(148));
        EditorGUILayout.LabelField(new GUIContent("LINK CODE"), skin.GetStyle("Subtitle"), GUILayout.Width(148));
        EditorGUILayout.LabelField(new GUIContent("ETH ADDRESS"), skin.GetStyle("Subtitle"), GUILayout.Width(156));
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(16);
        _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Width(880), GUILayout.Height(342));

        for (int i = 0; i < controller.IdentitiesList.Count; i++)
        {
            if (controller.SelectedIndex == i)
            {
                EditorGUILayout.BeginHorizontal(skin.box);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
            }

            EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].id.ToString()), skin.GetStyle("ContentDark"), GUILayout.Width(90));
            Rect lastRect = GUILayoutUtility.GetLastRect();

            if (GUI.Button(new Rect(lastRect.x, lastRect.y, 890.0f, lastRect.height), GUIContent.none, skin.button))
            {
                if (controller.SelectedIndex == 1)
                {
                    controller.CurrentIdentity = controller.IdentitiesList[controller.SelectedIndex];
                    controller.State           = IdentitiesTabController.IdentityState.EDIT;
                }

                controller.SelectedIndex = i;
            }

            GUILayout.Space(10);
            EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].user.id.ToString()), skin.GetStyle("ContentDark"), GUILayout.Width(130));
            EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].user.name), skin.GetStyle("ContentDark"), GUILayout.Width(150));

            if (controller.IdentitiesList[i].linking_code == null)
            {
                EditorGUILayout.LabelField(new GUIContent("Linked"), skin.GetStyle("ContentDark"), GUILayout.Width(150));
            }
            else
            {
                EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].linking_code), skin.GetStyle("ContentDark"), GUILayout.Width(150));
            }

            if (controller.IdentitiesList[i].ethereum_address == null)
            {
                EditorGUILayout.LabelField(new GUIContent("Not Linked"), skin.GetStyle("ContentDark"));
            }
            else
            {
                EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].ethereum_address), skin.GetStyle("ContentDark"));
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            GUI.backgroundColor = _bgDefault;

            if (controller.IdentitiesList[i].fields.Length != 0)
            {
                GUILayout.Space(4);
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                controller.FieldsFoldout[i] = EditorGUILayout.Foldout(controller.FieldsFoldout[i], new GUIContent("FIELDS (" + controller.IdentitiesList[i].id.ToString() + ")"));

                if (controller.FieldsFoldout[i])
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(14);
                    EditorGUILayout.LabelField(new GUIContent("KEY"), skin.GetStyle("Subtitle"), GUILayout.Width(120));
                    EditorGUILayout.LabelField(new GUIContent("VALUE"), skin.GetStyle("Subtitle"), GUILayout.Width(420));
                    EditorGUILayout.LabelField(new GUIContent("SEARCHABLE"), skin.GetStyle("Subtitle"), GUILayout.Width(100));
                    EditorGUILayout.LabelField(new GUIContent("DISPLAYABLE"), skin.GetStyle("Subtitle"), GUILayout.Width(100));
                    EditorGUILayout.LabelField(new GUIContent("UNIQUE"), skin.GetStyle("Subtitle"), GUILayout.Width(66));
                    EditorGUILayout.EndHorizontal();

                    for (int n = 0; n < controller.IdentitiesList[i].fields.Length; n++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(14);
                        EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].fields[n].key), GUILayout.Width(120));
                        EditorGUILayout.LabelField(new GUIContent(controller.IdentitiesList[i].fields[n].value), GUILayout.Width(420));
                        EditorGUILayout.LabelField(new GUIContent(EnjinHelpers.IntToBoolString(controller.IdentitiesList[i].fields[n].searchable)), GUILayout.Width(100));
                        EditorGUILayout.LabelField(new GUIContent(EnjinHelpers.IntToBoolString(controller.IdentitiesList[i].fields[n].displayable)), GUILayout.Width(100));
                        EditorGUILayout.LabelField(new GUIContent(EnjinHelpers.IntToBoolString(controller.IdentitiesList[i].fields[n].unique)), GUILayout.Width(66));
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUILayout.EndVertical();
            }

            GUILayout.Space(8);
        }

        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndHorizontal();

        // Pagination UX
        if (!controller.IsInSearchMode)
        {
            GUILayout.Space(30);
            EditorGUILayout.BeginHorizontal();

            if (controller.CurrentPage != 1)
            {
                if (GUILayout.Button(new GUIContent("<<"), GUILayout.Height(20)))
                {
                    if (controller.CurrentPage != 1)
                    {
                        controller.CurrentPage--;
                        controller.PageCheck();
                    }
                }
            }

            GUILayout.Space(10);

            for (int i = controller.FirstPage; i < controller.TotalPages + 1; i++)
            {
                if (i != controller.CurrentPage)
                {
                    _numStyle = skin.GetStyle("PageNumberDark");
                }
                else
                {
                    _numStyle = skin.GetStyle("PageNumberLight");
                }

                if (GUILayout.Button(new GUIContent(i.ToString()), _numStyle, GUILayout.Width(30)))
                {
                    controller.CurrentPage = i;
                    controller.PageCheck();
                }

                if (i - controller.FirstPage == 9)
                {
                    break;
                }
            }

            if (controller.CurrentPage != controller.TotalPages)
            {
                if (GUILayout.Button(new GUIContent(">>"), GUILayout.Height(20)))
                {
                    if (controller.CurrentPage != controller.TotalPages)
                    {
                        controller.CurrentPage++;
                        controller.PageCheck();
                    }
                }
            }

            GUILayout.FlexibleSpace();

            if (controller.IdentitiesList.Count > 0)
            {
                if (GUILayout.Button("VIEW", GUILayout.Width(100), GUILayout.Height(30)))
                {
                    controller.CurrentIdentity = controller.IdentitiesList[controller.SelectedIndex];
                    controller.State           = IdentitiesTabController.IdentityState.EDIT;
                }
            }

            GUILayout.Space(16);
            EditorGUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
        }

        GUILayout.EndArea();
    }
    public void DrawCreateEditPane(IdentitiesTabController controller, GUISkin skin)
    {
        GUILayout.BeginArea(new Rect(5, 10, 912, 606), skin.GetStyle("TopBackground"));
        EditorGUILayout.BeginHorizontal();

        if (controller.State == IdentitiesTabController.IdentityState.EDIT)
        {
            EditorGUILayout.LabelField(new GUIContent("VIEW IDENTITY"), skin.GetStyle("MainTitle"));
        }
        else
        {
            EditorGUILayout.LabelField(new GUIContent(controller.State.ToString() + " IDENTITY"), skin.GetStyle("MainTitle"));
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(30);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);
        EditorGUILayout.LabelField(new GUIContent("CURRENT APPLICATION"), skin.GetStyle("Subtitle"));
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);
        EditorGUILayout.LabelField(new GUIContent("ID: " + Enjin.AppID.ToString() + " -> " + EnjinEditor.AppsNameList[EnjinEditor.SelectedAppIndex]), skin.GetStyle("LargeTextDark"));
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(20);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);
        EditorGUILayout.LabelField(new GUIContent("USER ID"), skin.GetStyle("Subtitle"));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);

        if (controller.State == IdentitiesTabController.IdentityState.CREATE)
        {
            EditorStyles.popup.fixedHeight     = 30;
            EditorStyles.popup.fontSize        = 12;
            controller.CurrentIdentity.user.id = System.Convert.ToInt32(EditorGUILayout.Popup(controller.CurrentIdentity.user.id, controller.UserIDs.ToArray(), GUILayout.Width(220), GUILayout.Height(30)));
            EditorStyles.popup.fixedHeight     = 15;
            EditorStyles.popup.fontSize        = 11;
        }
        else
        {
            EditorGUILayout.LabelField(new GUIContent(controller.CurrentIdentity.user.id.ToString()), skin.GetStyle("LargeText"), GUILayout.Width(320), GUILayout.Height(30));
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);

        if (controller.State == IdentitiesTabController.IdentityState.CREATE)
        {
            EditorGUILayout.LabelField(new GUIContent("ETHEREUM ADDRESS"), skin.GetStyle("Subtitle"));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(14);

            controller.CurrentIdentity.ethereum_address = EditorGUILayout.TextField(controller.CurrentIdentity.ethereum_address, skin.textField, GUILayout.Width(320), GUILayout.Height(30));
        }
        else
        {
            if (controller.CurrentIdentity.linking_code == "")
            {
                EditorGUILayout.LabelField(new GUIContent("ETHEREUM ADDRESS"), skin.GetStyle("Subtitle"));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(14);

                EditorGUILayout.LabelField(new GUIContent(controller.CurrentIdentity.ethereum_address), skin.GetStyle("LargeText"), GUILayout.Width(320), GUILayout.Height(30));
            }
            else
            {
                EditorGUILayout.LabelField(new GUIContent("LINKING CODE"), skin.GetStyle("Subtitle"));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(14);

                EditorGUILayout.LabelField(new GUIContent(controller.CurrentIdentity.linking_code), skin.GetStyle("LargeText"), GUILayout.Width(320), GUILayout.Height(30));
            }
        }

        EditorGUILayout.EndHorizontal();


        if (controller.State != IdentitiesTabController.IdentityState.CREATE && controller.CurrentIdentity.linking_code == "")
        {
            GUILayout.Space(20);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(14);
            EditorGUILayout.LabelField(new GUIContent("To change your wallet addres you will need to unlink this wallet."), skin.GetStyle("ContentDark"));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(14);

            if (GUILayout.Button(new GUIContent("Unlink Wallet"), GUILayout.Width(120), GUILayout.Height(30)))
            {
                if (EditorUtility.DisplayDialog("Unlink Wallet", "This will unlink this editor from your developer wallet. Do you want to proceed?", "Accept", "Cancel"))
                {
                    Enjin.UnLinkIdentity(controller.CurrentIdentity.id);
                    EnjinEditor.CurrentUser = Enjin.GetUserRaw(controller.CurrentIdentity.id);
                    EnjinEditor.ExecuteMethod(EnjinEditor.CallMethod.RELOADALL);
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        /***
         * Disabled for V1
         */
        //GUILayout.Space(20);
        //EditorGUILayout.BeginHorizontal();
        //EditorGUILayout.LabelField(new GUIContent("FIELDS"), skin.GetStyle("MainTitle"));
        //EditorGUILayout.EndHorizontal();
        //GUILayout.Space(20);
        //EditorGUILayout.BeginHorizontal();
        //GUILayout.Space(14);

        ///* TODO POST V1
        // *      - Make fields additive so user can add fields as nessisary
        // */

        //if (controller.CurrentIdentity.fields == null || controller.CurrentIdentity.fields.Length == 0)
        //{
        //    controller.CurrentIdentity.fields = new Fields[2];
        //    controller.CurrentIdentity.fields = Enjin.DefaultFields;
        //}

        //_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Width(320), GUILayout.Height(140));

        //for (int i = 0; i < controller.CurrentIdentity.fields.Length; i++)
        //{
        //    EditorGUILayout.BeginVertical("helpBox");
        //    EditorGUILayout.BeginHorizontal();
        //    GUILayout.Space(14);
        //    EditorGUILayout.LabelField(new GUIContent("KEY"), skin.GetStyle("Subtitle"), GUILayout.Width(140));
        //    EditorGUILayout.LabelField(new GUIContent("VALUE"), skin.GetStyle("Subtitle"), GUILayout.Width(140));
        //    EditorGUILayout.EndHorizontal();
        //    EditorGUILayout.BeginHorizontal();
        //    GUILayout.Space(14);
        //    EditorGUILayout.LabelField(new GUIContent(controller.CurrentIdentity.fields[i].key), GUILayout.Width(140), GUILayout.Height(30));
        //    controller.CurrentIdentity.fields[i].value = EditorGUILayout.TextField(controller.CurrentIdentity.fields[i].value, skin.textField, GUILayout.Width(140), GUILayout.Height(30));
        //    EditorGUILayout.EndHorizontal();
        //    GUILayout.Space(8);
        //    EditorGUILayout.EndVertical();
        //}

        //EditorGUILayout.EndScrollView();
        //EditorGUILayout.EndHorizontal();

        GUILayout.Space(10);
        GUILayout.FlexibleSpace();
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (controller.State == IdentitiesTabController.IdentityState.CREATE)
        {
            if (GUILayout.Button(new GUIContent("CREATE"), GUILayout.Width(100), GUILayout.Height(30)))
            {
                controller.ProcessRequest(ProcessTasks.CREATE, controller.CurrentIdentity, _properties);

                //if (!Enjin.ValidateAddress(controller.CurrentIdentity.ethereum_address))
                //    EditorUtility.DisplayDialog("INVALID ADDRESS", "The address you entered is not valid. Please enter a valid address", "Ok");
                //else
                //{
                //    controller.ProcessRequest(ProcessTasks.CREATE, controller.CurrentIdentity, _properties);
                //}
            }
        }

        if (GUILayout.Button(new GUIContent("BACK"), GUILayout.Width(100), GUILayout.Height(30)))
        {
            controller.CurrentIdentity.fields = new Fields[0];
            controller.State = IdentitiesTabController.IdentityState.VIEW;
        }

        GUILayout.Space(10);
        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10);
        GUILayout.EndArea();
    }