import onVisible from './dom/onVisible'

/** For backwards compatibility with charts from v3 (from reporting plugin). */
onVisible('table[data-chart-type]', async (table) => {
  const { default: ChartCompat } = await import(
    /* webpackChunkName: 'ChartCompat' */ './ChartCompat'
  )
  if (table.tagName === 'TABLE') {
    // eslint-disable-next-line no-new
    new ChartCompat(table as HTMLTableElement)
  }
})

onVisible('.ChartTable', async (table) => {
  const { default: Chart } = await import(
    /* webpackChunkName: 'Chart' */ './Chart'
  )
  if (table.tagName === 'TABLE') {
    // eslint-disable-next-line no-new
    new Chart(table as HTMLTableElement)
  }
})
