import MODULE_DETAILS_QUERY from './gql/queries/modules/moduleDetailsQuery.gql';
import ME_QUERY from './gql/queries/meQuery.gql';
import { useRoute } from 'vue-router';
import { computed } from 'vue';
import { useQuery } from '@vue/apollo-composable';
import { graphql } from '@/__generated__/gql';

export function moduleQuery() {
  return {
    query: MODULE_DETAILS_QUERY,
    variables: {
      slug: this.$route.params.slug,
    },
  };
}

const getModule = () => {
  const route = useRoute();
  const query = graphql(MODULE_DETAILS_QUERY, {
    slug: route.params.slug
  });
  const { result } = useQuery(query);
  const module = computed(() => result.value?.module || {});

  return { module };
};

export function meQuery() {
  return {
    query: ME_QUERY,
  };
}

export { getModule };
