<template>
  <aside class="dev-sidebar" :class="{ 'is-collapsed': collapsed }">
    <div class="dev-sidebar-inner">
      <div class="dev-sidebar-head">
        <span class="dev-sidebar-title" v-show="!collapsed">BIM Dev</span>
        <button class="dev-sidebar-toggle" type="button" :title="collapsed ? '展开' : '收起'" @click="toggle">
          {{ collapsed ? '▸' : '◂' }}
        </button>
      </div>

      <nav class="dev-sidebar-nav" v-show="!collapsed">
        <router-link
          v-for="route in routes"
          :key="route.path"
          class="dev-sidebar-link"
          :to="route.path"
          :class="{ 'is-active': $route.path === route.path }"
        >
          <span class="dev-sidebar-dot"></span>
          <span class="dev-sidebar-label">{{ route.label }}</span>
        </router-link>
      </nav>
    </div>
  </aside>
</template>

<script setup>
import { computed } from "vue";
import { useRoute } from "vue-router";

const props = defineProps({
  collapsed: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(["update:collapsed"]);

const route = useRoute();

const routes = [
  { path: "/home", label: "首页" },
  { path: "/project", label: "项目" },
  { path: "/subcontract", label: "分包" },
  { path: "/measurement", label: "计量" },
  { path: "/plan", label: "计划" },
  { path: "/progress", label: "进度" },
  { path: "/change", label: "变更" },
  { path: "/material", label: "物资" },
  { path: "/inspection", label: "质检" },
  { path: "/debug", label: "调试" },
];

const collapsed = computed({
  get: () => props.collapsed,
  set: (val) => emit("update:collapsed", val),
});

function toggle() {
  collapsed.value = !collapsed.value;
}
</script>

<style scoped>
.dev-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 220px;
  z-index: 1000;
  border-right: 1px solid rgba(83, 214, 206, 0.24);
  background:
    radial-gradient(260px 160px at 0% 0%, rgba(83, 214, 206, 0.14), transparent 62%) padding-box,
    linear-gradient(180deg, rgba(14, 22, 26, 0.98), rgba(10, 16, 20, 0.96)) padding-box;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.35);
  transition: width 0.22s ease;
}

.dev-sidebar.is-collapsed {
  width: 44px;
}

.dev-sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px;
}

.dev-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.dev-sidebar-title {
  font-size: 14px;
  font-weight: 900;
  color: rgba(207, 247, 242, 0.96);
  white-space: nowrap;
}

.dev-sidebar-toggle {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(222, 238, 244, 0.9);
  font-weight: 900;
  cursor: pointer;
  flex: 0 0 auto;
}

.dev-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.dev-sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  text-decoration: none;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(222, 238, 244, 0.86);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dev-sidebar-link:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(83, 214, 206, 0.2);
}

.dev-sidebar-link.is-active {
  background: rgba(83, 214, 206, 0.18);
  border-color: rgba(83, 214, 206, 0.35);
  color: #fff;
}

.dev-sidebar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(83, 214, 206, 0.7);
  flex: 0 0 auto;
}

.dev-sidebar-link.is-active .dev-sidebar-dot {
  background: rgba(83, 214, 206, 0.98);
  box-shadow: 0 0 8px rgba(83, 214, 206, 0.6);
}

.dev-sidebar-label {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
</style>
