import { RootState } from "app/store";
import { TERMS_DOCUMENT_TYPE } from "features/terms/constants";

export const selectTermVersions = (state: RootState) => {
  const { termsInfo } = state.terms.domain;

  const acceptedVerDPA =
    termsInfo.find(
      (termInfo) => termInfo.documentType === TERMS_DOCUMENT_TYPE.DPA
    )?.version || "";

  const acceptedVerEULA =
    termsInfo.find(
      (termInfo) => termInfo.documentType === TERMS_DOCUMENT_TYPE.EULA
    )?.version || "";

  const acceptedVerPrivacyNotice =
    termsInfo.find(
      (termInfo) => termInfo.documentType === TERMS_DOCUMENT_TYPE.PRIVACY_NOTICE
    )?.version || "";
  return { acceptedVerDPA, acceptedVerEULA, acceptedVerPrivacyNotice };
};

export const selectTier = (state: RootState) => state.terms.domain.tier;

export const selectIsLoading = (state: RootState) =>
  state.terms.apps.isLoading === true;
