component ProfileMenuViewModel
{
    ProfileMenuView m_ProfileView;
    ProfileMenuModel m_Model;

    bool m_IsOpenedProfile;

    public ProfileMenuViewModel()
    {
        m_ProfileView = new ProfileMenuView();
        m_Model = system.Layer_GetComponentByName<ProfileMenuModel>("config_profile");

        m_IsOpenedProfile = false;
    }

    public void OnDecidedEnterDialog()
    {
        ClickNicknameUpdateButton("");
    }

    public void InitProfile()
    {
        m_Model.InitProfile();
    }

    public void OnResize()
    {
        m_ProfileView.ResizeCallback();
    }

    public void DrawProfileNameplateIcon()
    {
        m_ProfileView.DrawProfileNameplateIcon(m_Model.GetNamePlateIconURL());
    }

    public void UpdateViewDataByProfile(string UserName, string introduction, string IconURL, string UserCode, string UserType)
    {
        m_ProfileView.UpdateNameInputField(UserName);
        m_ProfileView.UpdateIntroInputField(introduction);
        m_ProfileView.UpdateMainMenuUserView(UserName, IconURL, UserType);

        if(!m_IsOpenedProfile)
        {
            return;
        }

        m_ProfileView.DrawProfile(UserName, introduction, IconURL);
    }

    public void ResponseInitSession()
    {
        m_Model.ResponseInitSession();
    }

    public void UpdateSelfUserData(string UserName, string introduction, string IconURL, string UserCode, string UserType)
    {
        // 自身のユーザーテーブル上のデータとメインメニューのログインステータスを更新する
        {
            LayerBundle layer = hsLayerGet("vcc_icon_only_base");
            if(layer !== null)
            {
                layer.CallComponentMethod("VCCViewModel", "UpdateSelfUserData",
                    "{" +
                    "\"" + "UserName" + "\"" + ":" + "\"" + UserName + "\"" + "," +
                    "\"" + "IconURL"  + "\"" + ":" + "\"" + IconURL  + "\"" + "," +
                    "\"" + "UserCode" + "\"" + ":" + "\"" + UserCode + "\"" + "," +
                    "\"" + "UserType" + "\"" + ":" + "\"" + UserType + "\"" + "," +
                "}"
                );
            }
        }

        // コミュニティ機能の画面
        {
            LayerBundle layer = hsLayerGet("mainmenu_community_base");
            if(layer !== null)
            {
                layer.CallComponentMethod("CommunityMenuViewModel", "FetchUserList", "");
            }
        }
    }

    public void OpenProfile(string param)
    {
        m_IsOpenedProfile = true;
        m_Model.FetchProfile(false);
    }

    public void OpenMyHome()
    {
        Player SelfPlayer = hsPlayerGet();
        string SelfUserCode = SelfPlayer.GetCustomState("UserCode");
        string SelfUserType = SelfPlayer.GetCustomState("UserType");

        if(SelfUserType == "login" && !SelfUserCode.IsEmpty())
        {
            // ボタン撤去されるのでAPIがなくなってもいいようにコメントアウト
            //heliport.v3.api.profiles.openMyVketUrl("/myroom/maker/?worldid=MyRoom-%s" % SelfUserCode);

        }
    }

    public void CloseProfile(string param)
    {
        m_IsOpenedProfile = false;
        m_ProfileView.Close();
    }

    public void ClickIconChangeButton(string param)
    {
        m_Model.UpdateIcon();
    }

    public void ClickNicknameChangeButton(string param)
    {
        m_ProfileView.CloseIntroEditDialog();
        m_ProfileView.OpenNicknameEditDialog();
    }

    public void ClickNicknameUpdateButton(string param)
    {
        m_Model.UpdateNickname();
        m_ProfileView.CloseNickNameEditDialog();
    }

    public void ClickCloseNicknameEditDialog()
    {
        m_ProfileView.CloseNickNameEditDialog();
    }

    public void ClickIntroductionChangeButton(string param)
    {
        m_ProfileView.CloseNickNameEditDialog();
        m_ProfileView.OpenIntroEditDialog();
    }

    public void ClickIntroductionUpdateButton(string param)
    {
        string inputIntroText = hel_get_HTMLElement_value(m_ProfileView.GetLocalInputTextIntro());
        if(inputIntroText.Length() > 200)
        {
            inputIntroText = inputIntroText.SubString(0, 200);
        }

        m_ProfileView.ClickIntroductionUpdateButton(inputIntroText);
        m_Model.UpdateIntroduction(inputIntroText);

        m_ProfileView.CloseIntroEditDialog();
    }

    public void ClickCloseIntroEditDialog()
    {
        m_ProfileView.CloseIntroEditDialog();
    }

    public void ClickMyVketBtn()
    {
        string CurrentUrl = GetCurrentUrl();
        bool IsTest = (CurrentUrl.IndexOf("test") != -1 || CurrentUrl.IndexOf("localhost") != -1 || CurrentUrl.IndexOf("hikky.dev") != -1);
        string Domain = (IsTest)? "cloud.hikky.dev" : "cloud.vket.com";
        string MyVketURL = "https://%s" % Domain;
        hsWebOpen(MyVketURL);
    }

    public void ClickLogin(string param)
    {
        heliport.v3.api.auths.login();

        // WebXRモード中は裏で別タブが開かれるのでユーザー通知を行う
        if(hsSystemIsVRMode())
        {
            string Ja = "リンクを新しいタブで開きました。\nHomeボタン、またはWebXR終了で確認できます。";
            string En = "Link opened in a new tab.\nCheck using Home button or exit WebXR.";
            string Message = hsIsLangJA() ? Ja : En;
            hsSendToastNotice(0,Message,5.0,"","");
        }
    }

    public void ClickSignup(string param)
    {
        //heliport.v3.api.profiles.openMyVketUrl("/mypage/profile");
        string LoginURL = "https://account.vket.com/auth/login?";
        hsWebOpen(LoginURL);

    }
    private string GetCurrentUrl()
    {
        JsVal val = heliport.v3.api.routers.getCurrentUrl();
        ReturnType result = hsLoadReturnType(val);
        if(!result.IsValid()) return "";

        return result.data.GetStr();
    }
}
