"use client"; import { Pencil, Check, Banknote, Eye } from "lucide-react"; import { cn } from "@/lib/utils"; import type { CostType } from "@/lib/types/api"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; interface CostFormatSelectorProps { value: CostType; isEditing: boolean; canEdit: boolean; onEdit: () => void; onChange: (value: CostType) => void; onCloseEdit: () => void; } const COST_FORMATS: { value: CostType; label: string; icon: typeof Banknote }[] = [ { value: "fixed", label: "Фикс", icon: Banknote }, { value: "cpm", label: "CPM", icon: Eye }, ]; export function CostFormatSelector({ value, isEditing, canEdit, onEdit, onChange, onCloseEdit, }: CostFormatSelectorProps) { const currentFormat = COST_FORMATS.find((f) => f.value === value) || COST_FORMATS[0]; const Icon = currentFormat.icon; if (isEditing) { return ( !open && onCloseEdit()}> {currentFormat.label} {COST_FORMATS.map((format) => { const FormatIcon = format.icon; const isSelected = format.value === value; return ( { onChange(format.value); onCloseEdit(); }} > {format.label} {isSelected && } ); })} ); } return ( {currentFormat.label} {canEdit && } ); }