import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../Screens/allTrips/plan_info_mdl.dart';
import '../Screens/allTrips/remarks_list.dart';
import '../data/models/plan.dart';
import '../services/apiService.dart';
import '../utils/travelAgent_remarks.dart';
import 'custom_popup.dart';

class PlanPopupMenu extends StatelessWidget {
  final Plan plan;
  final Function(String planId) deletePlan;
  final ApiService apiService;
  final Color? layoutColor;

  const PlanPopupMenu({
    Key? key,
    required this.plan,
    required this.deletePlan,
    required this.apiService,
    required this.layoutColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: Alignment.centerRight,
      child: PopupMenuButton<int>(
        color: Colors.white,
        padding: EdgeInsets.zero,
        offset: Offset(0, 30),
        icon: Icon(Icons.more_vert, color: Color(0xFF475569), size: 15),
        itemBuilder:
            (context) => [
              CustomPopupMenuEntry(
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
                  // padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      IconButton(
                        icon: Icon(Icons.remove_red_eye, size: 18),
                        onPressed: () {
                          Navigator.pop(context);
                          ApiService().viewPlan(
                            context,
                            plan.planId,
                            isViewMode: true,
                          );
                        },
                      ),

                      // IconButton(
                      //   icon: Image.asset('assets/images/IconsImg/edit.png',
                      //       width: 20, height: 15),
                      //   onPressed: () {
                      //     Navigator.pop(context);
                      //     ApiService.viewPlan(context, plan.planId,
                      //         isViewMode: false);
                      //   },
                      // ),
                      IconButton(
                        icon: Icon(Icons.cancel_rounded, size: 18),
                        onPressed: () {
                          Navigator.pop(context);
                          deletePlan(plan.planId);
                        },
                      ),
                      IconButton(
                        icon: Icon(
                          Icons.download,
                          color: Color(0xFF475569),
                          size: 18,
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                          apiService.getPdfDownload(context,plan.planId);
                        },
                      ),

                      if (plan.statusValue == "Approved" &&
                          plan.forexId != null &&
                          plan.forexId != '')
                        IconButton(
                          icon: Icon(
                            Icons.monetization_on_outlined,
                            color: Color(0xFF475569),
                            size: 18,
                          ),
                          tooltip: 'Download Forex PDF',
                          onPressed: () {
                            Navigator.pop(context);
                            apiService.getPdfDownload(context,plan.forexId);
                          },
                        ),
                      IconButton(
                        icon: const Icon(
                          Icons.comment,
                          color: Color(0xFF475569),
                          size: 11,
                        ),
                        onPressed: () {
                          showDialog(
                            context: context,
                            builder:
                                (context) => CommentModalList(
                                  // planId: plan.planId,
                                  planId: plan.planId.toString(),
                                  layoutColorForUser: layoutColor!,
                                  role: "User",
                                ),
                          );
                        },
                      ),
                      IconButton(
                        icon: const Icon(
                          Icons.comment,
                          color: Color(0xFF475569),
                          size: 11,
                        ),
                        onPressed: () {
                          showDialog(
                            context: context,
                            builder:
                                (context) => CommentModal(
                                  // planId: plan.planId,
                                  planId: plan.planId.toString(),
                                  layoutColorForUser: layoutColor!,
                                  role: "Travel Agent",
                                ),
                          );
                        },
                      ),

                      IconButton(
                        icon: const Icon(
                          Icons.info_outlined,
                          color: Color(0xFF475569),
                          size: 18,
                        ),
                        tooltip: 'Trip Info',
                        onPressed: () {
                          showDialog(
                            context: context,
                            builder:
                                (context) => TripInformation(
                                  // planId: plan.planId,
                                  planId: plan.planId.toString(),
                                  layoutColorForUser: layoutColor!,
                                ),
                          );
                        },
                      ),
                    ],
                  ),
                ),
              ),
            ],
      ),
    );
  }
}
