/** Konstanten und Spaltenreferenz für den Daten-Import-Dialog. */

export const IMPORT_DEBOUNCE_MS = 300;

export const IMPORT_STANDARD_HEADER = 'value;unit;headline;paragraph;smallPrint';

export const IMPORT_ALL_COLUMNS_HEADER = 'value;unit;headline;paragraph;smallPrint;link;linkNewTab;color;groupKey;scatterX;scatterY;annotation;annotationDesc';

export const IMPORT_EXAMPLE_HEADER = 'value;unit;headline;paragraph;smallPrint;groupKey';
export const IMPORT_EXAMPLE_ROW = '42;%;January;Quiet month…;Example 2025;Q1';
export const IMPORT_EXAMPLE_CSV = [
  IMPORT_EXAMPLE_HEADER,
  IMPORT_EXAMPLE_ROW,
  '58;%;February;Strong growth;Example 2025;Q1',
  '35;%;March;Spring pick-up;Example 2025;Q2',
  '48;%;April;Steady demand;Example 2025;Q2',
  '61;%;May;Peak season;Example 2025;Q3',
  '44;%;June;Slight dip;Example 2025;Q3',
].join('\n');

export const IMPORT_PREVIEW_MAX_ROWS = 6;

export const IMPORT_PREVIEW_FIELD_ORDER = [
  'value', 'unit', 'headline', 'paragraph', 'smallPrint', 'groupKey',
  'link', 'linkNewTab', 'color', 'scatterX', 'scatterY', 'annotation', 'annotationDesc',
];

export const IMPORT_COLUMN_REFERENCE = [
  { key: 'value', category: 'required', example: '42', aliases: 'wert, val' },
  { key: 'unit', category: 'usual', example: '%', aliases: null },
  { key: 'headline', category: 'usual', example: 'January', aliases: 'title, label' },
  { key: 'paragraph', category: 'usual', example: 'Quiet month…', aliases: 'desc, description' },
  { key: 'smallPrint', category: 'usual', example: 'Example 2025', aliases: 'source, note' },
  { key: 'link', category: 'optional', example: 'https://…', aliases: 'url, href' },
  { key: 'linkNewTab', category: 'optional', example: '1', aliases: 'newtab, ja' },
  { key: 'color', category: 'optional', example: '#ff6600', aliases: 'colour, hex' },
  { key: 'groupKey', category: 'optional', example: 'Q1', aliases: 'group' },
  { key: 'scatterX', category: 'optional', example: '12', aliases: null },
  { key: 'scatterY', category: 'optional', example: '8', aliases: null },
  { key: 'annotation', category: 'optional', example: 'Peak', aliases: null },
  { key: 'annotationDesc', category: 'optional', example: '…', aliases: 'desc' },
];

export const IMPORT_CATEGORY_ORDER = ['required', 'usual', 'optional'];

export function estimateImportDataLineCount(text) {
  const lines = String(text || '').trim().split(/\r?\n/).filter((l) => l.trim());
  if (!lines.length) return 0;
  const first = lines[0].toLowerCase();
  const headerish = /\b(value|wert|headline|unit)\b/.test(first);
  return headerish ? Math.max(0, lines.length - 1) : lines.length;
}
