<template>
	<view class="tab-bar-wrapper" :style="{ height: height }">
		<view v-for="(item, index) in tabs" :key="index" class="tab-bar-item" @click="tabBarClick(index, item)">
			<template v-if="item.isShow">
				<image
					:style="{
						width: iconSize,
						height: iconSize
					}"
					:src="currentIndex === index ? item.selectedIcon : item.unselectedIcon"
					mode="aspectFit"
				/>
				<view v-if="item.name" class="tab-bar-name" :class="{ 'tab-bar-name-active': currentIndex === index }">
					{{ item.name }}
				</view>
			</template>
		</view>
	</view>
</template>

<script setup lang="ts">
import { TabBarItemBasic } from ".";

defineProps({
	tabs: {
		type: Array<TabBarItemBasic>,
		default: []
	},
	currentIndex: {
		type: Number,
		default: 0
	},
	// 样式
	height: {
		type: String,
		default: "100rpx"
	},
	iconSize: {
		type: String,
		default: "50rpx"
	}
});

const emits = defineEmits<{
	(event: "click", index: number, item: TabBarItemBasic): void;
}>();

function tabBarClick(index: number, item: TabBarItemBasic) {
	emits("click", index, item);
}
</script>

<script lang="ts">
export default {
	name: "TabBar"
};
</script>

<style lang="scss" scoped>
.tab-bar-wrapper {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-around;
	width: 100%;
	.tab-bar-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		width: 100%;
		padding-top: var(--tab-bar-padding-top, 10rpx);
		.tab-bar-name {
			margin-top: 7rpx;
			font-size: var(--tab-bar-name-size, 20rpx);
			color: var(--tab-bar-name-color, rgb(192 196 204));
		}
		.tab-bar-name-active {
			font-size: var(--tab-bar-name-size-active, 20rpx);
			color: var(--tab-bar-name-color-active, rgb(255 83 111));
		}
	}
}
</style>
