import { computed } from "vue";
import { userStore } from "src/stores/user";

export const APPROVAL_STATUS = Object.freeze({
  ACCEPTED: "accepted",
  PENDING: "pending",
  REJECTED: "rejected",
});

export const useProviderApproval = () => {
  const user = userStore();

  const isProvider = computed(
    () => String(user.user?.type).toUpperCase() === "PROVIDER",
  );

  const approvalStatus = computed(() => user.user?.provider?.approval_status ?? null);

  const isPendingProvider = computed(
    () => isProvider.value && approvalStatus.value === APPROVAL_STATUS.PENDING,
  );

  const isRejectedProvider = computed(
    () => isProvider.value && approvalStatus.value === APPROVAL_STATUS.REJECTED,
  );

  return {
    approvalStatus,
    isPendingProvider,
    isProvider,
    isRejectedProvider,
  };
};
