<script setup lang="ts">
import UserInfo from '@/components/ui/sidebarShadcn/UserInfo.vue';
import { DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from '@/components/ui/dropdown-menu';
import type { User } from '@/types';
import { Link } from '@inertiajs/vue3';
import { LogOut, Settings, WifiOff } from 'lucide-vue-next';

interface Props {
    user: User;
    isOnline?: boolean;
}

withDefaults(defineProps<Props>(), {
    isOnline: true,
});
</script>

<template>
    <DropdownMenuLabel class="p-0 font-normal">
        <div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
            <UserInfo :user="user" />
        </div>
    </DropdownMenuLabel>
    <DropdownMenuSeparator />
    <DropdownMenuGroup>
        <DropdownMenuItem
            :as-child="true"
            :class="{ 'opacity-40 pointer-events-none': !isOnline }"
        >
            <Link class="block w-full" :href="isOnline ? route('profile.edit') : '#'" as="button">
                <Settings class="mr-2 h-4 w-4" />
                Settings
            </Link>
        </DropdownMenuItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuItem v-if="isOnline" :as-child="true">
        <Link class="block w-full" method="post" :href="route('logout')" as="button">
            <LogOut class="mr-2 h-4 w-4" />
            Log out
        </Link>
    </DropdownMenuItem>
    <DropdownMenuItem v-else disabled class="opacity-40">
        <WifiOff class="mr-2 h-4 w-4" />
        <span>Sin conexion para cerrar sesion</span>
    </DropdownMenuItem>
</template>
