<template>
	<view class="wrap-nav-button" v-if="menus && menus.length > 0">
		<nav-bottom height="152rpx">
			<view class="menu-layout">
				<u-button
					v-for="(item, index) in menus"
					:key="index"
					:text="item.title"
					:custom-style="{...btnStyle, color: item.plain?item.bgColor:'#FFFFFF',backgroundColor: item.plain?'transparent':item.bgColor,borderColor: item.plain?item.bgColor:'transparent',flex:'none',width: getBtnWidth()}"
					shape="square"
					:hair-line="item.plain || false"
					:plain="item.plain || false"
					:disabled="item.disabled"
					@click="onclick(index, item)"></u-button>
			</view>
		</nav-bottom>
	</view>
</template>

<script>
	import NavBottom from '@/components/nav-bottom/index.vue'
	
	export default {
		components: {
			NavBottom
		},
		props: {
			menus: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				btnStyle: {
					height: '100rpx',
					fontSize: '30rpx',
					borderRadius: '12rpx',
					overflow: 'hidden',
					margin: '0'
				}
			}
		},
		methods: {
			getBtnWidth() {
				if(this.menus.length === 1) {
					return '100%'
				} else if(this.menus.length === 2) {
					return '280rpx'
				} else {
					return '190rpx'
				}
			},
			onclick(index = 0, value) {
				this.$emit('itemClick', index, value)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap-nav-button {
		z-index: 998;
		position: fixed;
		left: 0;
		bottom: env(safe-area-inset-bottom);
		width: 100%;
		padding: 0;
		margin: 0;
		.menu-layout {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 60rpx;
			height: 100%;
		}
	}
</style>