<script setup lang="ts">
/**
 * NexusLayout — V2 Dashboard Shell
 * Flex row, 100vh, overflow hidden.
 * Sidebar (248px) + Main (flex:1, flex-column)
 * Mobile: Sidebar als Overlay mit Hamburger-Toggle
 */
import { ref } from 'vue'
import { RouterView } from 'vue-router'
import { useDashboardStore } from '../stores/dashboard'
import GalaxyBackground from '../components/background/GalaxyBackground.vue'
import Sidebar from '../components/layout/Sidebar.vue'
import Topbar from '../components/layout/Topbar.vue'

const dashboardStore = useDashboardStore()

/* ── Mobile Sidebar State ───────────────────────── */
const mobileMenuOpen = ref(false)

function closeMobileMenu() {
  mobileMenuOpen.value = false
}
</script>

<template>
  <div class="nexus-layout">
    <GalaxyBackground />
    <Sidebar
      :mobile-open="mobileMenuOpen"
      @close="closeMobileMenu"
    />

    <!-- Mobile Backdrop -->
    <div
      v-if="mobileMenuOpen"
      class="mobile-backdrop"
      @click="closeMobileMenu"
    ></div>

    <main class="nexus-main">
      <Topbar
        :connected="dashboardStore.isGatewayConnected"
        :status-label="dashboardStore.irisStatusLabel"
        @toggle-sidebar="mobileMenuOpen = !mobileMenuOpen"
      />
      <div class="nexus-content">
        <RouterView />
      </div>
    </main>
  </div>
</template>

<style scoped>
.nexus-layout {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.nexus-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.nexus-content {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.mobile-backdrop {
  display: none;
}

@media (max-width: 767px) {
  .nexus-main {
    width: 100%;
  }

  .mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.5);
  }
}
</style>
