package com.pichillilorenzo.flutter_inappwebview_android.find_interaction;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.internal.u1;
import com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.FindSession;
import ed.q;
import ed.t;
import ed.u;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
public class FindInteractionChannelDelegate extends ChannelDelegateImpl {

    @Nullable
    private FindInteractionController findInteractionController;

    public FindInteractionChannelDelegate(@NonNull FindInteractionController findInteractionController, @NonNull u uVar) {
        super(uVar);
        this.findInteractionController = findInteractionController;
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        super.dispose();
        this.findInteractionController = null;
    }

    public void onFindResultReceived(int i10, int i11, boolean z10) {
        FindInteractionController findInteractionController;
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        if (z10 && (findInteractionController = this.findInteractionController) != null && findInteractionController.webView != null) {
            findInteractionController.activeFindSession = new FindSession(i11, i10);
        }
        HashMap map = new HashMap();
        u1.t(i10, map, "activeMatchOrdinal", i11, "numberOfMatches");
        map.put("isDoneCounting", Boolean.valueOf(z10));
        channel.invokeMethod("onFindResultReceived", map);
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.IChannelDelegate, ed.s
    public void onMethodCall(@NonNull q qVar, @NonNull t tVar) {
        FindSession findSession;
        String str = qVar.f25842a;
        str.getClass();
        switch (str) {
            case "getSearchText":
                FindInteractionController findInteractionController = this.findInteractionController;
                if (findInteractionController == null) {
                    tVar.success(Boolean.FALSE);
                    break;
                } else {
                    tVar.success(findInteractionController.searchText);
                    break;
                }
                break;
            case "findAll":
                if (this.findInteractionController != null) {
                    this.findInteractionController.findAll((String) qVar.argument("find"));
                }
                tVar.success(Boolean.TRUE);
                break;
            case "findNext":
                if (this.findInteractionController != null) {
                    this.findInteractionController.findNext(((Boolean) qVar.argument("forward")).booleanValue());
                }
                tVar.success(Boolean.TRUE);
                break;
            case "setSearchText":
                FindInteractionController findInteractionController2 = this.findInteractionController;
                if (findInteractionController2 == null) {
                    tVar.success(Boolean.FALSE);
                    break;
                } else {
                    findInteractionController2.searchText = (String) qVar.argument("searchText");
                    tVar.success(Boolean.TRUE);
                    break;
                }
                break;
            case "clearMatches":
                FindInteractionController findInteractionController3 = this.findInteractionController;
                if (findInteractionController3 != null) {
                    findInteractionController3.clearMatches();
                }
                tVar.success(Boolean.TRUE);
                break;
            case "getActiveFindSession":
                FindInteractionController findInteractionController4 = this.findInteractionController;
                if (findInteractionController4 != null && (findSession = findInteractionController4.activeFindSession) != null) {
                    tVar.success(findSession.toMap());
                    break;
                } else {
                    tVar.success(null);
                    break;
                }
                break;
            default:
                tVar.notImplemented();
                break;
        }
    }
}
