import {Component} from '@angular/core';
import {AgGridAngular} from "ag-grid-angular";
import type {ColDef, GridReadyEvent} from "ag-grid-community";
import {HttpClient} from '@angular/common/http';

interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

@Component({
  selector: 'app-grid-demo',
  imports: [
    AgGridAngular
  ],
  templateUrl: './grid-demo.html',
  styleUrl: './grid-demo.scss'
})
export class GridDemo {

  rowData: IRow[] = [];
  colDefs: ColDef[] = [
    {field: "mission"},
    {field: "company"},
    {field: "location"},
    {field: "date"},
    {field: "price"},
    {field: "successful"},
    {field: "rocket"}
  ];

  constructor(private http: HttpClient) {
  }

  onGridReady(params: GridReadyEvent) {
    let self = this;
    this.http
      .get<any[]>('https://www.ag-grid.com/example-assets/space-mission-data.json')
      .subscribe((data): any => self.rowData = data);

  }

}
