Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 1x 1x 1x 1x 1x 1x 1x 1x 58x 58x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 4x 4x 4x 1x 1x 50x 50x 50x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 1x 1x 1x 1x 1x 1x 1x 1x 58x 58x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 59x 59x 59x 59x 59x 64x 64x 64x 64x 64x 64x 58x 58x 58x 58x 64x 64x 64x 64x 64x 64x 64x 64x 64x 53x 53x 53x 53x 53x 106x 106x 106x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 64x 64x 64x 64x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 64x 64x 64x 59x 64x 64x 64x 59x 64x 64x 64x 59x 64x 64x 64x 64x 64x 64x 10x 64x 64x 64x 64x 59x 59x 59x 59x 59x 301x 59x 59x 6x 6x 59x 59x 59x 59x 10x 10x 59x 49x 49x 59x 59x 59x 49x 49x 59x 64x 64x 64x 123x 74x 64x 64x 64x 3x 3x 3x 3x 3x 64x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 64x 64x 64x 64x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 64x 64x 64x 17x 17x 17x 17x 17x 17x 17x 64x 64x 64x 66x 66x 66x 66x 66x 66x 66x 66x 64x 64x 64x 6x 64x 64x 64x 8x 8x 8x 8x 8x 8x 64x 64x 64x 66x 66x 66x 66x 66x 66x 59x 59x 66x 8x 8x 66x 6x 6x 1x 6x 1x 5x 4x 4x 66x 65x 65x 64x 64x 64x 64x 64x 1x 1x 64x 64x 64x 59x 59x 59x 4x 59x 4x 4x 4x 64x 64x 64x 64x 64x 64x 64x 64x 64x 1x 1x 1x 64x 60x 60x 60x 64x 64x 64x 64x 64x 64x 64x 64x 63x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 210x 210x 210x 210x 210x 7x 7x 210x 6x 6x 6x 6x 6x 3x 6x 6x 6x 22x 64x 64x 64x 64x 123x 79x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 15x 15x 15x 15x 7x 7x 15x 5x 5x 10x 10x 10x 15x 5x 15x 15x 15x 64x 64x 64x 59x 59x 58x 64x 64x 64x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 64x 64x 64x 64x 58x 58x 58x 58x 58x 58x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 59x 59x 48x 59x 59x 47x 47x 47x 59x 59x 59x 47x 59x 59x 59x 47x 47x 64x 64x 64x 64x 64x 64x 64x 64x 25x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 58x 10x 64x 64x 64x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 1x 1x | <template>
<div class="match-detail-view p-3 sm:p-5">
<!-- Top bar: back on the left, the actions on the right (SB-1906). The
right padding keeps them clear of the modal's pinned close button
until the card is narrower than the window. -->
<div class="flex flex-wrap items-center gap-2 mb-3 pr-11 xl:pr-0">
<button
@click="$emit('back')"
data-testid="back-button"
class="inline-flex items-center gap-1.5 min-h-[44px] px-2 -ml-2 text-fg-muted hover:text-fg font-semibold text-sm rounded-lg hover:bg-surface-alt transition-colors"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="w-4 h-4"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 19l-7-7 7-7"
/>
</svg>
<span>{{ backLabel }}</span>
</button>
<div v-if="match" class="ml-auto flex items-center gap-2">
<!-- SB-1800: tournament matches only, and not for someone who can
already score this match. Outside the capture area so it never
lands in a shared image. -->
<LiveScoringHint v-if="isTournament && !canManageLineup" />
<!-- SB-32: Instagram share. -->
<button
v-if="canShareMatchPhoto"
@click="openIgShare"
data-testid="ig-share-button"
class="inline-flex items-center gap-2 h-10 px-3 sm:px-4 text-sm font-semibold rounded-lg border border-line bg-card text-fg hover:bg-surface-alt transition-colors"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="w-4 h-4 text-pink-600 dark:text-pink-400"
aria-hidden="true"
>
<rect
x="3"
y="3"
width="18"
height="18"
rx="5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<circle
cx="12"
cy="12"
r="4"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<circle cx="17.5" cy="6.5" r="1" fill="currentColor" />
</svg>
<span>Instagram</span>
</button>
<button
@click="shareScoreboard"
:disabled="shareStatus === 'copying'"
data-testid="share-button"
class="inline-flex items-center gap-2 h-10 px-3 sm:px-4 text-sm font-semibold rounded-lg border transition-colors"
:class="{
'bg-green-700 border-green-700 text-white':
shareStatus === 'success',
'bg-red-600 border-red-600 text-white': shareStatus === 'error',
'border-line bg-card text-fg hover:bg-surface-alt':
!shareStatus || shareStatus === 'copying',
}"
>
<!-- Copy icon -->
<svg
v-if="!shareStatus"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="w-4 h-4"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
/>
</svg>
<!-- Loading spinner -->
<svg
v-else-if="shareStatus === 'copying'"
class="w-4 h-4 animate-spin"
fill="none"
viewBox="0 0 24 24"
aria-hidden="true"
>
<circle
class="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
></path>
</svg>
<!-- Check icon -->
<svg
v-else-if="shareStatus === 'success'"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="w-4 h-4"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 13l4 4L19 7"
/>
</svg>
<!-- Error icon -->
<svg
v-else-if="shareStatus === 'error'"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="w-4 h-4"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
<span v-if="!shareStatus">Copy Scoreboard</span>
<span v-else-if="shareStatus === 'copying'">Copying...</span>
<span v-else-if="shareStatus === 'success'">Copied!</span>
<span v-else-if="shareStatus === 'error'">Failed</span>
</button>
</div>
</div>
<!-- Loading state -->
<div
v-if="loading"
class="flex flex-col items-center justify-center py-12"
data-testid="loading-state"
>
<div
class="w-8 h-8 border-3 border-line border-t-brand-500 rounded-full animate-spin mb-3"
></div>
<p class="text-fg-muted text-sm">Loading match details...</p>
</div>
<!-- Error state -->
<div
v-else-if="error"
class="flex flex-col items-center justify-center py-12 text-center"
data-testid="error-state"
>
<div
class="w-12 h-12 rounded-full bg-red-100 dark:bg-red-900/50 flex items-center justify-center text-red-600 dark:text-red-400 text-xl font-bold mb-3"
>
!
</div>
<p class="text-fg-muted mb-3 text-sm" data-testid="error-message">
{{ error }}
</p>
<button
@click="fetchMatch"
data-testid="retry-button"
class="px-4 py-2 bg-brand-600 hover:bg-brand-700 text-white rounded-lg font-medium text-sm transition-colors"
>
Try Again
</button>
</div>
<!-- Match content -->
<div v-else-if="match" data-testid="match-content">
<!-- The hero: what Copy Scoreboard captures. Theme tokens, so it reads
the same in light and dark mode (SB-1906). -->
<div
ref="scoreboardRef"
class="rounded-xl border border-line overflow-hidden"
data-testid="scoreboard"
>
<div
class="scoreboard bg-brand-50 dark:bg-surface-alt px-3 py-5 sm:px-8 sm:py-8"
>
<div
class="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3 sm:gap-8"
>
<!-- Home Team -->
<div
class="flex flex-col sm:flex-row items-center gap-2 sm:gap-5 text-center sm:text-left min-w-0"
>
<div
class="w-16 h-16 sm:w-24 sm:h-24 rounded-full flex items-center justify-center bg-card overflow-hidden border-2 flex-shrink-0"
:style="{ borderColor: homeTeamColor }"
>
<img
v-if="match.home_team_club?.logo_url"
:src="match.home_team_club.logo_url"
:alt="`${match.home_team_name} logo`"
class="w-12 h-12 sm:w-20 sm:h-20 object-contain"
/>
<div v-else class="text-lg sm:text-2xl font-bold text-fg-muted">
{{ getTeamInitials(match.home_team_name) }}
</div>
</div>
<div class="min-w-0">
<h2
class="text-base sm:text-2xl font-extrabold text-fg leading-tight break-words"
>
{{ match.home_team_name }}
</h2>
<span
class="text-[11px] font-bold text-fg-muted uppercase tracking-wider"
>Home</span
>
</div>
</div>
<!-- Centre: status, then the score once there is one, otherwise
when the match kicks off (SB-892). -->
<div class="flex flex-col items-center text-center min-w-[96px]">
<div
v-if="match.match_status === 'live'"
class="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-red-600 text-white font-bold uppercase tracking-wider text-xs animate-pulse"
data-testid="status-badge"
>
<span
class="w-1.5 h-1.5 rounded-full bg-white animate-ping"
></span>
LIVE
</div>
<div v-else class="flex flex-wrap justify-center gap-1.5">
<div
class="inline-flex items-center px-3 py-1 rounded-full text-[11px] font-bold uppercase tracking-wider"
:class="statusBadgeClass"
data-testid="status-badge"
>
{{ match.match_status || 'scheduled' }}
</div>
<!-- SB-1801: no name or role, just the fact. -->
<div
v-if="
match.match_status === 'completed' &&
match.scoring_mode === 'live'
"
class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-[10px] font-semibold uppercase tracking-wider text-fg-muted bg-card border border-line"
data-testid="scored-live-badge"
>
<span class="w-1.5 h-1.5 rounded-full bg-red-500"></span>
Scored live
</div>
</div>
<div
v-if="hasResult"
class="flex items-center gap-2 sm:gap-4 mt-3"
data-testid="score-display"
>
<span
class="score-number text-5xl sm:text-7xl font-extrabold text-fg tabular-nums leading-none"
data-testid="home-score"
>
{{ match.home_score }}
</span>
<span class="text-2xl sm:text-4xl font-light text-fg-muted"
>-</span
>
<span
class="score-number text-5xl sm:text-7xl font-extrabold text-fg tabular-nums leading-none"
data-testid="away-score"
>
{{ match.away_score }}
</span>
</div>
<!-- An MLS NEXT Flex fixture cannot end level: a draw is decided
on penalties (SB-1020). -->
<div
v-if="hasShootout"
class="mt-1 text-sm sm:text-base font-semibold text-fg-muted tabular-nums"
data-testid="penalty-display"
>
{{ match.home_penalty_score }} – {{
match.away_penalty_score
}} pk
</div>
<div
v-if="hasResult"
class="mt-2 text-xs sm:text-sm font-semibold text-fg-muted"
>
{{ formatDate(match.match_date) }}
</div>
<div v-else class="mt-3" data-testid="kickoff-display">
<div
v-if="kickoffClock"
class="text-3xl sm:text-6xl font-extrabold text-fg tabular-nums leading-none tracking-tight whitespace-nowrap"
>
{{ kickoffClock }}
</div>
<div
v-else
class="text-2xl sm:text-3xl font-light text-fg-muted leading-none"
>
vs
</div>
<div
v-if="kickoffDayLabel"
class="mt-2 text-xs sm:text-sm font-semibold text-fg"
>
{{ kickoffDayLabel
}}<span
v-if="kickoff?.zone"
class="text-fg-muted font-medium"
data-testid="kickoff-zone"
>
· {{ kickoff.zone }}</span
>
</div>
<div
v-if="kickoff?.yourTime"
class="mt-0.5 text-xs text-fg-muted"
data-testid="kickoff-your-time"
>
{{ kickoff.yourTime }} your time
</div>
</div>
</div>
<!-- Away Team -->
<div
class="flex flex-col sm:flex-row-reverse items-center gap-2 sm:gap-5 text-center sm:text-right min-w-0"
>
<div
class="w-16 h-16 sm:w-24 sm:h-24 rounded-full flex items-center justify-center bg-card overflow-hidden border-2 flex-shrink-0"
:style="{ borderColor: awayTeamColor }"
>
<img
v-if="match.away_team_club?.logo_url"
:src="match.away_team_club.logo_url"
:alt="`${match.away_team_name} logo`"
class="w-12 h-12 sm:w-20 sm:h-20 object-contain"
/>
<div v-else class="text-lg sm:text-2xl font-bold text-fg-muted">
{{ getTeamInitials(match.away_team_name) }}
</div>
</div>
<div class="min-w-0">
<h2
class="text-base sm:text-2xl font-extrabold text-fg leading-tight break-words"
>
{{ match.away_team_name }}
</h2>
<span
class="text-[11px] font-bold text-fg-muted uppercase tracking-wider"
>Away</span
>
</div>
</div>
</div>
<!-- Countdown to kickoff -->
<div
v-if="
(match.match_status === 'scheduled' ||
match.match_status === 'tbd') &&
match.scheduled_kickoff &&
!countdown.expired
"
class="flex justify-center mt-5"
data-testid="countdown"
>
<div
class="inline-flex items-baseline gap-2 px-4 py-2 rounded-lg bg-card border border-line tabular-nums"
>
<span class="text-xs sm:text-sm text-fg-muted">Kicks off in</span>
<span class="text-sm sm:text-base font-bold text-fg">
<template v-if="countdown.days > 0"
>{{ countdown.days }}
{{ countdown.days === 1 ? 'day' : 'days' }}
</template>
{{ String(countdown.hours).padStart(2, '0') }} hrs
{{ String(countdown.minutes).padStart(2, '0') }} min
</span>
</div>
</div>
<!-- Goal Scorers -->
<div
v-if="homeGoals.length || awayGoals.length"
class="flex justify-center gap-4 mt-5 pt-4 border-t border-line"
>
<div class="flex-1 text-right max-w-[220px]">
<div
v-for="goal in homeGoals"
:key="goal.id"
class="text-sm text-fg mb-1"
>
{{ goal.player_name }} {{ formatMinute(goal) }}
</div>
</div>
<div class="w-px bg-line flex-shrink-0"></div>
<div class="flex-1 text-left max-w-[220px]">
<div
v-for="goal in awayGoals"
:key="goal.id"
class="text-sm text-fg mb-1"
>
{{ goal.player_name }} {{ formatMinute(goal) }}
</div>
</div>
</div>
<!-- Cards -->
<div
v-if="homeCards.length || awayCards.length"
class="flex justify-center gap-4 mt-3 pt-3 border-t border-line"
>
<div class="flex-1 text-right max-w-[220px]">
<div
v-for="card in homeCards"
:key="card.id"
class="text-sm text-fg mb-1"
>
{{ card.player_name }}
<svg
width="10"
height="14"
viewBox="0 0 24 24"
class="inline-block align-middle mx-0.5"
aria-hidden="true"
>
<rect
x="4"
width="16"
height="24"
rx="2"
:fill="
card.event_type === 'red_card' ? '#EA3323' : '#FBBF24'
"
/>
</svg>
{{ formatMinute(card) }}
</div>
</div>
<div class="w-px bg-line flex-shrink-0"></div>
<div class="flex-1 text-left max-w-[220px]">
<div
v-for="card in awayCards"
:key="card.id"
class="text-sm text-fg mb-1"
>
{{ card.player_name }}
<svg
width="10"
height="14"
viewBox="0 0 24 24"
class="inline-block align-middle mx-0.5"
aria-hidden="true"
>
<rect
x="4"
width="16"
height="24"
rx="2"
:fill="
card.event_type === 'red_card' ? '#EA3323' : '#FBBF24'
"
/>
</svg>
{{ formatMinute(card) }}
</div>
</div>
</div>
</div>
<!-- Match details: one wrapping line under the hero, not a box with
the same weight as the kickoff (SB-1906). -->
<dl
class="flex flex-wrap justify-center gap-x-5 gap-y-1.5 px-4 py-3 bg-card border-t border-line text-xs sm:text-sm"
data-testid="match-meta"
>
<div
v-for="item in metaItems"
:key="item.label"
class="flex gap-1.5 min-w-0"
:data-testid="`match-meta-${item.key}`"
>
<dt class="text-fg-muted">{{ item.label }}</dt>
<dd class="m-0 font-semibold text-fg break-words">
{{ item.value }}
</dd>
</div>
</dl>
</div>
<!-- End capture area -->
<!-- Body: Match of the Week, then the preview across the full width.
Starting lineups are one of its tabs (SB-1915). -->
<div v-if="hasMain" class="mt-4 sm:mt-6 flex flex-col gap-4">
<!-- Match of the Week (SB-1577) -->
<section
v-if="isMotw && (motwBlurb || motwHasReasons)"
class="rounded-xl border border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-950/40 px-4 py-3 flex flex-col gap-2"
data-testid="motw-detail"
>
<span
class="text-xs font-bold uppercase tracking-wider text-amber-700 dark:text-amber-300"
>
<span aria-hidden="true">◆</span> Match of the Week
</span>
<p
v-if="motwBlurb"
class="m-0 text-sm text-fg"
data-testid="motw-detail-blurb"
>
{{ motwBlurb }}
</p>
<MotwReasons :reasons="motwReasons" />
</section>
<!-- Match Preview (scheduled/tbd matches only) -->
<div v-if="isUpcoming" data-testid="match-preview-section">
<MatchPreview
:homeTeamId="match.home_team_id"
:homeTeamName="match.home_team_name"
:awayTeamId="match.away_team_id"
:awayTeamName="match.away_team_name"
:seasonId="match.season_id"
:ageGroupId="match.age_group_id"
:matchTypeId="match.match_type_id"
:matchId="match.id"
:tournamentId="match.tournament_id ?? null"
:lineup-tab="showLineupTab"
>
<template #lineup>
<section data-testid="lineup-section">
<div
v-if="lineupDataLoading"
class="text-fg-muted text-sm text-center py-6"
>
Loading lineups...
</div>
<template v-else>
<!-- A manager with no roster for either team: say what to do -->
<p
v-if="
canManageLineup &&
rostersLoaded &&
!homeRoster.length &&
!awayRoster.length &&
!lineupSet
"
class="m-0 mb-3 text-fg-muted text-sm"
data-testid="no-roster-message"
>
Neither team has a roster yet. Add players to a team roster
to set lineups.
</p>
<div class="flex gap-2 mb-3">
<button
v-for="t in lineupTeams"
:key="t.side"
type="button"
@click="activeLineupTab = t.side"
:data-testid="`lineup-tab-${t.side}`"
:aria-pressed="activeLineupTab === t.side"
class="flex-1 min-h-[44px] py-2 px-3 text-sm font-semibold rounded-lg border-2 transition-colors truncate"
:class="
activeLineupTab === t.side
? 'border-brand-600 bg-brand-50 text-brand-700 dark:border-brand-300 dark:bg-brand-900/40 dark:text-brand-200'
: 'border-line text-fg-muted hover:text-fg'
"
>
{{ t.name }}
</button>
</div>
<!-- The pitch is drawn dark in both themes, as in live scoring. -->
<div class="rounded-lg bg-slate-900 p-2 sm:p-4">
<template v-for="t in lineupTeams" :key="t.side">
<div v-if="activeLineupTab === t.side">
<template v-if="t.canEdit">
<div
v-if="!t.roster.length"
class="text-slate-300 text-sm text-center py-4"
:data-testid="`no-roster-${t.side}`"
>
No roster available for {{ t.name }}.
</div>
<LineupManager
v-else
:team-id="t.id"
:team-name="t.name"
:roster="t.roster"
:initial-lineup="t.lineup"
:saving="savingLineup"
:sport-type="sportType"
@save="handleSaveLineup(t.id, $event)"
/>
</template>
<LineupPitch
v-else
:lineup="t.lineup"
:team-name="t.name"
:sport-type="sportType"
/>
</div>
</template>
</div>
</template>
</section>
</template>
</MatchPreview>
</div>
</div>
<!-- Post-Match Stats Editor (completed matches, authorized users only) -->
<PostMatchEditor
v-if="canManageLineup && match.match_status === 'completed'"
:match-id="matchId"
:match="match"
:events="events"
@events-changed="fetchMatch"
/>
<!-- Screen reader description -->
<span class="sr-only">
{{ match.home_team_name }} {{ match.home_score ?? 'no score' }} versus
{{ match.away_team_name }} {{ match.away_score ?? 'no score' }}. Match
status: {{ match.match_status || 'scheduled' }}.
{{ match.match_type_name }} match on {{ formatDate(match.match_date) }}.
</span>
<!-- SB-32: Instagram share modal -->
<IgShareModal
:open="igShareOpen"
:match="match"
:events="events"
:can-persist-photo="canPersistMatchPhoto"
:viewer-team-id="viewerTeamId"
:viewer-club-id="viewerClubId"
:is-motw="isMotw"
:blurb="motwBlurb"
:week-number="motwWeekNumber"
@close="closeIgShare"
@photo-uploaded="onPhotoUploaded"
/>
</div>
</div>
</template>
<script>
import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
import { subscribeToMatch } from '@/composables/useMatchRealtime';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '../config/api';
import html2canvas from 'html2canvas';
import { useMatchLineup } from '../composables/useMatchLineup';
import LineupManager from './live/LineupManager.vue';
import PostMatchEditor from './PostMatchEditor.vue';
import MatchPreview from './MatchPreview.vue';
import IgShareModal from './IgShareModal.vue';
import MotwReasons from './MotwReasons.vue';
import { hasReasons } from '../utils/featuredReasons';
import { roundLabel } from '../utils/tournamentRounds';
import { heroKickoff } from '../utils/matchHero';
import LiveScoringHint from './match/LiveScoringHint.vue';
import LineupPitch from './match/LineupPitch.vue';
export default {
name: 'MatchDetailView',
components: {
LineupManager,
PostMatchEditor,
MatchPreview,
IgShareModal,
MotwReasons,
LiveScoringHint,
LineupPitch,
},
props: {
matchId: {
type: [Number, String],
required: true,
},
// Where "back" actually goes. This view is reached inline from the Matches
// tab and as a modal from Tournaments, so a hardcoded "Back to Matches"
// was wrong in the second case (SB-890).
backLabel: {
type: String,
default: 'Back to Matches',
},
// Opened from the Match of the Week hero's share button (SB-1010): the
// person already said what they wanted, so don't make them find the
// button again. Only honoured once the match has actually loaded — the
// modal takes the match as a required prop.
autoOpenShare: {
type: Boolean,
default: false,
},
// SB-1010: passed down so the share modal can offer — and open on — the
// Match of the Week card. Only the caller knows this, since the match
// itself carries no MOTW flag.
isMotw: {
type: Boolean,
default: false,
},
motwBlurb: {
type: String,
default: null,
},
// [{text, kind}] or null (SB-1577).
motwReasons: {
type: Array,
default: null,
},
motwWeekNumber: {
type: Number,
default: null,
},
},
emits: ['back'],
setup(props) {
const authStore = useAuthStore();
const loading = ref(true);
const error = ref(null);
const match = ref(null);
const events = ref([]);
const scoreboardRef = ref(null);
const shareStatus = ref(null); // 'copying', 'success', 'error'
const igShareOpen = ref(false);
// Countdown timer for upcoming matches
// Only these statuses can carry a real scoreline. A `scheduled` match with
// stored zeros is not a 0-0 draw (SB-886), so the centre slot must not
// treat it as a result.
const SCORED_STATUSES = ['completed', 'in_progress', 'forfeit'];
const hasResult = computed(
() =>
!!match.value &&
SCORED_STATUSES.includes(match.value.match_status) &&
match.value.home_score !== null &&
match.value.home_score !== undefined &&
match.value.away_score !== null &&
match.value.away_score !== undefined
);
// Shown only alongside a real result, and only as a pair: half a shootout
// is not a shootout, and the DB stores both columns or neither.
const hasShootout = computed(
() =>
hasResult.value &&
match.value.home_penalty_score !== null &&
match.value.home_penalty_score !== undefined &&
match.value.away_penalty_score !== null &&
match.value.away_penalty_score !== undefined
);
// Kickoff takes the centre slot when there is no result. It is the thing
// the preview is opened for, and it used to sit in a six-cell grid with
// the same weight as "Season".
// Venue time for a tournament match, as its schedule shows it (SB-1906).
const kickoff = computed(() => heroKickoff(match.value));
const kickoffClock = computed(() => kickoff.value?.clock || null);
const kickoffDayLabel = computed(() => {
const raw = match.value?.match_date;
if (!raw) return null;
const date = new Date(`${String(raw).slice(0, 10)}T00:00:00`);
if (Number.isNaN(date.getTime())) return null;
const startOfDay = d => {
const x = new Date(d);
x.setHours(0, 0, 0, 0);
return x;
};
const delta = Math.round(
(startOfDay(date) - startOfDay(new Date())) / 86400000
);
const weekday = date.toLocaleDateString('en-US', {
weekday: 'short',
day: 'numeric',
month: 'short',
});
if (delta === 0) return `Today · ${weekday}`;
if (delta === 1) return `Tomorrow · ${weekday}`;
return weekday;
});
const countdown = ref({ days: 0, hours: 0, minutes: 0, expired: false });
let countdownTimer = null;
const updateCountdown = () => {
const kickoff = match.value?.scheduled_kickoff;
if (!kickoff) return;
const diff = new Date(kickoff) - Date.now();
if (diff <= 0) {
countdown.value = { days: 0, hours: 0, minutes: 0, expired: true };
clearInterval(countdownTimer);
return;
}
countdown.value = {
days: Math.floor(diff / 86400000),
hours: Math.floor((diff % 86400000) / 3600000),
minutes: Math.floor((diff % 3600000) / 60000),
expired: false,
};
};
// Get home team primary color for glow effect
const homeTeamColor = computed(() => {
return match.value?.home_team_club?.primary_color || '#3B82F6';
});
// Get away team primary color for glow effect
const awayTeamColor = computed(() => {
return match.value?.away_team_club?.primary_color || '#EF4444';
});
// Get league name from division object
const leagueName = computed(() => {
return match.value?.division?.leagues?.name || null;
});
// Tournament matches have no division; show the bracket round instead.
const isTournament = computed(
() => match.value?.match_type_name === 'Tournament'
);
const tournamentRoundLabel = computed(() =>
roundLabel(match.value?.tournament_round)
);
// The facts under the hero, one wrapping line (SB-1906). Each is left out
// when the match has no value for it, never shown blank.
const metaItems = computed(() => {
const m = match.value;
if (!m) return [];
const known = v => v && v !== 'Unknown';
const items = [];
const add = (key, label, value) => {
if (known(value)) items.push({ key, label, value });
};
if (hasResult.value) {
add('kickoff', 'Kickoff', formatLocalTime(m.scheduled_kickoff));
}
add('venue', 'Venue', m.location);
// Only what tells this match apart: the tournament, "Type: Tournament"
// and the season are already plain from the page around it (SB-1908).
if (isTournament.value) {
add('group', 'Group', m.tournament_group);
add('round', 'Round', tournamentRoundLabel.value);
} else {
add('type', 'Type', m.match_type_name || 'League');
}
add('age', 'Age Group', m.age_group_name);
add('league', 'League', leagueName.value);
if (!isTournament.value && m.match_type_name !== 'Friendly') {
add('division', 'Division', m.division_name);
}
return items;
});
const isUpcoming = computed(
() =>
match.value?.match_status === 'scheduled' ||
match.value?.match_status === 'tbd'
);
// Determine sport type from match data
const sportType = computed(() => {
return (
match.value?.sport_type ||
match.value?.division?.leagues?.sport_type ||
'soccer'
);
});
// Filter goals by team
const homeGoals = computed(() => {
return events.value
.filter(
e =>
e.event_type === 'goal' && e.team_id === match.value?.home_team_id
)
.sort((a, b) => (a.match_minute || 0) - (b.match_minute || 0));
});
const awayGoals = computed(() => {
return events.value
.filter(
e =>
e.event_type === 'goal' && e.team_id === match.value?.away_team_id
)
.sort((a, b) => (a.match_minute || 0) - (b.match_minute || 0));
});
// Filter cards by team
const homeCards = computed(() => {
return events.value
.filter(
e =>
['red_card', 'yellow_card'].includes(e.event_type) &&
e.team_id === match.value?.home_team_id
)
.sort((a, b) => (a.match_minute || 0) - (b.match_minute || 0));
});
const awayCards = computed(() => {
return events.value
.filter(
e =>
['red_card', 'yellow_card'].includes(e.event_type) &&
e.team_id === match.value?.away_team_id
)
.sort((a, b) => (a.match_minute || 0) - (b.match_minute || 0));
});
// Format minute display (e.g., "22'" or "90+5'")
const formatMinute = goal => {
if (!goal.match_minute) return '';
if (goal.extra_time) {
return `${goal.match_minute}+${goal.extra_time}'`;
}
return `${goal.match_minute}'`;
};
// Status badge class based on match status
const statusBadgeClass = computed(() => {
const status = match.value?.match_status || 'scheduled';
const classes = {
completed:
'bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-300',
scheduled:
'bg-brand-100 text-brand-700 dark:bg-brand-900/60 dark:text-brand-200',
postponed:
'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/50 dark:text-yellow-300',
cancelled:
'bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-300',
forfeit:
'bg-orange-100 text-orange-800 dark:bg-orange-900/50 dark:text-orange-300',
};
return classes[status] || classes.scheduled;
});
// Get team initials for fallback logo
const getTeamInitials = teamName => {
if (!teamName) return '?';
return teamName
.split(' ')
.map(word => word[0])
.join('')
.substring(0, 3)
.toUpperCase();
};
// Format date for display
const formatDate = dateString => {
if (!dateString) return '';
const date = new Date(dateString + 'T00:00:00');
return date.toLocaleDateString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
});
};
// Format UTC datetime to local time display
const formatLocalTime = isoString => {
if (!isoString) return null;
const date = new Date(isoString);
return date.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
};
// Fetch match events (goals, etc.)
const fetchEvents = async () => {
try {
const data = await authStore.apiRequest(
`${getApiBaseUrl()}/api/matches/${props.matchId}/live/events`
);
events.value = data || [];
} catch (err) {
// Events might not exist for older matches, that's ok
console.log('No events found for match:', err.message);
events.value = [];
}
};
// Fetch match details
const fetchMatch = async () => {
loading.value = true;
error.value = null;
try {
const data = await authStore.apiRequest(
`${getApiBaseUrl()}/api/matches/${props.matchId}`
);
match.value = data;
// Also fetch events for completed/live matches
if (data.match_status === 'completed' || data.match_status === 'live') {
await fetchEvents();
}
} catch (err) {
console.error('Error fetching match:', err);
if (err.message?.includes('401') || err.message?.includes('403')) {
error.value = 'You must be logged in to view match details';
} else if (err.message?.includes('404')) {
error.value = 'Match not found';
} else {
error.value = 'Failed to load match details';
}
} finally {
loading.value = false;
}
};
// Watch for matchId changes
watch(
() => props.matchId,
() => {
fetchMatch();
}
);
// Start/stop countdown timer as match loads
watch(match, m => {
clearInterval(countdownTimer);
if (
m?.scheduled_kickoff &&
(m.match_status === 'scheduled' || m.match_status === 'tbd')
) {
updateCountdown();
countdownTimer = setInterval(updateCountdown, 30000);
}
});
// ── SB-66: Realtime updates ──
// Subscribe whenever a match is loaded so score/status changes posted
// from another device land here without a manual refresh. The Supabase
// payload only carries raw matches-table columns, so refresh by
// re-fetching to keep joined display fields fresh too.
let matchRealtimeHandle = null;
function ensureMatchRealtime(matchId) {
if (matchRealtimeHandle) {
matchRealtimeHandle.unsubscribe();
matchRealtimeHandle = null;
}
if (matchId == null) return;
matchRealtimeHandle = subscribeToMatch(matchId, () => {
// Re-fetch on any change so joined data (teams, club, events) stays
// consistent. Cheap because /api/matches/{id} is keyed and tiny.
fetchMatch();
});
}
watch(
() => props.matchId,
newId => ensureMatchRealtime(newId),
{ immediate: false }
);
onMounted(async () => {
await fetchMatch();
if (props.autoOpenShare && match.value) {
igShareOpen.value = true;
}
ensureMatchRealtime(props.matchId);
});
onUnmounted(() => {
clearInterval(countdownTimer);
if (matchRealtimeHandle) {
matchRealtimeHandle.unsubscribe();
matchRealtimeHandle = null;
}
});
// Share scoreboard as image to clipboard
const shareScoreboard = async () => {
if (!scoreboardRef.value) return;
shareStatus.value = 'copying';
try {
const canvas = await html2canvas(scoreboardRef.value, {
backgroundColor: null, // the hero paints its own, light or dark
scale: 2, // Higher resolution
logging: false,
useCORS: true, // Enable CORS for cross-origin images (logos)
allowTaint: false, // Don't taint canvas (safer)
});
canvas.toBlob(async blob => {
try {
await navigator.clipboard.write([
new ClipboardItem({ 'image/png': blob }),
]);
shareStatus.value = 'success';
setTimeout(() => {
shareStatus.value = null;
}, 2000);
} catch (err) {
console.error('Failed to copy to clipboard:', err);
shareStatus.value = 'error';
setTimeout(() => {
shareStatus.value = null;
}, 2000);
}
}, 'image/png');
} catch (err) {
console.error('Failed to capture scoreboard:', err);
shareStatus.value = 'error';
setTimeout(() => {
shareStatus.value = null;
}, 2000);
}
};
// --- Pre-match lineup management ---
const {
homeRoster,
awayRoster,
homeLineup,
awayLineup,
fetchTeamRosters,
fetchLineups,
saveLineup,
} = useMatchLineup(props.matchId, match);
// Permission: may the viewer set this team's lineup? The same rule as the
// backend (SB-1915): admins any team, a team manager their own team, a
// club manager their club's teams.
const canEditLineupFor = teamId => {
const m = match.value;
if (!m || teamId == null) return false;
if (!authStore.isAuthenticated.value) return false;
if (authStore.isAdmin.value) return true;
if (authStore.isTeamManager.value) {
return authStore.userTeamId.value === teamId;
}
if (authStore.isClubManager.value) {
const clubId = authStore.userClubId?.value;
const teamClub =
teamId === m.home_team_id
? m.home_team_club?.id
: teamId === m.away_team_id
? m.away_team_club?.id
: null;
return clubId != null && teamClub === clubId;
}
return false;
};
// Can the viewer manage this match at all: either team's lineup.
const canManageLineup = computed(
() =>
canEditLineupFor(match.value?.home_team_id) ||
canEditLineupFor(match.value?.away_team_id)
);
// SB-659: Sharing and persisting are different permissions, and this
// used to conflate them.
//
// Generating the card is read-only — IgShareModal renders from a local
// object URL and rasterises in the browser, so it is just a picture of
// data the viewer can already see. Anyone signed in may do it, players
// very much included: they are the people most likely to post about
// their own match, and a shared card is MT's best route to recruiting
// the next team manager. Gating that on edit rights worked against the
// whole point of the feature.
//
// Writing the photo onto the match (POST /api/matches/{id}/photo) is a
// different matter — it persists to R2, everyone sees it afterwards,
// and these are photos of minors. That stays with the managers, via
// canPersistMatchPhoto below.
//
// Sharing is scoped by affiliation rather than by role: you may make a
// card for a match your own club or team is playing in, whatever your
// role — fan, player, manager alike. Admins get everything. A neutral
// signed-in user gets nothing, because a card for two clubs a person
// has no connection to is not the sharing this feature is for.
const isAffiliatedWithMatch = computed(() => {
if (!match.value) return false;
const teamId = authStore.userTeamId.value;
if (
teamId &&
(teamId === match.value.home_team_id ||
teamId === match.value.away_team_id)
) {
return true;
}
// Club affiliation covers club managers and club fans, and also team
// people whose club_id the store derives from their current teams.
const clubId = authStore.userClubId.value;
if (!clubId) return false;
return (
clubId === match.value.home_team_club?.id ||
clubId === match.value.away_team_club?.id
);
});
const canShareMatchPhoto = computed(
() =>
!!match.value &&
authStore.isAuthenticated.value &&
(authStore.isAdmin.value || isAffiliatedWithMatch.value)
);
const canPersistMatchPhoto = canManageLineup;
// The club the viewer belongs to, when it is one of the two playing.
// Lets a club fan with no team_id still get their own club's colors.
const viewerClubId = computed(() => {
const clubId = authStore.userClubId.value;
if (!clubId || !match.value) return null;
return clubId === match.value.home_team_club?.id ||
clubId === match.value.away_team_club?.id
? clubId
: null;
});
// Which of the two teams, if either, the viewer belongs to. Drives the
// default accent color: a player or manager posting about their own
// match wants their own club's colors without having to ask for them.
// Null for admins and neutrals, who fall back to automatic resolution.
const viewerTeamId = computed(() => {
const teamId = authStore.userTeamId.value;
if (!teamId || !match.value) return null;
return teamId === match.value.home_team_id ||
teamId === match.value.away_team_id
? teamId
: null;
});
const openIgShare = () => {
igShareOpen.value = true;
};
const closeIgShare = () => {
igShareOpen.value = false;
};
const onPhotoUploaded = uploaded => {
// Mirror the persisted photo back onto the local match so subsequent
// refreshes show it without a refetch.
if (match.value && uploaded?.photo_key) {
match.value = {
...match.value,
photo_url: uploaded.photo_url,
photo_key: uploaded.photo_key,
};
}
};
// Lineup state (SB-1915). Lineups load for everyone signed in on an
// upcoming match, since a fan sees the tab once one is set; rosters load
// only for the people who can edit.
const activeLineupTab = ref('home');
const rostersLoaded = ref(false);
const lineupsLoaded = ref(false);
const lineupDataLoading = ref(false);
const savingLineup = ref(false);
const loadLineupData = async () => {
if (!match.value || !isUpcoming.value) return;
if (!authStore.isAuthenticated.value || lineupDataLoading.value) return;
const wantLineups = !lineupsLoaded.value;
const wantRosters = canManageLineup.value && !rostersLoaded.value;
if (!wantLineups && !wantRosters) return;
lineupDataLoading.value = true;
try {
await Promise.all([
wantLineups ? fetchLineups() : null,
wantRosters ? fetchTeamRosters() : null,
]);
if (wantLineups) lineupsLoaded.value = true;
if (wantRosters) rostersLoaded.value = true;
} catch (err) {
console.error('Failed to load lineups and rosters:', err);
} finally {
lineupDataLoading.value = false;
}
};
watch(
() => [match.value?.id, canManageLineup.value, isUpcoming.value],
loadLineupData
);
const lineupHasPlayers = lineup => (lineup?.positions?.length || 0) > 0;
const lineupSet = computed(
() =>
lineupHasPlayers(homeLineup.value) || lineupHasPlayers(awayLineup.value)
);
// Managers always see the tab, to set it; everyone else once it is set.
const showLineupTab = computed(
() => isUpcoming.value && (canManageLineup.value || lineupSet.value)
);
// Handle lineup save from LineupManager component
const handleSaveLineup = async (teamId, lineupData) => {
savingLineup.value = true;
try {
const result = await saveLineup(
teamId,
lineupData.formation_name,
lineupData.positions
);
if (!result.success) {
console.error('Failed to save lineup:', result.error);
}
} catch (err) {
console.error('Error saving lineup:', err);
} finally {
savingLineup.value = false;
}
};
const motwHasReasons = computed(() => hasReasons(props.motwReasons));
// Body (SB-1906): the preview and the Match of the Week note.
const hasMain = computed(
() =>
isUpcoming.value ||
Boolean(props.isMotw && (props.motwBlurb || motwHasReasons.value))
);
// The two teams in the Lineups tab: who may edit, and what is set.
const lineupTeams = computed(() => {
const m = match.value;
if (!m) return [];
return [
{
side: 'home',
id: m.home_team_id,
name: m.home_team_name,
roster: homeRoster.value,
lineup: homeLineup.value,
canEdit: canEditLineupFor(m.home_team_id),
},
{
side: 'away',
id: m.away_team_id,
name: m.away_team_name,
roster: awayRoster.value,
lineup: awayLineup.value,
canEdit: canEditLineupFor(m.away_team_id),
},
];
});
return {
motwHasReasons,
hasResult,
hasShootout,
kickoffClock,
kickoff,
metaItems,
isUpcoming,
hasMain,
lineupTeams,
showLineupTab,
lineupSet,
kickoffDayLabel,
loading,
error,
match,
events,
countdown,
homeGoals,
awayGoals,
homeCards,
awayCards,
homeTeamColor,
awayTeamColor,
leagueName,
isTournament,
tournamentRoundLabel,
sportType,
statusBadgeClass,
getTeamInitials,
formatDate,
formatLocalTime,
formatMinute,
fetchMatch,
scoreboardRef,
shareStatus,
shareScoreboard,
// IG share (SB-32)
igShareOpen,
canShareMatchPhoto,
canPersistMatchPhoto,
viewerTeamId,
viewerClubId,
openIgShare,
closeIgShare,
onPhotoUploaded,
// Lineup
canManageLineup,
activeLineupTab,
homeRoster,
awayRoster,
homeLineup,
awayLineup,
rostersLoaded,
lineupDataLoading,
savingLineup,
handleSaveLineup,
};
},
};
</script>
<style scoped>
/* Glowing score numbers */
.score-number {
text-shadow:
0 0 20px rgba(255, 255, 255, 0.4),
0 0 40px rgba(255, 255, 255, 0.2),
0 0 60px rgba(255, 255, 255, 0.1);
}
/* Detail item styling */
.detail-item {
display: flex;
flex-direction: column;
gap: 4px;
}
/* Scoreboard subtle animation for live matches */
@keyframes pulse-glow {
0%,
100% {
box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}
50% {
box-shadow: 0 0 40px rgba(239, 68, 68, 0.5);
}
}
.scoreboard:has(.animate-pulse) {
animation: pulse-glow 2s ease-in-out infinite;
}
</style>
|