<script setup lang="ts">
withDefaults(defineProps<{
  text?: string
  fullscreen?: boolean
}>(), {
  text: '加载中...',
  fullscreen: false,
})
</script>

<template>
  <div v-if="fullscreen" class="app-loading-fullscreen">
    <div class="loading-spinner"></div>
    <div class="loading-text">{{ text }}</div>
  </div>
  <div v-else class="app-loading">
    <div class="loading-spinner"></div>
    <span class="loading-text">{{ text }}</span>
  </div>
</template>

<style scoped lang="scss">
.app-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: $gray-500;
  font-size: 14px;
}

.app-loading-fullscreen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  z-index: 9999;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid $gray-200;
  border-top-color: $primary;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: $gray-500;
  margin-top: 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
</style>