import { defineStore } from 'pinia'
import { computed } from 'vue'

import { useTraces } from '@/composables/useTraces'

/**
 * Pure data store for trace data.
 * Contains loaded traces from backend API.
 * Selection and filtering logic is in uiStore.
 */
export const useTracesStore = defineStore('traces', () => {
  // remote traces from API via TanStack Query
  const { data: traces, isLoading: isLoadingList } = useTraces()

  /**
   * Whether any traces were loaded from the API.
   * Used to determine empty state message and filter visibility.
   */
  const hasApiTraces = computed(() => (traces.value?.data.length || 0) > 0)

  return {
    traces,
    hasApiTraces,
    isLoadingList,
  }
})
