/* eslint-disable react/prop-types */
import React from 'react';
import PropTypes from 'prop-types';

let lastOptions = null;

export default function ApexCharts({ options, series }) {
  lastOptions = options;
  // Test tooltip custom function if exists
  if (options?.tooltip?.custom) {
    const mockSeries = series?.map(s => s.data) || [[1, 2, 3]];
    const mockW = {
      globals: {
        seriesNames: series?.map(s => s.name) || ['Test']
      }
    };
    // Call custom tooltip to ensure coverage
    options.tooltip.custom({
      series: mockSeries,
      seriesIndex: 0,
      dataPointIndex: 0,
      w: mockW
    });
  }
  return <div data-testid="mock-chart">Chart Rendered</div>;
}

ApexCharts.propTypes = {
  options: PropTypes.object,
  series: PropTypes.array,
  type: PropTypes.string,
  height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

ApexCharts.defaultProps = {
  options: {},
  series: [],
};

export function getLastOptions() {
  return lastOptions;
}
