'use strict';

const index = require('./index-8277cbb3.js');
const global = require('./global-b7b1b8fe.js');
const index_module = require('./index.module-f8c8495f.js');
const JSS = require('./JSS-8503a151.js');

const style = {
  Container: {
    display: "flex",
    flexDirection: "column",
    gap: "35px",
  },
  HeaderContainer: {
    display: "flex",
    flexDirection: "column",
    gap: "10px",
  },
};
const sheet = JSS.createStyleSheet(style);
const styleString = sheet.toString();
const LoadingView = () => {
  return (index.h("div", { class: sheet.classes.Container },
    index.h("style", { type: "text/css" }, styleString),
    index.h("sqm-skeleton", { width: "45%", height: "40px !important" }),
    index.h("div", { class: sheet.classes.HeaderContainer },
      index.h("sqm-skeleton", { width: "15%" }),
      index.h("sqm-skeleton", { width: "25%", height: "30px !important" })),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "75%", height: "35px" }),
    index.h("sqm-skeleton", { width: "15%" }),
    index.h("sqm-skeleton", { width: "80px", height: "30px !important" })));
};

function validTaxDocument(requiredType) {
  const validTypes = ["W9", "W8BENE", "W8BEN"];
  if (validTypes.includes(requiredType))
    return true;
  return false;
}
const objectIsFull = (obj) => {
  return !Object.keys(obj).find((k) => obj[k] == undefined);
};
const taxTypeToName = (taxType) => {
  switch (taxType) {
    case "W9":
      return "W-9";
    case "W8BEN":
    case "W8BENE":
      return "W-8";
    default:
      return "";
  }
};
function validateBillingField(regex, value) {
  const trimmed = value.trim();
  const idx = trimmed.search(regex);
  return idx > -1;
}
const formatErrorMessage = (fieldName, errorMessage) => {
  return global.intl.formatMessage({
    id: fieldName,
    defaultMessage: errorMessage,
  }, {
    fieldName,
  });
};
function getCountryObj({ countryCode, locale, }) {
  // @ts-ignore DisplayNames not in Intl type
  const displayName = new Intl.DisplayNames([locale], {
    type: "region",
  }).of(countryCode);
  return {
    countryCode,
    displayName,
  };
}

const TAX_CONTEXT_NAMESPACE = "sq:tax-and-cash";
const TAX_FORM_CONTEXT_NAMESPACE = "sq:tax-form-context";
const USER_QUERY_NAMESPACE = "sq:user-info-query";
const USER_FORM_CONTEXT_NAMESPACE = "sq:user-form-context";
const FINANCE_NETWORK_SETTINGS_NAMESPACE = "sq:finance-network-settings";
const COUNTRIES_NAMESPACE = "sq:countries:list";
const SORTED_COUNTRIES_NAMESPACE = "sq:countries:sorted";
const COUNTRIES_QUERY_NAMESPACE = "sq:countries:query";
const CURRENCIES_NAMESPACE = "sq:currencies:list";
const CURRENCIES_QUERY_NAMESPACE = "sq:currencies:query";
const GET_USER = index_module.dist.gql `
  query getUserTaxInfo {
    user: viewer {
      ... on User {
        id
        firstName
        lastName
        email
        countryCode
        customFields
        rewards(limit: 1000) {
          data {
            statuses
            partnerFundsTransfer {
              id
              status
              dateScheduled
              dateCreated
              dateTransferred
            }
          }
        }
        managedIdentity {
          uid
          email
          emailVerified
        }
        impactConnection {
          connected
          user {
            firstName
            lastName
          }
          publisher {
            id
            brandedSignup
            countryCode
            currency
            billingAddress
            billingCity
            billingState
            billingCountryCode
            billingPostalCode
            phoneNumberCountryCode
            phoneNumber
            taxInformation {
              indirectTaxId
              indirectTaxCountryCode
              indirectTaxRegion
              additionalTaxId
              withholdingTaxId
              withholdingTaxCountryCode
            }
            requiredTaxDocumentType
            currentTaxDocument {
              status
              type
              dateCreated
            }
            withdrawalSettings {
              paymentMethod
              paypalEmailAddress
              bankCountry
              bankAccountNumber
              paymentSchedulingType
              paymentThreshold
              paymentDay
            }
            payoutsAccount {
              hold
              holdReasons
              balance
            }
          }
        }
      }
    }
  }
`;
const GET_COUNTRIES = index_module.dist.gql `
  query getCountries {
    impactPayoutCountries(limit: 1000) {
      data {
        countryCode
        displayName
      }
    }
  }
`;
const GET_CURRENCIES = index_module.dist.gql `
  query currencies($locale: RSLocale) {
    currencies(limit: 300) {
      data {
        displayName(locale: $locale)
        currencyCode
      }
    }
  }
`;
const GET_FINANCE_NETWORK_SETTINGS = index_module.dist.gql `
  query impactFinanceNetworkSettings(
    $filter: ImpactFinanceNetworkSettingsFilterInput
  ) {
    impactFinanceNetworkSettings(filter: $filter, limit: 1000) {
      data {
        countryCode
        currency
        defaultFinancePaymentMethodId
        thresholdOptions
        withdrawalSettingId
        internationalEftFee
        foreignFxFee
        defaultFxFee
      }
      totalCount
    }
  }
`;
const FORM_STEPS = 4;

exports.COUNTRIES_NAMESPACE = COUNTRIES_NAMESPACE;
exports.COUNTRIES_QUERY_NAMESPACE = COUNTRIES_QUERY_NAMESPACE;
exports.CURRENCIES_NAMESPACE = CURRENCIES_NAMESPACE;
exports.CURRENCIES_QUERY_NAMESPACE = CURRENCIES_QUERY_NAMESPACE;
exports.FINANCE_NETWORK_SETTINGS_NAMESPACE = FINANCE_NETWORK_SETTINGS_NAMESPACE;
exports.FORM_STEPS = FORM_STEPS;
exports.GET_COUNTRIES = GET_COUNTRIES;
exports.GET_CURRENCIES = GET_CURRENCIES;
exports.GET_FINANCE_NETWORK_SETTINGS = GET_FINANCE_NETWORK_SETTINGS;
exports.GET_USER = GET_USER;
exports.LoadingView = LoadingView;
exports.SORTED_COUNTRIES_NAMESPACE = SORTED_COUNTRIES_NAMESPACE;
exports.TAX_CONTEXT_NAMESPACE = TAX_CONTEXT_NAMESPACE;
exports.TAX_FORM_CONTEXT_NAMESPACE = TAX_FORM_CONTEXT_NAMESPACE;
exports.USER_FORM_CONTEXT_NAMESPACE = USER_FORM_CONTEXT_NAMESPACE;
exports.USER_QUERY_NAMESPACE = USER_QUERY_NAMESPACE;
exports.formatErrorMessage = formatErrorMessage;
exports.getCountryObj = getCountryObj;
exports.objectIsFull = objectIsFull;
exports.taxTypeToName = taxTypeToName;
exports.validTaxDocument = validTaxDocument;
exports.validateBillingField = validateBillingField;
