import { DataFormat } from '../../models/sas/common/DateFormat'

/**
 * Builds the HTML shown in a column-header "info" dropdown item (viewer and
 * editor). NAME is listed first so it's visible regardless of whether
 * headers are currently displayed as NAME or LABEL.
 */
export function buildColInfoHtml(
  colName: string,
  colInfo?: DataFormat,
  hardRegexValue?: string,
  softRegexValue?: string
): string {
  if (!colInfo) return 'No info found'

  let html = `NAME: ${colName}<br>LABEL: ${colInfo.label}<br>TYPE: ${colInfo.type}<br>LENGTH: ${colInfo.length}<br>FORMAT: ${colInfo.format}`

  // HARDREGEX/SOFTREGEX are only distinguished by name when a column has
  // both - with just one rule, which one it is is already implied, so the
  // generic REGEX label keeps the common case uncluttered.
  if (hardRegexValue && softRegexValue) {
    html += `<br>HARDREGEX: ${hardRegexValue}<br>SOFTREGEX: ${softRegexValue}`
  } else if (hardRegexValue || softRegexValue) {
    html += `<br>REGEX: ${hardRegexValue || softRegexValue}`
  }

  return html
}
