import { type ReactNode } from "react";
import { Switch } from "antd";
import { ImageSettingsTheme } from "@/components/image-settings-panel";
import { boolConfig, isSeedanceFastModel, isSeedanceVideoConfig, normalizeSeedanceDuration, normalizeSeedanceRatio, normalizeSeedanceResolution, seedanceDurationOptions, seedancePixelLabel, seedanceRatioOptions, seedanceResolutionOptions } from "@/lib/seedance-video";
import { type CanvasTheme } from "@/lib/canvas-theme";
import { modelOptionName, type AiConfig } from "@/stores/use-config-store";
const resolutionOptions = [
{ value: "720", label: "720p" },
{ value: "480", label: "480p" },
];
const sizeOptions = [
{ value: "1280x720", label: "横屏", width: 1280, height: 720 },
{ value: "720x1280", label: "竖屏", width: 720, height: 1280 },
{ value: "1024x1024", label: "方形", width: 1024, height: 1024 },
{ value: "1792x1024", label: "宽屏", width: 1792, height: 1024 },
{ value: "1024x1792", label: "长图", width: 1024, height: 1792 },
{ value: "auto", label: "auto", width: 0, height: 0 },
];
const secondOptions = [6, 10, 12, 16, 20];
export const videoResolutionOptions = resolutionOptions.map((item) => ({ value: item.value, label: item.label }));
export const videoSizeOptions = sizeOptions.map((item) => ({ value: item.value, label: item.label }));
export const videoSecondOptions = secondOptions.map((value) => String(value));
type VideoSettingsPanelProps = {
config: AiConfig;
onConfigChange: (key: "vquality" | "size" | "videoSeconds" | "videoGenerateAudio" | "videoWatermark", value: string) => void;
theme: CanvasTheme;
showTitle?: boolean;
className?: string;
};
export function VideoSettingsPanel({ config, onConfigChange, theme, showTitle = true, className = "w-[320px] space-y-4 rounded-2xl px-1 py-0.5" }: VideoSettingsPanelProps) {
if (isSeedanceVideoConfig(config)) {
return ;
}
const seconds = config.videoSeconds || "6";
const size = normalizeVideoSizeValue(config.size);
const dimensions = readSizeDimensions(size);
const resolution = normalizeVideoResolutionValue(config.vquality);
const updateDimension = (key: "width" | "height", value: number | null) => {
const next = Math.max(1, Math.floor(value || dimensions[key] || 720));
onConfigChange("size", `${key === "width" ? next : dimensions.width}x${key === "height" ? next : dimensions.height}`);
};
return (
event.stopPropagation()}>
{showTitle ?
视频设置
: null}
{resolutionOptions.map((item) => (
onConfigChange("vquality", item.value)}>
{item.label}
))}
onConfigChange("vquality", value)} />
updateDimension("width", value)} />
↔
updateDimension("height", value)} />
{sizeOptions.map((item) => (
))}
{secondOptions.map((value) => (
onConfigChange("videoSeconds", String(value))}>
{value}s
))}
onConfigChange("videoSeconds", value)} />
);
}
function SeedanceVideoSettingsPanel({ config, onConfigChange, theme, showTitle, className }: VideoSettingsPanelProps) {
const model = modelOptionName(config.model || config.videoModel);
const resolution = normalizeSeedanceResolution(config.vquality, model);
const ratio = normalizeSeedanceRatio(config.size);
const duration = normalizeSeedanceDuration(config.videoSeconds);
const generateAudio = boolConfig(config.videoGenerateAudio, true);
const watermark = boolConfig(config.videoWatermark, false);
return (
event.stopPropagation()}>
{showTitle ?
视频设置
: null}
{seedanceResolutionOptions.map((item) => {
const disabled = item.value === "1080p" && isSeedanceFastModel(model);
return (
onConfigChange("vquality", item.value)}>
{item.label}
);
})}
{isSeedanceFastModel(model) ? fast 模型不支持 1080p,会自动使用 720p。
: null}
{seedanceRatioOptions.map((item) => (
))}
{seedanceDurationOptions.map((value) => (
onConfigChange("videoSeconds", String(value))}>
{value === -1 ? "智能" : `${value}s`}
))}
onConfigChange("videoSeconds", value)} />
onConfigChange("videoGenerateAudio", String(checked))} />
onConfigChange("videoWatermark", String(checked))} />
);
}
export function videoResolutionLabel(value: string) {
return `${normalizeVideoResolutionValue(value)}p`;
}
export function videoSizeLabel(value: string) {
const ratio = normalizeSeedanceRatio(value);
if (value === "adaptive" || value === "auto") return "自适应";
if (ratio === value) return seedanceRatioOptions.find((item) => item.value === ratio)?.label || ratio;
const size = normalizeVideoSizeValue(value);
return sizeOptions.find((item) => item.value === size)?.label || size;
}
export function videoSecondsLabel(value: string) {
if (String(value).trim() === "-1") return "智能";
return `${value || "6"}s`;
}
export function normalizeVideoSizeValue(value: string) {
if (value === "auto") return "auto";
if (/^\d+x\d+$/.test(value || "")) return value;
return ["9:16", "2:3", "3:4"].includes(value) ? "720x1280" : "1280x720";
}
export function normalizeVideoResolutionValue(value: string) {
if (value === "480p" || value === "low") return "480";
if (value === "720p" || value === "auto" || value === "high" || value === "medium") return "720";
return value.replace(/p$/i, "") || "720";
}
function OptionPill({ selected, disabled = false, theme, onClick, children }: { selected: boolean; disabled?: boolean; theme: CanvasTheme; onClick: () => void; children: ReactNode }) {
return (
);
}
function SettingGroup({ title, color, children }: { title: string; color: string; children: ReactNode }) {
return (
);
}
function ResolutionInput({ value, theme, onChange }: { value: string; theme: CanvasTheme; onChange: (value: string) => void }) {
return (
);
}
function DimensionInput({ prefix, value, disabled, theme, onChange }: { prefix: string; value: number; disabled: boolean; theme: CanvasTheme; onChange: (value: number | null) => void }) {
return (
);
}
function NumberInput({ value, min, max, theme, onChange }: { value: string; min: number; max: number; theme: CanvasTheme; onChange: (value: string) => void }) {
return onChange(event.target.value)} onMouseDown={(event) => event.stopPropagation()} />;
}
function SizePreview({ width, height, color }: { width: number; height: number; color: string }) {
if (!width || !height) return null;
const longSide = Math.max(width, height);
const previewWidth = Math.max(10, Math.round((width / longSide) * 26));
const previewHeight = Math.max(10, Math.round((height / longSide) * 26));
return ;
}
function ratioPreview(ratio: string) {
if (ratio === "9:16") return { width: 9, height: 16 };
if (ratio === "1:1") return { width: 1, height: 1 };
if (ratio === "4:3") return { width: 4, height: 3 };
if (ratio === "3:4") return { width: 3, height: 4 };
if (ratio === "21:9") return { width: 21, height: 9 };
if (ratio === "adaptive") return { width: 0, height: 0 };
return { width: 16, height: 9 };
}
function SwitchRow({ label, checked, theme, onChange }: { label: string; checked: boolean; theme: CanvasTheme; onChange: (checked: boolean) => void }) {
return (
{label}
event.stopPropagation()}>
);
}
function readSizeDimensions(size: string) {
if (size === "auto") return { width: 0, height: 0 };
const match = size.match(/^(\d+)x(\d+)$/);
return { width: Number(match?.[1]) || 1280, height: Number(match?.[2]) || 720 };
}