import { useLazyQuery } from "@vue/apollo-composable";
import {computed} from "vue";
import {GET_PRODUCT_BY_SLUG, GET_PRODUCT_TAGS} from "@/graphql/queries/products.js";

export function useProductTags() {
  const { result, loading, error, load } = useLazyQuery(GET_PRODUCT_TAGS);

  const tags = computed(() => result.value?.productTags.edges ?? []);

  if (error.value) {
    console.error("useProductTags error:", error.value);
  }

  return {
    tags,
    loading,
    error,
    getProductTags: load
  };
}