"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { NativeSelect, NativeSelectOptGroup, NativeSelectOption, } from "@suphark/ui/components/ui/native-select"; import { ToggleGroup, ToggleGroupItem } from "@suphark/ui/components/ui/toggle-group"; import { focusAfterRemove } from "@suphark/ui/lib/focus-after-remove"; import { cn } from "@suphark/ui/lib/utils"; import { Plus, X } from "lucide-react"; import type { ReactNode } from "react"; // ---------- ชนิดข้อมูล (แอปเก็บ/ส่ง server ในรูปนี้ได้ตรง ๆ) ---------- export type RuleLeaf = { field: F; operator: string; value: unknown }; export type RuleGroup = { op: "and" | "or"; items: RuleCondition[] }; export type RuleNot = { op: "not"; item: RuleCondition }; export type RuleCondition = RuleLeaf | RuleGroup | RuleNot; export function isRuleGroup(c: RuleCondition): c is RuleGroup { return "op" in c && (c.op === "and" || c.op === "or"); } export function isRuleNot(c: RuleCondition): c is RuleNot { return "op" in c && c.op === "not"; } export function emptyGroup(op: "and" | "or" = "and"): RuleGroup { return { op, items: [] }; } export interface RuleFieldDef { key: F; /** ชื่อฟิลด์ (ข้อความ — แสดงใน `