import type { PageProps } from "keycloakify/login/pages/PageProps";
import { kcSanitize } from "keycloakify/lib/kcSanitize";
import type { KcContext } from "../KcContext";
import type { I18n } from "../i18n";
import { Alert, Button,  Space} from "antd";

export default function Error(props: PageProps<Extract<KcContext, { pageId: "error.ftl" }>, I18n>) {
    const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
    const { message, client, skipLink } = kcContext;
    const { msg } = i18n;

    return (
        <Template
            kcContext={kcContext}
            i18n={i18n}
            doUseDefaultCss={doUseDefaultCss}
            classes={classes}
            displayMessage={false}
            headerNode={msg("errorTitle")}
        >
            <div style={{ margin: "0 15px" }}>
                <Space direction="vertical" size="middle" style={{ marginBottom: 24 }}>
                    <Alert message={<div dangerouslySetInnerHTML={{ __html: kcSanitize(message.summary) }} />} type="error" showIcon />
                </Space>
                {!skipLink && client !== undefined && client.baseUrl !== undefined && (
                    <Button type="primary" id="backToApplication" size={"large"} block href={client.baseUrl}>
                        {msg("backToApplication")}
                    </Button>
                )}
            </div>
        </Template>
    );
}
