import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:siro_service/controller/mainController/main_controller.dart';
import 'package:siro_service/views/widgets/my_scafold.dart';

import '../../functions/encrypt_decrypt.dart';

class PassengersCantRegister extends StatelessWidget {
  PassengersCantRegister({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(MainController());
    return MyScaffold(
      title: 'Passengers Cant Register'.tr,
      isleading: true,
      body: [
        GetBuilder<MainController>(builder: (mainController) {
          return ListView.builder(
            itemCount: mainController.passengerNotCompleteRegistration.length,
            itemBuilder: (context, index) {
              final passenger =
                  mainController.passengerNotCompleteRegistration[index];
              return Padding(
                padding: const EdgeInsets.all(8.0),
                child: CupertinoFormSection(
                  header: Text('Passenger ID: ${passenger['id']}'),
                  children: [
                    InkWell(
                      onTap: () =>
                          mainController.makePhoneCall(passenger['phone']),
                      child: CupertinoFormRow(
                        prefix: Text(' phone'.tr),
                        child: CupertinoTextFormFieldRow(
                          initialValue: ((passenger['phone'])),
                          readOnly: true,
                          placeholder: 'Phone Number'.tr,
                        ),
                      ),
                    ),
                    CupertinoFormRow(
                      prefix: Text('Created At'.tr),
                      child: CupertinoTextFormFieldRow(
                        initialValue: passenger['created_at'],
                        readOnly: true,
                        placeholder: 'Created At',
                      ),
                    ),
                    CupertinoFormRow(
                      prefix: Text('Notes'.tr),
                      child: CupertinoTextFormFieldRow(
                        controller: mainController.notesController,
                        placeholder:
                            passenger['note'] ?? 'Enter notes after call'.tr,
                      ),
                    ),
                    CupertinoButton(
                      child: Text('Save Notes'.tr),
                      onPressed: () {
                        // Save the notes for the Passenger
                        String notes = mainController.notesController.text;

                        mainController
                            .saveNoteForPassengerNotCompleteRegistration(
                                passenger['phone_number'], 'girls name', notes);
                        print('Notes for Passenger ${passenger['id']}: $notes');
                      },
                    ),
                  ],
                ),
              );
            },
          );
        }),
      ],
    );
  }
}
