package com.bytedance.assem.arch.core;

import X.0Bt;
import X.0CH;
import X.1hK;
import X.2Pr;
import X.2up;
import X.4OS;
import X.4hP;
import X.4tt;
import X.7eS;
import X.AgB;
import X.AoS;
import X.Aob;
import X.BDk;
import X.C0327Csp;
import X.C0333Csv;
import X.C0347Ctj;
import X.C0436Cwu;
import X.C0443Cxb;
import X.C0470Cyc;
import X.CuD;
import X.CuL;
import X.CuS;
import X.CxE;
import X.CxI;
import X.CxJ;
import X.CxK;
import X.CxL;
import X.CxM;
import X.CxN;
import X.CyI;
import X.D1G;
import X.LsC;
import X.M12;
import X.Pkb;
import android.view.View;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import kotlin.h.b.n;

public final class Assembler extends 0Bt {
    public static final AoS LIZ = new AoS((byte) 0);
    public final Map<0CH, AssemSupervisor> LIZIZ = new ConcurrentHashMap();
    public final WeakHashMap<0CH, Aob> LIZJ = new WeakHashMap<>();
    public final WeakHashMap<0CH, CxE> LIZLLL = new WeakHashMap<>();

    static {
        Covode.recordClassIndex(23896);
    }

    public final <REUSED extends CuD<? extends 4hP>> void LIZ(REUSED reused, D1G<? extends CuD<?>> d1g) {
        CuD cuD;
        Pkb<C0333Csv> LIZIZ2;
        M12.LIZ(reused, d1g);
        AssemSupervisor LIZ2 = LIZ(reused);
        if (LIZ2 != null && LIZ2.LJII.containsKey(d1g)) {
            CxI remove = LIZ2.LJII.remove(d1g);
            CuL cuL = null;
            if (remove != null) {
                cuL = remove.LIZ();
            }
            if ((cuL instanceof CuD) && (cuD = (CuD) cuL) != null) {
                cuD.LIZJ = true;
                LIZ2.LIZIZ(cuD);
                C0327Csp csp = reused.LJIILIIL;
                if (csp != null) {
                    csp.LIZ((CuD<? extends 4hP>) cuD);
                }
                cuD.LJJIIJ();
                C0327Csp csp2 = cuD.LJIILIIL;
                if (!(csp2 == null || (LIZIZ2 = csp2.LIZIZ()) == null)) {
                    LIZIZ2.onNext(new C0333Csv(C0347Ctj.HostAttach, cuD));
                }
                LIZ2.LIZ((CuL) cuD);
            }
        }
    }

    public final void LIZ(Fragment fragment, LsC<? super 4tt<4OS>, 2Pr> lsC) {
        M12.LIZ(fragment, lsC);
        4tt r0 = new 4tt();
        lsC.invoke(r0);
        C0436Cwu LIZ2 = r0.LIZ();
        String str = (String) LIZ2.getFirst();
        4OS r1 = (4OS) LIZ2.getSecond();
        Aob aob = this.LIZJ.get(fragment);
        if (aob != null) {
            aob.LIZ(r1, str);
        }
    }

    public final void LIZ(CuL cuL, LsC<? super 4tt<4OS>, 2Pr> lsC) {
        M12.LIZ(cuL, lsC);
        4tt r0 = new 4tt();
        lsC.invoke(r0);
        C0436Cwu LIZ2 = r0.LIZ();
        String str = (String) LIZ2.getFirst();
        4OS r1 = (4OS) LIZ2.getSecond();
        Aob aob = this.LIZJ.get(cuL);
        if (aob != null) {
            aob.LIZ(r1, str);
        }
    }

    public final void onCleared() {
        Assembler.super.onCleared();
        BDk bDk = CuS.LIZJ;
        if (bDk != null) {
            bDk.LIZ("AssemList", n.LIZ("Assembler onCleared: ", this));
        }
        this.LIZJ.clear();
        this.LIZIZ.clear();
        this.LIZLLL.clear();
    }

    public final AssemSupervisor LIZ(0CH r2) {
        return this.LIZIZ.get(r2);
    }

    public final Aob LIZIZ(0CH r2) {
        return this.LIZJ.get(r2);
    }

    public final CxE LIZJ(0CH r2) {
        return this.LIZLLL.get(r2);
    }

    public final void LIZLLL(0CH r4) {
        if (r4 != null) {
            BDk bDk = CuS.LIZJ;
            if (bDk != null) {
                bDk.LIZ("AssemList", "Assembler clearAsLifecycleOwner: " + r4 + ", " + this);
            }
            this.LIZJ.remove(r4);
            this.LIZLLL.remove(r4);
            this.LIZIZ.remove(r4);
        }
    }

    public final void LIZ(0CH r2, Aob aob) {
        if (r2 != null) {
            this.LIZJ.put(r2, aob);
        }
    }

    public final AssemSupervisor LIZ(0CH r6, LsC<? super CxJ, 2Pr> lsC) {
        M12.LIZ(r6, lsC);
        AssemSupervisor LIZ2 = LIZ(r6);
        if (LIZ2 == null) {
            return null;
        }
        CxJ cxJ = new CxJ();
        lsC.invoke(cxJ);
        CuL LIZ3 = cxJ.LIZ();
        LIZ(cxJ.LIZJ, LIZ3, LIZ2.LJ);
        LIZ2.LIZIZ(LIZ3);
        LIZ2.LIZ((CuL) null);
        return LIZ2;
    }

    /* JADX WARNING: type inference failed for: r2v0, types: [X.Cyd, X.CuL] */
    public final AssemSupervisor LIZIZ(0CH r6, LsC<? super CxM, 2Pr> lsC) {
        M12.LIZ(r6, lsC);
        AssemSupervisor LIZ2 = LIZ(r6);
        if (LIZ2 == null) {
            return null;
        }
        CxM cxM = new CxM();
        lsC.invoke(cxM);
        ? LIZIZ2 = cxM.LIZ();
        LIZ(cxM.LIZJ, LIZIZ2, LIZ2.LJ);
        LIZ2.LIZIZ(LIZIZ2);
        LIZ2.LIZ((CuL) null);
        return LIZ2;
    }

    public final AssemSupervisor LIZJ(0CH r6, LsC<? super CxN, 2Pr> lsC) {
        M12.LIZ(r6, lsC);
        AssemSupervisor LIZ2 = LIZ(r6);
        if (LIZ2 == null) {
            return null;
        }
        CxN cxN = new CxN();
        lsC.invoke(cxN);
        AgB LIZIZ2 = cxN.LIZ();
        LIZ(cxN.LIZJ, LIZIZ2, LIZ2.LJ);
        LIZ2.LIZIZ(LIZIZ2);
        LIZ2.LIZ((CuL) null);
        return LIZ2;
    }

    public final <REUSED extends CuD<? extends 4hP>> AssemSupervisor LIZ(REUSED reused, LsC<? super CxL, 2Pr> lsC) {
        M12.LIZ(reused, lsC);
        AssemSupervisor LIZ2 = LIZ(reused);
        BDk bDk = CuS.LIZJ;
        if (bDk != null) {
            bDk.LIZ("AssemList", "reusedUiSlotAssem: " + reused + ", " + LIZ2);
        }
        View view = null;
        if (LIZ2 == null) {
            return null;
        }
        CxL cxL = new CxL();
        lsC.invoke(cxL);
        if (cxL.LIZJ == C0443Cxb.LAZY) {
            View view2 = LIZ2.LJIIIIZZ;
            if (!(view2 == null || !CuS.LJII || cxL.LIZLLL == 0)) {
                view = view2.findViewById(cxL.LIZLLL);
            }
            cxL.LJFF = view;
            LIZ2.LJII.put(cxL.LIZIZ(), cxL);
            return reused.bZ_();
        }
        C0470Cyc<? extends 4hP> LIZJ2 = cxL.LIZ();
        LIZ2.LIZIZ(LIZJ2);
        C0327Csp csp = reused.LJIILIIL;
        if (csp != null) {
            csp.LIZ((CuD<? extends 4hP>) LIZJ2);
        }
        return reused.bZ_();
    }

    public final <REUSED extends CuD<? extends 4hP>> AssemSupervisor LIZIZ(REUSED reused, LsC<? super CxK, 2Pr> lsC) {
        M12.LIZ(reused, lsC);
        AssemSupervisor LIZ2 = LIZ(reused);
        BDk bDk = CuS.LIZJ;
        if (bDk != null) {
            bDk.LIZ("AssemList", "reusedUiContentAssem: " + reused + ", " + LIZ2);
        }
        if (LIZ2 == null) {
            return null;
        }
        CxK cxK = new CxK();
        lsC.invoke(cxK);
        if (cxK.LIZJ == C0443Cxb.LAZY) {
            LIZ2.LJII.put(cxK.LIZIZ(), cxK);
            return reused.bZ_();
        }
        CyI<? extends 4hP> LIZJ2 = cxK.LIZ();
        LIZ2.LIZIZ(LIZJ2);
        C0327Csp csp = reused.LJIILIIL;
        if (csp != null) {
            csp.LIZ((CuD<? extends 4hP>) LIZJ2);
        }
        return reused.bZ_();
    }

    public final void LIZ(0CH r2, CxE cxE) {
        if (r2 != null && cxE != null) {
            this.LIZLLL.put(r2, cxE);
        }
    }

    public final void LIZ(0CH r5, AssemSupervisor assemSupervisor) {
        BDk bDk = CuS.LIZJ;
        if (bDk != null) {
            bDk.LIZ("AssemList", "new setAssemSupervisor: " + r5 + ", " + assemSupervisor + ", " + Thread.currentThread());
        }
        if (r5 != null && assemSupervisor != null) {
            this.LIZIZ.put(r5, assemSupervisor);
            BDk bDk2 = CuS.LIZJ;
            if (bDk2 != null) {
                bDk2.LIZ("AssemList", n.LIZ("after setAssemSupervisor: ", this.LIZIZ.get(r5)));
            }
        }
    }

    public final void LIZ(1hK r4, LsC<? super 4tt<4OS>, 2Pr> lsC) {
        M12.LIZ(r4, lsC);
        4tt r0 = new 4tt();
        lsC.invoke(r0);
        C0436Cwu LIZ2 = r0.LIZ();
        String str = (String) LIZ2.getFirst();
        4OS r1 = (4OS) LIZ2.getSecond();
        Aob aob = this.LIZJ.get(r4);
        if (aob != null) {
            aob.LIZ(r1, str);
        }
    }

    private final void LIZ(List<7eS> list, CuL cuL, CxE cxE) {
        if (list != null && !list.isEmpty()) {
            for (7eS next : list) {
                if (next.LIZ.isAssignableFrom(cuL.getClass())) {
                    cxE.LIZ(next, (2up) cuL);
                } else {
                    throw new IllegalStateException("The serviceClazz must be super interface of this Assem".toString());
                }
            }
        } else if (cuL instanceof 2up) {
            2up r10 = (2up) cuL;
            Class cls = r10.getClass();
            while (cls != Object.class) {
                Class[] interfaces = cls.getInterfaces();
                M12.LIZ(interfaces);
                ArrayList<Class> arrayList = new ArrayList<>();
                for (Class cls2 : interfaces) {
                    if (2up.class.isAssignableFrom(cls2)) {
                        arrayList.add(cls2);
                    }
                }
                for (Class cls3 : arrayList) {
                    n.LIZIZ(cls3, "");
                    cxE.LIZ((Class<?>) cls3, r10);
                }
                cls = cls.getSuperclass();
                if (cls == null) {
                    return;
                }
            }
        }
    }
}
