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

// src/hooks/api/members.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var MEMBERS_QUERY_KEY = "members";
var membersQueryKeys = {
  ...queryKeysFactory(MEMBERS_QUERY_KEY),
  me: () => [MEMBERS_QUERY_KEY, "me"]
};
var useMe = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.members.me.query(
      query
    ),
    queryKey: query ? [...membersQueryKeys.me(), query] : membersQueryKeys.me(),
    ...options
  });
  return {
    ...data,
    ...rest
  };
};
var useUpdateMe = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.members.me.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: membersQueryKeys.me() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSellerMembers = (sellerId, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.sellers.$id.members.query({ $id: sellerId, ...query }),
    queryKey: membersQueryKeys.list({ sellerId, ...query }),
    ...options
  });
  return {
    ...data,
    ...rest
  };
};
var useMember = (id) => {
  const meResult = useMe();
  const sellerId = meResult.member?.seller?.id ?? "";
  const membersResult = useSellerMembers(
    sellerId,
    {},
    { enabled: !!sellerId && !!id }
  );
  const user = (membersResult.members ?? []).find((m) => m.id === id);
  return { user };
};
var useRemoveSellerMember = (sellerId, memberId, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.sellers.$id.members.$memberId.delete({
      $id: sellerId,
      $memberId: memberId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/sellers.tsx
import {
  useMutation as useMutation2,
  useQuery as useQuery2
} from "@tanstack/react-query";
var SELLERS_QUERY_KEY = "sellers";
var sellersQueryKeys = queryKeysFactory(SELLERS_QUERY_KEY);
var useCurrentSeller = () => {
  const { seller_member, isPending, isError, error, isFetching } = useMe();
  const seller = seller_member?.seller;
  return {
    seller,
    currency_code: seller?.currency_code,
    isPending,
    isFetching,
    isError,
    error
  };
};
var useSeller = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryKey: sellersQueryKeys.detail(id, query),
    queryFn: () => sdk.vendor.sellers.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useSellers = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryKey: sellersQueryKeys.list(query),
    queryFn: () => sdk.vendor.sellers.query({ ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useSelectSeller = (options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.select.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.me()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSeller = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.me()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerAddress = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.$id.address.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.me()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerPaymentDetails = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.$id.paymentDetails.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.me()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerProfessionalDetails = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.$id.professionalDetails.mutate({
      $id: id,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.all
      });
      queryClient.invalidateQueries({
        queryKey: membersQueryKeys.me()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateSellerAccount = (options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.sellers.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.all
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  membersQueryKeys,
  useMe,
  useUpdateMe,
  useSellerMembers,
  useMember,
  useRemoveSellerMember,
  useCurrentSeller,
  useSeller,
  useSellers,
  useSelectSeller,
  useUpdateSeller,
  useUpdateSellerAddress,
  useUpdateSellerPaymentDetails,
  useUpdateSellerProfessionalDetails,
  useCreateSellerAccount
};
