<template>
  <uni-nav-bar
    fixed
    shadow
    background-color="#fff"
    color="#0A1F13"
    :border="false"
    :left-icon="leftIcon ? 'left' : ''"
    :title="title"
    @clickLeft="onLeftClick"
  >
    <template #right> <slot></slot> </template>
  </uni-nav-bar>
</template>
<script setup lang="ts">
import router from '@/router/router'

const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  leftIcon: {
    type: Boolean,
    default: true,
  },
  custom: {
    type: Boolean,
    default: false,
  },
})

const emits = defineEmits(['back'])
function onLeftClick() {
  emits('back')
  if (props.custom) {
    return
  }
  const canNavBack = getCurrentPages()
  if (canNavBack && canNavBack.length > 1) {
    router.navigateBack()
  } else {
    history.back()
  }
}
</script>
