<script lang="ts" context="module">
  export function load({ params, url }: LoadEvent): LoadOutput {
    const type = getTypeByName(params.type);

    const page = findPageByHref(url.pathname);

    if (!type || !page) {
      return {
        status: 404,
        error: `Type ${params.type} not found.`
      };
    }

    return {
      props: {
        type,
        page
      }
    };
  }
</script>

<script lang="ts">
  import {
     GraphQLNamedType, isObjectType,
  } from 'graphql'
  import type { LoadEvent, LoadOutput } from '@sveltejs/kit'
  import { findPageByHref } from '$lib/pages'
  import PreviousNextPage from '$lib/components/nav/PreviousNextPage.svelte'
  import type { WebsitePage } from 'src/app'
  import { getTypeByName, getTypeUsages } from '$lib/model'
  import type { TypeReverseMapping } from '@magidoc/plugin-reverse-schema-mapper'
  import UpsertDetails from '$lib/components/upsert/UpsertDetails.svelte';

  export let type: GraphQLNamedType
  export let usages: TypeReverseMapping | undefined
  export let page: WebsitePage
</script>

<svelte:head>
  <title>Upsert - {type.name}</title>
</svelte:head>

{#if isObjectType(type)}
  <UpsertDetails {type} />
{/if}

<PreviousNextPage {page} />
