<script setup>
definePageMeta({
  middleware: "auth"
})

const supabase = useSupabaseClient()
const dataStore = useDataStore()
const profileStore = useProfileStore()
const profileStore = useProfileStore()



const resources = {
  customers: {
    label: "Kunden"
  },
  vendors: {
    label: "Lieferanten"
  },
  products: {
    label: "Artikel"
  },
  spaces: {
    label: "Lagerplätze"
  },
  invoices: {
    label: "Rechnungen"
  },
  quotes: {
    label: "Angebote"
  },
  inventoryitems: {
    label: "Inventarartikel"
  },
  projects: {
    label: "Projekte"
  },
  confirmationOrders: {
    label: "Auftragsbestätigungen"
  }
}

const numberRanges = ref(profileStore.ownTenant.numberRanges)

const updateNumberRanges = async (range) => {

  const {data,error} = await supabase
      .from("tenants")
      .update({numberRanges: numberRanges.value})
      .eq('id',profileStore.currentTenant)

  await dataStore.fetchOwnTenant()
}


</script>

<template>
  <UDashboardNavbar
    title="Nummernkreise bearbeiten"
  >

  </UDashboardNavbar>
  <UDashboardToolbar>
    <UAlert
        title="Änderungen an diesen Werten betreffen nur neu Erstellte Einträge."
        color="rose"
        variant="outline"
        icon="i-heroicons-exclamation-triangle"
    />
  </UDashboardToolbar>

  <table
    class="m-3"
  >
    <tr class="text-left">
      <th>Typ</th>
      <th>Prefix</th>
      <th>Nächste Nummer</th>
      <th>Suffix</th>
    </tr>
    <tr
      v-for="key in Object.keys(resources)"
    >
      <td>{{resources[key].label}}</td>
      <td>
        <UInput
          v-model="numberRanges[key].prefix"
          @change="updateNumberRanges"
        />
      </td>
      <td>
        <UInput
            v-model="numberRanges[key].nextNumber"
            @change="updateNumberRanges"
            type="number"
            step="1"
        />
      </td>
      <td>
        <UInput
            v-model="numberRanges[key].suffix"
            @change="updateNumberRanges"
        />
      </td>
    </tr>
  </table>
</template>

<style scoped>

</style>