<script setup lang="ts">
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import api from '../../api';

const route = useRoute();
const router = useRouter();

onMounted(async () => {
  const matchId = String(route.params.matchId ?? '').trim();
  if (!matchId) {
    await router.replace('/matches/outrights');
    return;
  }
  try {
    const { data } = await api.get(`/admin/outrights/${matchId}`);
    const leagueId = data.data?.leagueId as string | undefined;
    if (leagueId) {
      await router.replace(`/matches/outrights/leagues/${leagueId}`);
      return;
    }
    await router.replace({
      path: '/matches/outrights',
      query: { matchId },
    });
  } catch {
    await router.replace('/matches/outrights');
  }
});
</script>

<template>
  <div />
</template>
