<script setup lang="ts">
import { cn } from '@/lib/utils';
import { useSidebar } from './utils';

defineOptions({ inheritAttrs: false });

const { toggleSidebar } = useSidebar();
</script>

<template>
  <button
    v-bind="$attrs"
    data-sidebar="rail"
    data-slot="sidebar-rail"
    aria-label="Toggle Sidebar"
    :tabindex="-1"
    title="Toggle Sidebar"
    :class="
      cn(
        'hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex',
        'cursor-pointer',
        'hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full',
        '[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
        '[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
        $attrs.class ?? '',
      )
    "
    @click="toggleSidebar"
  >
    <slot />
  </button>
</template>
