import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:intl/intl.dart'; import 'package:jwt_decode/jwt_decode.dart'; import 'package:nhance_app_pwa/customAppBar/customAppBar.dart'; import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart'; import 'package:nhance_app_pwa/pages/postEnrollment/service/svg_service.dart'; import 'package:ribbon_widget/ribbon_widget.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import '../../customAppBar/customFooter.dart'; import '../../customAppBar/responsive.dart'; import '../../customAppBar/tabs.dart'; import '../../customAppBar/toastHelper.dart'; import '../service/SessionManager.dart'; import '../service/TokenService.dart'; import '../service/popup_helper.dart'; import 'claimshistory.dart'; import 'package:nhance_app_pwa/logger.dart'; class claims extends StatefulWidget { final int initialTab; const claims({super.key, required this.initialTab}); @override State createState() => _claimsState(); } const TextStyle _kTextStyle = TextStyle( color: Color(0xFFFFFFFF), fontSize: 12, fontWeight: FontWeight.w900, height: 1.0); enum RibbonLocation { topStart, topEnd, bottomStart, bottomEnd, } class _claimsState extends State { bool isLoading = false; late ApiService apiService; int _currentIndex = 0; bool isActive = true; dynamic _token; dynamic decodedToken; dynamic empCodeString; dynamic empPrimaryId; dynamic client_id; dynamic empName; dynamic policyList; dynamic policyDataIsEmpty = 1; dynamic trackClaimsIsEmpty = 1; dynamic policyHeading; dynamic policyName; dynamic EmployeePolicy; dynamic emailId; List> employeeDetails = []; dynamic argumentsData; dynamic empMobileNo; List reversedClaimsList = []; List trackClaimsList = []; int trackClaimsActive = 1; int yourPlanActive = 0; int? serviceId; dynamic client_branch_id; dynamic mobileNo; final session = SessionManager(); List retailPolicyDetails = []; List> getDepartmentItems() { return [ DropdownMenuItem(value: 1, child: Text('Department 1')), DropdownMenuItem(value: 2, child: Text('Department 2')), DropdownMenuItem(value: 3, child: Text('Department 3')), ]; } void _onTabChanged(int index) { setState(() { _currentIndex = index; }); } @override void initState() { super.initState(); apiService = ApiService(context); _loadToken(); } @override void dispose() { super.dispose(); } void didChangeDependencies() { super.didChangeDependencies(); dynamic arguments = widget.initialTab; logDebug('arguments $arguments'); if (arguments == 0) { logDebug(arguments); trackClaimsActive = 0; yourPlanActive = 1; isActive = false; } else if (arguments == 2) { logDebug(arguments); trackClaimsActive = 0; yourPlanActive = 1; isActive = false; } else { logDebug("Arguments are null or not in the expected format"); } } Future _loadToken() async { logDebug('_loadToken'); final String? token = await TokenService.getPostToken(); if (token != null && token.isNotEmpty) { // Decode the JWT token received from the API response mobileNo = session.mobileNo ?? ''; client_branch_id = session.empClientBranchId; empCodeString = session.empCodeString; empName = session.gpaEmpName; logDebug(empCodeString); // Check if emp_code is correct empPrimaryId = session.empPrimaryId; client_id = session.client_id; emailId = session.empEmailCorporate ?? ''; logDebug(client_id); getActiveAndInactivePolicyDetails(); getTrackClaimsList(); } } Future getActiveAndInactivePolicyDetails() async { if (client_id == null || empCodeString == null) { return; } setState(() { isLoading = true; }); try { // Call both APIs final responseActive = await apiService.getActiveAndInactivePolicyDetails( client_id!, empCodeString!, 'Active', client_branch_id, mobileNo,emailId); final responseInactive = await apiService.getActiveAndInactivePolicyDetails(client_id!, empCodeString!, 'Inactive', client_branch_id, mobileNo,emailId); final bool isActiveSuccess = responseActive['status'] == 'success' && responseActive['data'] != null; final bool isInactiveSuccess = responseInactive['status'] == 'success' && responseInactive['data'] != null; final List> activeData = isActiveSuccess ? List>.from(responseActive['data']) : []; final List> inactiveData = isInactiveSuccess ? List>.from(responseInactive['data']) : []; retailPolicyDetails = List.from(responseActive['retail_policy_data'] ?? []); // Remove retail objects without policy_transaction_id final filteredRetail = retailPolicyDetails .where((item) => item.containsKey('policy_transaction_id')) .toList(); final combinedPolicies = [...activeData, ...inactiveData, ...filteredRetail]; setState(() { policyList = combinedPolicies; policyDataIsEmpty = combinedPolicies.isEmpty ? 0 : 1; }); logDebug("Merged policyList: $policyList"); } catch (e) { logDebug('Error occurred while fetching policies: $e'); setState(() { policyDataIsEmpty = 0; }); } finally { setState(() { isLoading = false; }); } } Future getTrackClaimsList() async { if (client_id == null || empCodeString == null) { return; } logDebug('check 1'); final response = await apiService.getTrackClaimsList(empPrimaryId!,mobileNo,emailId); logDebug('check 1'); // if (response['success'] == true) { setState(() { List data = response['ticket_data']; logDebug('Data from response: $data'); // trackClaimsList = data.where((item) { // // Check if item is a Map and has the departmentId key // if (item is Map && item.containsKey('department_id')) { // final departmentId = item['department_id']; // // // Print each departmentId for debugging // logDebug('Item department_id: $departmentId'); // // // Ensure departmentId is an int or string, and compare // if (departmentId is int) { // return departmentId == 3 || departmentId == 4; // } else if (departmentId is String) { // return int.tryParse(departmentId) == 3 || // int.tryParse(departmentId) == 4; // } // } // return false; // }).toList(); logDebug('Filtered trackClaimsList: $data'); reversedClaimsList = List>.from(data); logDebug('reversedClaimsList $reversedClaimsList'); trackClaimsList = reversedClaimsList.reversed.toList(); logDebug('trackClaimsList $trackClaimsList'); }); logDebug(trackClaimsList); // } else { // setState(() { // trackClaimsIsEmpty = 0; // }); // logDebug('API request failed with status: ${response['status']}'); // } } String formatDate(String timestamp) { // Convert the timestamp string to milliseconds int milliseconds = int.parse(timestamp) * 1000; // Create a DateTime object from milliseconds DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds); // Format the DateTime object String formattedDate = DateFormat('d MMM, y').format(date); return formattedDate; } @override Widget build(BuildContext context) { // dynamic arguments = ModalRoute.of(context)!.settings.arguments; // logDebug('arguments'); // dynamic arguments = widget.initialTab; // logDebug('arguments $arguments'); // if (arguments == 0) { // logDebug(arguments); // trackClaimsActive = 0; // yourPlanActive = 1; // isActive = false; // } else { // logDebug("Arguments are null or not in the expected format"); // } return PopScope( canPop: false, onPopInvokedWithResult: (didPop, result) { if (didPop) return; if (widget.initialTab == 2) { context.go('/home'); } else { context.pop(); } }, child: Scaffold( backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( child: Container( padding: Responsive.isDesktop(context) ? EdgeInsets.symmetric( horizontal: MediaQuery.of(context).size.width * 0.2, // 30% of screen width as horizontal padding vertical: MediaQuery.of(context).size.height * 0.03, // 5% of screen height as vertical padding ) : EdgeInsets.all(10), color: Colors.white, child: Column(children: [ Container( child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( flex: 12, child: InkWell( onTap: () { logDebug("CACLAIMS - ${widget.initialTab}"); if (widget.initialTab == 2) { context.go('/home'); } if (Navigator.canPop(context)) { context.pop(); } else { context.go('/home'); } // if (widget.initialTab == 0) { // context.pop(); // } else { // context.pop(); // } }, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Icon( Icons .chevron_left, // Replace with your desired icon color: Color(0xFF000000), size: 30, ), SizedBox( width: 5), // Adjust space between icon and text Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Claims Assistance', textAlign: TextAlign.start, style: GoogleFonts.poppins( fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF000000), ), ), Text( 'Manage your claims', textAlign: TextAlign.start, style: GoogleFonts.poppins( fontSize: 12, // Adjust the font size as needed fontWeight: FontWeight.w400, color: Color(0xFF000000), ), ), ], ), ], ), ), ), ], ), // Add more rows as needed ], ), ), SizedBox(height: 15), MouseRegion( cursor: SystemMouseCursors.click, child: InkWell( onTap: () { context.push('/help'); }, child: Card( elevation: 0, shape: RoundedRectangleBorder( side: BorderSide( color: Color(0xFFD9D9D9), // Set the border color here width: 1.0, // Set the border width here ), borderRadius: BorderRadius.circular( 8.0), // Set the border radius here ), child: Column( children: [ Container( decoration: BoxDecoration( color: Colors .white, // Set background color for the container ), padding: Responsive.isDesktop(context) ? EdgeInsets.only( top: 15, bottom: 15, left: 10, right: 10) : EdgeInsets.only( top: 15, bottom: 15, left: 10, right: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 11, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SvgPicture.string( SvgService.getSvg('contactUs'), width: 25, height: 25, ), SizedBox( width: 7), // Adjust space between icon and text Text( 'Contact Us', textAlign: TextAlign.center, style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 18 : 12, fontWeight: FontWeight.w500, color: Color(0xFF000000), ), ), ], ), ), Expanded( flex: 1, child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Icon( Icons .chevron_right, // Replace with your desired icon color: Color(0xFFE26728), size: 20, ), ], ), ), ], ), ), ], ), ), ), ), SizedBox(height: 15), MouseRegion( cursor: SystemMouseCursors.click, child: InkWell( onTap: () { context.go('/claimprocess'); }, child: Card( elevation: 0, shape: RoundedRectangleBorder( side: BorderSide( color: Color(0xFFD9D9D9), // Set the border color here width: 1.0, // Set the border width here ), borderRadius: BorderRadius.circular( 8.0), // Set the border radius here ), child: Column(children: [ Container( decoration: BoxDecoration( color: Colors .white, // Set background color for the container ), padding: Responsive.isDesktop(context) ? EdgeInsets.only( top: 15, bottom: 15, left: 10, right: 10) : EdgeInsets.only( top: 15, bottom: 15, left: 10, right: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 11, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SvgPicture.string( SvgService.getSvg('fileClaims'), width: 25, height: 25, ), SizedBox( width: 7), // Adjust space between icon and text Text( 'Know how to file a claim', textAlign: TextAlign.center, style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 18 : 12, fontWeight: FontWeight.w500, color: Color(0xFF000000), ), ), ], ), ), Expanded( flex: 1, child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Icon( Icons .chevron_right, // Replace with your desired icon color: Color(0xFFE26728), size: 20, ), ], ), ), ], ), ), ])), ), ), SizedBox(height: 15), Container( decoration: BoxDecoration( color: Color( 0xFFF6FAFF), // Set background color for the container borderRadius: BorderRadius.circular( 5), // Set border radius for the container ), padding: Responsive.isDesktop(context) ? EdgeInsets.only( top: 10, bottom: 10, left: 25, right: 25) : EdgeInsets.only( top: 10, bottom: 10, left: 10, right: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 12, child: Container( alignment: Alignment.center, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( flex: 6, child: Container( alignment: Alignment.center, child: GestureDetector( onTap: () { setState(() { isActive = true; // policyList.clear(); yourPlanActive = 0; trackClaimsActive = 1; }); getActiveAndInactivePolicyDetails(); }, child: isActive ? Material( elevation: 5, borderRadius: BorderRadius.circular( 10), color: Colors.white, child: TextButton( onPressed: () {}, style: TextButton .styleFrom( padding: EdgeInsets.symmetric( horizontal: Responsive .isDesktop( context) ? 70 : 30 , vertical: Responsive .isDesktop( context) ? 15 : 5), // primary: Color(0xFF000000), ), child: Text( 'Register a Claim', style: GoogleFonts.poppins( fontSize: Responsive .isDesktop( context) ? 18 : 13, fontWeight: FontWeight .w500, color: Color( 0xFF000000)), ), ), ) : Text( 'Register a Claim', style: GoogleFonts.poppins( fontSize: Responsive .isDesktop( context) ? 18 : 13, fontWeight: FontWeight.w400, color: Color(0xFF636363), ), ), ), )), Expanded( flex: 6, child: Container( alignment: Alignment.center, child: GestureDetector( onTap: () { setState(() { isActive = false; // trackClaimsList.clear(); yourPlanActive = 1; trackClaimsActive = 0; }); getTrackClaimsList(); }, child: !isActive ? Material( elevation: 5, borderRadius: BorderRadius.circular( 10), color: Colors.white, child: TextButton( onPressed: () {}, style: TextButton .styleFrom( padding: EdgeInsets.symmetric( horizontal: Responsive .isDesktop( context) ? 70 : 30, vertical: Responsive .isDesktop( context) ? 15 : 5), // primary: Color(0xFF000000), ), child: Text( 'Track claims', style: GoogleFonts .poppins( fontSize: Responsive .isDesktop( context) ? 18 : 13, color: Color( 0xFF000000), fontWeight: FontWeight.w500, ), ), ), ) : Text( 'Track claims', style: GoogleFonts.poppins( fontSize: Responsive .isDesktop( context) ? 18 : 13, fontWeight: FontWeight.w400, color: Color(0xFF636363), ), ), ), )) ], ) ], ))), ], ), ), SizedBox(height: 15), if (policyList != null && policyList.length > 0) if (yourPlanActive == 0) Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ...generateYourPlanList(policyList), ], ), if (trackClaimsList != null && trackClaimsList.length > 0) if (trackClaimsActive == 0) SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: generateTrackList(trackClaimsList), ), ), SizedBox(height: Responsive.isDesktop(context) ? 40 : 70), ]), )), if (isLoading) Container( color: Color(0x98FFFCE5), // Semi-transparent background child: Center( child: // Your GIF loader widget Image.asset( height: 60, width: 60, 'assets/nhance-loader.gif'), // Adjust path to your GIF loader ), ), if (Responsive.isDesktop(context)) Align( alignment: Alignment.bottomCenter, child: Container( width: double.infinity, // Make the footer full width child: CustomFooter(), ), ), ]), // floatingActionButton: Responsive.isDesktop(context) // ? null // : FloatingActionButton( // onPressed: () { // Navigator.pushNamed(context, 'chatbot'); // }, // child: Icon(Icons.chat), // ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( onTabChanged: (index) { // Add your navigation logic here // repositionBotman(); if (index == 0) { context.push('/home'); } else if (index == 1) { context.push('/claims'); } else if (index == 2) { context.push('/faqs'); } else if (index == 3) { context.push('/profile'); } else if (index == 4) { context.push('/help'); } // else if (index == 4) { // // context.push('/wellness'); // // Wellness tab clicked → show popup // if(!isRetailLoggedIn) // PopupHelper.showRedirectPopup( // context: context, // apiService: apiService, // empPrimaryId: session.empPrimaryId, // ); // } }, icons: [ Icons.home_outlined, Icons.sticky_note_2_outlined, Icons.question_answer_outlined, Icons.person_outline_outlined, Icons.headset_mic_outlined, ], labels: ["Home", "Claims", "FAQs", "Profile","Help"], initialIndex: 1, // Initial index of the bottom navigation bar ), )); } // List generateYourPlanList(List data) { // return [ // ListView.builder( // shrinkWrap: true, // physics: NeverScrollableScrollPhysics(), // itemCount: data.length, // itemBuilder: (BuildContext context, int index) { // var item = data[index]; // String policyHeading = item['heading']; // String policyName = item['policy_name']; // String policyStatus = item['policy_status']; // String si_value = item['si_value']; // String policyEndDate = item['policy_end_date']; // String policyNo = item['policy_no']; // String clientPolicyId = item['client_policy_id']; // String sumInsuredLabel = item['sum_insured_label']; // List employeePolicy = item['EmployeePolicy']; // // return GestureDetector( // onTap: () { // var details = {'claimsDetails': item, 'fromClaimPage': 0}; // context.go('/planclaimsform', extra: details); // }, // child: MouseRegion( // cursor: SystemMouseCursors.click, // child: Card( // elevation: 5, // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(15.0), // ), // child: Container( // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(15.0), // ), // padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15), // child: Row( // mainAxisAlignment: MainAxisAlignment // .spaceBetween, // Center content horizontally // crossAxisAlignment: // CrossAxisAlignment.center, // Center content vertically // children: [ // Expanded( // flex: 4, // child: Container( // alignment: Alignment.centerLeft, // child: Column( // mainAxisAlignment: MainAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // Text( // 'Insurer', // textAlign: TextAlign.left, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 16 : 12, // fontWeight: FontWeight.w400, // color: Color(0xFF979797), // ), // ), // Text( // policyName ?? '', // textAlign: TextAlign.left, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 18 : 14, // fontWeight: FontWeight.w600, // color: Color(0xFF000000), // ), // ), // ], // ), // ), // ), // Expanded( // flex: 3, // child: Container( // alignment: Alignment.centerLeft, // child: Column( // mainAxisAlignment: MainAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // Text( // 'Status', // textAlign: TextAlign.center, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 16 : 12, // fontWeight: FontWeight.w400, // color: Color(0xFF979797), // ), // ), // Text( // policyStatus ?? '', // textAlign: TextAlign.center, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 18 : 14, // fontWeight: FontWeight.w600, // color: policyStatus == 'Active' // ? Colors.green // : Colors.red, // ), // ), // ], // ), // ), // ), // Expanded( // flex: 4, // child: Container( // alignment: Alignment.centerRight, // child: Column( // mainAxisAlignment: MainAxisAlignment.end, // crossAxisAlignment: CrossAxisAlignment.end, // children: [ // Text( // sumInsuredLabel ?? '', // textAlign: TextAlign.end, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 16 : 12, // fontWeight: FontWeight.w400, // color: Color(0xFF979797), // ), // ), // Text( // '₹ $si_value', // textAlign: TextAlign.end, // style: GoogleFonts.poppins( // fontSize: // Responsive.isDesktop(context) ? 18 : 14, // fontWeight: FontWeight.w600, // color: Color(0xFF000000), // ), // ), // ], // ), // ), // ), // Expanded( // flex: 1, // child: Container( // alignment: Alignment.centerRight, // child: Icon( // Icons.chevron_right, // color: Color(0xFFE26728), // size: Responsive.isDesktop(context) ? 30 : 26, // ), // ), // ), // ], // ), // ), // ), // ), // ); // }, // ), // ]; // } TextStyle _registerClaimLabelStyle(BuildContext context) { return GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 14 : 12, fontWeight: FontWeight.w400, color: const Color(0xFF777777), ); } TextStyle _registerClaimValueStyle(BuildContext context) { return GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 16 : 14, fontWeight: FontWeight.w600, color: const Color(0xFF000000), ); } TextStyle _registerClaimInsurerValueStyle(BuildContext context) { return GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 14 : 12, fontWeight: FontWeight.w600, color: const Color(0xFF000000), ); } TextStyle _registerClaimHeadingStyle(BuildContext context) { return GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 18 : 16, fontWeight: FontWeight.w600, color: const Color(0xFF000000), ); } String _registerClaimFieldValue(dynamic value) { if (value == null) return '-'; final text = value.toString().trim(); return text.isEmpty ? '-' : text; } String _formattedRegisterClaimSiValue(String raw) { if (raw == '-') return raw; return '₹ $raw'; } Color _policyStatusColor(String status) { if (status.toLowerCase() == 'active') return const Color(0xFF2E7D32); if (status.toLowerCase() == 'inactive') return const Color(0xFFC62828); return const Color(0xFF000000); } Widget _buildRegisterClaimField( BuildContext context, String label, String value, { Color? valueColor, bool alignEnd = false, TextStyle? valueStyle, }) { final resolvedValueStyle = (valueStyle ?? _registerClaimValueStyle(context)) .copyWith(color: valueColor); return Column( crossAxisAlignment: alignEnd ? CrossAxisAlignment.end : CrossAxisAlignment.start, children: [ Text( label, textAlign: alignEnd ? TextAlign.end : TextAlign.start, style: _registerClaimLabelStyle(context), ), const SizedBox(height: 4), Text( value, textAlign: alignEnd ? TextAlign.end : TextAlign.start, style: resolvedValueStyle, ), ], ); } Widget _buildRegisterClaimDivider() { return const Padding( padding: EdgeInsets.symmetric(vertical: 12), child: Divider(height: 1, thickness: 1, color: Color(0xFFD9D9D9)), ); } Widget _buildRegisterClaimCardHeader( BuildContext context, String heading, ) { final isDesktop = Responsive.isDesktop(context); return Container( width: double.infinity, padding: EdgeInsets.symmetric( horizontal: isDesktop ? 20 : 16, vertical: isDesktop ? 14 : 12, ), decoration: const BoxDecoration( color: Color(0xFFECF2FF), borderRadius: BorderRadius.only( topLeft: Radius.circular(11), topRight: Radius.circular(11), ), ), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Text( _registerClaimFieldValue(heading), style: _registerClaimHeadingStyle(context), ), ), const SizedBox(width: 8), const Icon( Icons.chevron_right, color: Color(0xFFE26728), size: 26, ), ], ), ); } Widget _buildRegisterClaimCard({ required BuildContext context, required VoidCallback onTap, required bool isRetail, String? heading, String? insurerName, String? policyStatus, String? siValue, String? sumInsuredLabel, String? insurerShortName, String? policyType, String? vehicleNo, }) { final isDesktop = Responsive.isDesktop(context); final cardHeading = isRetail ? _registerClaimFieldValue(policyType) : _registerClaimFieldValue(heading); return Padding( padding: const EdgeInsets.only(bottom: 12), child: MouseRegion( cursor: SystemMouseCursors.click, child: InkWell( onTap: onTap, borderRadius: BorderRadius.circular(12), child: Container( width: double.infinity, clipBehavior: Clip.antiAlias, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), border: Border.all(color: const Color(0xFFD9D9D9)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ _buildRegisterClaimCardHeader(context, cardHeading), Padding( padding: EdgeInsets.all(isDesktop ? 20 : 16), child: isRetail ? _buildRetailRegisterClaimContent( context, insurerShortName: insurerShortName ?? '', vehicleNo: vehicleNo ?? '', ) : _buildNormalRegisterClaimContent( context, insurerName: insurerName ?? '', policyStatus: policyStatus ?? '', siValue: siValue ?? '', sumInsuredLabel: sumInsuredLabel ?? 'Sum Insured', ), ), ], ), ), ), ), ); } Widget _buildNormalRegisterClaimContent( BuildContext context, { required String insurerName, required String policyStatus, required String siValue, required String sumInsuredLabel, }) { final isDesktop = Responsive.isDesktop(context); final status = _registerClaimFieldValue(policyStatus); final siLabel = _registerClaimFieldValue(sumInsuredLabel); final formattedSi = _formattedRegisterClaimSiValue( _registerClaimFieldValue(siValue), ); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildRegisterClaimField( context, 'Insurer', _registerClaimFieldValue(insurerName), valueStyle: _registerClaimInsurerValueStyle(context), ), _buildRegisterClaimDivider(), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: _buildRegisterClaimField( context, 'Status', status, valueColor: _policyStatusColor(status), ), ), SizedBox(width: isDesktop ? 24 : 16), Expanded( child: _buildRegisterClaimField( context, siLabel, formattedSi, alignEnd: true, ), ), ], ), ], ); } Widget _buildRetailRegisterClaimContent( BuildContext context, { required String insurerShortName, required String vehicleNo, }) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildRegisterClaimField( context, 'Insurer', _registerClaimFieldValue(insurerShortName), valueStyle: _registerClaimInsurerValueStyle(context), ), _buildRegisterClaimDivider(), _buildRegisterClaimField( context, 'Vehicle No', _registerClaimFieldValue(vehicleNo), ), ], ); } List generateYourPlanList(List data) { return [ ListView.builder( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemCount: data.length, itemBuilder: (BuildContext context, int index) { var item = data[index]; bool isRetail = item.containsKey('policy_transaction_id'); String policyHeading = item['heading'] ?? ''; String policyStatus = item['policy_status'] ?? ''; String siValue = item['si_value'] ?? ''; String sumInsuredLabel = item['sum_insured_label'] ?? 'Sum Insured'; String insurerName = item['insurer_name'] ?? ''; String insurerShortName = item['insurer_short_name'] ?? ''; String policyType = item['policy_type'] ?? ''; String vehicleNo = item['vehicle_no'] ?? ''; return _buildRegisterClaimCard( context: context, isRetail: isRetail, heading: policyHeading, insurerName: insurerName, policyStatus: policyStatus, siValue: siValue, sumInsuredLabel: sumInsuredLabel, insurerShortName: insurerShortName, policyType: policyType, vehicleNo: vehicleNo, onTap: () { if (isRetail) { context.push('/retailClaimForm', extra: { 'retailDetails': item, }); } else { context.push('/planclaimsform', extra: { 'claimsDetails': item, 'fromClaimPage': 0, }); } }, ); }, ), ]; } List generateTrackList(List data) { return [ ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: data.length, itemBuilder: (BuildContext context, int index) { var item = data[index]; // String claimsName = item['user_name']; String ticketId = item['id'] ?? ''; String claimsSubject = item['subject'] ?? ''; String claimsDate = item['created_at'] ?? ''; String claimStatus = item['claim_status'] ?? ''; String claimsDepartmentName = item['ticket_policy_type'] ?? ''; String rawClaimNumber = item['claim_number']?.toString().trim() ?? ''; String claimNumber = rawClaimNumber.isNotEmpty ? ' - ($rawClaimNumber)' : ''; // String claimsReplies = item['replies']; // List messageList = item['message_list']; logDebug('generateTrackList'); logDebug('generateTrackList- $data'); logDebug('generateTrackList- $ticketId'); logDebug(claimsSubject); logDebug(claimsDate); logDebug(claimStatus); logDebug(claimsDepartmentName); final Map statusColors = { 'Claim Received': Colors.blueGrey, 'Under Process' : Colors.orangeAccent, 'Information Required': Colors.deepOrange, 'Approved': Colors.green, 'Settled': Colors.teal, 'Denial Review Awaited':Colors.redAccent, 'Rejected': Colors.red, // 'Received': Colors.blueGrey, // New / Received // 'Under Process': Colors.orangeAccent, // Work in progress // 'Approved': Colors.green, // Approved // 'Settled': Colors.teal, // Completed successfully // 'Returned': Colors.deepOrange, // Sent back for correction // 'Rejected': Colors.red, // Rejected // 'Cancelled': Colors.redAccent, // Cancelled // 'Closed': Colors.grey, // Closed }; // Determine the color based on the claimStatus Color statusColor; if (claimStatus != null) { statusColor = statusColors[claimStatus!] ?? Color(0xFF979797); } else { statusColor = Color(0xFF979797); // Default color if status is null } bool isRetailPolicy = false; String? policyTxId = item['policy_transaction_id']; if (policyTxId != null && policyTxId.toString().trim().isNotEmpty) { isRetailPolicy = true; // Retail } else { isRetailPolicy = false; // Nhance GMC/GPA } return GestureDetector( onTap: () { logDebug("Tappp - $ticketId"); // Navigator.pushNamed(context, 'claimtracklist', arguments: item); showDialog( context: context, barrierDismissible: true, builder: (BuildContext context) { return Dialog( backgroundColor: Colors.transparent, insetPadding: EdgeInsets.all(16), child: ClaimHistoryPopup( ticket_id: item['id'], empName: isRetailPolicy ? '' : item['emp_name'], empCode: isRetailPolicy ? '' : item['emp_code'], policyType: item['ticket_policy_type']!, clientPolicyNo: item['policy_no']?.toString(), claimAmount: item['claim_amount']?.toString(), claimNo: item['claim_number']?.toString(), isRetailPolicy: isRetailPolicy, // ⬅️ NEW ), ); }, ); }, child: MouseRegion( cursor: SystemMouseCursors.click, child: Card( elevation: 5, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15.0), ), child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(15.0), ), padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 6, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ // Adjust space between icon and text Container( alignment: Alignment.centerLeft, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ RichText( text: TextSpan( children: [ // First Part: claimsDepartmentName → e.g., "GMC" TextSpan( text: claimsDepartmentName ?? '', style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 18 : 16, fontWeight: FontWeight.w700, color: const Color(0xFF000000), ), ), // Second Part: claimNumber → e.g., "(54534543)" TextSpan( text: '${claimNumber ?? ''}', style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 16 : 12, fontWeight: FontWeight.w500, color: const Color(0xFF555555), // lighter color ), ), ], ), ), SizedBox(height: 5), Tooltip( message: claimsSubject, // Full text shown on hover child: Text( claimsSubject.length > 20 ? '${claimsSubject.substring(0, 20)}...' : claimsSubject, textAlign: TextAlign.left, style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 14 : 12, fontWeight: FontWeight.w400, color: Color(0xFF777777), ), ), ) ], )) ], ), ), Expanded( flex: 5, child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ // Adjust space between icon and text Container( alignment: Alignment.centerRight, child: Column( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ Container( width: 100, decoration: BoxDecoration( color: statusColor, borderRadius: BorderRadius.circular( 50), // Border radius set to 50 ), child: Padding( padding: const EdgeInsets.all(5.0), child: Text( claimStatus, textAlign: TextAlign.center, style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 12 : 10, fontWeight: FontWeight.w400, color: Colors .white, // Text color against the background ), ), ), ), SizedBox(height: 5), Text( formatDateWithTime(claimsDate), textAlign: TextAlign.right, style: GoogleFonts.poppins( fontSize: Responsive.isDesktop(context) ? 14 : 12, fontWeight: FontWeight.w400, color: Color(0xFF777777), ), // Ensure text automatically wraps ), ], )) ], ), ), Expanded( flex: 1, child: Container( alignment: Alignment.centerRight, child: Icon( Icons.chevron_right, color: Color(0xFFE26728), size: Responsive.isDesktop(context) ? 30 : 26, ), ), ), ], ), ), ), ), ); }, ), ]; } String formatDateWithTime(String timestamp) { // Parse the timestamp string to DateTime DateTime date = DateTime.parse(timestamp); // Format the DateTime object with date and time String formattedDate = DateFormat('d MMM y hh:mm a').format(date); return formattedDate; } }