package com.google.android.gms.internal.ads;

import android.app.Activity;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import androidx.media3.exoplayer.upstream.CmcdData;
import java.util.Collections;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class bt implements ys {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Map f9652d;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final m7.b f9653a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ux f9654b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final zx f9655c;

    static {
        String[] strArr = {"resize", "playVideo", "storePicture", "createCalendarEvent", "setOrientationProperties", "closeResizedAd", "unload"};
        Integer[] numArr = {1, 2, 3, 4, 5, 6, 7};
        androidx.collection.f fVar = new androidx.collection.f(7);
        for (int i10 = 0; i10 < 7; i10++) {
            fVar.put(strArr[i10], numArr[i10]);
        }
        f9652d = Collections.unmodifiableMap(fVar);
    }

    public bt(m7.b bVar, ux uxVar, zx zxVar) {
        this.f9653a = bVar;
        this.f9654b = uxVar;
        this.f9655c = zxVar;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:109:0x01f5  */
    /* JADX WARN: Removed duplicated region for block: B:155:0x02e3 A[Catch: all -> 0x0070, TryCatch #0 {all -> 0x0070, RuntimeException -> 0x04de, blocks: (B:25:0x0064, B:27:0x0068, B:28:0x006d, B:32:0x0073, B:34:0x007b, B:35:0x0080, B:37:0x0083, B:39:0x008d, B:40:0x0092, B:42:0x0095, B:44:0x009b, B:45:0x00a0, B:47:0x00a3, B:49:0x00b1, B:50:0x00c3, B:52:0x00d1, B:53:0x00e3, B:55:0x00f1, B:56:0x0103, B:58:0x0111, B:59:0x0123, B:61:0x0131, B:62:0x013f, B:64:0x014d, B:65:0x014f, B:67:0x0153, B:69:0x0157, B:71:0x015d, B:74:0x0165, B:78:0x0197, B:84:0x01a3, B:155:0x02e3, B:156:0x02e8, B:158:0x02eb, B:160:0x0314, B:162:0x0320, B:164:0x0355, B:195:0x040e, B:202:0x0441, B:203:0x0459, B:204:0x0480, B:206:0x0488, B:207:0x0495, B:208:0x04b1, B:209:0x04d7, B:210:0x04dc, B:213:0x04df, B:215:0x050d, B:216:0x051f, B:196:0x0415, B:197:0x041c, B:198:0x0425, B:199:0x042c, B:200:0x0432, B:201:0x043b, B:163:0x0352, B:218:0x0521, B:219:0x0526, B:86:0x01ab, B:88:0x01af, B:119:0x0205, B:120:0x020f, B:129:0x0262, B:131:0x0267, B:133:0x026c, B:136:0x0273, B:121:0x0213, B:122:0x021d, B:123:0x0224, B:124:0x0230, B:125:0x0238, B:126:0x024c, B:127:0x0258, B:137:0x0285, B:145:0x02be, B:151:0x02ce, B:148:0x02c4, B:150:0x02cc, B:141:0x02b4, B:143:0x02ba, B:152:0x02d3, B:153:0x02da, B:221:0x0528, B:222:0x052d, B:224:0x052f, B:225:0x0534), top: B:251:0x0064 }] */
    /* JADX WARN: Removed duplicated region for block: B:158:0x02eb A[Catch: all -> 0x0070, TryCatch #0 {all -> 0x0070, RuntimeException -> 0x04de, blocks: (B:25:0x0064, B:27:0x0068, B:28:0x006d, B:32:0x0073, B:34:0x007b, B:35:0x0080, B:37:0x0083, B:39:0x008d, B:40:0x0092, B:42:0x0095, B:44:0x009b, B:45:0x00a0, B:47:0x00a3, B:49:0x00b1, B:50:0x00c3, B:52:0x00d1, B:53:0x00e3, B:55:0x00f1, B:56:0x0103, B:58:0x0111, B:59:0x0123, B:61:0x0131, B:62:0x013f, B:64:0x014d, B:65:0x014f, B:67:0x0153, B:69:0x0157, B:71:0x015d, B:74:0x0165, B:78:0x0197, B:84:0x01a3, B:155:0x02e3, B:156:0x02e8, B:158:0x02eb, B:160:0x0314, B:162:0x0320, B:164:0x0355, B:195:0x040e, B:202:0x0441, B:203:0x0459, B:204:0x0480, B:206:0x0488, B:207:0x0495, B:208:0x04b1, B:209:0x04d7, B:210:0x04dc, B:213:0x04df, B:215:0x050d, B:216:0x051f, B:196:0x0415, B:197:0x041c, B:198:0x0425, B:199:0x042c, B:200:0x0432, B:201:0x043b, B:163:0x0352, B:218:0x0521, B:219:0x0526, B:86:0x01ab, B:88:0x01af, B:119:0x0205, B:120:0x020f, B:129:0x0262, B:131:0x0267, B:133:0x026c, B:136:0x0273, B:121:0x0213, B:122:0x021d, B:123:0x0224, B:124:0x0230, B:125:0x0238, B:126:0x024c, B:127:0x0258, B:137:0x0285, B:145:0x02be, B:151:0x02ce, B:148:0x02c4, B:150:0x02cc, B:141:0x02b4, B:143:0x02ba, B:152:0x02d3, B:153:0x02da, B:221:0x0528, B:222:0x052d, B:224:0x052f, B:225:0x0534), top: B:251:0x0064 }] */
    @Override // com.google.android.gms.internal.ads.ys
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(Object obj, Map map) {
        int[] iArr;
        int i10;
        byte b10;
        int i11;
        int i12;
        int i13;
        int i14;
        x50 x50Var = (x50) obj;
        int iIntValue = ((Integer) f9652d.get((String) map.get(CmcdData.OBJECT_TYPE_AUDIO_ONLY))).intValue();
        if (iIntValue != 5) {
            if (iIntValue != 7) {
                m7.b bVar = this.f9653a;
                if (!bVar.a()) {
                    bVar.zzc(null);
                    return;
                }
                if (iIntValue == 1) {
                    ux uxVar = this.f9654b;
                    synchronized (uxVar.f17418l) {
                        try {
                            Activity activity = uxVar.Q;
                            if (activity == null) {
                                uxVar.c("Not an activity context. Cannot resize.");
                                return;
                            }
                            x50 x50Var2 = uxVar.f17419m;
                            if (x50Var2.zzN() == null) {
                                uxVar.c("Webview is not yet available, size is not set.");
                                return;
                            }
                            if (x50Var2.zzN().b()) {
                                uxVar.c("Is interstitial. Cannot resize an interstitial.");
                                return;
                            }
                            if (x50Var2.y()) {
                                uxVar.c("Cannot resize an expanded banner.");
                                return;
                            }
                            if (!TextUtils.isEmpty((CharSequence) map.get("width"))) {
                                p7.r0 r0Var = m7.n.C.f30464c;
                                uxVar.f17417k = p7.r0.l((String) map.get("width"));
                            }
                            if (!TextUtils.isEmpty((CharSequence) map.get("height"))) {
                                p7.r0 r0Var2 = m7.n.C.f30464c;
                                uxVar.f17414h = p7.r0.l((String) map.get("height"));
                            }
                            if (!TextUtils.isEmpty((CharSequence) map.get("offsetX"))) {
                                p7.r0 r0Var3 = m7.n.C.f30464c;
                                uxVar.f17415i = p7.r0.l((String) map.get("offsetX"));
                            }
                            if (!TextUtils.isEmpty((CharSequence) map.get("offsetY"))) {
                                p7.r0 r0Var4 = m7.n.C.f30464c;
                                uxVar.f17416j = p7.r0.l((String) map.get("offsetY"));
                            }
                            if (!TextUtils.isEmpty((CharSequence) map.get("allowOffscreen"))) {
                                uxVar.f17411e = Boolean.parseBoolean((String) map.get("allowOffscreen"));
                            }
                            String str = (String) map.get("customClosePosition");
                            if (!TextUtils.isEmpty(str)) {
                                uxVar.f17410d = str;
                            }
                            if (uxVar.f17417k < 0 || uxVar.f17414h < 0) {
                                uxVar.c("Invalid width and height options. Cannot resize.");
                                return;
                            }
                            Window window = activity.getWindow();
                            if (window != null && window.getDecorView() != null) {
                                p7.r0 r0Var5 = m7.n.C.f30464c;
                                int[] iArrM = p7.r0.m(activity);
                                n7.x xVar = n7.x.f31085g;
                                int[] iArr2 = {xVar.f31086a.b(activity, iArrM[0]), xVar.f31086a.b(activity, iArrM[1])};
                                int[] iArrN = p7.r0.n(activity);
                                int i15 = iArr2[0];
                                int i16 = iArr2[1];
                                int i17 = uxVar.f17417k;
                                if (i17 < 50 || i17 > i15) {
                                    q7.j.d("Width is too small or too large.");
                                } else {
                                    int i18 = uxVar.f17414h;
                                    if (i18 < 50 || i18 > i16) {
                                        q7.j.d("Height is too small or too large.");
                                    } else {
                                        if (i18 != i16 || i17 != i15) {
                                            if (uxVar.f17411e) {
                                                String str2 = uxVar.f17410d;
                                                switch (str2.hashCode()) {
                                                    case -1364013995:
                                                        b10 = !str2.equals("center") ? (byte) -1 : (byte) 2;
                                                        break;
                                                    case -1012429441:
                                                        if (str2.equals("top-left")) {
                                                            b10 = 0;
                                                            break;
                                                        }
                                                        break;
                                                    case -655373719:
                                                        if (str2.equals("bottom-left")) {
                                                            b10 = 3;
                                                            break;
                                                        }
                                                        break;
                                                    case 1163912186:
                                                        if (str2.equals("bottom-right")) {
                                                            b10 = 5;
                                                            break;
                                                        }
                                                        break;
                                                    case 1288627767:
                                                        if (str2.equals("bottom-center")) {
                                                            b10 = 4;
                                                            break;
                                                        }
                                                        break;
                                                    case 1755462605:
                                                        if (str2.equals("top-center")) {
                                                            b10 = 1;
                                                            break;
                                                        }
                                                        break;
                                                }
                                                if (b10 == 0) {
                                                    i11 = uxVar.f17415i + uxVar.f17412f;
                                                    i12 = uxVar.f17413g;
                                                } else if (b10 != 1) {
                                                    if (b10 != 2) {
                                                        if (b10 == 3) {
                                                            i11 = uxVar.f17415i + uxVar.f17412f;
                                                            i14 = uxVar.f17413g;
                                                        } else if (b10 == 4) {
                                                            i11 = ((uxVar.f17412f + uxVar.f17415i) + (i17 >> 1)) - 25;
                                                            i14 = uxVar.f17413g;
                                                        } else if (b10 != 5) {
                                                            i11 = ((uxVar.f17412f + uxVar.f17415i) + i17) - 50;
                                                            i12 = uxVar.f17413g;
                                                        } else {
                                                            i11 = ((uxVar.f17412f + uxVar.f17415i) + i17) - 50;
                                                            i14 = uxVar.f17413g;
                                                        }
                                                        i13 = ((i14 + uxVar.f17416j) + i18) - 50;
                                                    } else {
                                                        i11 = ((uxVar.f17412f + uxVar.f17415i) + (i17 >> 1)) - 25;
                                                        i13 = ((uxVar.f17413g + uxVar.f17416j) + (i18 >> 1)) - 25;
                                                    }
                                                    if (i11 < 0 && i11 + 50 <= i15 && i13 >= iArrN[0] && i13 + 50 <= iArrN[1]) {
                                                        iArr = new int[]{uxVar.f17412f + uxVar.f17415i, uxVar.f17413g + uxVar.f17416j};
                                                    }
                                                } else {
                                                    i11 = ((uxVar.f17412f + uxVar.f17415i) + (i17 >> 1)) - 25;
                                                    i12 = uxVar.f17413g;
                                                }
                                                i13 = i12 + uxVar.f17416j;
                                                if (i11 < 0) {
                                                }
                                            } else {
                                                int[] iArrM2 = p7.r0.m(activity);
                                                int[] iArr3 = {xVar.f31086a.b(activity, iArrM2[0]), xVar.f31086a.b(activity, iArrM2[1])};
                                                int[] iArrN2 = p7.r0.n(activity);
                                                int i19 = iArr3[0];
                                                int i20 = uxVar.f17412f + uxVar.f17415i;
                                                int i21 = uxVar.f17413g + uxVar.f17416j;
                                                if (i20 < 0) {
                                                    i10 = 0;
                                                } else {
                                                    int i22 = uxVar.f17417k;
                                                    i10 = i20 + i22 > i19 ? i19 - i22 : i20;
                                                }
                                                int i23 = iArrN2[0];
                                                if (i21 < i23) {
                                                    i21 = i23;
                                                } else {
                                                    int i24 = uxVar.f17414h;
                                                    int i25 = i21 + i24;
                                                    int i26 = iArrN2[1];
                                                    if (i25 > i26) {
                                                        i21 = i26 - i24;
                                                    }
                                                }
                                                iArr = new int[]{i10, i21};
                                            }
                                            if (iArr != null) {
                                                uxVar.c("Resize location out of screen or close button is not visible.");
                                                return;
                                            }
                                            q7.e eVar = xVar.f31086a;
                                            int iG = q7.e.g(activity.getResources().getDisplayMetrics(), uxVar.f17417k);
                                            int iG2 = q7.e.g(activity.getResources().getDisplayMetrics(), uxVar.f17414h);
                                            ViewParent parent = ((View) x50Var2).getParent();
                                            if (!(parent instanceof ViewGroup)) {
                                                uxVar.c("Webview is detached, probably in the middle of a resize or expand.");
                                                return;
                                            }
                                            ViewGroup viewGroup = (ViewGroup) parent;
                                            viewGroup.removeView((View) x50Var2);
                                            PopupWindow popupWindow = uxVar.V;
                                            if (popupWindow == null) {
                                                uxVar.X = viewGroup;
                                                ((View) x50Var2).setDrawingCacheEnabled(true);
                                                Bitmap bitmapCreateBitmap = Bitmap.createBitmap(((View) x50Var2).getDrawingCache());
                                                ((View) x50Var2).setDrawingCacheEnabled(false);
                                                ImageView imageView = new ImageView(activity);
                                                uxVar.S = imageView;
                                                imageView.setImageBitmap(bitmapCreateBitmap);
                                                uxVar.R = x50Var2.zzN();
                                                uxVar.X.addView(uxVar.S);
                                            } else {
                                                popupWindow.dismiss();
                                            }
                                            RelativeLayout relativeLayout = new RelativeLayout(activity);
                                            uxVar.W = relativeLayout;
                                            relativeLayout.setBackgroundColor(0);
                                            uxVar.W.setLayoutParams(new ViewGroup.LayoutParams(iG, iG2));
                                            PopupWindow popupWindow2 = new PopupWindow((View) uxVar.W, iG, iG2, false);
                                            uxVar.V = popupWindow2;
                                            popupWindow2.setOutsideTouchable(false);
                                            uxVar.V.setTouchable(true);
                                            uxVar.V.setClippingEnabled(!uxVar.f17411e);
                                            byte b11 = -1;
                                            uxVar.W.addView((View) x50Var2, -1, -1);
                                            uxVar.T = new LinearLayout(activity);
                                            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(q7.e.g(activity.getResources().getDisplayMetrics(), 50), q7.e.g(activity.getResources().getDisplayMetrics(), 50));
                                            String str3 = uxVar.f17410d;
                                            switch (str3.hashCode()) {
                                                case -1364013995:
                                                    if (str3.equals("center")) {
                                                        b11 = 2;
                                                    }
                                                    break;
                                                case -1012429441:
                                                    if (str3.equals("top-left")) {
                                                        b11 = 0;
                                                    }
                                                    break;
                                                case -655373719:
                                                    if (str3.equals("bottom-left")) {
                                                        b11 = 3;
                                                    }
                                                    break;
                                                case 1163912186:
                                                    if (str3.equals("bottom-right")) {
                                                        b11 = 5;
                                                    }
                                                    break;
                                                case 1288627767:
                                                    if (str3.equals("bottom-center")) {
                                                        b11 = 4;
                                                    }
                                                    break;
                                                case 1755462605:
                                                    if (str3.equals("top-center")) {
                                                        b11 = 1;
                                                    }
                                                    break;
                                            }
                                            if (b11 == 0) {
                                                layoutParams.addRule(10);
                                                layoutParams.addRule(9);
                                            } else if (b11 == 1) {
                                                layoutParams.addRule(10);
                                                layoutParams.addRule(14);
                                            } else if (b11 == 2) {
                                                layoutParams.addRule(13);
                                            } else if (b11 == 3) {
                                                layoutParams.addRule(12);
                                                layoutParams.addRule(9);
                                            } else if (b11 == 4) {
                                                layoutParams.addRule(12);
                                                layoutParams.addRule(14);
                                            } else if (b11 != 5) {
                                                layoutParams.addRule(10);
                                                layoutParams.addRule(11);
                                            } else {
                                                layoutParams.addRule(12);
                                                layoutParams.addRule(11);
                                            }
                                            uxVar.T.setOnClickListener(new tx(uxVar));
                                            uxVar.T.setContentDescription("Close button");
                                            uxVar.W.addView(uxVar.T, layoutParams);
                                            uxVar.V.showAtLocation(window.getDecorView(), 0, q7.e.g(activity.getResources().getDisplayMetrics(), iArr[0]), q7.e.g(activity.getResources().getDisplayMetrics(), iArr[1]));
                                            int i27 = iArr[0];
                                            int i28 = iArr[1];
                                            zx zxVar = uxVar.U;
                                            if (zxVar != null) {
                                                ((aq0) ((dh0) zxVar).f10402b).f9220c.H0(mf0.f14099a);
                                            }
                                            uxVar.f17419m.G(new d70(1, iG, iG2));
                                            try {
                                                ((x50) uxVar.f19404b).e("onSizeChanged", new JSONObject().put("x", iArr[0]).put("y", iArr[1] - p7.r0.n(uxVar.Q)[0]).put("width", uxVar.f17417k).put("height", uxVar.f17414h));
                                            } catch (JSONException unused) {
                                            }
                                            uxVar.h("resized");
                                            return;
                                        }
                                        q7.j.d("Cannot resize to a full-screen ad.");
                                    }
                                }
                                iArr = null;
                                if (iArr != null) {
                                }
                            }
                            uxVar.c("Activity context is not ready, cannot get window or decor view.");
                            return;
                        } catch (RuntimeException e10) {
                            String message = e10.getMessage();
                            StringBuilder sb = new StringBuilder(String.valueOf(message).length() + 26);
                            sb.append("Cannot show popup window: ");
                            sb.append(message);
                            uxVar.c(sb.toString());
                            RelativeLayout relativeLayout2 = uxVar.W;
                            x50 x50Var3 = uxVar.f17419m;
                            relativeLayout2.removeView((View) x50Var3);
                            ViewGroup viewGroup2 = uxVar.X;
                            if (viewGroup2 != null) {
                                viewGroup2.removeView(uxVar.S);
                                uxVar.X.addView((View) x50Var3);
                                x50Var3.G(uxVar.R);
                            }
                            return;
                        } finally {
                        }
                    }
                }
                if (iIntValue == 3) {
                    new wx(x50Var, map).mo5zza();
                    return;
                }
                if (iIntValue == 4) {
                    new sx(x50Var, map).mo5zza();
                    return;
                } else if (iIntValue != 5) {
                    if (iIntValue == 6) {
                        this.f9654b.j(true);
                        return;
                    } else if (iIntValue != 7) {
                        q7.j.c("Unknown MRAID command called.");
                        return;
                    }
                }
            }
            ((dh0) this.f9655c).zzc();
            return;
        }
        String str4 = (String) map.get("forceOrientation");
        boolean z10 = map.containsKey("allowOrientationChange") ? Boolean.parseBoolean((String) map.get("allowOrientationChange")) : true;
        if (x50Var == null) {
            q7.j.d("AdWebView is null");
        } else {
            x50Var.C("portrait".equalsIgnoreCase(str4) ? 7 : "landscape".equalsIgnoreCase(str4) ? 6 : z10 ? -1 : 14);
        }
    }
}
