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/collections.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var COLLECTION_QUERY_KEY = "collections";
var collectionsQueryKeys = queryKeysFactory(COLLECTION_QUERY_KEY);
var useCollection = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: collectionsQueryKeys.detail(id),
    queryFn: () => sdk.admin.collections.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCollections = (query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: collectionsQueryKeys.list(query),
    queryFn: () => sdk.admin.collections.query({ ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateCollection = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.collections.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: collectionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: collectionsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateCollectionProducts = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.collections.$id.products.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: collectionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: collectionsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: productsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateCollection = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.collections.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: collectionsQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCollection = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.collections.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: collectionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: collectionsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  collectionsQueryKeys,
  useCollection,
  useCollections,
  useUpdateCollection,
  useUpdateCollectionProducts,
  useCreateCollection,
  useDeleteCollection
};
