<template>
  <MaintenanceTile
    icon="mdi-vector-triangle"
    title="Tag centroids"
    blurb="Rebuild SigLIP centroids for similarity suggestions."
    :open="busy"
  >
      <p class="text-body-2 mb-3">
        Rebuild the per-tag SigLIP centroids that power similarity-based
        suggestions. Runs nightly automatically; trigger manually after a
        large tagging session.
      </p>
      <v-btn color="primary" rounded="pill" :loading="busy" @click="run">
        <v-icon start>mdi-vector-triangle</v-icon> Recompute centroids
      </v-btn>
      <span v-if="done" class="ml-3 text-caption">Enqueued.</span>
      <QueueStatusBar queue="ml" queue-label="ML" />
  </MaintenanceTile>
</template>

<script setup>
import { toast } from '../../utils/toast.js'
import { ref } from 'vue'
import { useMLStore } from '../../stores/ml.js'
import MaintenanceTile from '../common/MaintenanceTile.vue'
import QueueStatusBar from './QueueStatusBar.vue'
const store = useMLStore()
const busy = ref(false)
const done = ref(false)
async function run() {
  busy.value = true
  try { await store.triggerRecomputeCentroids(); done.value = true }
  catch (e) { toast({ text: e.message, type: 'error' }) }
  finally { busy.value = false }
}
</script>
