package com.ss.android.ugc.aweme.ecommerce.pdp.jsb.service;

import X.2Pr;
import X.2nK;
import X.C6369CYz;
import X.C6404Ca8;
import X.CBZ;
import X.CYB;
import X.CYM;
import X.CYN;
import X.CYO;
import X.CYU;
import X.CYV;
import X.CZ8;
import X.Lnj;
import X.Ls2;
import X.LsC;
import X.M12;
import X.Qx3;
import android.content.Context;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.ecommerce.libtrack.api.data.LaneParams;
import com.ss.android.ugc.aweme.ecommerce.pdp.PdpViewModel;
import com.ss.android.ugc.aweme.ecommerce.pdp.repository.dto.BrickInfo;
import com.ss.android.ugc.aweme.ecommerce.pdp.repository.dto.ProductPackStruct;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class PdpCardBridgeServiceImpl implements IPdpCardBridgeService {
    static {
        Covode.recordClassIndex(71410);
    }

    public static IPdpCardBridgeService LIZ() {
        MethodCollector.i(2128);
        IPdpCardBridgeService iPdpCardBridgeService = (IPdpCardBridgeService) Lnj.LIZ(IPdpCardBridgeService.class, false);
        if (iPdpCardBridgeService != null) {
            MethodCollector.o(2128);
            return iPdpCardBridgeService;
        }
        Object LIZIZ = Lnj.LIZIZ(IPdpCardBridgeService.class, false);
        if (LIZIZ != null) {
            IPdpCardBridgeService iPdpCardBridgeService2 = (IPdpCardBridgeService) LIZIZ;
            MethodCollector.o(2128);
            return iPdpCardBridgeService2;
        }
        if (Lnj.LLJJJJJIL == null) {
            synchronized (IPdpCardBridgeService.class) {
                try {
                    if (Lnj.LLJJJJJIL == null) {
                        Lnj.LLJJJJJIL = new PdpCardBridgeServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(2128);
                    throw th;
                }
            }
        }
        PdpCardBridgeServiceImpl pdpCardBridgeServiceImpl = (PdpCardBridgeServiceImpl) Lnj.LLJJJJJIL;
        MethodCollector.o(2128);
        return pdpCardBridgeServiceImpl;
    }

    public final void LIZ(PdpViewModel pdpViewModel) {
        if (pdpViewModel != null) {
            pdpViewModel.LIZ(false, true, true);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:5:0x001f, code lost:
        if (r0 != null) goto L_0x0021;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final java.util.HashMap<java.lang.String, java.lang.Object> LIZ(X.CZ8 r5) {
        /*
            r4 = this;
            java.util.HashMap r3 = new java.util.HashMap
            r3.<init>()
            if (r5 == 0) goto L_0x0049
            java.lang.String r0 = "lib_track_builtin_lane_business"
            X.M12.LIZ(r5, r0)
            boolean r0 = kotlin.h.b.n.LIZ(r0, r0)
            if (r0 == 0) goto L_0x0043
            X.CZA r0 = new X.CZA
            r0.<init>()
            r0.LIZ((X.CZ8) r5)
            r0.LIZJ()
            com.ss.android.ugc.aweme.ecommerce.libtrack.api.data.LaneParams r0 = r0.LIZIZ
            if (r0 == 0) goto L_0x0049
        L_0x0021:
            java.util.Set r0 = r0.entrySet()
            java.util.Iterator r2 = r0.iterator()
        L_0x0029:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x0049
            java.lang.Object r0 = r2.next()
            java.util.Map$Entry r0 = (java.util.Map.Entry) r0
            java.lang.Object r1 = r0.getValue()
            if (r1 == 0) goto L_0x0029
            java.lang.Object r0 = r0.getKey()
            r3.put(r0, r1)
            goto L_0x0029
        L_0x0043:
            com.ss.android.ugc.aweme.ecommerce.libtrack.api.data.LaneParams r0 = new com.ss.android.ugc.aweme.ecommerce.libtrack.api.data.LaneParams
            r0.<init>()
            goto L_0x0021
        L_0x0049:
            return r3
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.ecommerce.pdp.jsb.service.PdpCardBridgeServiceImpl.LIZ(X.CZ8):java.util.HashMap");
    }

    public final CYO LIZ(PdpViewModel pdpViewModel, C6369CYz cYz) {
        int i;
        int i2;
        boolean z;
        Ls2<Boolean> ls2;
        Boolean bool;
        if (pdpViewModel != null) {
            i = pdpViewModel.LJJIZ;
        } else {
            i = 0;
        }
        if (cYz != null) {
            i2 = cYz.getTop();
        } else {
            i2 = 0;
        }
        if (pdpViewModel == null || (ls2 = pdpViewModel.LJJJ) == null || (bool = (Boolean) ls2.invoke()) == null) {
            z = false;
        } else {
            z = bool.booleanValue();
        }
        return new CYO(!z, C6404Ca8.LIZ(Integer.valueOf(Qx3.LIZJ(i - i2, 0))));
    }

    public final String LIZ(PdpViewModel pdpViewModel, int i) {
        Integer valueOf;
        ProductPackStruct productPackStruct;
        List<BrickInfo> list;
        T t;
        if (!(pdpViewModel == null || (valueOf = Integer.valueOf(i)) == null || (productPackStruct = pdpViewModel.LIZLLL) == null || (list = productPackStruct.LJJIJIL) == null)) {
            Iterator<T> it = list.iterator();
            while (true) {
                if (!it.hasNext()) {
                    t = null;
                    break;
                }
                t = it.next();
                if (((BrickInfo) t).LIZLLL == valueOf.intValue()) {
                    break;
                }
            }
            BrickInfo brickInfo = (BrickInfo) t;
            if (brickInfo != null) {
                return brickInfo.LIZ;
            }
        }
        return null;
    }

    public final void LIZ(CZ8 cz8, String str, Map<String, ? extends Object> map) {
        M12.LIZ(str);
        CYV LIZ = CYB.LIZ.LIZ(str);
        if (LIZ == null) {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("exist", map);
            HashMap hashMap = new HashMap();
            hashMap.put("event_name", "ec_send_page_log");
            hashMap.put("type", "unregister");
            String jSONObject2 = jSONObject.toString();
            n.LIZIZ(jSONObject2, "");
            hashMap.put("params", jSONObject2);
            2nK.LIZ("rd_tiktokec_event_monitor", hashMap);
        } else if (cz8 != null) {
            CBZ.LIZ(cz8, LIZ, (LsC<? super LaneParams, 2Pr>) new CYN(map));
        }
    }

    public final void LIZ(CZ8 cz8, Context context, String str, Map<String, ? extends Object> map) {
        M12.LIZ(str);
        if (context != null && cz8 != null) {
            SmartRoute buildRoute = SmartRouter.buildRoute(context, str);
            n.LIZIZ(buildRoute, "");
            CYU.LIZ(buildRoute, cz8, new CYM(map));
            buildRoute.open();
        }
    }
}
