package cc.winboll.studio.positions.activities;

/**
 * @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
 * @Date 2025/09/29 00:11
 * @Describe WinBoLL 窗口基础类
 */
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.App;
import cc.winboll.studio.positions.PointLevel;
import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.utils.ActivityAliasUtils;
import cc.winboll.studio.positions.utils.AppConfigsUtil;

public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {

    public static final String TAG = "WinBoLLActivity";

	public static volatile PointLevel _mPointLevel = PointLevel.WUKONG;

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public String getTag() {
        return TAG;
    }

    @Override
    protected void onResume() {
        super.onResume();
		//ToastUtils.show("onResume");

		// ActivityAliasUtils 工具使用示例
		//
//		// 获取真实的目标组件名（即使通过 alias 启动，也能拿到 OriginalActivity）
//        String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
//        LogUtils.d("AliasActivity", "真实组件名：" + realTargetName);
		// 获取真实的目标组件名（即使通过 alias 启动，也能拿到 OriginalActivity）
//        String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
//        LogUtils.d(TAG, "真实组件名：" + realTargetName);
//		ToastUtils.show(realTargetName);
//		// 判断某个组件是否为 alias
//		String componentName = "com.winboll.app.AliasActivity";
//		boolean isAlias = ActivityAliasUtils.isActivityAlias(getApplicationContext(), componentName);
//		LogUtils.d("判断结果", componentName + " 是否为 alias：" + isAlias);  // true
//		// 获取启动当前 Activity 的组件名（兼容 alias 场景）
//        String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
//        LogUtils.d("MainActivity", "启动组件名：" + launchComponent);

		/*
		 * 应用入口逻辑模块
		 */
		//
		// 检查当前活动的启动组件名，设置应用入口级别。
		String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
        LogUtils.d("MainActivity", "启动组件名：" + launchComponent);
		ToastUtils.show(launchComponent);
		// 当前应用处于活动暂停的状态时，就检查应用的入口组件名称，设置应用入口级别。
		if (WinBoLLActivity._mPointLevel == PointLevel.DORAEMON) {
			if (launchComponent.equals(App.COMPONENT_WUKONG)) {
				getSupportActionBar().setTitle(getString(R.string.appplus_name));
				ToastUtils.show("WUKONG");
				_mPointLevel = PointLevel.WUKONG;
			} else if (launchComponent.equals(App.COMPONENT_LAOJUN)) {
				getSupportActionBar().setTitle(getString(R.string.app_name));
				ToastUtils.show("LAOJUN");
				_mPointLevel = PointLevel.LAOJUN;
			} else {
				// 如果是其他应用组件入口，就关闭活动
				finish();
			}
		}

		/*
		 * 应用级别设置模块
		 */
		// 读取并配置应用级别
		App._mAppLevel = AppConfigsUtil.getInstance(getApplicationContext()).getAppLevel(true);

        LogUtils.d(TAG, String.format("onResume %s", getTag()));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        /*if (item.getItemId() == R.id.item_log) {
		 WinBoLLActivityManager.getInstance().startLogActivity(this);
		 return true;
		 } else if (item.getItemId() == R.id.item_home) {
		 startActivity(new Intent(this, MainActivity.class));
		 return true;
		 }*/
        // 在switch语句中处理每个ID，并在处理完后返回true，未处理的情况返回false。
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        WinBoLLActivityManager.getInstance().add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        WinBoLLActivityManager.getInstance().registeRemove(this);
    }
}
