import { useRuleStore } from "@/stores/ruleStore"; import { Input } from "@/components/ui/input"; import { SegmentedControl } from "@/components/ui/segmented-control"; import { Checkbox } from "@/components/ui/checkbox"; import { IconPlus, IconTrash } from "@tabler/icons-react"; import type { ExtensionConfig as ExtensionConfigType } from "@/types/rules"; const extModes = [ { value: "Same", label: "Same" }, { value: "Lower", label: "lower" }, { value: "Upper", label: "UPPER" }, { value: "Title", label: "Title" }, { value: "Extra", label: "Extra" }, { value: "Remove", label: "Remove" }, { value: "Fixed", label: "Fixed" }, ] as const; export function ExtensionConfig({ ruleId }: { ruleId: string }) { const rule = useRuleStore((s) => s.pipeline.find((r) => r.id === ruleId))?.config as ExtensionConfigType | undefined; const updateRule = useRuleStore((s) => s.updateRule); if (!rule) return null; const update = (changes: Partial) => updateRule(ruleId, changes); const mappings = rule.mapping || []; const addMapping = () => { update({ mapping: [...mappings, ["", ""]] }); }; const removeMapping = (idx: number) => { const next = mappings.filter((_, i) => i !== idx); update({ mapping: next.length > 0 ? next : null }); }; const updateMapping = (idx: number, pos: 0 | 1, val: string) => { const next = mappings.map((m, i) => { if (i !== idx) return m; const copy: [string, string] = [...m]; copy[pos] = val; return copy; }); update({ mapping: next }); }; return (
Mode update({ mode: m })} options={extModes} size="sm" />
{rule.mode === "Fixed" && ( )} {mappings.length > 0 && (
Extension mappings {mappings.map((m, idx) => (
updateMapping(idx, 0, e.target.value)} placeholder="From..." className="h-7 text-xs font-mono flex-1" /> {"->"} updateMapping(idx, 1, e.target.value)} placeholder="To..." className="h-7 text-xs font-mono flex-1" />
))}
)}
); }