"use client";

import { useQuery } from "convex/react";
import { api } from "../../../../../convex/_generated/api";
import type { Id } from "../../../../../convex/_generated/dataModel";
import type { OrderDetail } from "./types";

export function useOrderDetail(orderId: string): {
  order: OrderDetail | null;
  isLoading: boolean;
  error: string | null;
} {
  const result = useQuery(api.orders.getById, {
    id: orderId as Id<"orders">,
  });

  return {
    order: (result as OrderDetail | undefined) ?? null,
    isLoading: result === undefined,
    error: null,
  };
}
