import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  fetchQuery,
  sdk
} from "./chunk-DTGEFKK4.js";

// src/hooks/api/feature-flags.tsx
import { useQuery } from "@tanstack/react-query";
var FEATURE_FLAGS_QUERY_KEY = "feature_flags";
var featureFlagsQueryKeys = queryKeysFactory(FEATURE_FLAGS_QUERY_KEY);
var useFeatureFlags = (options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.featureFlags.query(),
    queryKey: featureFlagsQueryKeys.lists(),
    ...options
  });
  return { ...data, ...rest };
};

// src/hooks/api/tags.tsx
import {
  useMutation,
  useQuery as useQuery2
} from "@tanstack/react-query";
var TAGS_QUERY_KEY = "tags";
var productTagsQueryKeys = queryKeysFactory(TAGS_QUERY_KEY);
var useProductTag = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryKey: productTagsQueryKeys.detail(id, query),
    queryFn: async () => sdk.vendor.productTags.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useProductTags = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryKey: productTagsQueryKeys.list(query),
    queryFn: async () => sdk.vendor.productTags.query({ ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateProductTag = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.productTags.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: productTagsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: productTagsQueryKeys.detail(data.product_tag.id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteProductTag = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.productTags.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: productTagsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: productTagsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/currencies.tsx
import { useQuery as useQuery3 } from "@tanstack/react-query";
var CURRENCIES_QUERY_KEY = "currencies";
var currenciesQueryKeys = queryKeysFactory(CURRENCIES_QUERY_KEY);

// src/hooks/api/fulfillment.tsx
import { useMutation as useMutation2 } from "@tanstack/react-query";
var FULFILLMENTS_QUERY_KEY = "fulfillments";
var fulfillmentsQueryKeys = queryKeysFactory(FULFILLMENTS_QUERY_KEY);

// src/hooks/api/invites.tsx
import {
  useMutation as useMutation3,
  useQuery as useQuery4
} from "@tanstack/react-query";
var INVITES_QUERY_KEY = "invites";
var invitesQueryKeys = queryKeysFactory(INVITES_QUERY_KEY);
var useInvites = (sellerId, query, options) => {
  const { data, ...rest } = useQuery4({
    queryFn: () => sdk.vendor.sellers.$id.members.invites.query({
      $id: sellerId,
      ...query
    }),
    queryKey: invitesQueryKeys.list({ sellerId, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useAcceptInvite = (options) => {
  return useMutation3({
    mutationFn: (payload) => sdk.vendor.members.invites.accept.mutate({
      invite_token: payload.invite_token,
      first_name: payload.first_name,
      last_name: payload.last_name,
      fetchOptions: {
        headers: {
          Authorization: `Bearer ${payload.auth_token}`
        }
      }
    }),
    ...options
  });
};
var useCreateInvite = (sellerId, options) => {
  return useMutation3({
    mutationFn: (payload) => sdk.vendor.sellers.$id.members.mutate({ $id: sellerId, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/notification.tsx
import { useQuery as useQuery5 } from "@tanstack/react-query";
var NOTIFICATION_QUERY_KEY = "notification";
var notificationQueryKeys = queryKeysFactory(NOTIFICATION_QUERY_KEY);
var useNotifications = (query, options) => {
  const { data, ...rest } = useQuery5({
    queryFn: () => fetchQuery(`/vendor/notifications`, {
      method: "GET",
      query
    }),
    queryKey: notificationQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};

// src/hooks/api/product-variants.tsx
import {
  useQuery as useQuery6
} from "@tanstack/react-query";
var PRODUCT_VARIANT_QUERY_KEY = "product_variant";
var productVariantQueryKeys = queryKeysFactory(
  PRODUCT_VARIANT_QUERY_KEY
);

// src/hooks/api/regions.tsx
import {
  useMutation as useMutation4,
  useQuery as useQuery7
} from "@tanstack/react-query";
var REGIONS_QUERY_KEY = "regions";
var regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY);
var useRegions = (query, options) => {
  const { data, ...rest } = useQuery7({
    queryFn: () => sdk.vendor.regions.query({ ...query }),
    queryKey: regionsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};

// src/hooks/api/shipping-option-types.tsx
import {
  useMutation as useMutation5,
  useQuery as useQuery8
} from "@tanstack/react-query";
var SHIPPING_OPTION_TYPES_QUERY_KEY = "shipping_option_types";
var shippingOptionTypesQueryKeys = queryKeysFactory(
  SHIPPING_OPTION_TYPES_QUERY_KEY
);

// src/hooks/api/store.tsx
import { useQuery as useQuery9 } from "@tanstack/react-query";
import { ClientError } from "@mercurjs/client";
var STORE_QUERY_KEY = "store";
var storeQueryKeys = queryKeysFactory(STORE_QUERY_KEY);
async function retrieveActiveStore(query) {
  const response = await sdk.vendor.stores.query({ ...query });
  const activeStore = response.stores?.[0];
  if (!activeStore) {
    throw new ClientError("No active store found", "Not Found", 404);
  }
  return { store: activeStore };
}
var useStore = (query, options) => {
  const { data, ...rest } = useQuery9({
    queryFn: () => retrieveActiveStore(query),
    queryKey: storeQueryKeys.details(),
    ...options
  });
  return {
    ...data,
    ...rest
  };
};

export {
  useFeatureFlags,
  useInvites,
  useAcceptInvite,
  useCreateInvite,
  notificationQueryKeys,
  useNotifications,
  useRegions,
  storeQueryKeys,
  retrieveActiveStore,
  useStore,
  productTagsQueryKeys,
  useProductTag,
  useProductTags,
  useUpdateProductTag,
  useDeleteProductTag
};
