import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; import { getWidgetIcon } from './widgetIcons.js'; export interface LayerWidget { uuid: string; name: string | null; type: string; rawSettings: Record | null; columns?: Array<{ index: number; widgets: LayerWidget[]; }>; } /** * Minimal shape from the widget-type registry — the Layers panel renders * the canonical widget name + description (not the instance's per-row * name/code, which were terse and not human-friendly). */ export interface LayerNodeWidgetType { code: string; name: string; description: string; /** Optional lucide icon name; resolved via `getWidgetIcon`. */ icon?: string | null; } interface LayerNodeProps { widget: LayerWidget; selectedUid: string | null; onSelect: ( uid: string, type: string, settings: Record ) => void; depth?: number; /** * Lookup from widget code → registry entry. Parent builds the map once * from `widgetTypes` and passes it through; LayerNode threads it into * its recursive children so the lookup stays O(1) at every depth. */ widgetTypesByCode: ReadonlyMap; } export function LayerNode({ widget, selectedUid, onSelect, depth = 0, widgetTypesByCode }: LayerNodeProps): React.ReactElement { const isSelected = selectedUid === widget.uuid; const cols = widget.columns ?? []; const hasChildren = cols.some((c) => (c.widgets ?? []).length > 0); const def = widgetTypesByCode.get(widget.type); // Fall back to the raw code when the registry doesn't know this type // (e.g. an instance of a deleted/renamed widget type). Description omitted // in that case to keep the row from displaying a misleading blank line. const displayName = def?.name ? _(def.name) : widget.type; const description = def?.description ? _(def.description) : ''; const WidgetIcon = getWidgetIcon(def?.icon); return (
  • {hasChildren && (
      {cols.map((col) => ( {(col.widgets ?? []).length > 0 && (
    • {_('Column ${index}', { index: String(col.index + 1) })}
        {col.widgets.map((kid) => ( ))}
    • )}
      ))}
    )}
  • ); }