import { Line } from 'react-chartjs-2'
import 'chart.js/auto'
import { useTranslation } from 'react-i18next'
import type { FlightPoint } from './types'

interface Props {
  points: FlightPoint[]
}

export default function AltitudeChart({ points }: Props) {
  const { t } = useTranslation()

  if (points.length === 0) return null

  const data = {
    labels: points.map((_, i) => i + 1),
    datasets: [{
      label: t('flights.planner.altitude'),
      data: points.map(p => p.altitude),
      borderColor: '#36D6C5',
      backgroundColor: 'rgba(54,214,197,0.18)',
      pointBackgroundColor: '#FF9D3D',
      pointBorderColor: '#1e1e1e',
      pointBorderWidth: 1,
      tension: 0.1,
    }],
  }

  const options = {
    responsive: true,
    maintainAspectRatio: false,
    plugins: { legend: { display: false } },
    scales: {
      x: { ticks: { font: { size: 10 }, color: '#9AA4B2' }, grid: { color: 'rgba(255,255,255,0.06)' } },
      y: { ticks: { font: { size: 10 }, color: '#9AA4B2' }, grid: { color: 'rgba(255,255,255,0.06)' } },
    },
  }

  return (
    <div className="h-16">
      <Line data={data} options={options} />
    </div>
  )
}
