export type AgentType =
  | 'list-column'
  | 'form-field'
  | 'show-field'
  | 'list-search-bar'
  | 'list-header'
  | 'list-row-actions'
  | 'list-bulk-actions'
  | 'canvas-component'
  | 'show-header'
  | 'app-header'
  | 'app-title';

export interface AgentAttrsOptions {
  type: AgentType;
  field?: string;
  resource?: string;
  file?: string;
  meta?: Record<string, any>;
}

/**
 * Generate data-agent-* attributes for element inspector.
 * Only returns attributes in development mode; returns empty object in production.
 */
export function agentAttrs(options: AgentAttrsOptions): Record<string, string> {
  if (process.env.NODE_ENV !== 'development') {
    return {};
  }

  const attrs: Record<string, string> = {
    'data-agent-type': options.type,
  };

  if (options.resource) {
    attrs['data-agent-resource'] = options.resource;
  }

  if (options.field) {
    attrs['data-agent-field'] = options.field;
  }

  if (options.file) {
    attrs['data-agent-file'] = options.file;
  }

  if (options.meta) {
    attrs['data-agent-meta'] = JSON.stringify(options.meta);
  }

  return attrs;
}

/**
 * Returns Table.Column props (onHeaderCell) to inject row-actions agent attributes on the header.
 * Spread onto the actions `<Table.Column>`:
 * ```tsx
 * <Table.Column title="Actions" {...getRowActionsColumnProps(resourceName)} render={...} />
 * ```
 */
export function getRowActionsColumnProps(
  resource: string,
): Record<string, any> {
  if (process.env.NODE_ENV !== 'development') {
    return {};
  }
  return {
    onHeaderCell: () => agentAttrs({ type: 'list-row-actions', resource }),
  };
}
