import { platformAdminApi } from '@/api/businessApi.js';

const BUSINESS_PACKAGE_ROOT = '/subPackages/sub_business_shared';
const PLATFORM_HOME = '/subPackages/sub_platform_admin/home/index';
const PLATFORM_MY = '/subPackages/sub_platform_admin/my/index';

export function getPlatformAdminContext() {
	return {
		mode: 'platform_admin',
		api: platformAdminApi,
		userStorageKey: 'platform_admin_user',
		homePath: PLATFORM_HOME,
		myPath: PLATFORM_MY,
		packageRoot: '/subPackages/sub_platform_admin',
		businessPackageRoot: BUSINESS_PACKAGE_ROOT,
		brandTitle: '平台管理工作台',
		capabilities: {
			canShip: true,
			canRefund: true,
			canStoreFilter: true,
			canWithdraw: true,
			canWithdrawAudit: true,
			canWarehouse: true,
			warehouseType: 'platform',
			canStoreInput: true,
			canDoctorInput: true,
			canStoreInputAudit: true,
			canDoctorInputAudit: true,
		},
		tabList: [
			{ text: '工作台', iconPath: '/static/tabbar/home.png', selectedIconPath: '/static/tabbar/home-active.png', pagePath: PLATFORM_HOME },
			{ text: '我的', iconPath: '/static/tabbar/my.png', selectedIconPath: '/static/tabbar/my-active.png', pagePath: PLATFORM_MY },
		],
	};
}

export function resolveBusinessContext(injected) {
	if (injected && injected.api) return injected;
	if (uni.getStorageSync('loginMode') === 'platform_admin') return getPlatformAdminContext();
	return getPlatformAdminContext();
}

export function businessPageRoot(ctx) {
	return ctx.businessPackageRoot || ctx.packageRoot;
}

export function pageUrl(ctx, subPath) {
	return `${businessPageRoot(ctx)}/${subPath}`;
}
