import 'package:flutter/material.dart'; /// 배지(Chip) 스타일 매핑과 헬퍼 class BadgeStyles { // 색상 팔레트 static const Color primary = Color(0xFF1565C0); // Blue 700 static const Color success = Color(0xFF2E7D32); // Green 800 static const Color warning = Color(0xFFEF6C00); // Orange 800 static const Color danger = Color(0xFFC62828); // Red 800 // 배경 톤 (100 계열 느낌) static final Color primaryBg = Colors.blue.shade100; static final Color successBg = Colors.green.shade100; static final Color dangerBg = Colors.red.shade100; static final Color neutralBg = Colors.grey.shade200; // 회원 유형 컬러/아이콘 매핑 static Chip memberType(String type) { late final Color bg; late final IconData icon; switch (type) { case '정회원': bg = primaryBg; icon = Icons.person; break; case '준회원': bg = Colors.indigo.shade100; icon = Icons.person_outline; break; case '게스트': bg = neutralBg; icon = Icons.person_add_alt; break; default: bg = neutralBg; icon = Icons.person_outline; } return _chip(type, bg, icon); } // 참가 상태 컬러/아이콘 매핑 static Chip participantStatus(String status) { late final Color bg; late final IconData icon; switch (status) { case '등록됨': bg = neutralBg; icon = Icons.how_to_reg; break; case '확인됨': bg = successBg; icon = Icons.check_circle; break; case '취소됨': bg = dangerBg; icon = Icons.cancel; break; case '참석함': bg = primaryBg; icon = Icons.event_available; break; default: bg = neutralBg; icon = Icons.help_outline; } return _chip(status, bg, icon); } // 회원 상태 컬러/아이콘 매핑 (라벨 기준: 활성/비활성/정지/삭제됨) static Chip memberStatus(String label) { late final Color bg; late final IconData icon; switch (label) { case '활성': bg = successBg; icon = Icons.check_circle; break; case '비활성': bg = neutralBg; icon = Icons.pause_circle_filled; break; case '정지': bg = dangerBg; icon = Icons.block; break; case '삭제됨': bg = Colors.grey.shade300; icon = Icons.delete_forever; break; default: bg = neutralBg; icon = Icons.person; } return _chip(label, bg, icon); } // 결제 상태 컬러/아이콘 매핑 static Chip payment(bool isPaid) { return _chip( isPaid ? '결제완료' : '미결제', isPaid ? successBg : dangerBg, isPaid ? Icons.check_circle : Icons.cancel, ); } // 이벤트 상태 컬러/아이콘 매핑 static Chip eventStatus(String status) { late final Color bg; late final IconData icon; switch (status) { case '활성': bg = successBg; icon = Icons.check_circle; break; case '대기': bg = Colors.amber.shade100; icon = Icons.hourglass_top; break; case '취소': bg = dangerBg; icon = Icons.cancel; break; case '완료': bg = Colors.grey.shade300; icon = Icons.done_all; break; default: bg = neutralBg; icon = Icons.event; } return _chip(status, bg, icon); } static Chip _chip(String text, Color bg, IconData icon) { // 배경 대비에 따라 텍스트/아이콘 색상을 자동 설정 (흰/검정 중 더 높은 대비 선택) double lumBg = bg.computeLuminance(); // 대비비 계산 함수 (WCAG 근사) double contrast(double lum1, double lum2) { final double l1 = lum1 > lum2 ? lum1 : lum2; final double l2 = lum1 > lum2 ? lum2 : lum1; return (l1 + 0.05) / (l2 + 0.05); } final double contrastWithWhite = contrast(lumBg, Colors.white.computeLuminance()); final double contrastWithBlack = contrast(lumBg, Colors.black.computeLuminance()); final Color fg = contrastWithWhite >= contrastWithBlack ? Colors.white : Colors.black; return Chip( avatar: Icon(icon, size: 16, color: fg), label: Text(text, style: TextStyle(color: fg)), backgroundColor: bg, padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 0), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, ); } }