"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeedbackModalInternal = void 0;
const react_1 = __importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const deprecated_1 = require("@patternfly/react-core/deprecated");
const react_icons_1 = require("@patternfly/react-icons");
const pf_feedback_svg_1 = __importDefault(require("../images/pf_feedback.svg"));
const FeedbackForm_1 = require("./FeedbackForm");
const FeedbackSuccess_1 = __importDefault(require("./FeedbackSuccess"));
const FeedbackError_1 = __importDefault(require("./FeedbackError"));
const LocaleContext_1 = require("../context/LocaleContext");
exports.FeedbackModalInternal = (0, react_1.memo)(({ email, isOpen, onShareFeedback, onJoinMailingList, onReportABug, onOpenSupportCase, onClose, feedbackImg }) => {
    const intl = react_1.default.useContext(LocaleContext_1.LocaleContext);
    const emailRef = (0, react_1.useRef)(email ? email : '');
    const [modalPage, setModalPage] = (0, react_1.useState)('feedbackHome');
    const handleCloseModal = () => {
        if (onClose) {
            onClose();
        }
        setModalPage('feedbackHome');
    };
    const updateEmail = (email) => {
        if (emailRef.current !== email && email !== '') {
            emailRef.current = email;
        }
    };
    const onSubmit = (feedbackPage, results) => {
        if (results instanceof Promise) {
            results.then((results) => {
                results === false ? setModalPage('feedbackError') : setModalPage(feedbackPage);
            });
        }
        else {
            results === false ? setModalPage('feedbackError') : setModalPage(feedbackPage);
        }
    };
    const ModalDescription = ({ modalPage }) => {
        switch (modalPage) {
            case 'feedbackHome':
                return (react_1.default.createElement(react_core_1.Panel, { isScrollable: true, className: "chr-c-feedback-content" },
                    react_1.default.createElement(react_core_1.PanelHeader, { className: "chr-c-feedback-heading" },
                        react_1.default.createElement(react_core_1.FlexItem, null,
                            react_1.default.createElement(react_core_1.Content, { component: react_core_1.ContentVariants.h1 }, intl.tellAboutExperience)),
                        react_1.default.createElement(react_core_1.FlexItem, null,
                            react_1.default.createElement(react_core_1.Content, { component: "p" }, intl.helpUsImproveHCC))),
                    react_1.default.createElement(react_core_1.PanelMain, { tabIndex: 0, className: "chr-c-feedback-content-main" },
                        react_1.default.createElement(react_core_1.PanelMainBody, { className: "chr-c-feedback-cards" },
                            react_1.default.createElement(react_core_1.Card, { isCompact: true, isClickable: true, variant: "secondary" },
                                react_1.default.createElement(react_core_1.CardHeader, { selectableActions: {
                                        // eslint-disable-next-line no-console
                                        onClickAction: () => {
                                            typeof onShareFeedback === 'string'
                                                ? window.open(onShareFeedback, '_blank')
                                                : setModalPage('feedbackOne');
                                        },
                                        selectableActionId: 'feedback-card-1',
                                        selectableActionAriaLabelledby: 'feedback-card-1',
                                        name: 'feedback-card'
                                    } }),
                                react_1.default.createElement(react_core_1.CardTitle, null,
                                    intl.shareFeedback,
                                    " ",
                                    typeof onShareFeedback === 'string' ? react_1.default.createElement(react_icons_1.ExternalLinkAltIcon, null) : null),
                                react_1.default.createElement(react_core_1.CardBody, null,
                                    intl.howIsConsoleExperience,
                                    " ")),
                            onReportABug && (react_1.default.createElement(react_core_1.Card, { isCompact: true, isClickable: true, variant: "secondary" },
                                react_1.default.createElement(react_core_1.CardHeader, { selectableActions: {
                                        // eslint-disable-next-line no-console
                                        onClickAction: () => {
                                            typeof onReportABug === 'string'
                                                ? window.open(onReportABug, '_blank')
                                                : setModalPage('reportBugOne');
                                        },
                                        selectableActionId: 'report-bug-card-1',
                                        selectableActionAriaLabelledby: 'report-bug-card-1',
                                        name: 'report-bug-card'
                                    } }),
                                react_1.default.createElement(react_core_1.CardTitle, null,
                                    intl.reportABug,
                                    " ",
                                    typeof onReportABug === 'string' ? react_1.default.createElement(react_icons_1.ExternalLinkAltIcon, null) : null,
                                    ' '),
                                react_1.default.createElement(react_core_1.CardBody, null, intl.describeBugUrgentCases))),
                            onOpenSupportCase && (react_1.default.createElement(react_core_1.Card, { isCompact: true, isClickable: true, variant: "secondary" },
                                react_1.default.createElement(react_core_1.CardHeader, { selectableActions: {
                                        // eslint-disable-next-line no-console
                                        onClickAction: () => {
                                            window.open(onOpenSupportCase, '_blank');
                                        },
                                        selectableActionId: 'open-support-case-card-1',
                                        selectableActionAriaLabelledby: 'open-support-case-card-1',
                                        name: 'open-support-case-card'
                                    } }),
                                react_1.default.createElement(react_core_1.CardTitle, null,
                                    react_1.default.createElement(react_core_1.Content, { component: "p" },
                                        intl.openSupportCase,
                                        " ",
                                        react_1.default.createElement(react_icons_1.ExternalLinkAltIcon, null))),
                                react_1.default.createElement(react_core_1.CardBody, null, intl.getSupport))),
                            onJoinMailingList && (react_1.default.createElement(react_core_1.Card, { isCompact: true, isClickable: true, variant: "secondary" },
                                react_1.default.createElement(react_core_1.CardHeader, { selectableActions: {
                                        // eslint-disable-next-line no-console
                                        onClickAction: () => {
                                            typeof onJoinMailingList === 'string'
                                                ? window.open(onJoinMailingList, '_blank')
                                                : setModalPage('informDirection');
                                        },
                                        selectableActionId: 'join-mailing-list-card-1',
                                        selectableActionAriaLabelledby: 'join-mailing-list-card-1',
                                        name: 'join-mailing-list-card'
                                    } }),
                                react_1.default.createElement(react_core_1.CardTitle, null,
                                    react_1.default.createElement(react_core_1.Content, { component: "p" },
                                        intl.informDirection,
                                        ' ',
                                        typeof onJoinMailingList === 'string' ? react_1.default.createElement(react_icons_1.ExternalLinkAltIcon, null) : null)),
                                react_1.default.createElement(react_core_1.CardBody, null, intl.learnAboutResearchOpportunities))))),
                    react_1.default.createElement(react_core_1.PanelFooter, { className: "chr-c-feedback-footer" },
                        react_1.default.createElement(react_core_1.Button, { ouiaId: "cancel-feedback", key: "cancel", variant: "link", onClick: handleCloseModal }, intl.cancel))));
            case 'feedbackOne':
                return (react_1.default.createElement(FeedbackForm_1.FeedbackForm, { email: emailRef.current, onCloseModal: handleCloseModal, onSubmit: (email, textAreaValue) => {
                        let results = true;
                        if (onShareFeedback && typeof onShareFeedback === 'function') {
                            results = onShareFeedback(email, textAreaValue);
                            updateEmail(email);
                        }
                        onSubmit('feedbackSuccess', results);
                    }, onClickBack: () => setModalPage('feedbackHome'), handleFeedbackError: () => setModalPage('feedbackError'), modalTitle: intl.shareYourFeedback, textareaLabel: intl.enterFeedback, feedbackType: "Feedback", checkboxDescription: intl.learnAboutResearchOpportunities, submitTitle: intl.submitFeedback }));
            case 'reportBugOne':
                return (react_1.default.createElement(FeedbackForm_1.FeedbackForm, { email: emailRef.current, onCloseModal: handleCloseModal, onSubmit: (email, textAreaValue) => {
                        let results = true;
                        if (onReportABug && typeof onReportABug === 'function') {
                            results = onReportABug(email, textAreaValue);
                            updateEmail(email);
                        }
                        onSubmit('bugReportSuccess', results);
                    }, onClickBack: () => setModalPage('feedbackHome'), handleFeedbackError: () => setModalPage('feedbackError'), modalTitle: intl.reportABug, modalDescription: react_1.default.createElement(react_core_1.Content, { component: "p" },
                        intl.describeReportBug,
                        ' ',
                        react_1.default.createElement(react_core_1.Content, { component: "a", href: "https://access.redhat.com/support/cases/#/case/new/open-case?caseCreate=true", target: "_blank" },
                            intl.openSupportCase,
                            " ",
                            react_1.default.createElement(react_icons_1.ExternalLinkAltIcon, null))), feedbackType: "Bug", checkboxDescription: `${intl.learnAboutResearchOpportunities} ${intl.weNeverSharePersonalInformation}`, submitTitle: intl.submitFeedback }));
            case 'informDirection':
                return (react_1.default.createElement(FeedbackForm_1.FeedbackForm, { email: emailRef.current, onCloseModal: handleCloseModal, onSubmit: (email, _textAreaValue) => {
                        let results = true;
                        if (onJoinMailingList && typeof onJoinMailingList === 'function') {
                            results = onJoinMailingList(email);
                            updateEmail(email);
                        }
                        onSubmit('informDirectionSuccess', results);
                    }, onClickBack: () => setModalPage('feedbackHome'), handleFeedbackError: () => setModalPage('feedbackError'), modalTitle: intl.informDirection, modalDescription: react_1.default.createElement(react_core_1.Content, { component: "p" },
                        intl.informDirectionDescription,
                        react_1.default.createElement(react_core_1.Content, { component: "a", href: "https://www.redhat.com/en/about/user-research", target: "_blank" }, intl.userResearchTeam),
                        intl.directInfluence), feedbackType: "[Research Opportunities]", textAreaHidden: true, checkboxDescription: intl.weNeverSharePersonalInformation, submitTitle: intl.joinMailingList }));
            case 'feedbackSuccess':
                return (react_1.default.createElement(FeedbackSuccess_1.default, { successTitle: intl.feedbackSent, successDescription: intl.thankYouForFeedback, onCloseModal: handleCloseModal }));
            case 'bugReportSuccess':
                return (react_1.default.createElement(FeedbackSuccess_1.default, { successTitle: intl.bugReported, successDescription: intl.teamWillReviewBug, onCloseModal: handleCloseModal }));
            case 'informDirectionSuccess':
                return (react_1.default.createElement(FeedbackSuccess_1.default, { successTitle: intl.responseSent, successDescription: intl.thankYouForInterest, onCloseModal: handleCloseModal }));
            case 'feedbackError':
                return react_1.default.createElement(FeedbackError_1.default, { onCloseModal: handleCloseModal });
        }
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(deprecated_1.Modal, { "aria-label": "Feedback modal", isOpen: isOpen, className: "chr-c-feedback-modal", variant: deprecated_1.ModalVariant.large, onClose: handleCloseModal, hasNoBodyWrapper: true },
            react_1.default.createElement(react_core_1.Flex, { className: "chr-c-feedback-flex", direction: { default: 'row' }, alignItems: { default: 'alignItemsStretch' } },
                react_1.default.createElement(react_core_1.FlexItem, { className: "chr-c-feedback-description", flex: { default: 'flex_2' } },
                    react_1.default.createElement(ModalDescription, { modalPage: modalPage })),
                react_1.default.createElement(react_core_1.FlexItem, { className: "chr-c-feedback-image", flex: { default: 'flex_1' } },
                    react_1.default.createElement("img", { alt: "feedback illustration", src: feedbackImg ? feedbackImg : pf_feedback_svg_1.default }))))));
});
exports.FeedbackModalInternal.displayName = 'FeedbackModal';
exports.default = exports.FeedbackModalInternal;
