import { Settings } from "lucide-react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Badge } from "@app/components/ui/badge"; import { Label } from "@app/components/ui/label"; import { useEffect, useState } from "react"; import { Input } from "./ui/input"; import { Button } from "./ui/button"; import { Credenza, CredenzaContent, CredenzaDescription, CredenzaFooter, CredenzaHeader, CredenzaTitle, CredenzaTrigger } from "./Credenza"; import { useTranslations } from "next-intl"; export function PathMatchModal({ value, onChange, trigger }: { value: { path: string | null; pathMatchType: string | null }; onChange: (config: { path: string | null; pathMatchType: string | null; }) => void; trigger: React.ReactNode; }) { const t = useTranslations(); const [open, setOpen] = useState(false); const [matchType, setMatchType] = useState( value?.pathMatchType || "prefix" ); const [path, setPath] = useState(value?.path || ""); useEffect(() => { if (open) { setMatchType(value?.pathMatchType || "prefix"); setPath(value?.path || ""); } }, [open, value]); const handleSave = () => { onChange({ pathMatchType: matchType as any, path: path.trim() }); setOpen(false); }; const handleClear = () => { onChange({ pathMatchType: null, path: null }); setOpen(false); }; const getPlaceholder = () => (matchType === "regex" ? t("pathMatchRegexPlaceholder") : t("pathMatchDefaultPlaceholder")); const getHelpText = () => { switch (matchType) { case "prefix": return t("pathMatchPrefixHelp"); case "exact": return t("pathMatchExactHelp"); case "regex": return t("pathMatchRegexHelp"); default: return ""; } }; return ( {trigger} {t("pathMatchModalTitle")} {t("pathMatchModalDescription")}
setPath(e.target.value)} />

{getHelpText()}

{/* {value?.path && ( )} */}
); } export function PathRewriteModal({ value, onChange, trigger, disabled }: { value: { rewritePath: string | null; rewritePathType: string | null }; onChange: (config: { rewritePath: string | null; rewritePathType: string | null; }) => void; trigger: React.ReactNode; disabled?: boolean; }) { const t = useTranslations(); const [open, setOpen] = useState(false); const [rewriteType, setRewriteType] = useState( value?.rewritePathType || "prefix" ); const [rewritePath, setRewritePath] = useState(value?.rewritePath || ""); useEffect(() => { if (open) { setRewriteType(value?.rewritePathType || "prefix"); setRewritePath(value?.rewritePath || ""); } }, [open, value]); const handleSave = () => { onChange({ rewritePathType: rewriteType as any, rewritePath: rewritePath.trim() }); setOpen(false); }; const handleClear = () => { onChange({ rewritePathType: null, rewritePath: null }); setOpen(false); }; const getPlaceholder = () => { switch (rewriteType) { case "regex": return t("pathRewriteRegexPlaceholder"); case "stripPrefix": return ""; default: return t("pathRewriteDefaultPlaceholder"); } }; const getHelpText = () => { switch (rewriteType) { case "prefix": return t("pathRewritePrefixHelp"); case "exact": return t("pathRewriteExactHelp"); case "regex": return t("pathRewriteRegexHelp"); case "stripPrefix": return t("pathRewriteStripPrefixHelp"); default: return ""; } }; return ( !disabled && setOpen(v)}> {trigger} {t("pathRewriteModalTitle")} {t("pathRewriteModalDescription")}
setRewritePath(e.target.value)} />

{getHelpText()}

{value?.rewritePath && ( )}
); } export function PathMatchDisplay({ value }: { value: { path: string | null; pathMatchType: string | null }; }) { const t = useTranslations(); if (!value?.path) return null; const getTypeLabel = (type: string | null) => { const labels: Record = { prefix: t("pathMatchPrefix"), exact: t("pathMatchExact"), regex: t("pathMatchRegex") }; return labels[type || ""] || type; }; return (
{getTypeLabel(value.pathMatchType)} {value.path}
); } export function PathRewriteDisplay({ value }: { value: { rewritePath: string | null; rewritePathType: string | null }; }) { const t = useTranslations(); if (!value?.rewritePath && value?.rewritePathType !== "stripPrefix") return null; const getTypeLabel = (type: string | null) => { const labels: Record = { prefix: t("pathRewritePrefix"), exact: t("pathRewriteExact"), regex: t("pathRewriteRegex"), stripPrefix: t("pathRewriteStrip") }; return labels[type || ""] || type; }; return (
{getTypeLabel(value.rewritePathType)} {value.rewritePath || ( ({t("pathRewriteStripLabel")}) )}
); }