import useGetCartOrders from "~/composables/api/orders/useGetCartOrders";
import { useToast } from "~/composables/global/useToast";

export default defineNuxtRouteMiddleware(async () => {
    const { addToast } = useToast();
    const { data: cart, suspense } = useGetCartOrders();

    if (!!cart.value) {
        if (!!cart.value?.address) {
            return;
        } else {
            addToast({
                message: "لطفا آدرس سفارش خود را انتخاب کنید",
                options: {
                    status: "error",
                },
            });
            return navigateTo("/cart/delivery");
        }
    } else {
        await suspense();
    }
});
