import { ceil, floor } from "lodash";
import { RootState } from "../../../app/store";
import { ACCOUNTS_VIEW_LIMIT } from "./constants";

export const selectMyAccountInfo = (state: RootState) =>
  state.partnerLicense.domain.myAccountInfo;
export const selectTotal = (state: RootState) =>
  state.partnerLicense.domain.total;
export const selectOwnPartnerLicense = (state: RootState) =>
  state.partnerLicense.domain.ownPartnerLicense;
export const selectChildrenPartnerLicenses = (state: RootState) =>
  state.partnerLicense.domain.childrenPartnerLicenses;
export const selectHierarchicalElements = (state: RootState) =>
  state.partnerLicense.apps.hierarchicalElements;
export const selectTotalPage = (state: RootState) => {
  const { total } = state.partnerLicense.domain;
  const page = ceil(total / ACCOUNTS_VIEW_LIMIT);
  return page;
};
export const selectIsLoading = (state: RootState) =>
  state.partnerLicense.apps.isLoading;
export const selectLimit = (state: RootState) =>
  state.partnerLicense.apps.limit;
export const selectOffset = (state: RootState) =>
  state.partnerLicense.apps.offset;
export const selectCurrentPage = (state: RootState) => {
  const { limit, offset } = state.partnerLicense.apps;
  const page = floor(offset / limit) + 1;
  return page;
};
export const selectSelectedRow = (state: RootState) =>
  state.partnerLicense.apps.selectedRow;
