import { useLazyQuery } from "@vue/apollo-composable";
import {computed} from "vue";
import {GET_BRAND_BY_UUID} from "@/graphql/queries/brands.js";

export function useBrandByUuid() {
  const { result, loading, error, load } = useLazyQuery(GET_BRAND_BY_UUID);

  const brand = computed(() => result.value?.brands.edges[0].node ?? []);

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

  const getBrand = (uuid) => {
    return load(null, { uuid });
  };

  return {
    brand,
    loading,
    error,
    getBrand
  };
}