<script setup lang="ts">
import type { HTMLAttributes } from 'vue'

import { useSidebar } from './utils'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { useUiStore } from '@/stores/uiStore'

const props = defineProps<{
  class?: HTMLAttributes['class']
}>()

const uiStore = useUiStore()
const { toggleSidebar, open } = useSidebar()

function handleManualSidebarToggle() {
  toggleSidebar()
  uiStore.setSidebarUserOverride(true)
}
</script>

<template>
  <Button
    data-sidebar="trigger"
    data-slot="sidebar-trigger"
    variant="ghost"
    size="icon"
    :class="cn('h-7 w-7', props.class)"
    @click="handleManualSidebarToggle"
  >
    <i v-if="!open" class="dku-icon-left-panel-open-16" />
    <i v-else class="dku-icon-left-panel-close-16" />
    <span class="sr-only">Toggle Sidebar</span>
  </Button>
</template>
