import { RootState } from "app/store";

export const selectInputValidationErrors = (state: RootState) => {
  // 必須項目のチェック
  const hasErrorEmptyCompany = state.partner.apps.addPartner.companyName === "";
  const hasErrorEmptyCountry = state.partner.apps.addPartner.country === "";
  const hasErrorEmptyAdminName = state.partner.apps.addPartner.adminName === "";
  const hasErrorEmptyEmail = state.partner.apps.addPartner.email === "";

  const hasErrorIncorrectEmail =
    (state.partner.apps.addPartner.email as string).match(/^[^@]+@[^@]+$/)
      ?.length !== 1;

  return {
    hasErrorEmptyCompany,
    hasErrorEmptyCountry,
    hasErrorEmptyAdminName,
    hasErrorEmptyEmail,
    hasErrorIncorrectEmail,
  };
};

// Account Info
export const selectCompany = (state: RootState) =>
  state.partner.apps.addPartner.companyName;
export const selectCountry = (state: RootState) =>
  state.partner.apps.addPartner.country;

// Admin Info
export const selectAdminName = (state: RootState) =>
  state.partner.apps.addPartner.adminName;
export const selectEmail = (state: RootState) =>
  state.partner.apps.addPartner.email;
export const selectIsLoading = (state: RootState) =>
  state.partner.apps.isLoading;
