package Z0;

import C0.O;
import K.C0463l;
import K.C0490z;
import T0.L;
import T0.N;
import android.graphics.Rect;
import android.view.Choreographer;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.compose.runtime.collection.MutableVector;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import o0.C2632c;

/* JADX INFO: loaded from: classes.dex */
public final class B implements t {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final View f9053a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C4.f f9054b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f9056d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public J4.c f9057e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public J4.c f9058f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public y f9059g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public k f9060h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final ArrayList f9061i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Object f9062j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public Rect f9063k;
    public final C0862c l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final MutableVector f9064m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public F1.r f9065n;

    public B(View view, J0.A a6) {
        C4.f fVar = new C4.f(view);
        C c6 = new C(Choreographer.getInstance(), 0);
        this.f9053a = view;
        this.f9054b = fVar;
        this.f9055c = c6;
        this.f9057e = C0861b.f9078d;
        this.f9058f = C0861b.f9079e;
        this.f9059g = new y("", N.f6481b, 4);
        this.f9060h = k.f9110g;
        this.f9061i = new ArrayList();
        this.f9062j = m1.g.j(w4.i.f25467c, new B0.b(this, 11));
        this.l = new C0862c(a6, fVar);
        this.f9064m = new MutableVector(new A[16], 0);
    }

    @Override // Z0.t
    public final void a(y yVar, k kVar, C0463l c0463l, C0490z c0490z) {
        this.f9056d = true;
        this.f9059g = yVar;
        this.f9060h = kVar;
        this.f9057e = c0463l;
        this.f9058f = c0490z;
        i(A.f9048a);
    }

    @Override // Z0.t
    public final void b(C2632c c2632c) {
        Rect rect;
        this.f9063k = new Rect(L4.a.d0(c2632c.f21787a), L4.a.d0(c2632c.f21788b), L4.a.d0(c2632c.f21789c), L4.a.d0(c2632c.f21790d));
        if (!this.f9061i.isEmpty() || (rect = this.f9063k) == null) {
            return;
        }
        this.f9053a.requestRectangleOnScreen(new Rect(rect));
    }

    @Override // Z0.t
    public final void c() {
        i(A.f9048a);
    }

    @Override // Z0.t
    public final void d() {
        i(A.f9050c);
    }

    /* JADX WARN: Type inference failed for: r12v14, types: [java.lang.Object, w4.h] */
    /* JADX WARN: Type inference failed for: r12v22, types: [java.lang.Object, w4.h] */
    /* JADX WARN: Type inference failed for: r12v8, types: [java.lang.Object, w4.h] */
    /* JADX WARN: Type inference failed for: r5v3, types: [java.lang.Object, w4.h] */
    @Override // Z0.t
    public final void e(y yVar, y yVar2) {
        boolean z6 = (N.b(this.f9059g.f9137b, yVar2.f9137b) && kotlin.jvm.internal.o.c(this.f9059g.f9138c, yVar2.f9138c)) ? false : true;
        this.f9059g = yVar2;
        int size = this.f9061i.size();
        for (int i6 = 0; i6 < size; i6++) {
            u uVar = (u) ((WeakReference) this.f9061i.get(i6)).get();
            if (uVar != null) {
                uVar.f9124d = yVar2;
            }
        }
        C0862c c0862c = this.l;
        synchronized (c0862c.f9085c) {
            c0862c.f9092j = null;
            c0862c.l = null;
            c0862c.f9093k = null;
            c0862c.f9094m = C0861b.f9076b;
            c0862c.f9095n = null;
            c0862c.f9096o = null;
        }
        if (kotlin.jvm.internal.o.c(yVar, yVar2)) {
            if (z6) {
                C4.f fVar = this.f9054b;
                int iF = N.f(yVar2.f9137b);
                int iE = N.e(yVar2.f9137b);
                N n6 = this.f9059g.f9138c;
                int iF2 = n6 != null ? N.f(n6.f6483a) : -1;
                N n7 = this.f9059g.f9138c;
                ((InputMethodManager) fVar.f742c.getValue()).updateSelection((View) fVar.f741b, iF, iE, iF2, n7 != null ? N.e(n7.f6483a) : -1);
                return;
            }
            return;
        }
        if (yVar != null && (!kotlin.jvm.internal.o.c(yVar.f9136a.f6510b, yVar2.f9136a.f6510b) || (N.b(yVar.f9137b, yVar2.f9137b) && !kotlin.jvm.internal.o.c(yVar.f9138c, yVar2.f9138c)))) {
            C4.f fVar2 = this.f9054b;
            ((InputMethodManager) fVar2.f742c.getValue()).restartInput((View) fVar2.f741b);
            return;
        }
        int size2 = this.f9061i.size();
        for (int i7 = 0; i7 < size2; i7++) {
            u uVar2 = (u) ((WeakReference) this.f9061i.get(i7)).get();
            if (uVar2 != null) {
                y yVar3 = this.f9059g;
                C4.f fVar3 = this.f9054b;
                if (uVar2.f9128h) {
                    uVar2.f9124d = yVar3;
                    if (uVar2.f9126f) {
                        ((InputMethodManager) fVar3.f742c.getValue()).updateExtractedText((View) fVar3.f741b, uVar2.f9125e, W0.e.J(yVar3));
                    }
                    N n8 = yVar3.f9138c;
                    int iF3 = n8 != null ? N.f(n8.f6483a) : -1;
                    N n9 = yVar3.f9138c;
                    int iE2 = n9 != null ? N.e(n9.f6483a) : -1;
                    long j4 = yVar3.f9137b;
                    ((InputMethodManager) fVar3.f742c.getValue()).updateSelection((View) fVar3.f741b, N.f(j4), N.e(j4), iF3, iE2);
                }
            }
        }
    }

    @Override // Z0.t
    public final void f() {
        this.f9056d = false;
        this.f9057e = C0861b.f9080f;
        this.f9058f = C0861b.f9081j;
        this.f9063k = null;
        i(A.f9049b);
    }

    @Override // Z0.t
    public final void g(y yVar, r rVar, L l, O o6, C2632c c2632c, C2632c c2632c2) {
        C0862c c0862c = this.l;
        synchronized (c0862c.f9085c) {
            try {
                c0862c.f9092j = yVar;
                c0862c.l = rVar;
                c0862c.f9093k = l;
                c0862c.f9094m = o6;
                c0862c.f9095n = c2632c;
                c0862c.f9096o = c2632c2;
                if (c0862c.f9087e || c0862c.f9086d) {
                    c0862c.a();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // Z0.t
    public final void h() {
        i(A.f9051d);
    }

    public final void i(A a6) {
        this.f9064m.add(a6);
        if (this.f9065n == null) {
            F1.r rVar = new F1.r(this, 5);
            this.f9055c.execute(rVar);
            this.f9065n = rVar;
        }
    }
}
