<script setup lang="ts">
import { ApiReference } from '@scalar/api-reference';

const getHostName = () => {
  let hostName =
    typeof window !== 'undefined' ? window.location.hostname : 'coscine.rwth-aachen.de';
  if (hostName.indexOf(':') !== -1) {
    if (hostName.indexOf('https://') !== -1) {
      hostName = hostName.replace('https://', '');
    }
    hostName = hostName.substr(0, hostName.indexOf(':'));
  }
  return hostName;
};
</script>

<template>
  <ApiReference
    :configuration="{
      spec: { url: 'https://' + getHostName() + '/coscine/api/swagger/v2/swagger.json' }
    }"
  >
    <template #footer>
      <div class="center">
        <div class="mb_center info__tos">
          <a
            target="_blank"
            href="https://git.rwth-aachen.de/coscine/docs/public/terms/-/blob/master/TermsOfUse.md"
            rel="noopener noreferrer"
            class="link"
            >Terms of service</a
          >
        </div>
        <div class="mb_center info__contact">
          <a href="mailto:servicedesk@itc.rwth-aachen.de" rel="noopener noreferrer" class="link"
            >Contact Coscine Team</a
          >
        </div>
      </div>
    </template>
  </ApiReference>
</template>

<style scoped>
.center {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.mb_center {
  margin-bottom: 0.5rem;
}
</style>
