package o0;

import android.graphics.Rect;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import androidx.compose.ui.platform.d2;
import androidx.compose.ui.platform.y2;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import o0.p1;

/* loaded from: classes.dex */
public final class r1 implements d2 {

    /* renamed from: a, reason: collision with root package name */
    private final View f30495a;

    /* renamed from: b, reason: collision with root package name */
    private final k1 f30496b;

    /* renamed from: e, reason: collision with root package name */
    private l0.z f30499e;

    /* renamed from: f, reason: collision with root package name */
    private r0.f0 f30500f;

    /* renamed from: g, reason: collision with root package name */
    private y2 f30501g;

    /* renamed from: k, reason: collision with root package name */
    private final rm.o f30505k;

    /* renamed from: l, reason: collision with root package name */
    private Rect f30506l;

    /* renamed from: m, reason: collision with root package name */
    private final o1 f30507m;

    /* renamed from: c, reason: collision with root package name */
    private dn.l f30497c = c.f30510p;

    /* renamed from: d, reason: collision with root package name */
    private dn.l f30498d = d.f30511p;

    /* renamed from: h, reason: collision with root package name */
    private w2.q0 f30502h = new w2.q0("", q2.m0.f33348b.a(), (q2.m0) null, 4, (kotlin.jvm.internal.k) null);

    /* renamed from: i, reason: collision with root package name */
    private w2.s f30503i = w2.s.f40817g.a();

    /* renamed from: j, reason: collision with root package name */
    private List f30504j = new ArrayList();

    /* loaded from: classes.dex */
    static final class a extends kotlin.jvm.internal.v implements dn.a {
        a() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final BaseInputConnection invoke() {
            return new BaseInputConnection(r1.this.i(), false);
        }
    }

    /* loaded from: classes.dex */
    public static final class b implements j1 {
        b() {
        }

        @Override // o0.j1
        public void a(KeyEvent keyEvent) {
            r1.this.h().sendKeyEvent(keyEvent);
        }

        @Override // o0.j1
        public void b(boolean z10, boolean z11, boolean z12, boolean z13, boolean z14, boolean z15) {
            r1.this.f30507m.b(z10, z11, z12, z13, z14, z15);
        }

        @Override // o0.j1
        public void c(int i10) {
            r1.this.f30498d.invoke(w2.r.j(i10));
        }

        @Override // o0.j1
        public void d(List list) {
            r1.this.f30497c.invoke(list);
        }

        @Override // o0.j1
        public void e(t1 t1Var) {
            int size = r1.this.f30504j.size();
            for (int i10 = 0; i10 < size; i10++) {
                if (kotlin.jvm.internal.t.b(((WeakReference) r1.this.f30504j.get(i10)).get(), t1Var)) {
                    r1.this.f30504j.remove(i10);
                    return;
                }
            }
        }
    }

    /* loaded from: classes.dex */
    static final class c extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final c f30510p = new c();

        c() {
            super(1);
        }

        public final void a(List list) {
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((List) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    static final class d extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final d f30511p = new d();

        d() {
            super(1);
        }

        public final void a(int i10) {
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a(((w2.r) obj).p());
            return rm.n0.f34904a;
        }
    }

    public r1(View view, dn.l lVar, k1 k1Var) {
        rm.o b10;
        this.f30495a = view;
        this.f30496b = k1Var;
        b10 = rm.q.b(rm.s.NONE, new a());
        this.f30505k = b10;
        this.f30507m = new o1(lVar, k1Var);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final BaseInputConnection h() {
        return (BaseInputConnection) this.f30505k.getValue();
    }

    private final void k() {
        this.f30496b.e();
    }

    @Override // androidx.compose.ui.platform.d2
    /* renamed from: g, reason: merged with bridge method [inline-methods] */
    public t1 a(EditorInfo editorInfo) {
        z.c(editorInfo, this.f30502h.h(), this.f30502h.g(), this.f30503i, null, 8, null);
        q1.d(editorInfo);
        t1 t1Var = new t1(this.f30502h, new b(), this.f30503i.b(), this.f30499e, this.f30500f, this.f30501g);
        this.f30504j.add(new WeakReference(t1Var));
        return t1Var;
    }

    public final View i() {
        return this.f30495a;
    }

    public final void j(r1.i iVar) {
        int c10;
        int c11;
        int c12;
        int c13;
        Rect rect;
        c10 = fn.c.c(iVar.i());
        c11 = fn.c.c(iVar.l());
        c12 = fn.c.c(iVar.j());
        c13 = fn.c.c(iVar.e());
        this.f30506l = new Rect(c10, c11, c12, c13);
        if (!this.f30504j.isEmpty() || (rect = this.f30506l) == null) {
            return;
        }
        this.f30495a.requestRectangleOnScreen(new Rect(rect));
    }

    public final void l(w2.q0 q0Var, p1.a aVar, w2.s sVar, dn.l lVar, dn.l lVar2) {
        this.f30502h = q0Var;
        this.f30503i = sVar;
        this.f30497c = lVar;
        this.f30498d = lVar2;
        this.f30499e = aVar != null ? aVar.u1() : null;
        this.f30500f = aVar != null ? aVar.o0() : null;
        this.f30501g = aVar != null ? aVar.getViewConfiguration() : null;
    }

    public final void m(w2.q0 q0Var, w2.q0 q0Var2) {
        boolean z10 = true;
        boolean z11 = (q2.m0.g(this.f30502h.g(), q0Var2.g()) && kotlin.jvm.internal.t.b(this.f30502h.f(), q0Var2.f())) ? false : true;
        this.f30502h = q0Var2;
        int size = this.f30504j.size();
        for (int i10 = 0; i10 < size; i10++) {
            t1 t1Var = (t1) ((WeakReference) this.f30504j.get(i10)).get();
            if (t1Var != null) {
                t1Var.g(q0Var2);
            }
        }
        this.f30507m.a();
        if (kotlin.jvm.internal.t.b(q0Var, q0Var2)) {
            if (z11) {
                k1 k1Var = this.f30496b;
                int l10 = q2.m0.l(q0Var2.g());
                int k10 = q2.m0.k(q0Var2.g());
                q2.m0 f10 = this.f30502h.f();
                int l11 = f10 != null ? q2.m0.l(f10.r()) : -1;
                q2.m0 f11 = this.f30502h.f();
                k1Var.d(l10, k10, l11, f11 != null ? q2.m0.k(f11.r()) : -1);
                return;
            }
            return;
        }
        if (q0Var == null || (kotlin.jvm.internal.t.b(q0Var.h(), q0Var2.h()) && (!q2.m0.g(q0Var.g(), q0Var2.g()) || kotlin.jvm.internal.t.b(q0Var.f(), q0Var2.f())))) {
            z10 = false;
        }
        if (z10) {
            k();
            return;
        }
        int size2 = this.f30504j.size();
        for (int i11 = 0; i11 < size2; i11++) {
            t1 t1Var2 = (t1) ((WeakReference) this.f30504j.get(i11)).get();
            if (t1Var2 != null) {
                t1Var2.h(this.f30502h, this.f30496b);
            }
        }
    }

    public final void n(w2.q0 q0Var, w2.h0 h0Var, q2.j0 j0Var, r1.i iVar, r1.i iVar2) {
        this.f30507m.d(q0Var, h0Var, j0Var, iVar, iVar2);
    }
}
