<script setup lang="ts">
import type { StandardScreenState } from '../../contracts/screenContract'
import QueryStateBoundary from '../../QueryStateBoundary.vue'
withDefaults(defineProps<{ state?: StandardScreenState; warning?: string; error?: Error | null; staleAt?: string; correlationId?: string }>(), { state: 'READY' })
const emit = defineEmits<{ retry: [] }>()
</script>
<template>
  <QueryStateBoundary
    :loading="state === 'LOADING'"
    :processing="state === 'PROCESSING'"
    :dirty="state === 'DIRTY'"
    :empty="state === 'EMPTY'"
    :partial="state === 'PARTIAL'"
    :unauthorized="state === 'UNAUTHORIZED'"
    :forbidden="state === 'FORBIDDEN'"
    :conflict="state === 'CONFLICT'"
    :expired="state === 'EXPIRED'"
    :readonly="state === 'READONLY'"
    :warning="state === 'WARN' ? warning : undefined"
    :error="state === 'ERROR' ? (error ?? new Error('화면 상태 오류')) : undefined"
    :stale-at="staleAt"
    :correlation-id="correlationId"
    @retry="emit('retry')"
  ><slot /></QueryStateBoundary>
</template>
