<script lang='ts' setup>
import { chevronBackOutline } from "ionicons/icons";

const { text = "返回" } = defineProps<{
  text?: string;
}>();
const router = useRouter();

function onBack() {
  if (window.history.length > 1) {
    router.back();
  }
  else {
    router.replace("/");
  }
}
</script>

<template>
  <button class="z-1 flex items-center" @click="onBack">
    <slot name="icon">
      <ion-icon :icon="chevronBackOutline" class="text-2xl" />
    </slot>
    <span v-if="text" class="text-base">{{ text }}</span>
  </button>
</template>

<style lang='css' scoped></style>
