import { PlusCircle, Trash2 } from "lucide-react"; import { useFieldArray } from "react-hook-form"; import { Button } from "@/src/components/ui/button"; import { Input } from "@/src/components/ui/input"; import { Checkbox } from "@/src/components/ui/checkbox"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/src/components/ui/select"; import type { UseFormReturn } from "react-hook-form"; import type { FormUpsertModel } from "../../validation"; type TierConditionsEditorProps = { tierIndex: number; form: UseFormReturn; }; export type { TierConditionsEditorProps }; export function TierConditionsEditor({ tierIndex, form, }: TierConditionsEditorProps) { const { fields, append, remove } = useFieldArray({ control: form.control, name: `pricingTiers.${tierIndex}.conditions`, }); return (
Conditions
{fields.length === 0 && (
Warning: Non-default tiers require at least one condition. This tier will fail validation.
)} {fields.map((condition, conditionIndex) => (
Condition {conditionIndex + 1}
{/* Pattern */} ( Usage Detail Pattern (Regex) Match usage type keys (e.g., ^input, .*cache.*, output_tokens) )} /> {/* Operator + Value */}
( Operator )} /> ( Value field.onChange(parseFloat(e.target.value)) } /> )} />
{/* Case Sensitive */} ( Case sensitive )} />
))}
); }