<template>
	<view class="fe-mp-nav-wrap">
		<view class="fe-mp-nav" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="fe-mp-nav__inner" :style="{ height: navBarHeight + 'px' }">
				<view class="fe-mp-nav__back fe-nav-btn" @tap="$emit('back')">‹</view>
				<text class="fe-mp-nav__title">{{ title }}</text>
				<view class="fe-mp-nav__side" />
			</view>
		</view>
		<view class="fe-mp-nav__placeholder" :style="{ height: totalHeight + 'px' }" />
	</view>
</template>

<script>
export default {
	name: 'FeMpNavBar',
	props: {
		title: { type: String, default: '' }
	},
	data() {
		return {
			statusBarHeight: 20,
			navBarHeight: 44
		}
	},
	computed: {
		totalHeight() {
			return this.statusBarHeight + this.navBarHeight
		}
	},
	created() {
		const sys = uni.getSystemInfoSync()
		this.statusBarHeight = sys.statusBarHeight || 20
		// #ifdef MP-WEIXIN
		const menu = uni.getMenuButtonBoundingClientRect()
		if (menu && menu.top) {
			this.navBarHeight = (menu.top - this.statusBarHeight) * 2 + menu.height
		}
		// #endif
	}
}
</script>

<style lang="scss" scoped>
.fe-mp-nav {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 99;
	background: #fff;
	border-bottom: 1rpx solid $fe-border-light;
}

.fe-mp-nav__placeholder {
	flex-shrink: 0;
}

.fe-mp-nav__inner {
	display: flex;
	align-items: center;
	padding: 0 16rpx 0 8rpx;
	box-sizing: border-box;
}

.fe-mp-nav__back {
	width: 72rpx;
	height: 72rpx;
	font-size: 48rpx;
	line-height: 1;
	color: $fe-foreground;
}

.fe-mp-nav__title {
	flex: 1;
	text-align: center;
	font-size: 34rpx;
	font-weight: 700;
	color: $fe-foreground;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.fe-mp-nav__side {
	width: 72rpx;
	flex-shrink: 0;
}
</style>
