/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see .
*/
import {Trans, useLingui} from '@lingui/react/macro';
import clsx from 'clsx';
import {observer} from 'mobx-react-lite';
import React from 'react';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import type {GuildSplashCardAlignmentValue} from '~/Constants';
import {GuildFeatures, GuildSplashCardAlignment} from '~/Constants';
import {AuthBackground} from '~/components/auth/AuthBackground';
import {AuthBottomLink} from '~/components/auth/AuthBottomLink';
import {AuthCardContainer} from '~/components/auth/AuthCardContainer';
import authPageStyles from '~/components/auth/AuthPageStyles.module.css';
import {PreviewGuildInviteHeader} from '~/components/auth/InviteHeader';
import {MockMinimalRegisterForm} from '~/components/auth/MockMinimalRegisterForm';
import authLayoutStyles from '~/components/layout/AuthLayout.module.css';
import {Button} from '~/components/uikit/Button/Button';
import {CardAlignmentControls} from '~/components/uikit/CardAlignmentControls/CardAlignmentControls';
import {useAuthBackground} from '~/hooks/useAuthBackground';
import foodPatternUrl from '~/images/i-like-food.svg';
import GuildMemberStore from '~/stores/GuildMemberStore';
import GuildStore from '~/stores/GuildStore';
import PresenceStore from '~/stores/PresenceStore';
import WindowStore from '~/stores/WindowStore';
import * as AvatarUtils from '~/utils/AvatarUtils';
import styles from './InvitePagePreviewModal.module.css';
import * as Modal from './Modal';
interface InvitePagePreviewModalProps {
guildId: string;
previewSplashUrl?: string | null;
previewIconUrl?: string | null;
previewName?: string | null;
previewSplashAlignment?: GuildSplashCardAlignmentValue;
onAlignmentChange?: (alignment: GuildSplashCardAlignmentValue) => void;
}
const ALIGNMENT_MIN_WIDTH = 1600;
export const InvitePagePreviewModal: React.FC = observer(
({guildId, previewSplashUrl, previewIconUrl, previewName, previewSplashAlignment, onAlignmentChange}) => {
const {t} = useLingui();
const guild = GuildStore.getGuild(guildId);
const initialAlignment = previewSplashAlignment ?? guild?.splashCardAlignment ?? GuildSplashCardAlignment.CENTER;
const [localAlignment, setLocalAlignment] = React.useState(initialAlignment);
const alignmentControlsEnabled = WindowStore.windowSize.width >= ALIGNMENT_MIN_WIDTH;
const splashUrl = React.useMemo(() => {
if (previewSplashUrl) return previewSplashUrl;
if (guild?.splash) {
return AvatarUtils.getGuildSplashURL({id: guild.id, splash: guild.splash}, 4096);
}
return null;
}, [previewSplashUrl, guild?.id, guild?.splash]);
const {patternReady, splashLoaded, splashDimensions} = useAuthBackground(splashUrl, foodPatternUrl);
const shouldShowSplash = Boolean(splashUrl && splashDimensions);
const handleClose = React.useCallback(() => {
ModalActionCreators.pop();
}, []);
const handleAlignmentChange = React.useCallback(
(alignment: GuildSplashCardAlignmentValue) => {
setLocalAlignment(alignment);
onAlignmentChange?.(alignment);
},
[onAlignmentChange],
);
if (!guild) return null;
const splashAlignment = localAlignment;
const isVerified = guild.features.has(GuildFeatures.VERIFIED);
const presenceCount = PresenceStore.getPresenceCount(guildId);
const memberCount = GuildMemberStore.getMemberCount(guildId);
return (