/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.desktop.main.disputes.arbitrator;

import bisq.desktop.common.view.FxmlView;
import bisq.desktop.main.disputes.trader.TraderDisputeView;
import bisq.desktop.main.overlays.windows.ContractWindow;
import bisq.desktop.main.overlays.windows.DisputeSummaryWindow;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;

import bisq.core.alert.PrivateNotificationManager;
import bisq.core.app.AppOptionKeys;
import bisq.core.arbitration.DisputeManager;
import bisq.core.trade.TradeManager;
import bisq.core.util.BSFormatter;

import bisq.network.p2p.P2PService;

import bisq.common.crypto.KeyRing;

import com.google.inject.name.Named;

import javax.inject.Inject;

@FxmlView
public class ArbitratorDisputeView extends TraderDisputeView {

    @Inject
    public ArbitratorDisputeView(DisputeManager disputeManager, KeyRing keyRing, TradeManager tradeManager,
                                 BSFormatter formatter, DisputeSummaryWindow disputeSummaryWindow,
                                 PrivateNotificationManager privateNotificationManager,
                                 ContractWindow contractWindow, TradeDetailsWindow tradeDetailsWindow,
                                 P2PService p2PService, @Named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
        super(disputeManager, keyRing, tradeManager, formatter,
                disputeSummaryWindow, privateNotificationManager, contractWindow,
                tradeDetailsWindow, p2PService, useDevPrivilegeKeys);
    }

    @Override
    public void initialize() {
        super.initialize();

        filterBox.setVisible(true);
        filterBox.setManaged(true);
    }

    @Override
    protected void applyFilteredListPredicate(String filterString) {
        // If in arbitrator view we must only display disputes where we are selected as arbitrator (must not receive others anyway)
        filteredList.setPredicate(dispute ->
                dispute.getArbitratorPubKeyRing().equals(keyRing.getPubKeyRing()) &&
                        (filterString.isEmpty() ||
                                (dispute.getId().contains(filterString) ||
                                        (!dispute.isClosed() && filterString.toLowerCase().equals("open")) ||
                                        formatter.formatDate(dispute.getOpeningDate()).contains(filterString)) ||
                                getBuyerOnionAddressColumnLabel(dispute).contains(filterString) ||
                                getSellerOnionAddressColumnLabel(dispute).contains(filterString)

                        ));
    }

}



@@ -2606,16 +2606,18 @@
 spute -%3E
+ %7B
 %0A       
@@ -2625,172 +2625,257 @@
     
-    dispute.getArbitratorPubKeyRing().equals(keyRing.getPubKeyRing()) &&%0A                        (filterString.isEmpty() %7C%7C%0A                                
+boolean matchesTradeId = dispute.getTradeId().contains(filterString);%0A            boolean matchesDate = formatter.formatDate(dispute.getOpeningDate()).contains(filterString);%0A            boolean isBuyerOnion = getBuyerOnionAddressColumnLabel
 (dispute
 .get
@@ -2874,15 +2874,8 @@
 pute
-.getId(
 ).co
@@ -2886,37 +2886,34 @@
 ns(filterString)
- %7C%7C%0A 
+;%0A
                 
@@ -2912,191 +2912,379 @@
     
-                           (!dispute.isClosed() && filterString.toLowerCase().equals(%22open%22)) %7C%7C%0A                                        formatter.formatDate(dispute.getOpeningDate
+boolean isSellerOnion = getSellerOnionAddressColumnLabel(dispute).contains(filterString);%0A            boolean matchesBuyersPaymentAccountData = dispute.getContract().getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);%0A            boolean matchesSellersPaymentAccountData = dispute.getContract().getSellerPaymentAccountPayload().getPaymentDetails
 ()
-)
 .con
@@ -3302,20 +3302,18 @@
 rString)
-) %7C%7C
+;%0A
 %0A       
@@ -3321,218 +3321,460 @@
     
-                    getBuyerOnionAddressColumnLabel(dispute).contains(filterString) %7C%7C%0A                                getSellerOnionAddressColumnLabel(dispute).contains(filterString)%0A%0A                   
+boolean anyMatch = matchesTradeId %7C%7C matchesDate %7C%7C isBuyerOnion %7C%7C isSellerOnion %7C%7C%0A                    matchesBuyersPaymentAccountData %7C%7C matchesSellersPaymentAccountData;%0A%0A            boolean open = !dispute.isClosed() && filterString.toLowerCase().equals(%22open%22);%0A            boolean isMyCase = dispute.getArbitratorPubKeyRing().equals(keyRing.getPubKeyRing());%0A            return isMyCase && (open %7C%7C filterString.isEmpty() %7C%7C anyMatch);%0A
      
-)
+   %7D
 );%0A 

Improve filter