"use client"
import axios from "@/network/axios";
import { useQuery } from "@tanstack/react-query"

export type Permission = {
    id: number;
    name: string;
    name_en: string;
    name_ar: string;
    section: string;
    section_ar: string;
}

export type Role = {
    id: number;
    name: string;
    name_ar: string;
    permissions: Permission[];
}

type RolesResponse = {
    status: boolean;
    message: string;
    data: Role[];
}

const getRoles = async () => {
    const response = await axios.get<RolesResponse>(`/roles`)
    return response.data?.data
}

export const useRoles = () => {
    return useQuery({
        queryKey: ["roles"],
        queryFn: getRoles,
        enabled: true,
    })
}

// Keep the old export for backward compatibility
export const Roles = useRoles;