All files / src/components InfrastructureVmDrawer.vue

100% Statements 432/432
100% Branches 0/0
100% Functions 0/0
100% Lines 432/432

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556                                          1x 1x   1x 1x                         1x   1x         1x       1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x     1x     1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x               1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x                   1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x           1x 1x 1x 1x   1x 1x 1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x   1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x    
<script setup lang="ts">
/**
 * Inline detail panel for ONE VM, shown directly under the clicked
 * ``InfrastructureVmCard`` inside the deployment-detail page's
 * Infrastruktur section.
 *
 * Previously this was a side-drawer (fixed-position slide-in over a
 * darkened backdrop) — that pulled focus too aggressively and felt
 * detached from the rest of the page. The new shape is a normal
 * Vue component that renders as part of the parent's flow, looking
 * like just another card in the Infrastruktur section.
 *
 * Layout: a rounded card with the same ``bg-white border shadow-sm``
 * vocabulary as the surrounding deployment-page sections, internal
 * sub-cards on ``bg-gray-50`` for each data group (Identity,
 * Lifecycle, Hardware, Addresses, Ports, SGs, Volumes, Metadata).
 *
 * The component still owns its own fetch+loading+error state — the
 * parent only mounts it with a target address and listens for
 * ``close`` to collapse the inline panel.
 */
import { onMounted, ref, watch, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import type { DeploymentResource } from '@/types'
import { deploymentApi } from '@/api/deployment.api'
import {
  X,
  RefreshCw,
  AlertTriangle,
  Server,
  Cpu,
  Network as NetworkIcon,
  Shield,
  HardDrive,
  Tag,
  Activity,
} from 'lucide-vue-next'
 
const { t } = useI18n()
 
const props = defineProps<{
  deploymentId: string
  address: string
}>()
 
const emit = defineEmits<{
  (e: 'close'): void
}>()
 
const isLoading = ref(false)
const detail = ref<DeploymentResource | null>(null)
const errorMessage = ref<string | null>(null)
 
const load = async () => {
  isLoading.value = true
  errorMessage.value = null
  try {
    const response = await deploymentApi.getResourceDetail(
      props.deploymentId,
      props.address,
    )
    detail.value = response.data
  } catch (err: any) {
    // 404 — resource removed since the list was rendered. 412 — user
    // lost their OpenStack credentials between mount and click. Both
    // are surfaced inline; the page-level toast is reserved for
    // harder errors.
    const status = err?.response?.status
    if (status === 404) {
      errorMessage.value = t('vm.drawer.errors.notFound')
    } else if (status === 412) {
      errorMessage.value = t('vm.drawer.errors.missingCredentials')
    } else if (status === 502) {
      errorMessage.value = t('vm.drawer.errors.unreachable')
    } else {
      errorMessage.value = err?.message || t('vm.drawer.errors.generic')
    }
  } finally {
    isLoading.value = false
  }
}
 
onMounted(load)
// Re-fetch when the parent swaps which VM we look at without
// unmounting the panel.
watch(() => props.address, load)
 
// --- Lifecycle pill colour (matches InfrastructureVmCard) ---
const lifecycleTone = computed<'green' | 'red' | 'amber' | 'gray'>(() => {
  const s = detail.value?.lifecycle?.status
  if (!s) return 'gray'
  if (s === 'ACTIVE') return 'green'
  if (s === 'ERROR') return 'red'
  if (s === 'BUILD' || s === 'REBUILD') return 'amber'
  return 'gray'
})
 
const lifecyclePillClass = computed(() => {
  switch (lifecycleTone.value) {
    case 'green':
      return 'bg-emerald-100 text-emerald-700 border-emerald-200'
    case 'red':
      return 'bg-red-100 text-red-700 border-red-200'
    case 'amber':
      return 'bg-amber-100 text-amber-800 border-amber-200'
    default:
      return 'bg-gray-100 text-gray-700 border-gray-200'
  }
})
 
const uptime = computed(() => {
  const ts = detail.value?.hardware?.launched_at
  if (!ts) return null
  const launched = new Date(ts).getTime()
  if (!Number.isFinite(launched)) return null
  const delta = Date.now() - launched
  if (delta < 0) return null
  const minutes = Math.floor(delta / 60_000)
  if (minutes < 60) return `${minutes}m`
  const hours = Math.floor(minutes / 60)
  if (hours < 24) return `${hours}h ${minutes % 60}m`
  const days = Math.floor(hours / 24)
  return `${days}d ${hours % 24}h`
})
 
// --- Map network IDs / fixed IPs to the human-friendly network name.
// The Stage-2 ``ports`` block only carries the ``network_id`` (UUID).
// The Stage-1 ``addresses`` block, on the other hand, is keyed by
// the OpenStack-side network NAME (e.g. ``"NAT"``) and carries the
// fixed_ip for that network. So we walk addresses to build two cheap
// lookups: by-fixed-ip first, then by-mac as fallback.
const portNetworkName = (port: { fixed_ip: string | null; mac: string | null }): string | null => {
  const addrs = detail.value?.addresses
  if (!addrs || addrs.length === 0) return null
  if (port.fixed_ip) {
    const m = addrs.find((a) => a.fixed_ip === port.fixed_ip)
    if (m) return m.network
  }
  if (port.mac) {
    const m = addrs.find((a) => a.mac === port.mac)
    if (m) return m.network
  }
  return null
}
</script>
 
<template>
  <!--
    The outer container blends into the parent's Infrastruktur
    section: same ``bg-white rounded-xl border shadow-sm`` shell as
    the deployment-page cards. ``flex flex-col`` lets the body
    consume remaining height when the parent constrains us via
    ``flex-1 min-h-0`` (sidebar context); inline-card contexts just
    grow naturally because no parent flex is constraining us. The
    ``overflow-hidden`` on this wrapper keeps the rounded corners
    intact even when the inner body has its own ``overflow-y-auto``.
  -->
  <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden flex flex-col">
    <!-- Header — icon tile + title + close button. ``shrink-0`` so
         the body, not the header, absorbs any height squeeze. The
         gradient gives a soft visual top-edge without needing a
         separate accent line. -->
    <header class="shrink-0 px-5 py-4 border-b border-gray-200 flex items-center justify-between gap-3 bg-gradient-to-r from-gray-50 to-white">
      <div class="flex items-center gap-3 min-w-0">
        <div class="p-2 bg-white rounded-lg shrink-0 border border-gray-200">
          <Server :size="18" class="text-gray-600" />
        </div>
        <div class="min-w-0">
          <p class="text-[10px] uppercase tracking-wider text-gray-500 font-bold">
            {{ t('vm.drawer.title') }}
          </p>
          <h3 class="text-base font-semibold text-gray-900 truncate" :title="detail?.display_name || address">
            {{ detail?.display_name || address }}
          </h3>
        </div>
      </div>
      <div class="flex items-center gap-1 shrink-0">
        <button
          @click="load"
          :disabled="isLoading"
          class="p-2 text-gray-500 hover:text-gray-800 hover:bg-gray-100 rounded-lg disabled:opacity-50 transition-colors"
          :title="t('vm.actions.refresh')"
        >
          <RefreshCw :size="15" :class="isLoading ? 'animate-spin' : ''" />
        </button>
        <button
          @click="emit('close')"
          class="p-2 text-gray-500 hover:text-gray-800 hover:bg-gray-100 rounded-lg transition-colors"
          :title="t('vm.actions.closeDetails')"
        >
          <X :size="16" />
        </button>
      </div>
    </header>
 
    <!-- Body — ``min-h-0`` is the Tailwind incantation that lets a
         flex child shrink below its content's natural size, which is
         what enables ``overflow-y-auto`` to engage when the parent
         (the sidebar's flex column) constrains us to a viewport-
         bounded height. In a non-flex context (inline card) this
         is a no-op: the body grows to fit content. -->
    <div class="flex-1 min-h-0 overflow-y-auto p-4 space-y-3">
      <div v-if="isLoading && !detail" class="text-sm text-gray-500 italic px-4 py-6 bg-gray-50 rounded-lg border border-gray-100 text-center">
        {{ t('vm.drawer.loading') }}
      </div>
 
      <div
        v-else-if="errorMessage"
        class="text-sm p-3 rounded-lg border bg-red-50 text-red-800 border-red-200 flex items-start gap-2"
      >
        <AlertTriangle :size="16" class="mt-0.5 shrink-0" />
        <p>{{ errorMessage }}</p>
      </div>
 
      <template v-else-if="detail">
        <!-- Identity card -->
        <section class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3">
          <div class="flex items-center gap-2 mb-1">
            <Tag :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.identity') }}</h4>
            <span
              v-if="detail.team"
              class="ml-auto text-[10px] font-bold uppercase tracking-wider bg-blue-100 text-blue-700 px-2 py-0.5 rounded border border-blue-200"
            >
              {{ detail.team }}
            </span>
            <span
              v-else
              class="ml-auto text-[10px] font-bold uppercase tracking-wider bg-gray-100 text-gray-600 px-2 py-0.5 rounded border border-gray-200"
            >
              {{ t('vm.sharedTeam') }}
            </span>
          </div>
          <div class="text-xs space-y-1.5">
            <div class="flex items-baseline gap-2">
              <span class="text-gray-500 w-20 shrink-0">{{ t('vm.drawer.address') }}</span>
              <code class="font-mono text-gray-800 break-all">{{ detail.address }}</code>
            </div>
            <div class="flex items-baseline gap-2">
              <span class="text-gray-500 w-20 shrink-0">{{ t('vm.drawer.osUuid') }}</span>
              <code class="font-mono text-gray-700 break-all">{{ detail.provider_id }}</code>
            </div>
          </div>
        </section>
 
        <!-- Lifecycle card -->
        <section
          v-if="detail.lifecycle"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <Activity :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.lifecycle') }}</h4>
            <span
              v-if="detail.lifecycle.status"
              class="ml-auto text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded border"
              :class="lifecyclePillClass"
            >
              {{ detail.lifecycle.status }}
            </span>
          </div>
          <div class="grid grid-cols-2 gap-x-4 gap-y-1.5 text-xs">
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.lifecycle.taskState') }}</span>
              <p class="font-medium text-gray-800">{{ detail.lifecycle.task_state || '—' }}</p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.lifecycle.vmState') }}</span>
              <p class="font-medium text-gray-800">{{ detail.lifecycle.vm_state || '—' }}</p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.lifecycle.powerState') }}</span>
              <p class="font-medium text-gray-800">{{ detail.lifecycle.power_state || '—' }}</p>
            </div>
            <div v-if="uptime">
              <span class="text-gray-500">{{ t('vm.uptimePrefix') }}</span>
              <p class="font-medium text-gray-800">{{ uptime }}</p>
            </div>
          </div>
          <div
            v-if="detail.lifecycle.fault_message"
            class="text-xs p-2 rounded border bg-red-50 text-red-800 border-red-200"
          >
            <p class="font-semibold mb-0.5">{{ t('vm.openstackFault') }}</p>
            <p class="font-mono break-all">{{ detail.lifecycle.fault_message }}</p>
          </div>
        </section>
 
        <!-- Hardware card -->
        <section
          v-if="detail.hardware"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <Cpu :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.hardware') }}</h4>
          </div>
          <div class="grid grid-cols-2 gap-x-4 gap-y-1.5 text-xs">
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.hardware.flavor') }}</span>
              <p class="font-medium text-gray-800">{{ detail.hardware.flavor_name || '—' }}</p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.units.vcpu') }}</span>
              <p class="font-medium text-gray-800">{{ detail.hardware.vcpus ?? '—' }}</p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.hardware.ram') }}</span>
              <p class="font-medium text-gray-800">
                {{ detail.hardware.ram_mb != null ? `${detail.hardware.ram_mb} MB` : '—' }}
              </p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.hardware.disk') }}</span>
              <p class="font-medium text-gray-800">
                {{ detail.hardware.disk_gb != null ? `${detail.hardware.disk_gb} ${t('vm.units.gb')}` : '—' }}
              </p>
            </div>
            <div class="col-span-2">
              <span class="text-gray-500">{{ t('vm.drawer.hardware.image') }}</span>
              <p class="font-medium text-gray-800 break-all">
                <span v-if="detail.hardware.image_name">{{ detail.hardware.image_name }}</span>
                <code v-else-if="detail.hardware.image_id" class="font-mono text-xs">
                  {{ detail.hardware.image_id }}
                </code>
                <span v-else>—</span>
              </p>
            </div>
            <div>
              <span class="text-gray-500">{{ t('vm.drawer.hardware.az') }}</span>
              <p class="font-medium text-gray-800">{{ detail.hardware.availability_zone || '—' }}</p>
            </div>
          </div>
        </section>
 
        <!-- Network addresses card (high-level: one row per network name) -->
        <section
          v-if="detail.addresses && detail.addresses.length > 0"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <NetworkIcon :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.addresses') }}</h4>
            <span
              class="ml-auto text-[10px] font-bold bg-gray-200 text-gray-600 px-2 py-0.5 rounded"
            >
              {{ detail.addresses.length }}
            </span>
          </div>
          <div class="space-y-2">
            <div
              v-for="addr in detail.addresses"
              :key="`${addr.network}::${addr.fixed_ip || addr.mac || ''}`"
              class="text-xs bg-white rounded border border-gray-200 p-2.5 space-y-1"
            >
              <p class="font-semibold text-gray-900">{{ addr.network }}</p>
              <div class="grid grid-cols-2 gap-x-3 gap-y-0.5 text-gray-700">
                <div>
                  <span class="text-gray-500">{{ t('vm.drawer.network.fixedIp') }}</span>
                  <code class="ml-1 font-mono">{{ addr.fixed_ip || '—' }}</code>
                </div>
                <div v-if="addr.floating_ip">
                  <span class="text-gray-500">{{ t('vm.drawer.network.floatingIp') }}</span>
                  <code class="ml-1 font-mono text-emerald-700">{{ addr.floating_ip }}</code>
                </div>
                <div v-if="addr.mac">
                  <span class="text-gray-500">{{ t('vm.drawer.network.mac') }}</span>
                  <code class="ml-1 font-mono">{{ addr.mac }}</code>
                </div>
              </div>
            </div>
          </div>
        </section>
 
        <!-- Network ports card (low-level per-port detail) -->
        <section
          v-if="detail.ports"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <NetworkIcon :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.ports') }}</h4>
            <span
              v-if="detail.ports.length > 0"
              class="ml-auto text-[10px] font-bold bg-gray-200 text-gray-600 px-2 py-0.5 rounded"
            >
              {{ detail.ports.length }}
            </span>
          </div>
          <div v-if="detail.ports.length === 0" class="text-xs text-gray-500 italic">
            {{ t('vm.drawer.network.noPorts') }}
          </div>
          <div v-else class="space-y-2">
            <div
              v-for="port in detail.ports"
              :key="port.port_id"
              class="text-xs bg-white rounded border border-gray-200 p-2.5 space-y-1"
            >
              <div class="flex items-center justify-between gap-2">
                <div class="flex items-center gap-2 min-w-0">
                  <code class="font-mono text-gray-700 truncate" :title="port.port_id">
                    {{ port.port_id.slice(0, 8) }}…
                  </code>
                  <span
                    v-if="portNetworkName(port)"
                    class="text-[10px] font-semibold bg-blue-50 text-blue-700 border border-blue-200 px-2 py-0.5 rounded"
                    :title="port.network_id || ''"
                  >
                    {{ portNetworkName(port) }}
                  </span>
                </div>
                <span
                  class="text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded border whitespace-nowrap"
                  :class="port.status === 'ACTIVE'
                    ? 'bg-emerald-100 text-emerald-700 border-emerald-200'
                    : 'bg-gray-100 text-gray-600 border-gray-200'"
                >
                  {{ port.status || 'unknown' }}
                </span>
              </div>
              <div class="grid grid-cols-2 gap-x-3 gap-y-0.5 text-gray-700">
                <div>
                  <span class="text-gray-500">IP</span>
                  <code class="ml-1 font-mono">{{ port.fixed_ip || '—' }}</code>
                </div>
                <div>
                  <span class="text-gray-500">{{ t('vm.drawer.network.mac') }}</span>
                  <code class="ml-1 font-mono">{{ port.mac || '—' }}</code>
                </div>
              </div>
              <p v-if="port.security_group_ids.length > 0" class="text-gray-500">
                {{ t('vm.drawer.network.securityGroupCount', { count: port.security_group_ids.length }) }}
              </p>
            </div>
          </div>
        </section>
 
        <!-- Security Groups card -->
        <section
          v-if="detail.security_groups"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <Shield :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.securityGroups') }}</h4>
            <span
              v-if="detail.security_groups.length > 0"
              class="ml-auto text-[10px] font-bold bg-gray-200 text-gray-600 px-2 py-0.5 rounded"
            >
              {{ detail.security_groups.length }}
            </span>
          </div>
          <div v-if="detail.security_groups.length === 0" class="text-xs text-gray-500 italic">
            {{ t('vm.drawer.network.noSecurityGroups') }}
          </div>
          <div v-else class="space-y-2">
            <div
              v-for="sg in detail.security_groups"
              :key="sg.id"
              class="text-xs bg-white rounded border border-gray-200 p-2.5 space-y-1"
            >
              <p class="font-semibold text-gray-900">{{ sg.name }}</p>
              <p v-if="sg.description" class="text-gray-500">{{ sg.description }}</p>
              <div class="flex items-center gap-2 pt-1">
                <span class="text-[10px] font-semibold uppercase tracking-wider bg-blue-50 text-blue-700 border border-blue-200 px-2 py-0.5 rounded">
                  {{ sg.ingress_rules }} {{ t('vm.drawer.network.ingress') }}
                </span>
                <span class="text-[10px] font-semibold uppercase tracking-wider bg-purple-50 text-purple-700 border border-purple-200 px-2 py-0.5 rounded">
                  {{ sg.egress_rules }} {{ t('vm.drawer.network.egress') }}
                </span>
              </div>
            </div>
          </div>
        </section>
 
        <!-- Volumes card -->
        <section
          v-if="detail.volumes"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <HardDrive :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.volumes') }}</h4>
            <span
              v-if="detail.volumes.length > 0"
              class="ml-auto text-[10px] font-bold bg-gray-200 text-gray-600 px-2 py-0.5 rounded"
            >
              {{ detail.volumes.length }}
            </span>
          </div>
          <div v-if="detail.volumes.length === 0" class="text-xs text-gray-500 italic">
            {{ t('vm.drawer.volumes.empty') }}
          </div>
          <div v-else class="space-y-2">
            <div
              v-for="vol in detail.volumes"
              :key="vol.volume_id"
              class="text-xs bg-white rounded border border-gray-200 p-2.5 space-y-1"
            >
              <div class="flex items-center justify-between gap-2">
                <p class="font-semibold text-gray-900 truncate">
                  {{ vol.name || vol.volume_id.slice(0, 8) + '…' }}
                </p>
                <span
                  v-if="vol.status"
                  class="text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded border whitespace-nowrap"
                  :class="vol.status === 'in-use'
                    ? 'bg-emerald-100 text-emerald-700 border-emerald-200'
                    : 'bg-gray-100 text-gray-600 border-gray-200'"
                >
                  {{ vol.status }}
                </span>
              </div>
              <div class="grid grid-cols-2 gap-x-3 gap-y-0.5 text-gray-700">
                <div v-if="vol.size_gb != null">
                  <span class="text-gray-500">{{ t('vm.drawer.volumes.size') }}</span>
                  <span class="ml-1 font-medium">{{ vol.size_gb }} {{ t('vm.units.gb') }}</span>
                </div>
                <div v-if="vol.device">
                  <span class="text-gray-500">{{ t('vm.drawer.volumes.device') }}</span>
                  <code class="ml-1 font-mono">{{ vol.device }}</code>
                </div>
              </div>
              <p v-if="vol.bootable" class="text-[10px] font-semibold uppercase tracking-wider text-emerald-700">
                {{ t('vm.drawer.volumes.bootable') }}
              </p>
            </div>
          </div>
        </section>
 
        <!-- Metadata card -->
        <section
          v-if="detail.metadata && Object.keys(detail.metadata).length > 0"
          class="bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-3"
        >
          <div class="flex items-center gap-2 mb-1">
            <Tag :size="14" class="text-gray-400" />
            <h4 class="text-sm font-semibold text-gray-700">{{ t('vm.drawer.sections.metadata') }}</h4>
          </div>
          <div class="space-y-1 text-xs">
            <div
              v-for="(value, key) in detail.metadata"
              :key="key"
              class="flex items-baseline gap-2"
            >
              <code class="font-mono text-gray-600 shrink-0">{{ key }}</code>
              <span class="text-gray-400">=</span>
              <span class="text-gray-800 break-all">{{ value }}</span>
            </div>
          </div>
        </section>
      </template>
    </div>
  </div>
</template>