/*
Copyright (C) 2025 QuantumNous
This program 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.
This program 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 this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useRef, useState } from 'react';
import {
Button,
Collapsible,
Dropdown,
Select,
Skeleton,
Tag,
TextArea,
Toast,
Tooltip,
Typography,
} from '@/components/ui';
import {
ChevronDown,
ChevronUp,
Command,
History as HistoryIcon,
Image as ImageIcon,
Lock,
RotateCcw,
Settings,
Sparkles,
Type,
Wallet,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { MODEL_CATEGORY } from '../../../../constants';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
import { useModelSelector } from '../../../../hooks/models/useModelSelector';
import { useOptimizePrompt } from '../../../../hooks/playground/useOptimizePrompt';
import { formatQuoteAmount } from '../../../../hooks/creation/useCreationQuote';
import { MODE_LABEL_KEYS } from '../../../../hooks/image/imageCreation';
import {
ImageSlot,
OptionGroup,
ParamRenderer,
} from '../../../../components/creation/params';
import ImageSizePicker from './Image/ImageSizePicker';
import './Image/ImageGenerationForm.css';
const { Title, Text } = Typography;
// sessionStorage prompt 历史 key
const PROMPT_HISTORY_KEY = 'expCenter.imageGen.promptHistory.v1';
const PROMPT_HISTORY_MAX = 10;
const PROMPT_TEMPLATES = [
{
label: '风景',
text: '一片壮丽的山水风景,远山起伏,湖面如镜,柔和自然光,超精细,4K,电影感',
},
{
label: '人像',
text: '一张专业人像摄影,自然光,柔焦背景,皮肤质感真实,电影质感色调',
},
{
label: '二次元',
text: '动漫风格人物,鲜明配色,精致线条,干净背景,高质量数字绘画',
},
{
label: '科幻',
text: '未来都市夜景,霓虹灯,飞行器,赛博朋克风格,高细节,电影感',
},
{
label: '极简',
text: '极简风格,纯色背景,几何构图,柔和色调,留白美学',
},
{
label: '产品',
text: '产品摄影,纯白背景,柔光,锐利对焦,专业商业摄影',
},
];
const MODE_ICONS = { text2image: Type, edit: ImageIcon };
// 与视频页一致的预算来源文案(估价 budget_source 的前缀)
const BUDGET_SOURCE_LABELS = {
org_budget: '部门 / 项目预算',
token: '令牌额度',
org_member: '成员额度',
org_gift: '企业赠送额度',
org: '企业额度',
membership: '会员额度',
gift: '赠送余额',
user: '账户余额',
};
const budgetSourceLabel = (source) =>
BUDGET_SOURCE_LABELS[String(source || '').split(':')[0]] || '';
const PRICE_UNIT_KEYS = { image: '/张', task: '/次' };
/** schema 单价:"¥0.2/张"。 */
const formatModelPrice = (t, model) => {
const pricing = model?.pricing;
if (!pricing || pricing.price === undefined || pricing.price === null) {
return '';
}
const amount = formatQuoteAmount(pricing.price, pricing.currency);
if (!amount) return '';
const unit = PRICE_UNIT_KEYS[pricing.unit];
return unit ? `${amount}${t(unit)}` : amount;
};
// 检测当前平台是否为 Mac(决定快捷键文案)
const IS_MAC =
typeof navigator !== 'undefined' &&
/Mac|iPod|iPhone|iPad/.test(navigator.platform);
// 检测 DataTransfer 是否携带历史卡片拖出的任务(兼容 Safari 老版本 DOMStringList)
const hasImageTaskType = (dataTransfer) =>
Boolean(
dataTransfer &&
dataTransfer.types &&
Array.from(dataTransfer.types).includes('application/x-image-task'),
);
const Section = ({ title, extra, children, className = '' }) => (