import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:garage/car/service/car_service.dart';
import 'package:get_it/get_it.dart';

import '../../car/model/car.dart';
import '../../car/page/info_car_page.dart';

class NotificationRow extends StatefulWidget {
  final RemoteMessage? message;

  const NotificationRow({super.key, this.message});

  @override
  State<NotificationRow> createState() => _NotificationRowState();
}

class _NotificationRowState extends State<NotificationRow> {
  final String carId = "AneEbNx2XsRq0YCUy3W4";

  @override
  Widget build(BuildContext context) {
    final CarService carService = GetIt.instance<CarService>();
    final futureCar = carService.getItemById(carId);
    return InkWell(
      onTap: () {
        Navigator.of(context).push(MaterialPageRoute(builder: (context) {
          return FutureBuilder<Car?>(
            future: futureCar,
            builder: (context, snapshot) {
              if (snapshot.hasError) {
                return Center(child: Text("WRONG ${snapshot.error}"));
              }
              if (!snapshot.hasData) {
                return Center(child: CircularProgressIndicator());
              }

              return InfoCarPage(
                car: snapshot.data!,
                refresh: () => setState(() {}),
              );
            },
          );
        }));
      },
      child: Row(
        children: const [Text("STK")],
      ),
    );
  }
}
