<script setup>
import AdminLayout from "@/Layouts/AdminLayout.vue";
import { Head, Link } from "@inertiajs/vue3";

const props = defineProps({ log: { type: Object, required: true } });
</script>

<template>
  <AdminLayout title="SMS log">
    <Head title="SMS log" />

    <div class="mb-4 flex items-center justify-between">
      <div class="flex items-center gap-3">
        <Link :href="route('admin.sms-logs.index')" class="text-sm text-indigo-600 hover:underline">← Nazaj na dnevnike</Link>
        <div class="text-gray-700 text-sm">#{{ log.id }}</div>
      </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
      <div class="lg:col-span-2 space-y-4">
        <div class="rounded-lg border bg-white p-4 shadow-sm">
          <div class="font-semibold text-gray-800 mb-2">Sporočilo</div>
          <pre class="text-sm whitespace-pre-wrap">{{ log.message }}</pre>
        </div>
        <div class="rounded-lg border bg-white p-4 shadow-sm">
          <div class="font-semibold text-gray-800 mb-2">Meta</div>
          <pre class="text-xs whitespace-pre-wrap">{{ JSON.stringify(log.meta || {}, null, 2) }}</pre>
        </div>
      </div>
      <div class="space-y-4">
        <div class="rounded-lg border bg-white p-4 shadow-sm">
          <div class="grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
            <div class="text-gray-500">Prejemnik</div>
            <div class="text-gray-800">{{ log.to_number }}</div>

            <div class="text-gray-500">Sender</div>
            <div class="text-gray-800">{{ log.sender || '—' }}</div>

            <div class="text-gray-500">Profil</div>
            <div class="text-gray-800">{{ log.profile?.name || '—' }}</div>

            <div class="text-gray-500">Predloga</div>
            <div class="text-gray-800">{{ log.template?.slug || log.template?.name || '—' }}</div>

            <div class="text-gray-500">Status</div>
            <div class="text-gray-800">{{ log.status }}</div>

            <div class="text-gray-500">Cena</div>
            <div class="text-gray-800">{{ log.cost != null ? (Number(log.cost).toFixed(2) + ' ' + (log.currency || '')) : '—' }}</div>

            <div class="text-gray-500">Provider ID</div>
            <div class="text-gray-800">{{ log.provider_message_id || '—' }}</div>

            <div class="text-gray-500">Čas</div>
            <div class="text-gray-800">{{ new Date(log.created_at).toLocaleString() }}</div>

            <div class="text-gray-500">Sent</div>
            <div class="text-gray-800">{{ log.sent_at ? new Date(log.sent_at).toLocaleString() : '—' }}</div>

            <div class="text-gray-500">Delivered</div>
            <div class="text-gray-800">{{ log.delivered_at ? new Date(log.delivered_at).toLocaleString() : '—' }}</div>

            <div class="text-gray-500">Failed</div>
            <div class="text-gray-800">{{ log.failed_at ? new Date(log.failed_at).toLocaleString() : '—' }}</div>

            <div class="text-gray-500">Napaka (koda)</div>
            <div class="text-gray-800">{{ log.error_code || '—' }}</div>

            <div class="text-gray-500">Napaka (opis)</div>
            <div class="text-gray-800">{{ log.error_message || '—' }}</div>
          </div>
        </div>
      </div>
    </div>
  </AdminLayout>
</template>

<style scoped>
.label { display: block; font-size: 0.65rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: #6b7280; margin-bottom: 0.25rem; }
</style>
