package com.pichillilorenzo.flutter_inappwebview_android.webview.web_message;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bytedance.sdk.component.pglcrypt.PglCryptUtils;
import com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.WebMessageCompatExt;
import com.pichillilorenzo.flutter_inappwebview_android.webview.in_app_webview.InAppWebView;
import ed.q;
import ed.t;
import ed.u;
import java.util.HashMap;
import java.util.Map;

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

    @Nullable
    private WebMessageChannel webMessageChannel;

    public WebMessageChannelChannelDelegate(@NonNull WebMessageChannel webMessageChannel, @NonNull u uVar) {
        super(uVar);
        this.webMessageChannel = webMessageChannel;
    }

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

    public void onMessage(int i10, @Nullable WebMessageCompatExt webMessageCompatExt) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("index", Integer.valueOf(i10));
        map.put(PglCryptUtils.KEY_MESSAGE, webMessageCompatExt != null ? webMessageCompatExt.toMap() : null);
        channel.invokeMethod("onMessage", 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) {
        String str = qVar.f25842a;
        str.getClass();
        switch (str) {
            case "close":
                WebMessageChannel webMessageChannel = this.webMessageChannel;
                if (webMessageChannel != null && (webMessageChannel.webView instanceof InAppWebView)) {
                    this.webMessageChannel.closeForInAppWebView((Integer) qVar.argument("index"), tVar);
                    break;
                } else {
                    tVar.success(Boolean.FALSE);
                    break;
                }
                break;
            case "setWebMessageCallback":
                WebMessageChannel webMessageChannel2 = this.webMessageChannel;
                if (webMessageChannel2 != null && (webMessageChannel2.webView instanceof InAppWebView)) {
                    this.webMessageChannel.setWebMessageCallbackForInAppWebView(((Integer) qVar.argument("index")).intValue(), tVar);
                    break;
                } else {
                    tVar.success(Boolean.FALSE);
                    break;
                }
                break;
            case "postMessage":
                WebMessageChannel webMessageChannel3 = this.webMessageChannel;
                if (webMessageChannel3 != null && (webMessageChannel3.webView instanceof InAppWebView)) {
                    this.webMessageChannel.postMessageForInAppWebView((Integer) qVar.argument("index"), WebMessageCompatExt.fromMap((Map) qVar.argument(PglCryptUtils.KEY_MESSAGE)), tVar);
                    break;
                } else {
                    tVar.success(Boolean.FALSE);
                    break;
                }
                break;
            default:
                tVar.notImplemented();
                break;
        }
    }
}
