<!-- front-end/app/pages/sistema/configuracoes.vue -->
<script setup lang="ts">
const { apiFetch } = useApi()

interface ApiTenant {
  ID: string
  Slug: string
  Name: string
  Plan: string
  MaxUsers: number
  IsActive: boolean
}

const { data: tenant, refresh } = await useAsyncData('tenant-me', () =>
  apiFetch<ApiTenant>('/tenant/me')
)

const nome = ref(tenant.value?.Name ?? '')
const saving = ref(false)
const saved = ref(false)

async function salvar() {
  saving.value = true
  saved.value = false
  await apiFetch('/tenant/me', { method: 'PUT', body: { name: nome.value } })
  await refresh()
  saving.value = false
  saved.value = true
  setTimeout(() => { saved.value = false }, 3000)
}
</script>

<template>
  <div class="page">
    <AppTopbar title="Configurações" breadcrumb="Sistema · Configurações" />
    <div class="content">
      <div class="card pad">
        <h2 class="section-title">Dados da Empresa</h2>
        <UFormField label="Nome da Empresa" class="field">
          <UInput v-model="nome" />
        </UFormField>
        <UFormField label="Slug" class="field">
          <UInput :model-value="tenant?.Slug ?? ''" disabled />
        </UFormField>
        <UFormField label="Plano Atual" class="field">
          <UInput :model-value="tenant?.Plan ?? ''" disabled />
        </UFormField>
        <div class="actions">
          <UButton class="btn-primary" size="sm" :loading="saving" @click="salvar">Salvar Alterações</UButton>
          <span v-if="saved" class="saved-msg">Salvo!</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.page { display: flex; flex-direction: column; height: 100vh; }
.content { padding: 20px 22px; flex: 1; overflow-y: auto; }
.card { background: white; border-radius: 11px; border: 1px solid #e2e8f0; }
.pad { padding: 24px; }
.section-title { font-size: 15px; font-weight: 700; color: #0f172a; margin-bottom: 20px; }
.field { margin-bottom: 16px; }
.actions { display: flex; align-items: center; gap: 12px; }
.btn-primary { background: linear-gradient(135deg, #667eea, #764ba2) !important; }
.saved-msg { font-size: 13px; color: #10b981; font-weight: 500; }
</style>
