/// <reference types="@microsoft/msfs-types/pages/vcockpit/core/vcockpit" />
/// <reference types="@microsoft/msfs-types/pages/vcockpit/instruments/shared/baseinstrument" />
/// <reference types="@microsoft/msfs-types/js/datastorage" />
/// <reference types="@microsoft/msfs-types/js/simvar" />

import { createRoot } from 'react-dom/client';
import App from './App';

import './index.scss';

class KH_FE_FPLAN extends BaseInstrument {
  get templateID(): string {
    return 'kh-fe-fplan';
  }

  get isInteractive() {
    return true;
  }

  constructor() {
    super();
  }

  protected Update(): void {
    super.Update();
  }

  public connectedCallback(): void {
    super.connectedCallback();

    //@ts-expect-error
    const url = new URL(this.getAttribute('Url') ?? '');
    const type = url.searchParams.get('type') ?? '';

    const container = document.getElementById('root');
    if (container) {
      const root = createRoot(container);
      root.render(<App type={type} />);
    }
  }
}

//@ts-expect-error
registerInstrument('kh-fe-fplan', KH_FE_FPLAN);
