import { h } from "@stencil/core";
import { intl } from "../../../global/global";
import { createStyleSheet } from "../../../styling/JSS";
const style = {
  ButtonContainer: {
    display: "flex",
    gap: "var(--sl-spacing-medium)",
    marginTop: "var(--sl-spacing-medium)",
    flexWrap: "wrap",
  },
  SkeletonOne: {
    width: "50%",
    height: "16px",
  },
  AlertDescriptionText: {
    margin: "0",
    marginBottom: "var(--sl-spacing-small)",
  },
  Dialog: {
    "&::part(panel)": {
      height: "600px",
    },
    "&::part(close-button)": {
      marginBottom: "var(--sl-spacing-xx-large)",
    },
    "&::part(title)": {
      display: "none",
    },
    "&::part(header)": {},
    "&::part(body)": { padding: "0" },
    "&::part(footer)": {},
  },
};
const vanillaStyle = `
  a {
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
  }
`;
const sheet = createStyleSheet(style);
const styleString = sheet.toString();
export function PayoutStatusAlertView(props) {
  const { text, states, data, callbacks } = props;
  function getAlert(status) {
    if (states.error)
      return {
        header: text.errorHeader,
        description: text.errorDescription,
        buttonText: null,
        alertType: "error",
      };
    switch (status) {
      case "INFORMATION_REQUIRED":
        return {
          header: text.informationRequiredHeader,
          description: text.informationRequiredDescription,
          buttonText: text.informationRequiredButtonText,
          alertType: "info",
        };
      case "VERIFICATION:REQUIRED":
        return {
          header: text.verificationRequiredHeader,
          description: intl.formatMessage({
            id: "verificationRequiredDescription",
            defaultMessage: text.verificationRequiredDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          buttonText: text.verificationRequiredButtonText,
          alertType: "warning",
        };
      case "VERIFICATION:INTERNAL":
        return {
          header: text.verificationRequiredInternalHeader,
          description: intl.formatMessage({
            id: "verificationRequiredInternalDescription",
            defaultMessage: text.verificationRequiredInternalDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          alertType: "warning",
        };
      case "VERIFICATION:REVIEW":
        return {
          header: text.verificationReviewInternalHeader,
          description: intl.formatMessage({
            id: "verificationReviewInternalDescription",
            defaultMessage: text.verificationReviewInternalDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          alertType: "warning",
        };
      case "VERIFICATION:FAILED":
        return {
          header: text.verificationFailedInternalHeader,
          description: intl.formatMessage({
            id: "verificationFailedInternalDescription",
            defaultMessage: text.verificationFailedInternalDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          alertType: "error",
        };
      case "OVER_W9_THRESHOLD":
        if (states.enforceUsTaxComplianceOption === "CASH_ONLY_DEFER_W9") {
          return {
            header: text.w9RequiredHeader,
            description: intl.formatMessage({
              id: "w9RequiredDescription",
              defaultMessage: text.w9RequiredDescription,
            }, {
              termsAndConditions: (h("a", { target: "_blank", href: `https://terms.advocate.impact.com/PayoutTermsAndConditions.html` }, text.termsAndConditions)),
            }),
            buttonText: text.w9RequiredButtonText,
            alertType: "warning",
            icon: "exclamation-triangle",
          };
        }
        else {
          return {
            header: text.holdHeader,
            description: intl.formatMessage({
              id: "holdDescription",
              defaultMessage: text.holdDescription,
            }, {
              supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
            }),
            buttonText: null,
            alertType: "warning",
            icon: "exclamation-triangle",
          };
        }
      case "NEW_PAYEE_REVIEW":
        return {
          header: text.accountReviewHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.accountReviewDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          buttonText: null,
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "PAYMENT_HOLD_ON_CHANGE":
        return {
          header: text.paymentHoldOnChangeHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.paymentHoldOnChangeDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          buttonText: null,
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "BENEFICIARY_NAME_INVALID":
        return {
          header: text.beneficiaryNameInvalidHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.beneficiaryNameInvalidDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          button: (h("div", { class: sheet.classes.ButtonContainer },
            h("sl-button", { disabled: states.loading, type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onPaymentInfoClick }, text.editPaymentInformationButton),
            h("sl-button", { disabled: states.loading, type: "secondary", exportparts: "base: secondarybutton-base", onClick: callbacks.onNewFormClick }, text.newFormButton))),
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "BENEFICIARY_NAME_MISMATCH":
        return {
          header: text.beneficiaryNameMismatchHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.beneficiaryNameMismatchDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          button: (h("div", { class: sheet.classes.ButtonContainer },
            h("sl-button", { disabled: states.loading, type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onPaymentInfoClick }, text.editPaymentInformationButton),
            h("sl-button", { disabled: states.loading, type: "secondary", exportparts: "base: secondarybutton-base", onClick: callbacks.onNewFormClick }, text.newFormButton))),
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "BANK_TAX_NAME_MISMATCH":
        return {
          header: text.bankTaxNameMismatchHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.bankTaxNameMismatchDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          button: (h("div", { class: sheet.classes.ButtonContainer },
            h("sl-button", { disabled: states.loading, type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onPaymentInfoClick }, text.editPaymentInformationButton),
            h("sl-button", { disabled: states.loading, type: "secondary", exportparts: "base: secondarybutton-base", onClick: callbacks.onNewFormClick }, text.newFormButton))),
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "WITHDRAWAL_SETTINGS_INVALID":
        return {
          header: text.withdrawalSettingsInvalidHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.withdrawalSettingsInvalidDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          button: (h("div", { class: sheet.classes.ButtonContainer },
            h("sl-button", { disabled: states.loading, type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onPaymentInfoClick }, text.editPaymentInformationButton))),
          alertType: "warning",
          icon: "exclamation-triangle",
        };
      case "PAYMENT_RETURNED":
        return {
          header: text.paymentReturnedHeader,
          description: intl.formatMessage({
            id: "accountReviewDescription",
            defaultMessage: text.paymentReturnedDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          button: (h("div", { class: sheet.classes.ButtonContainer },
            h("sl-button", { disabled: states.loading, type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onPaymentInfoClick }, text.editPaymentInformationButton))),
          alertType: "error",
          icon: "exclamation-triangle",
        };
      case "HOLD":
        return {
          header: text.holdHeader,
          description: intl.formatMessage({
            id: "holdDescription",
            defaultMessage: text.holdDescription,
          }, {
            supportLink: (h("a", { target: "_blank", href: `mailto:advocate-support@impact.com` }, text.supportLink)),
          }),
          buttonText: null,
          alertType: "warning",
        };
      default:
        return;
    }
  }
  function getButton(status) {
    switch (status) {
      case "OVER_W9_THRESHOLD":
        if (states.enforceUsTaxComplianceOption === "CASH_ONLY")
          return;
        return data.type === "SquatchJS2" ? (h("sqm-scroll", { "scroll-tag-name": "sqm-tabs", "button-text": text.w9RequiredButtonText, "scroll-animation": "smooth" })) : data.type === "SquatchPortal" ? (h("sl-button", { type: "primary", exportparts: "base: primarybutton-base", onClick: callbacks.onTermsClick }, text.w9RequiredButtonText)) : (
        // Demo case
        h("sl-button", { type: "primary", exportparts: "base: primarybutton-base" }, text.w9RequiredButtonText));
      case "INFORMATION_REQUIRED":
        return data.type === "SquatchJS2" ? (h("div", { style: { paddingTop: "10px" } },
          h("sqm-scroll", { "scroll-tag-name": "sqm-tabs", "button-text": text.informationRequiredButtonText, "scroll-animation": "smooth" }))) : data.type === "SquatchPortal" ? (h("div", { style: { paddingTop: "10px" } },
          h("sl-button", { type: "secondary", exportparts: "base: secondarybutton-base", onClick: callbacks.onTermsClick }, text.informationRequiredButtonText))) : (
        // Demo case
        h("div", { style: { paddingTop: "10px" } },
          h("sl-button", { type: "secondary", exportparts: "base: secondarybutton-base" }, text.informationRequiredButtonText)));
      case "VERIFICATION:REQUIRED":
        return (h("div", { style: { paddingTop: "10px" } },
          h("sl-button", { type: "secondary", exportparts: "base: secondarybutton-base", loading: states.veriffLoading, onClick: callbacks.onClick }, text.verificationRequiredButtonText)));
      default:
        if (alertDetails.button)
          return alertDetails.button;
        return;
    }
  }
  const alertDetails = getAlert(states.status);
  if (states.status === "DONE" || !alertDetails) {
    return h("div", null);
  }
  return (h("div", { part: "sqm-base" },
    h("style", { type: "text/css" }, styleString),
    h("style", { type: "text/css" }, vanillaStyle),
    h("sqm-form-message", { loading: states.loading, type: alertDetails.alertType },
      h("p", { part: "alert-title" }, alertDetails.header),
      h("p", { part: "alert-description" }, alertDetails.description),
      getButton(states.status))));
}
