<template>
	<view class="subpackage-host">
		<SubpackageCommonBeginReception v-if="implReady" v-bind="$attrs" />
		<view v-else class="loading">
			<text v-if="error">{{ error }}</text>
			<text v-else>正在加载...</text>
		</view>
	</view>
</template>

<script>
import SubpackageCommonBeginReception from '@/pages-subpackage/furniture_reception/common_begin_reception.vue';

export default {
	inheritAttrs: false,
	components: {
		SubpackageCommonBeginReception
	},
	data() {
		return {
			implReady: false,
			error: ''
		};
	},
	created() {
		this.loadImpl();
	},
	methods: {
		loadSubPackagePagesSubpackage() {
			return new Promise((resolve, reject) => {
				if (!uni || !uni.loadSubPackage) {
					resolve();
					return;
				}
				uni.loadSubPackage({
					name: 'pages-subpackage',
					success: resolve,
					fail: () => {
						uni.loadSubPackage({
							root: 'pages-subpackage',
							success: resolve,
							fail: reject
						});
					}
				});
			});
		},
		async loadImpl() {
			try {
				await this.loadSubPackagePagesSubpackage();
				this.implReady = true;
			} catch (e) {
				console.error('[CommonBeginReceptionHost] loadImpl failed:', e);
				this.error = '模块加载失败';
			}
		}
	}
};
</script>

<style>
.subpackage-host {
	min-height: 1px;
}
.loading {
	padding: 24rpx 16rpx;
	color: #666;
	font-size: 28rpx;
}
</style>