<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { useSmartBack } from '../composables/useSmartBack';

const props = withDefaults(
  defineProps<{
    fallback?: string;
    variant?: 'desktop' | 'mobile';
    showLabel?: boolean;
  }>(),
  {
    variant: 'desktop',
    showLabel: true,
  },
);

const { t } = useI18n();
const { goBack } = useSmartBack(() => props.fallback);
</script>

<template>
  <button
    type="button"
    class="page-back-btn"
    :class="[`page-back-btn--${variant}`]"
    :aria-label="t('common.back')"
    @click="goBack"
  >
    <span class="page-back-icon" aria-hidden="true">‹</span>
    <span v-if="showLabel && variant === 'desktop'" class="page-back-label">
      {{ t('common.back') }}
    </span>
  </button>
</template>

<style scoped>
.page-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s;
}

.page-back-btn--desktop {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.page-back-btn--desktop:hover {
  color: var(--text);
}

.page-back-btn--mobile {
  color: #003d6b;
  font-size: 24px;
  line-height: 1;
  padding: 0 8px;
}

.page-back-icon {
  line-height: 1;
}

.page-back-btn--desktop .page-back-icon {
  font-size: 18px;
}
</style>
