<script lang="ts" setup>
import type { LucideIcon } from 'lucide-vue-next'
import type { RouteLocationRaw } from 'vue-router'
import type { SidebarProps } from '~/components/ui/sidebar'

export interface SidebarNavItem {
  title: string
  url?: string | RouteLocationRaw
  icon: LucideIcon | string
  isActive?: boolean
  isExternal?: boolean
  items?: {
    title: string
    url: string
  }[]
}

export interface SidebarNavGroup {
  label?: string
  items: SidebarNavItem[]
}

const props = withDefaults(
  defineProps<
    SidebarProps & {
      nav: SidebarNavGroup[]
    }
  >(),
  {
    collapsible: 'offcanvas',
    variant: 'sidebar',
  },
)

const loginState = useLoginState()
</script>

<template>
  <Sidebar v-bind="props">
    <SidebarHeader>
      <div
        class="flex h-12 justify-center items-center gap-2 rounded truncate group-has-[[data-collapsible=icon]]/sidebar-wrapper:justify-start transition-all duration-200 ease-in-out"
      >
        <img
          src="/images/xsh_logo.png"
          alt="Logo"
          class="size-10 -ml-4 aspect-square group-has-[[data-collapsible=icon]]/sidebar-wrapper:w-full transition-all duration-200 ease-in-out"
        />
        <div class="flex flex-col items-start justify-center">
          <h1 class="text-base font-bold">智慧课程平台</h1>
          <p class="text-xs font-medium text-muted-foreground">AI 助教</p>
        </div>
      </div>
    </SidebarHeader>
    <SidebarContent>
      <slot name="extra-header" />
      <AppSidebarNavMain :nav="nav" />
    </SidebarContent>
    <SidebarFooter>
      <AppSidebarNavUser :user="loginState.user" />
    </SidebarFooter>
    <SidebarRail />
  </Sidebar>
</template>

<style scoped></style>
