"use client"; import { memo, useCallback, useState, type DragEvent } from "react"; import Icon from "../../../../components/asset/icon"; import { ADD_CUSTOM_FIELD_TYPE_ICONS } from "../../../../components/controls/AddCustomField/AddCustomField.types"; import type { AddCustomFieldType } from "../../../../components/controls/AddCustomField/AddCustomField.types"; import type { CustomMethodCardFieldBlock } from "../../../../../lib/create/customMethodCardFieldBlocks"; import { reorderCustomMethodCardFieldBlocks } from "../../../../../lib/create/reorderCustomMethodCardFieldBlocks"; function DragHandleGlyph({ className }: { className?: string }) { return ( ); } export interface CustomMethodCardWizardBlocksListViewProps { blocks: CustomMethodCardFieldBlock[]; fieldTypeLabels: Record; dragHandleAriaLabel: string; listLabel: string; onBlocksReorder: (_next: CustomMethodCardFieldBlock[]) => void; } function CustomMethodCardWizardBlocksListViewComponent({ blocks, fieldTypeLabels, dragHandleAriaLabel, listLabel, onBlocksReorder, }: CustomMethodCardWizardBlocksListViewProps) { const [draggingIndex, setDraggingIndex] = useState(null); const [overIndex, setOverIndex] = useState(null); const clearDragUi = useCallback(() => { setDraggingIndex(null); setOverIndex(null); }, []); const handleDragStart = useCallback( (index: number) => (e: DragEvent) => { e.dataTransfer.effectAllowed = "move"; e.dataTransfer.setData("text/plain", String(index)); setDraggingIndex(index); }, [], ); const handleDragOver = useCallback((index: number) => { return (e: DragEvent) => { e.preventDefault(); e.dataTransfer.dropEffect = "move"; setOverIndex(index); }; }, []); const handleDrop = useCallback( (index: number) => (e: DragEvent) => { e.preventDefault(); const from = Number.parseInt(e.dataTransfer.getData("text/plain"), 10); if (Number.isNaN(from)) { clearDragUi(); return; } onBlocksReorder( reorderCustomMethodCardFieldBlocks(blocks, from, index), ); clearDragUi(); }, [blocks, clearDragUi, onBlocksReorder], ); return (
    {blocks.map((block, index) => { const kind = block.kind as AddCustomFieldType; const typeLabel = fieldTypeLabels[kind]; const isOver = overIndex === index && draggingIndex !== index; return (
  • {block.blockTitle.trim() || typeLabel} {typeLabel}
  • ); })}
); } export const CustomMethodCardWizardBlocksListView = memo( CustomMethodCardWizardBlocksListViewComponent, ); CustomMethodCardWizardBlocksListView.displayName = "CustomMethodCardWizardBlocksListView";