Initial commit for intaleq_admin

This commit is contained in:
Hamza-Ayed
2026-01-20 23:39:59 +03:00
parent 0b17f93aaa
commit a367bc7e5c
53 changed files with 20383 additions and 14662 deletions

View File

@@ -1,205 +1,390 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_admin1/controller/functions/encrypt_decrypt.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/admin/passenger_admin_controller.dart';
import '../../../main.dart'; // للوصول إلى box
import '../../widgets/elevated_btn.dart';
import '../../widgets/my_scafold.dart';
import '../../widgets/my_textField.dart';
import '../../widgets/mycircular.dart';
import 'form_passenger.dart';
import 'passenger_details_page.dart';
class Passengrs extends StatelessWidget {
Passengrs({super.key});
final PassengerAdminController passengerAdminController =
Get.put(PassengerAdminController());
@override
Widget build(BuildContext context) {
// 1. منطق السوبر أدمن
String myPhone = box.read(BoxName.adminPhone).toString();
bool isSuperAdmin = myPhone == '963942542053' || myPhone == '963992952235';
return MyScafolld(
title: 'Passengrs'.tr,
title: 'Passengers Management'.tr,
isleading: true,
body: [
GetBuilder<PassengerAdminController>(
builder: (passengerAdminController) => Column(
children: [
passengerAdminController.isLoading
? const MyCircularProgressIndicator()
: Column(
children: [
Padding(
padding: const EdgeInsets.all(5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
passengerAdmin(
passengerAdminController,
'Passengers Count',
'countPassenger',
),
MyElevatedButton(
title: 'Add Prize to Gold Passengers',
onPressed: () {
var date = DateTime.now();
var day = date.weekday;
// استخدام Expanded أو Container بطول الشاشة لتجنب المشاكل
SizedBox(
height: Get.height, // تأمين مساحة العمل
child: GetBuilder<PassengerAdminController>(
builder: (controller) {
if (controller.isLoading) {
return const Center(child: MyCircularProgressIndicator());
}
if (day == 6) {
// Saturday is 6
Get.defaultDialog(
title:
'Add Prize to Gold Passengers',
titleStyle: AppStyle.title,
content: Column(
children: [
Text(
'Add Points to their wallet as prize'
.tr,
style: AppStyle.title,
),
Form(
key:
passengerAdminController
.formPrizeKey,
child: MyTextForm(
controller:
passengerAdminController
.passengerPrizeController,
label:
'Count of prize'
.tr,
hint: 'Count of prize'
.tr,
type: TextInputType
.number))
],
),
confirm: MyElevatedButton(
title: 'Add',
onPressed: () async {
if (passengerAdminController
.formPrizeKey
.currentState!
.validate()) {
passengerAdminController
.addPassengerPrizeToWalletSecure();
}
},
),
);
} else {
Get.defaultDialog(
title:
'This day is not allowed',
titleStyle: AppStyle.title,
middleText:
'Saturday only Allowed day',
middleTextStyle: AppStyle.title,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
Get.back();
}));
}
})
],
),
),
const SizedBox(
height: 10,
),
formSearchPassengers(),
SizedBox(
height: Get.height * .5,
child: ListView.builder(
itemCount: passengerAdminController
.passengersData['message'].length,
itemBuilder: (context, index) {
final user = passengerAdminController
.passengersData['message'][index];
return Column(
children: [
// --- قسم الإحصائيات والجوائز (Dashboard) ---
Padding(
padding: const EdgeInsets.all(16.0),
child: _buildDashboardCard(context, controller),
),
return InkWell(
onTap: () {
Get.to(const PassengerDetailsPage(),
arguments: {
'data': user,
});
},
child: Padding(
padding: const EdgeInsets.all(3),
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 2)),
child: ListTile(
title: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Text(
'Name : ${(user['first_name'])} ${(user['last_name'])}',
style: AppStyle.title,
),
Text(
'Rating : ${user['ratingPassenger']}',
style: AppStyle.title,
),
],
),
subtitle: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Text(
'Count Trip : ${user['countPassengerRide']}',
style: AppStyle.title,
),
Text(
'Count Driver Rate : ${user['countDriverRate']}',
style: AppStyle.title,
),
],
),
),
),
),
);
},
),
),
],
),
],
))
// --- عنوان القائمة ---
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"All Passengers".tr,
style: AppStyle.title.copyWith(
fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
"${controller.passengersData['message']?.length ?? 0} Users",
style:
TextStyle(color: Colors.grey[600], fontSize: 12),
),
],
),
),
const SizedBox(height: 10),
// --- قائمة الركاب ---
// استخدام Expanded هنا هو الحل الجذري لمكلة Overflow
Expanded(
child: _buildPassengersList(controller, isSuperAdmin),
),
// مساحة سفلية صغيرة لضمان عدم التصاق القائمة بالحافة
const SizedBox(height: 20),
],
);
},
),
),
],
);
}
Container passengerAdmin(PassengerAdminController passengerAdminController,
String title, String jsonField) {
// --- تصميم بطاقة الإحصائيات (Dashboard) ---
Widget _buildDashboardCard(
BuildContext context, PassengerAdminController controller) {
// جلب العدد بأمان
final String countValue = (controller.passengersData['message'] != null &&
controller.passengersData['message'].isNotEmpty)
? controller.passengersData['message'][0]['countPassenger']
?.toString() ??
'0'
: '0';
return Container(
height: Get.height * .1,
decoration: BoxDecoration(border: Border.all(width: 2)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {},
child: Column(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 15,
offset: const Offset(0, 5),
),
],
),
child: Column(
children: [
Row(
children: [
Text(
title.tr,
style: AppStyle.title,
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: AppColor.primaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(Icons.groups_rounded,
color: AppColor.primaryColor, size: 30),
),
Text(
passengerAdminController.passengersData['message'][0][jsonField]
.toString(),
style: AppStyle.title,
const SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Total Passengers'.tr,
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
Text(
countValue,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
],
),
],
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
height: 45,
child: ElevatedButton.icon(
icon: const Icon(Icons.card_giftcard,
color: Colors.white, size: 20),
label: Text('Add Prize to Gold Passengers'.tr,
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.yellowColor, // لون ذهبي
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
elevation: 0,
),
onPressed: () {
_showAddPrizeDialog(controller);
},
),
),
],
),
);
}
// --- بناء قائمة الركاب ---
Widget _buildPassengersList(
PassengerAdminController controller, bool isSuperAdmin) {
final List<dynamic> passengers = controller.passengersData['message'] ?? [];
if (passengers.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person_off_outlined, size: 60, color: Colors.grey[300]),
const SizedBox(height: 10),
Text("No passengers found".tr,
style: TextStyle(color: Colors.grey[400])),
],
),
);
}
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16),
physics: const BouncingScrollPhysics(),
itemCount: passengers.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) {
final user = passengers[index];
return _buildPassengerItem(user, isSuperAdmin);
},
);
}
// --- عنصر الراكب الواحد (Card) ---
Widget _buildPassengerItem(dynamic user, bool isSuperAdmin) {
String firstName = user['first_name'] ?? '';
String lastName = user['last_name'] ?? '';
String fullName = '$firstName $lastName'.trim();
if (fullName.isEmpty) fullName = 'Unknown User';
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.grey.withOpacity(0.1)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.05),
blurRadius: 5,
offset: const Offset(0, 2),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(15),
onTap: () {
// الانتقال للتفاصيل مع تمرير صلاحية الأدمن
Get.to(
() => const PassengerDetailsPage(),
arguments: {'data': user, 'isSuperAdmin': isSuperAdmin},
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: [
// Avatar
CircleAvatar(
radius: 25,
backgroundColor: AppColor.primaryColor.withOpacity(0.1),
child: Text(
fullName.isNotEmpty ? fullName[0].toUpperCase() : 'U',
style: TextStyle(
color: AppColor.primaryColor,
fontWeight: FontWeight.bold,
fontSize: 18),
),
),
const SizedBox(width: 15),
// Info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
fullName,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
),
const SizedBox(height: 4),
// Stats Row
Row(
children: [
Icon(Icons.star_rounded,
size: 16, color: Colors.amber[700]),
Text(
" ${user['ratingPassenger'] ?? '0.0'} ",
style: const TextStyle(
fontSize: 12, fontWeight: FontWeight.bold),
),
const SizedBox(width: 8),
Icon(Icons.directions_car,
size: 14, color: Colors.grey[400]),
Text(
" ${user['countPassengerRide'] ?? '0'} Trips",
style: TextStyle(
fontSize: 12, color: Colors.grey[600]),
),
],
),
const SizedBox(height: 4),
// Phone Number (Masked logic)
Row(
children: [
Icon(Icons.phone_iphone,
size: 12, color: Colors.grey[400]),
const SizedBox(width: 4),
Text(
_formatPhoneNumber(
user['phone'].toString(), isSuperAdmin),
style: TextStyle(
fontSize: 12,
color: Colors.grey[500],
fontFamily: 'monospace'),
),
],
),
// Email (Show only if Super Admin)
if (isSuperAdmin && user['email'] != null) ...[
const SizedBox(height: 2),
Text(
user['email'],
style:
TextStyle(fontSize: 10, color: Colors.grey[400]),
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
]
],
),
),
// Arrow
Icon(Icons.arrow_forward_ios_rounded,
size: 16, color: Colors.grey[300]),
],
),
),
),
),
);
}
// --- دالة تنسيق الرقم (إظهار آخر 4 أرقام لغير الأدمن) ---
String _formatPhoneNumber(String phone, bool isSuperAdmin) {
if (isSuperAdmin) return phone; // إظهار الرقم كاملاً للسوبر أدمن
// لغير الأدمن
if (phone.length <= 4) return phone;
String lastFour = phone.substring(phone.length - 4);
String masked = '*' * (phone.length - 4);
return '$masked$lastFour'; // النتيجة: *******5678
}
// --- دالة إضافة الجوائز ---
void _showAddPrizeDialog(PassengerAdminController controller) {
// التحقق من يوم السبت
if (DateTime.now().weekday == DateTime.saturday) {
Get.defaultDialog(
title: 'Add Prize'.tr,
titleStyle: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
contentPadding: const EdgeInsets.all(20),
content: Form(
key: controller.formPrizeKey,
child: Column(
children: [
Text(
'Add Points to Gold Passengers wallet'.tr,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
const SizedBox(height: 20),
MyTextForm(
controller: controller.passengerPrizeController,
label: 'Prize Amount'.tr,
hint: '1000...',
type: TextInputType.number,
),
],
),
),
confirm: SizedBox(
width: 120,
child: MyElevatedButton(
title: 'Add',
onPressed: () async {
if (controller.formPrizeKey.currentState!.validate()) {
controller.addPassengerPrizeToWalletSecure();
Get.back();
}
},
),
),
cancel: TextButton(
onPressed: () => Get.back(),
child:
Text('Cancel'.tr, style: const TextStyle(color: Colors.grey))),
);
} else {
Get.snackbar(
'Not Allowed'.tr,
'Prizes can only be added on Saturdays.'.tr,
backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red,
icon: const Icon(Icons.error_outline, color: Colors.red),
snackPosition: SnackPosition.TOP,
margin: const EdgeInsets.all(10),
);
}
}
}

View File

@@ -1,167 +1,458 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/admin/passenger_admin_controller.dart';
import '../../../controller/functions/crud.dart';
import '../../../controller/firebase/firbase_messge.dart';
import '../../../constant/links.dart';
import '../../../main.dart'; // To access 'box' for admin phone check
import '../../widgets/elevated_btn.dart';
import '../../widgets/my_scafold.dart';
import '../../widgets/my_textField.dart';
import 'form_passenger.dart';
class PassengerDetailsPage extends StatelessWidget {
const PassengerDetailsPage({super.key});
@override
Widget build(BuildContext context) {
final arguments = Get.arguments;
final Map<String, dynamic> data = arguments['data'];
var key = Get.find<PassengerAdminController>().formPrizeKey;
var titleNotify = Get.find<PassengerAdminController>().titleNotify;
var bodyNotify = Get.find<PassengerAdminController>().bodyNotify;
final Map<String, dynamic> data = Get.arguments['data'];
final controller = Get.find<PassengerAdminController>();
// 1. Define Super Admin Logic (Same as Captains Page)
String myPhone = box.read(BoxName.adminPhone).toString();
bool isSuperAdmin = myPhone == '963942542053' || myPhone == '963992952235';
return MyScafolld(
title: data['first_name'],
title: 'Passenger Profile'.tr,
isleading: true,
body: [
Padding(
padding: const EdgeInsets.all(8.0),
SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Email is ${data['email']}',
style: AppStyle.title,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Phone is ${data['phone']}',
style: AppStyle.title,
),
Text(
'gender is ${data['gender']}',
style: AppStyle.title,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'status is ${data['status']}',
style: AppStyle.title,
),
Text(
'birthdate is ${data['birthdate']}',
style: AppStyle.title,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'site is ${data['site']}',
style: AppStyle.title,
),
Text(
'sosPhone is ${data['sosPhone']}',
style: AppStyle.title,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Count Feedback is ${data['countFeedback']}',
style: AppStyle.title,
),
Text(
'Count Driver Rate is ${data['countDriverRate']}',
style: AppStyle.title,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Count Cancel is ${data['countPassengerCancel']}',
style: AppStyle.title,
),
Text(
'Count Ride is ${data['countPassengerRide']}',
style: AppStyle.title,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Rating Captain Avarage is ${data['passengerAverageRating']}',
style: AppStyle.title,
),
Text(
'Rating is ${data['ratingPassenger']}',
style: AppStyle.title,
),
],
),
Container(
decoration: BoxDecoration(
border: Border.all(width: 3, color: AppColor.yellowColor)),
child: TextButton(
onPressed: () async {
Get.defaultDialog(
title: 'Send Notification'.tr,
titleStyle: AppStyle.title,
content: Form(
key: key,
child: Column(
children: [
MyTextForm(
controller: titleNotify,
label: 'title'.tr,
hint: 'title notificaton'.tr,
type: TextInputType.name),
const SizedBox(
height: 10,
),
MyTextForm(
controller: bodyNotify,
label: 'body'.tr,
hint: 'body notificaton'.tr,
type: TextInputType.name)
],
),
// --- Header Section (Avatar & Name) ---
_buildHeaderSection(context, data),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
// --- Personal Information Card ---
_buildInfoCard(
title: 'Personal Information',
icon: Icons.person,
children: [
_buildDetailTile(
Icons.email_outlined,
'Email',
isSuperAdmin
? data['email']
: _maskEmail(data['email']),
),
confirm: MyElevatedButton(
title: 'Send',
onPressed: () {
if (key.currentState!.validate()) {
FirebaseMessagesController()
.sendNotificationToAnyWithoutData(
titleNotify.text,
bodyNotify.text,
data['passengerToken'],
'order.wav');
Get.back();
}
}));
},
child: Text(
"Send Notificaion to Passenger ".tr,
style: AppStyle.title,
),
_buildDetailTile(
Icons.phone_iphone,
'Phone',
_formatPhoneNumber(
data['phone'].toString(), isSuperAdmin),
),
_buildDetailTile(
Icons.transgender,
'Gender',
data['gender'] ?? 'Not specified',
),
_buildDetailTile(
Icons.cake_outlined,
'Birthdate',
data['birthdate'] ?? 'N/A',
),
_buildDetailTile(
Icons.location_on_outlined,
'Site',
data['site'] ?? 'N/A',
),
// SOS Phone is critical, usually shown, but we can mask it too if needed
_buildDetailTile(
Icons.sos,
'SOS Phone',
data['sosPhone'] ?? 'N/A',
valueColor: Colors.redAccent,
),
],
),
const SizedBox(height: 16),
// --- Ride Statistics Card ---
_buildInfoCard(
title: 'Activity & Stats',
icon: Icons.bar_chart_rounded,
children: [
_buildDetailTile(
Icons.star_rate_rounded,
'Rating',
'${data['ratingPassenger'] ?? 0.0}',
valueColor: Colors.amber[700],
),
_buildDetailTile(
Icons.directions_car_filled_outlined,
'Total Rides',
data['countPassengerRide'],
),
_buildDetailTile(
Icons.cancel_outlined,
'Canceled Rides',
data['countPassengerCancel'],
valueColor: Colors.redAccent,
),
_buildDetailTile(
Icons.rate_review_outlined,
'Feedback Given',
data['countFeedback'],
),
],
),
const SizedBox(height: 30),
// --- Action Buttons ---
_buildActionButtons(
context, controller, data, isSuperAdmin),
],
),
)
),
],
),
)
),
],
isleading: true,
);
}
// --- Header with Gradient/White Background ---
Widget _buildHeaderSection(BuildContext context, Map<String, dynamic> data) {
String firstName = data['first_name'] ?? '';
String lastName = data['last_name'] ?? '';
String fullName = '$firstName $lastName'.trim();
if (fullName.isEmpty) fullName = "Passenger";
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 25),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 10,
offset: const Offset(0, 5),
)
],
borderRadius: const BorderRadius.vertical(bottom: Radius.circular(30)),
),
child: Column(
children: [
CircleAvatar(
radius: 45,
backgroundColor: AppColor.primaryColor.withOpacity(0.1),
child: Text(
fullName[0].toUpperCase(),
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: AppColor.primaryColor),
),
),
const SizedBox(height: 12),
Text(
fullName,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.black87),
),
const SizedBox(height: 4),
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
),
child: Text(
data['status'] ?? 'Active',
style: const TextStyle(
fontSize: 12,
color: Colors.blue,
fontWeight: FontWeight.w600),
),
),
],
),
);
}
Widget _buildInfoCard(
{required String title,
required IconData icon,
required List<Widget> children}) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.05),
spreadRadius: 2,
blurRadius: 10)
],
border: Border.all(color: Colors.grey.withOpacity(0.1)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: AppColor.primaryColor, size: 22),
const SizedBox(width: 10),
Text(title.tr,
style: const TextStyle(
fontSize: 17, fontWeight: FontWeight.bold)),
],
),
Divider(height: 25, color: Colors.grey.withOpacity(0.2)),
...children,
],
),
);
}
Widget _buildDetailTile(IconData icon, String label, dynamic value,
{Color? valueColor}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(8)),
child: Icon(icon, color: Colors.grey[600], size: 18),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label.tr,
style: TextStyle(fontSize: 12, color: Colors.grey[500])),
Text(
value?.toString() ?? 'N/A',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: valueColor ?? Colors.black87),
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
);
}
Widget _buildActionButtons(
BuildContext context,
PassengerAdminController controller,
Map<String, dynamic> data,
bool isSuperAdmin) {
return Column(
children: [
// --- Send Notification (For All Admins) ---
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton.icon(
icon: const Icon(Icons.notifications_active_outlined,
color: Colors.white),
label: Text("Send Notification".tr,
style: const TextStyle(color: Colors.white, fontSize: 16)),
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
),
onPressed: () => _showSendNotificationDialog(controller, data),
),
),
// --- Edit/Delete (Super Admin Only) ---
if (isSuperAdmin) ...[
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: ElevatedButton.icon(
icon: const Icon(Icons.edit_note_rounded, size: 20),
label: Text("Edit".tr),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: AppColor.yellowColor,
elevation: 0,
side: BorderSide(color: AppColor.yellowColor),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
padding: const EdgeInsets.symmetric(vertical: 12),
),
onPressed: () {
// Get.to(() => const FormPassenger(), arguments: {
// 'isEditMode': true,
// 'passengerData': data,
// });
},
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton.icon(
icon: const Icon(Icons.delete_outline_rounded, size: 20),
label: Text("Delete".tr),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red[50],
foregroundColor: Colors.red,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
padding: const EdgeInsets.symmetric(vertical: 12),
),
onPressed: () => _showDeleteConfirmation(data),
),
),
],
),
] else ...[
// Message for normal admins
const SizedBox(height: 15),
Text(
"Only Super Admins can edit or delete passengers.",
style: TextStyle(
color: Colors.grey[400],
fontSize: 12,
fontStyle: FontStyle.italic),
)
],
],
);
}
// --- Helper: Format Phone (Last 4 digits for normal admin) ---
String _formatPhoneNumber(String phone, bool isSuperAdmin) {
if (isSuperAdmin) return phone;
if (phone.length <= 4) return phone;
return '${'*' * (phone.length - 4)}${phone.substring(phone.length - 4)}';
}
// --- Helper: Mask Email ---
String _maskEmail(String? email) {
if (email == null || email.isEmpty) return 'N/A';
int atIndex = email.indexOf('@');
if (atIndex <= 1) return email; // Too short to mask
return '${email.substring(0, 2)}****${email.substring(atIndex)}';
}
void _showSendNotificationDialog(
PassengerAdminController controller, Map<String, dynamic> data) {
Get.defaultDialog(
title: 'Send Notification'.tr,
titleStyle: const TextStyle(fontWeight: FontWeight.bold),
content: Form(
key: controller.formPrizeKey,
child: Column(
children: [
MyTextForm(
controller: controller.titleNotify,
label: 'Title'.tr,
hint: 'Notification title'.tr,
type: TextInputType.text),
const SizedBox(height: 10),
MyTextForm(
controller: controller.bodyNotify,
label: 'Body'.tr,
hint: 'Message body'.tr,
type: TextInputType.text)
],
),
),
confirm: SizedBox(
width: 100,
child: MyElevatedButton(
title: 'Send',
onPressed: () {
// Validate form safely
if (controller.formPrizeKey.currentState?.validate() ?? false) {
FirebaseMessagesController().sendNotificationToAnyWithoutData(
controller.titleNotify.text,
controller.bodyNotify.text,
data['passengerToken'],
'order.wav');
Get.back();
Get.snackbar('Success', 'Notification sent successfully!',
backgroundColor: Colors.green.withOpacity(0.2));
}
},
),
),
cancel: TextButton(
onPressed: () => Get.back(),
child: Text('Cancel'.tr, style: const TextStyle(color: Colors.grey))),
);
}
void _showDeleteConfirmation(Map<String, dynamic> user) {
Get.defaultDialog(
title: 'Confirm Deletion'.tr,
titleStyle:
const TextStyle(color: Colors.redAccent, fontWeight: FontWeight.bold),
middleText:
'Are you sure you want to delete ${user['first_name']}? This action cannot be undone.'
.tr,
confirm: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.redAccent),
onPressed: () async {
// 1. Close Dialog
Get.back();
// 2. Perform Delete Operation
var res = await CRUD().post(
link: AppLink.admin_delete_and_blacklist_passenger,
payload: {
'id': user['id'],
'phone': user['phone'],
'reason': 'Deleted by admin',
},
);
// 3. Handle Result
if (res['status'] == 'success') {
Get.back(); // Go back to list page
Get.snackbar('Deleted', 'Passenger removed successfully',
backgroundColor: Colors.red.withOpacity(0.2));
// Ideally, trigger a refresh on the controller here
// Get.find<PassengerAdminController>().getAll();
} else {
Get.snackbar('Error', res['message'] ?? 'Failed to delete',
backgroundColor: Colors.red.withOpacity(0.2));
}
},
child: Text('Delete'.tr, style: const TextStyle(color: Colors.white)),
),
cancel: TextButton(
onPressed: () => Get.back(),
child: Text('Cancel'.tr, style: const TextStyle(color: Colors.grey)),
),
);
}
}