import {
  productsQueryKeys
} from "./chunk-BA2HXHTW.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.js";

// src/hooks/api/categories.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var CATEGORIES_QUERY_KEY = "categories";
var categoriesQueryKeys = queryKeysFactory(CATEGORIES_QUERY_KEY);
var useProductCategory = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: categoriesQueryKeys.detail(id, query),
    queryFn: () => sdk.admin.productCategories.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useProductCategories = (query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: categoriesQueryKeys.list(query),
    queryFn: () => sdk.admin.productCategories.query({ ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateProductCategory = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.productCategories.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: categoriesQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductCategory = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.productCategories.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: categoriesQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: categoriesQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteProductCategory = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.productCategories.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: categoriesQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({ queryKey: categoriesQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateProductCategoryProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.productCategories.$id.products.mutate({
      $id: id,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: categoriesQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: categoriesQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  categoriesQueryKeys,
  useProductCategory,
  useProductCategories,
  useCreateProductCategory,
  useUpdateProductCategory,
  useDeleteProductCategory,
  useUpdateProductCategoryProducts
};
