import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
import { useMemo } from "react";
import {
appJumpExploreGameCodeOptions,
appJumpTargetOptions,
appJumpWindowOptions,
buildAppJumpParam,
normalizeJumpConfigType,
parseAppJumpParam,
} from "@/shared/app-jump/appJumpConfig.js";
import { AdminFormFieldGrid } from "@/shared/ui/AdminFormDialog.jsx";
import styles from "@/shared/ui/AppJumpConfigField.module.css";
export function AppJumpConfigField({
allowCustom = true,
allowH5 = true,
appParamLabel = "APP 参数 JSON",
className = "",
disabled = false,
h5Label = "H5 链接",
messages = {},
onChange,
paramValue,
required = false,
showHint = true,
typeLabel = "跳转类型",
typeValue,
}) {
const type = normalizeJumpConfigType(typeValue);
const appJump = useMemo(() => parseAppJumpParam(paramValue), [paramValue]);
const appTargetOptions = useMemo(
() => (allowCustom ? appJumpTargetOptions : appJumpTargetOptions.filter(([value]) => value !== "custom")),
[allowCustom],
);
const appTargetValue = !allowCustom && appJump.target === "custom" ? "wallet" : appJump.target;
const setType = (nextType) => {
if (nextType === "app") {
onChange({ param: buildAppJumpParam({ target: "wallet" }), type: "app" });
return;
}
onChange({ param: "", type: "h5" });
};
const setAppJump = (patch) => {
const next = { ...appJump, ...patch };
if (next.target === "custom") {
onChange({ param: next.raw, type: "app" });
return;
}
onChange({ param: buildAppJumpParam(next), type: "app" });
};
return (
setType(event.target.value)}
>
{allowH5 ? : null}
{type === "h5" ? (
onChange({ param: event.target.value, type: "h5" })}
/>
) : (
<>
setAppJump({ target: event.target.value })}
>
{appTargetOptions.map(([value, label]) => (
))}
onChange({ param: event.target.value, type: "app" })}
/>
>
)}
{type === "app" && showHint ? (
{messages.hint || "APP 参数会按公共跳转方案生成 JSON;需要特殊参数时可直接编辑 JSON。"}
) : null}
);
}
function AppJumpStructuredFields({ appJump, disabled, messages, onChange }) {
if (appJump.target === "custom" || appJump.target === "wallet" || appJump.target === "room_random") {
return null;
}
return (
<>
{needsRoomId(appJump.target) ? (
onChange({ roomId: event.target.value })}
/>
) : null}
{needsWindow(appJump.target) ? (
onChange({ window: event.target.value })}
>
{appJumpWindowOptions.map(([value, label]) => (
))}
) : null}
{needsGameId(appJump.target, appJump.window) ? (
onChange({ gameId: event.target.value })}
/>
) : null}
{needsExploreGameCode(appJump.target) ? (
onChange({ gameCode: event.target.value })}
>
{appJumpExploreGameCodeOptions.map(([value, label]) => (
))}
) : null}
{needsGiftId(appJump.target, appJump.window) ? (
onChange({ giftId: event.target.value })}
/>
) : null}
{needsRedPacketNo(appJump.target, appJump.window) ? (
onChange({ redPacketNo: event.target.value })}
/>
) : null}
>
);
}
function needsRoomId(target) {
return target === "room" || target === "room_window" || target === "room_game";
}
function needsWindow(target) {
return target === "room_window" || target === "room_random_window";
}
function needsGameId(target, window) {
return target === "room_game" || target === "room_random_game" || window === "game_window";
}
function needsExploreGameCode(target) {
return target === "explore_game";
}
function needsGiftId(target, window) {
return needsWindow(target) && window === "gift_panel";
}
function needsRedPacketNo(target, window) {
return needsWindow(target) && window === "red_packet_claim";
}