import {
	defineStore
} from 'pinia';
import {
	ref
} from 'vue';
export const useNavbarStore = defineStore('navbar', {
	state: () => ({
		showBack: true,
		rightText: '',
		showSearch: false,
		title: '',
		isTransparent: false,
		height: 0,
		hasPlaceholder: true,
		scrollTop: 0 ,//滚动高度
		screenHeight:375
	}),
	actions: {
		updateNavbarConfig(config) {
			Object.assign(this, config);
		},
		initNavbarHeight() {
			uni.getSystemInfo({
				success: (res) => {
					const statusBarHeight = res.statusBarHeight;
					// 总高度
					this.screenHeight = res.screenHeight
					let navBarHeight;
					// 微信小程序的特殊处理
					if (res.uniPlatform === 'mp-weixin' || res.uniPlatform === 'mp-alipay') {
						const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
						const topGap = menuButtonInfo.top - statusBarHeight;
						const bottomGap = statusBarHeight + menuButtonInfo.height + topGap * 2 - (
							menuButtonInfo.top + menuButtonInfo.height);
						navBarHeight = menuButtonInfo.height + topGap + bottomGap - 4;
					} else if (uni.getSystemInfoSync().platform === 'ios') {
						navBarHeight = 44;
					} else {
						navBarHeight = 48;
					}
					this.height = statusBarHeight + navBarHeight;
				},
				fail: (err) => {
					console.error('获取系统信息失败:', err);
					this.height = 64; // 失败时设置一个默认高度
				}
			});
		}
	}
});