All files / src/shared/GiveFilter constants.tsx

93.13% Statements 95/102
73.07% Branches 19/26
83.33% Functions 15/18
93.81% Lines 91/97

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                                                  263x 263x               263x             263x 9846x                                                   263x                                                                             263x                                                             263x                                                     263x     1094x   1094x           1094x             1094x   1094x     263x                     263x                     263x                             263x                                     263x                             263x               263x   263x                         263x                                                     263x                                     263x                                           263x         263x         263x     263x                                                                                                                                                               263x                   263x   263x 263x 4471x       263x               1315x         263x   263x     263x 526x                                       263x 263x                                       263x 263x                               263x 263x                                       263x 263x                                                                                     263x                                                     263x               263x               263x             263x             263x               2188x                   263x             263x             263x             263x   1094x     360x           263x               263x             263x               263x               263x                   263x               263x               263x               263x             263x           263x   263x                                                                                                                                     263x                                                                                     263x                   263x                                                                                                   263x                                 263x           263x                         263x           263x                           263x           263x                                   263x                       263x                       263x 17x 3x 4x   3x                                                                                             263x  
import {
  QKEY_ACQUIRER_MANAGE_MONEY_TRANSACTIONS_LIST,
  QKEY_EVENT_TICKETS,
  QKEY_EVENT_TRANSACTIONS,
  QKEY_LIST_ACQUIRER_MERCHANTS,
  QKEY_LIST_ENTERPRISE_STATS,
  QKEY_MANAGE_MONEY_TRANSACTIONS_LIST,
  QKEY_PROCESSING_LIST,
  QKEY_PROVIDER_PROCESSING,
  QKEY_RISK_MONITOR_TRANSACTIONS,
} from "@constants/queryKeys";
import { Stack } from "@mui/material";
import { BookmarkSimpleIcon } from "@phosphor-icons/react";
import {
  CardPropsTypes as CardProps,
  FilterChip,
} from "@pages/ManageMoney/Modal/filter.types";
import { CustomFilterType } from "@pages/ManageMoney/types";
import GiveText from "@shared/Text/GiveText";
import { businessClassificationType } from "@pages/AcquirerPortal/Enterprises/Modal/constants";
import { getFormattedTimezoneRange } from "@utils/date.helpers";
import { DISPUTES_QUERY_KEY } from "@components/Disputes/DisputesList/hooks/useDisputesTable";
import { TRANSFERS_QUERY_KEY } from "@components/Tranfers/hooks/useTransfersTable";
import { useDisputeTableNewTable } from "@components/Disputes/DisputesList/hooks/useDisputeTableNewTable";
 
export const rangeRegex = /^\d+-\d+$/;
const formatDate = (date: Date): string => {
  return date.toLocaleDateString("en-US", {
    month: "2-digit",
    day: "2-digit",
    year: "numeric",
  });
};
 
const getDateRange = (daysAgo: number): string => {
  const startDate = new Date();
  startDate.setDate(startDate.getDate() - daysAgo);
  const endDate = new Date();
  return `${formatDate(startDate)}-${formatDate(endDate)}`;
};
 
const getTransactionDateChips = (timezone?: string): FilterChip[] => {
  return [
    {
      label: "Today",
      value: timezone
        ? getFormattedTimezoneRange(1, timezone).dateString
        : formatDate(new Date()),
    },
    {
      label: "Last 7 Days",
      value: timezone
        ? getFormattedTimezoneRange(7, timezone).dateString
        : getDateRange(7),
    },
    {
      label: "Last 30 Days",
      value: timezone
        ? getFormattedTimezoneRange(30, timezone).dateString
        : getDateRange(30),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
const transactionStatusChips: FilterChip[] = [
  {
    value: "Pending",
    label: "Pending",
  },
  {
    value: "Authorized",
    label: "Authorized ",
  },
  {
    value: "Voided",
    label: "Voided",
  },
  {
    value: "Settled",
    label: "Settled",
  },
  {
    value: "Chargeback",
    label: "Chargeback",
  },
  {
    value: "Chargeback Reversal",
    label: "Chargeback Reversal",
  },
  {
    value: "Refund pending",
    label: "Refunded Pending",
  },
  {
    value: "Refunded",
    label: "Refunded",
  },
  {
    value: "Declined",
    label: "Declined",
  },
];
 
const transferStatusChips: FilterChip[] = [
  {
    value: "Requested",
    label: "Requested",
  },
  {
    value: "Ready to Process",
    label: "Ready to Process",
  },
  {
    value: "Sending",
    label: "Sending",
  },
  {
    value: "Sent",
    label: "Sent",
  },
  {
    value: "Canceled",
    label: "Canceled",
  },
  {
    value: "Declined",
    label: "Declined",
  },
  {
    value: "Error",
    label: "Error",
  },
];
 
const disputeStatusChips: FilterChip[] = [
  {
    label: "Open",
    value: "open",
  },
  {
    label: "Under Review",
    value: "under_review",
  },
  {
    label: "Won",
    value: "won",
  },
  {
    label: "Lost",
    value: "lost",
  },
  {
    label: "Prevented",
    value: "prevented",
  },
  {
    label: "Pending",
    value: "pending",
  },
];
 
export const useGetDisputeStatus = () => {
  const {
    tabs: { isClosedTabSelected, isUnderReviewTabSelected, isOpenTabSelected },
  } = useDisputeTableNewTable();
 
  const chips = isClosedTabSelected
    ? disputeStatusChips.filter(
        (el) => !["Open", "Under Review", "Pending"].includes(el.label),
      )
    : disputeStatusChips;
 
  const disputeStatus: CardProps = {
    title: "Status",
    chips: chips,
    selected: [],
    apiKeyName: endpointNames.disputeStatus,
  };
 
  Iif (isUnderReviewTabSelected || isOpenTabSelected) return [];
 
  return [disputeStatus];
};
 
const paymentMethodChips: FilterChip[] = [
  {
    label: "Credit Card",
    value: "Credit",
  },
  {
    label: "Debit Card",
    value: "Debit",
  },
];
 
const cardInfoTypeChips: FilterChip[] = [
  {
    label: "Credit Card",
    value: "CREDIT",
  },
  {
    label: "Debit Card",
    value: "DEBIT",
  },
];
 
const riskLevel: FilterChip[] = [
  {
    label: "Medium",
    value: "medium",
  },
  {
    label: "High",
    value: "high",
  },
  {
    label: "Critical",
    value: "critical",
  },
];
 
const minimalRiskLevel: FilterChip[] = [
  {
    label: "Low",
    value: 0,
  },
  {
    label: "Medium",
    value: 1,
  },
  {
    label: "High",
    value: 2,
  },
  {
    label: "Critical",
    value: 3,
  },
];
 
const riskStatus: FilterChip[] = [
  {
    label: "Routine Monitoring",
    value: "routine_monitoring",
  },
  {
    label: "Alerted",
    value: "alerted",
  },
  {
    label: "Active Monitoring",
    value: "active_monitoring",
  },
];
 
const providerStatus: FilterChip[] = [
  { label: "KYB", value: "ready_for_kyb" },
  { label: "Underwriting", value: "ready_for_underwriting" },
  { label: "Approved", value: "approved" },
  { label: "Suspended", value: "suspended" },
  { label: "Declined", value: "declined" },
];
 
export const CLOSED_MERCHANT_STATUS = "closed";
 
const merchantStatus: FilterChip[] = [
  { label: "Invited", value: "invited" },
  { label: "Pending", value: "onboarding" },
  { label: "KYB", value: "ready_for_kyb" },
  { label: "Underwriting", value: "ready_for_underwriting" },
  { label: "Sponsor", value: "ready_for_review" },
  { label: "Approved", value: "approved" },
  { label: "Suspended", value: "suspended" },
  { label: "Declined", value: "declined" },
  { label: "Closed", value: CLOSED_MERCHANT_STATUS },
  //{ label: "Deleted", value: "deleted" }, TODO: we do not have this filter yet, to be added later
];
 
export const transactionsCount = [
  {
    label: "0 - 1,000",
    value: "0-1000",
  },
  {
    label: "1,001 - 5,000",
    value: "1001-5000",
  },
  {
    label: "5,001 - 10,000",
    value: "5001-10000",
  },
  {
    label: "10,001 - 15,000",
    value: "10001-15000",
  },
  {
    label: "> 15,000",
    value: "15000",
  },
  {
    label: "Custom",
    value: "custom",
  },
];
 
export const approvedMerchantsCount = [
  {
    label: "0",
    value: "<=0",
  },
  {
    label: "1 - 100",
    value: "1-100",
  },
  {
    label: "> 100",
    value: "100",
  },
  {
    label: "Custom",
    value: "custom",
  },
];
 
const emailStatusChip: FilterChip[] = [
  {
    label: "Valid",
    value: "valid",
  },
  {
    label: "Pending",
    value: "pending",
  },
  {
    label: "Undeliverable",
    value: "rejected",
  },
];
 
enum TRANSACTION_TRANSFER {
  TRANSFER = "transfer",
  TRANSACTION = "purchase",
}
 
// A returned transfer is modeled as a separate transfer_return transaction (the
// original transfer keeps its own status). Single source of truth for that type.
const TRANSFER_RETURN_TYPE = "transfer_return";
 
// Base transaction types for the Transfers tab: the transfer itself plus its
// return, so Returned transfers stay visible and a "Returned" status filter
// (type:"transfer_return") isn't AND-ed away by a transfer-only base filter.
const TRANSFERS_TAB_BASE_TYPES = [
  TRANSACTION_TRANSFER.TRANSFER,
  TRANSFER_RETURN_TYPE,
];
 
const inflowOutFlowApiKey = "balanceAdjustment";
 
// These are the keys used in react hook form and for API filter request
const endpointNames = {
  date: "createdAt",
  settledAt: "settledAt",
  transactionStatus: TRANSACTION_TRANSFER.TRANSACTION,
  transferStatus: TRANSACTION_TRANSFER.TRANSFER,
  merchantName: "merchantName",
  inFlow: "inflow",
  outFlow: "outflow",
  paymentMethod: "cardIsDebit",
  watchlist: "watchlist",
  providerName: "parentName",
  assignee: "underwriterEmail",
  categoryCode: "categoryCode",
  approvedDate: "approvedAt",
  canProcessMoney: "canProcessMoney",
  canTransferMoney: "canTransferMoney",
  processedVolume: "totalProcessed",
  riskLevelLabelDisplayName: "riskLevelLabelDisplayName",
  operationalSection: "operationalSection",
  approvalAt: "approvalAt",
  stateName: "stateName",
  className: "className",
  transactionsCount: "transactionsCount",
  approvedSubmerchants: "approvedSubmerchants",
  charged: "charged",
  cost: "cost",
  fees: "fees",
  processor: "processorName",
  riskStatusDisplayName: "riskStatusDisplayName",
  lastEscalationAt: "lastEscalationAt",
  lastRiskActivityAt: "lastRiskActivityAt",
  disputeStatus: "status",
  disputePreChargebackRefundTransactionID: "preChargebackRefundTransactionID",
  disputeStatusOutcome: "outcome",
  disputeCaseType: "stage",
  disputeMSPCaseType: "mspCaseTypeName",
  disputeAmount: "disputedAmount",
  disputeMerchantName: "merchant.name",
  // for disputes filter by merchant.accID to avoid matching multiple merchants with the same name
  disputeMerchantAccID: "merchant.accID",
  //for transaction-base insted of merrchantName we need to filter by dstAccMerchantName and srcAccMerchantName
  srcAccMerchantName: "srcAccMerchantName",
  dstAccMerchantName: "dstAccMerchantName",
  // for transactions and transactions-basic filter by accID to avoid matching multiple merchants with the same name
  srcAccountId: "sourceAccount.id",
  dstAccountId: "destinationAccount.id",
  srcParentName: "srcParentName",
  dstParentName: "dstParentName",
  // for transactions and transactions-basic filter by parent accID to avoid matching multiple providers with the same name
  srcParentAccID: "srcParentAccID",
  dstParentAccID: "dstParentAccID",
  merchantNameTransfer: "merchAccName",
  providerNameTransfer: "parentAccName",
  merchantTypeTransfer: "merchAccType",
  emailStatus: "emailStatus",
  flagSection: "flagSection",
  isBlocked: "isBlocked",
  isFalsePositive: "isFalsePositive",
  cardInfoType: "cardInfoType",
  riskLevel: "riskLevel",
  txnDisplayStatus: "txnDisplayStatus",
  // Event Tickets tab (PayBuilder 032, frame 7397-90376). The chip VALUES are
  // event_ticket_holders_view's own enum values, so no translation layer is
  // needed — but the FORM keys are deliberately prefixed: a bare `status` is
  // already claimed by the disputes panel, whose formatter would pick up the
  // ticket statuses as dispute statuses. useGeneralFilters maps these to the
  // API field names in ticketApiKeys below.
  ticketStatus: "ticketStatus",
  ticketPaymentStatus: "ticketPaymentStatus",
  ticketType: "ticketType",
  ticketPickupStatus: "ticketPickupStatus",
  // Event Detail Transactions tab (frame 7397-80180). Its list is
  // `products/{id}/transaction-items`, so the fields are that view's, not the
  // transactions list's — hence keys of their own rather than reusing
  // txnDisplayStatus (which the risk panel filters on a different endpoint).
  eventTxnStatus: "eventTxnStatus",
  eventTxnTicketType: "eventTxnTicketType",
};
 
/** Form key → `event_ticket_holders_view` field, for the URL filter. */
const ticketApiKeys = {
  [endpointNames.ticketStatus]: "status",
  [endpointNames.ticketPaymentStatus]: "paymentStatus",
  [endpointNames.ticketType]: "ticketType",
  [endpointNames.ticketPickupStatus]: "pickupState",
  // Same chips as the Tickets tab's Ticket Name, different endpoint: on
  // transaction-items the tier is the product variant.
  [endpointNames.eventTxnTicketType]: "product.variant.name",
};
 
export const customAmountArrayKey = "customAmountArray";
 
export const urlFilterFormat = "urlFilterFormat";
const generateFlow = (start: number, end?: number) => {
  return end !== undefined ? `${start}-${end}` : `${start}`;
};
 
function createVolumeChips(useCustom = true): FilterChip[] {
  const ranges = [
    { min: 0, max: 1000 },
    { min: 1000, max: 10000 },
    { min: 10000, max: 100000 },
    { min: 100000, max: 500000 },
    { min: 500000, max: 1000000 },
  ];
 
  const chips = ranges.map(({ min, max }) => ({
    label: `${min.toLocaleString()} - ${max.toLocaleString()} USD`,
    value: `${min}-${max}`,
  }));
 
  Eif (useCustom) chips.push({ label: "Custom", value: "custom" });
 
  return chips;
}
 
export const generateFlowArray = () => {
  return [
    {
      label: "0 USD",
      value: generateFlow(0),
    },
    {
      label: "1 - 500 USD",
      value: generateFlow(0.01, 500),
    },
    {
      label: "> 500 USD",
      value: generateFlow(500),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
export const generateAmountArray = () => {
  return [
    {
      label: "< 200 USD",
      value: generateFlow(0, 200),
    },
    {
      label: "200-500 USD",
      value: generateFlow(200, 500),
    },
    {
      label: "> 500 USD",
      value: generateFlow(500),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
export const generateDisputeAmountArray = () => {
  return [
    {
      label: "0 - 1,000 USD",
      value: generateFlow(10, 1000),
    },
    {
      label: "1,001 - 10,000 USD",
      value: generateFlow(1001, 10001),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
export const generateAmountTransfersArray = () => {
  return [
    {
      label: "10 - 1,000 USD",
      value: generateFlow(10, 1000),
    },
    {
      label: "1,001 - 5,000 USD",
      value: generateFlow(1001, 5000),
    },
    {
      label: "> 5,000 USD",
      value: generateFlow(5000),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
export const generateFeeArray = () => {
  return [
    {
      label: "< 5 USD",
      value: generateFlow(0, 5),
    },
    {
      label: "5-50 USD",
      value: generateFlow(5, 50),
    },
    {
      label: "> 50 USD",
      value: generateFlow(50),
    },
    {
      label: "Custom",
      value: "custom",
    },
  ];
};
 
enum FilterPagesEnum {
  MANAGE_MONEY = "manage_money",
  PROVIDER_PROCESSING = "providerProcessing",
  MERCHANT_ALL_TAB = "portfolio",
  MERCHANT_RISK_TAB = "risk",
  MERCHANT_KYB_TAB = "kyb",
  MERCHANT_UNDERWRITING_TAB = "underwriting_admin",
  MERCHANT_SPONSOR_TAB = "sponsor",
  MERCHANT_APPROVED_TAB = "approved",
  MERCHANT_PENDING_TAB = "pending",
  PROVIDER_ALL_TAB = "providerAll",
  PROVIDER_UNDERWRITING_TAB = "providerUnderwriting",
  PROVIDER_KYB_TAB = "providerKYB",
  PROVIDER_APPROVED_TAB = "providerApproved",
  ACQUIRER_PROCESSING = "acquirerProcessing",
  ACQUIRER_MANAGE_MONEY = "acquirerMangeMoney",
  ACQUIRER_DISPUTES = "disputes",
  TRANSFERS = "transfers",
  MERCHANT_RISK_PANEL = "riskPanel",
  EVENT_TICKETS = "eventTickets",
  EVENT_TRANSACTIONS = "eventTransactions",
}
 
export const reduxFilterKeys = {
  [FilterPagesEnum.MANAGE_MONEY]: QKEY_MANAGE_MONEY_TRANSACTIONS_LIST,
  [FilterPagesEnum.PROVIDER_PROCESSING]: QKEY_PROVIDER_PROCESSING,
  [FilterPagesEnum.MERCHANT_ALL_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_RISK_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_KYB_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_UNDERWRITING_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_SPONSOR_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_APPROVED_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.MERCHANT_PENDING_TAB]: QKEY_LIST_ACQUIRER_MERCHANTS,
  [FilterPagesEnum.PROVIDER_ALL_TAB]: QKEY_LIST_ENTERPRISE_STATS,
  [FilterPagesEnum.PROVIDER_UNDERWRITING_TAB]: QKEY_LIST_ENTERPRISE_STATS,
  [FilterPagesEnum.PROVIDER_KYB_TAB]: QKEY_LIST_ENTERPRISE_STATS,
  [FilterPagesEnum.PROVIDER_APPROVED_TAB]: QKEY_LIST_ENTERPRISE_STATS,
  [FilterPagesEnum.ACQUIRER_PROCESSING]: QKEY_PROCESSING_LIST,
  [FilterPagesEnum.ACQUIRER_MANAGE_MONEY]:
    QKEY_ACQUIRER_MANAGE_MONEY_TRANSACTIONS_LIST,
  [FilterPagesEnum.ACQUIRER_DISPUTES]: DISPUTES_QUERY_KEY,
  [FilterPagesEnum.TRANSFERS]: TRANSFERS_QUERY_KEY,
  [FilterPagesEnum.MERCHANT_RISK_PANEL]: QKEY_RISK_MONITOR_TRANSACTIONS,
  [FilterPagesEnum.EVENT_TICKETS]: QKEY_EVENT_TICKETS,
  [FilterPagesEnum.EVENT_TRANSACTIONS]: QKEY_EVENT_TRANSACTIONS,
};
 
export type FilterPageValuesTYpes =
  (typeof FilterPagesEnum)[keyof typeof FilterPagesEnum];
 
const inFlow: CardProps = {
  title: "Credit",
  chips: generateFlowArray(),
  selected: "",
  apiKeyName: endpointNames.inFlow,
  type: CustomFilterType.amountRange,
};
 
const outFlow: CardProps = {
  title: "Debit",
  chips: generateFlowArray(),
  selected: "",
  apiKeyName: endpointNames.outFlow,
  type: CustomFilterType.amountRange,
};
 
const paymentMethod: CardProps = {
  title: "Payment Method",
  chips: paymentMethodChips,
  selected: "",
  apiKeyName: endpointNames.paymentMethod,
};
 
const cardInfoType: CardProps = {
  title: "Payment Method",
  chips: cardInfoTypeChips,
  selected: [],
  apiKeyName: endpointNames.cardInfoType,
};
 
const processedVolume: CardProps = {
  title: "Processed Volume",
  chips: createVolumeChips(),
  selected: "",
  apiKeyName: endpointNames.processedVolume, // TODO check right endpoint from backend
  type: CustomFilterType.amountRange,
};
 
const riskLevelChips = (opts?: { extraChips?: FilterChip[] }): CardProps => ({
  title: "Risk Level",
  chips: [
    ...riskLevel, // original default chips
    ...(opts?.extraChips ?? []), // optional extra chips
  ],
  selected: [],
  apiKeyName: endpointNames.riskLevelLabelDisplayName,
});
 
const minimalRiskLevelChips: CardProps = {
  title: "Risk Level",
  chips: minimalRiskLevel,
  selected: [],
  apiKeyName: endpointNames.riskLevel,
};
 
const riskStatusChips: CardProps = {
  title: "Risk Status",
  chips: riskStatus,
  selected: [],
  apiKeyName: endpointNames.riskStatusDisplayName,
};
 
const providerStatusChips: CardProps = {
  title: "Provider Status",
  chips: providerStatus,
  selected: [],
  apiKeyName: endpointNames.stateName,
};
 
const merchantStatusChips = ({
  hideClosed,
}: { hideClosed?: boolean } = {}): CardProps => ({
  title: "Merchant Status",
  chips: hideClosed
    ? merchantStatus.filter(({ value }) => value !== CLOSED_MERCHANT_STATUS)
    : merchantStatus,
  selected: [],
  apiKeyName: endpointNames.stateName,
});
 
const disputeAmountsRange: CardProps = {
  title: "Amount",
  chips: generateDisputeAmountArray(),
  selected: "",
  apiKeyName: endpointNames.disputeAmount,
  type: CustomFilterType.amountRange,
};
 
const businessClassificationTypeChips: CardProps = {
  title: "Business Classification Type",
  chips: businessClassificationType,
  selected: [],
  apiKeyName: endpointNames.className,
};
 
const transactionsCountChips: CardProps = {
  title: "Transactions",
  chips: transactionsCount,
  selected: "",
  apiKeyName: endpointNames.transactionsCount,
  type: CustomFilterType.numberRange,
};
 
const approvedMerchantsChips: CardProps = {
  title: "Approved Merchants",
  chips: approvedMerchantsCount,
  selected: "",
  apiKeyName: endpointNames.approvedSubmerchants,
  type: CustomFilterType.numberRange,
};
 
const watchlistOnly: CardProps = {
  toggleTitle: (
    <Stack direction="row" alignItems="center" gap="8px">
      <BookmarkSimpleIcon size={20} />
      <GiveText variant="bodyS">Watchlist Only</GiveText>
    </Stack>
  ),
  apiKeyName: endpointNames.watchlist,
};
 
const amountRange: CardProps = {
  title: "Amount",
  chips: generateAmountArray(),
  selected: "",
  apiKeyName: endpointNames.charged,
  type: CustomFilterType.amountRange,
};
 
const amountTransfersRange: CardProps = {
  title: "Transfer Amount",
  chips: generateAmountTransfersArray(),
  selected: "",
  apiKeyName: endpointNames.cost,
  type: CustomFilterType.amountRange,
};
 
const feeRange: CardProps = {
  title: "Fee",
  chips: generateFeeArray(),
  selected: "",
  apiKeyName: endpointNames.fees,
  type: CustomFilterType.amountRange,
};
 
const pendingTransactionMap = [
  "processing_issue",
  "captured",
  "created",
  "authorized",
];
 
const acquirerTransactionStatuses = ["Authorized", "Captured", "Created"];
 
/**
 * Not a server value: the merchant portal shows this label wherever the
 * transaction's display status is one of `acquirerTransactionStatuses`.
 */
const EVENT_TXN_PROCESSING = "Processing";
 
const transactionStatuses = [
  {
    label: "Captured",
    value: "purchase_captured",
    typeName: "purchase",
  },
  {
    label: "Created",
    value: "purchase_created",
    typeName: "purchase",
  },
  {
    label: "Declined",
    value: "purchase_declined",
    typeName: "purchase",
  },
  {
    label: "Processing Issue",
    value: "purchase_processing_issue",
    typeName: "purchase",
  },
  {
    label: "Settled",
    value: "purchase_settled",
    typeName: "purchase",
  },
  {
    label: "Voided",
    value: "purchase_voided",
    typeName: "purchase",
  },
  {
    label: "Refund Canceled",
    value: "refund_canceled",
    typeName: "refund",
  },
  {
    label: "Refund Created",
    value: "refund_created",
    typeName: "refund",
  },
  {
    label: "Refunded",
    value: "refund",
    typeName: "refund",
  },
  {
    label: "Refund Pending",
    value: "refund_pending",
    typeName: "refund",
  },
  {
    label: "Chargeback",
    value: "chargeback_settled",
    typeName: "chargeback",
  },
  {
    label: "Chargeback Reversal",
    value: "chargeback_reversal_settled",
    typeName: "chargeback_reversal",
  },
  {
    label: "Chargeback Refund",
    value: "pre_chargeback_refund_", //should return all of them regardless of processingState
    typeName: "pre_chargeback_refund",
  },
];
const transferStatuses = [
  {
    label: "Requested",
    value: "enqueued",
    typeName: "transfer",
  },
  {
    label: "Ready to Process",
    value: "approved",
    typeName: "transfer",
  },
  {
    label: "Sending",
    value: "processing",
    typeName: "transfer",
  },
  {
    label: "Sent",
    value: "settled",
    typeName: ["transfer", "reserve_deposit", "reserve_release"],
  },
  {
    label: "Error",
    value: "failed",
    typeName: "transfer",
  },
  {
    label: "Declined",
    value: "declined",
    typeName: "transfer",
  },
  {
    label: "Canceled",
    value: "canceled",
    typeName: "transfer",
  },
  {
    label: "Returned",
    value: "returned",
    typeName: "transfer",
  },
];
 
const emailStatus: CardProps = {
  title: "Email Status",
  chips: emailStatusChip,
  selected: [],
  apiKeyName: endpointNames.emailStatus,
};
 
//for merchant risk panel we use /transactions-minimal endpoint
//for now we cant filter by the transaction status logic
//probably in the future this will be refactored
const transactionMinimalStatusChips: FilterChip[] = [
  {
    label: "Created",
    value: "Created",
  },
  {
    label: "Processing Issue",
    value: "Processing Issue",
  },
  {
    label: "Captured",
    value: "Captured",
  },
  {
    label: "Declined",
    value: "Declined",
  },
  {
    label: "Settled",
    value: "Settled",
  },
  {
    label: "Voided",
    value: "Voided",
  },
  {
    label: "Refund Canceled",
    value: "Refund Canceled",
  },
  {
    label: "Refunded",
    value: "Refunded",
  },
  {
    label: "Refund Pending",
    value: "Refund Pending",
  },
  {
    label: "Chargeback",
    value: "Chargeback",
  },
  {
    label: "Refund Created",
    value: "Refund Created",
  },
  {
    label: "Chargeback Reversal",
    value: "Chargeback Reversal",
  },
];
const transactionMinimalStatus: CardProps = {
  title: "Transaction Status",
  chips: transactionMinimalStatusChips,
  selected: [],
  apiKeyName: endpointNames.txnDisplayStatus,
};
 
/**
 * Event Tickets tab — frame 7397-90376.
 *
 * Labels are the mockup's; values are `event_ticket_holders_view`'s own enums, so
 * the URL filter is just `status:"consumed"` with no mapping table. "Pending" is
 * `usable` (issued, not yet scanned) and "Do not admit" is `cancelled` — the
 * ticket status is the admit decision, which is why the reason lives in its own
 * section below. `expired` is deliberately not offered: the mockup has no chip
 * for it, and an unfiltered list still shows those tickets.
 */
const eventTicketStatusChips: FilterChip[] = [
  { label: "Checked-in", value: "consumed" },
  { label: "Pending", value: "usable" },
  { label: "Do not admit", value: "cancelled" },
];
 
const eventTicketStatus: CardProps = {
  title: "Check-in Status",
  chips: eventTicketStatusChips,
  selected: [],
  apiKeyName: endpointNames.ticketStatus,
};
 
/**
 * Why a do-not-admit ticket is invalid. Independent of the section above so
 * "every refunded ticket" is answerable without also picking Do not admit — the
 * server only sets `paymentStatus` on a cancelled ticket, so the two AND
 * harmlessly.
 */
const eventTicketReasonChips: FilterChip[] = [
  { label: "Voided", value: "voided" },
  { label: "Refunded", value: "refunded" },
  { label: "Chargeback", value: "chargeback" },
];
 
const eventTicketReason: CardProps = {
  title: "Reason (do not admit)",
  chips: eventTicketReasonChips,
  selected: [],
  apiKeyName: endpointNames.ticketPaymentStatus,
};
 
/**
 * Physical-ticket fulfilment (frame 7594-66313). Offered even for events without
 * printed tickets: every ticket carries a pickup state server-side, so the
 * section still filters correctly — the panel just has nothing interesting to
 * separate there. Gating it would mean threading the event's flag into the shared
 * filter machinery for one card.
 */
const eventTicketPickupChips: FilterChip[] = [
  { label: "Pending", value: "pending" },
  { label: "Collected", value: "collected" },
  { label: "Delivered", value: "delivered" },
];
 
const eventTicketPickup: CardProps = {
  title: "Ticket Picked Up",
  chips: eventTicketPickupChips,
  selected: [],
  apiKeyName: endpointNames.ticketPickupStatus,
};
 
/**
 * Event Detail Transactions tab (frame 7397-80180). Values are the API's own
 * `DisplayStatus` strings, so they go straight into the filter — except
 * "Processing", which has no server-side equivalent: it is the label the MERCHANT
 * portal shows for Authorized / Captured / Created (see `getDisplayStatusPortal`,
 * which collapses `acquirerTransactionStatuses` to it). Selecting it therefore
 * has to expand to those three — {@link expandEventTxnStatuses}.
 *
 * "Authorized" is listed separately because the mockup lists it; in this portal it
 * is a subset of Processing, so its rows still read "Processing" in the table.
 */
const eventTransactionStatusChips: FilterChip[] = [
  { label: "Processing", value: EVENT_TXN_PROCESSING },
  { label: "Settled", value: "Settled" },
  { label: "Authorized", value: "Authorized" },
  { label: "Declined", value: "Declined" },
  { label: "Voided", value: "Voided" },
  { label: "Chargeback", value: "Chargeback" },
  { label: "Chargeback Reversal", value: "Chargeback Reversal" },
  { label: "Refunded", value: "Refunded" },
  { label: "Chargeback Refund", value: "Chargeback Refund" },
];
 
const eventTransactionStatus: CardProps = {
  title: "Transaction Status",
  chips: eventTransactionStatusChips,
  selected: [],
  apiKeyName: endpointNames.eventTxnStatus,
};
 
/**
 * Replaces the portal-only "Processing" pseudo-status with the display statuses
 * it stands for, leaving every other selection alone. Duplicates are dropped so
 * picking Processing AND Authorized doesn't emit the same clause twice.
 */
const expandEventTxnStatuses = (statuses?: string[]) => {
  if (!statuses?.length) return [];
  const expanded = statuses.flatMap((status) =>
    status === EVENT_TXN_PROCESSING ? acquirerTransactionStatuses : [status],
  );
  return Array.from(new Set(expanded));
};
 
export {
  getTransactionDateChips,
  transactionStatusChips,
  transferStatusChips,
  paymentMethodChips,
  riskLevelChips,
  inFlow,
  outFlow,
  paymentMethod,
  cardInfoType,
  FilterPagesEnum,
  endpointNames,
  TRANSACTION_TRANSFER,
  TRANSFER_RETURN_TYPE,
  TRANSFERS_TAB_BASE_TYPES,
  inflowOutFlowApiKey,
  watchlistOnly,
  processedVolume,
  pendingTransactionMap,
  acquirerTransactionStatuses,
  providerStatusChips,
  businessClassificationTypeChips,
  transactionsCountChips,
  approvedMerchantsChips,
  transactionStatuses,
  transferStatuses,
  amountRange,
  amountTransfersRange,
  feeRange,
  merchantStatusChips,
  riskStatusChips,
  disputeAmountsRange,
  disputeStatusChips,
  emailStatus,
  minimalRiskLevelChips,
  transactionMinimalStatus,
  eventTicketStatus,
  eventTicketReason,
  eventTicketPickup,
  eventTransactionStatus,
  expandEventTxnStatuses,
  ticketApiKeys,
};
 
export const FILTER_PANEL_WIDTH = 500;