import 'package:flutter/material.dart'; import '../../../../core/constants/ui_constants.dart'; import '../../../../core/theme/colors.dart'; import '../../domain/entities/price_document.dart'; /// Document card widget displaying price policy or price list document class DocumentCard extends StatelessWidget { final PriceDocument document; final VoidCallback onDownload; const DocumentCard({ super.key, required this.document, required this.onDownload, }); @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: AppColors.white, borderRadius: BorderRadius.circular(12), border: Border.all(color: AppColors.grey100), boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.05), blurRadius: 4, offset: const Offset(0, 2), ), ], ), child: Material( color: Colors.transparent, child: InkWell( borderRadius: BorderRadius.circular(12), onTap: onDownload, child: Padding( padding: const EdgeInsets.all(AppSpacing.md), child: LayoutBuilder( builder: (context, constraints) { // Responsive layout: column on mobile, row on larger screens final isNarrow = constraints.maxWidth < 600; if (isNarrow) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ _buildIcon(), const SizedBox(width: AppSpacing.md), Expanded(child: _buildInfo()), ], ), const SizedBox(height: AppSpacing.md), SizedBox( width: double.infinity, child: _buildDownloadButton(), ), ], ); } return Row( children: [ _buildIcon(), const SizedBox(width: AppSpacing.md), Expanded(child: _buildInfo()), const SizedBox(width: AppSpacing.md), _buildDownloadButton(), ], ); }, ), ), ), ), ); } Widget _buildIcon() { final iconData = document.isPdf ? Icons.picture_as_pdf : Icons.table_chart; final iconColor = document.isPdf ? Colors.red.shade600 : Colors.green.shade600; return Container( width: 50, height: 50, decoration: BoxDecoration( color: AppColors.grey50, borderRadius: BorderRadius.circular(8), ), child: Icon(iconData, size: 28, color: iconColor), ); } Widget _buildInfo() { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( document.title, style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w600, color: AppColors.grey900, ), ), const SizedBox(height: 4), Row( children: [ const Icon( Icons.calendar_today, size: 13, color: AppColors.grey500, ), const SizedBox(width: 4), Text( document.formattedDateWithPrefix, style: const TextStyle(fontSize: 13, color: AppColors.grey500), ), if (document.fileSize != null) ...[ const SizedBox(width: 8), const Text( '•', style: TextStyle(fontSize: 13, color: AppColors.grey500), ), const SizedBox(width: 8), Text( document.fileSize!, style: const TextStyle(fontSize: 13, color: AppColors.grey500), ), ], ], ), const SizedBox(height: 6), Text( document.description, style: const TextStyle( fontSize: 14, color: AppColors.grey500, height: 1.4, ), maxLines: 2, overflow: TextOverflow.ellipsis, ), ], ); } Widget _buildDownloadButton() { return ElevatedButton.icon( onPressed: onDownload, style: ElevatedButton.styleFrom( backgroundColor: AppColors.primaryBlue, foregroundColor: AppColors.white, elevation: 0, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), ), icon: const Icon(Icons.download, size: 18), label: const Text( 'Tải về', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500), ), ); } }