package com.ss.android.ugc.aweme.commercialize.depend;

import X.0HH;
import X.2Pr;
import X.3i8;
import X.3jJ;
import X.4Ek;
import X.4RU;
import X.4sH;
import X.7he;
import X.9xA;
import X.C2553Kue;
import X.C2555Kug;
import X.C2624Kvn;
import X.C3236LDn;
import X.C3292LFr;
import X.C3293LFs;
import X.C3294LFt;
import X.C3295LFu;
import X.C3296LFv;
import X.C4672Lnj;
import X.C4939Ls2;
import X.C4950LsD;
import X.Crj;
import X.FKq;
import X.LFW;
import X.LG8;
import X.M12;
import X.MMg;
import X.TSt;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
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.google.gson.Gson;
import com.ss.android.ugc.aweme.ad.comment.depend.IAdCommentDepend;
import com.ss.android.ugc.aweme.arch.widgets.base.Widget;
import com.ss.android.ugc.aweme.awemeservice.AwemeService;
import com.ss.android.ugc.aweme.comment.CommentServiceImpl;
import com.ss.android.ugc.aweme.comment.widgets.CommentHeaderWidget;
import com.ss.android.ugc.aweme.comment.widgets.NewCommentAdWidget;
import com.ss.android.ugc.aweme.commercialize.im.OpenChatExt;
import com.ss.android.ugc.aweme.compliance.api.a;
import com.ss.android.ugc.aweme.compliance.api.services.report.IReportService;
import com.ss.android.ugc.aweme.crossplatform.activity.CrossPlatformActivity;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import com.ss.android.ugc.aweme.global.config.settings.pojo.AwemeFEConfigs;
import com.ss.android.ugc.aweme.global.config.settings.pojo.LinkPlan;
import com.ss.android.ugc.aweme.model.TextExtraStruct;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONException;
import org.json.JSONObject;

public final class AdCommentDependImpl implements IAdCommentDepend {
    public final Crj LIZ = 7he.LIZ(C3294LFt.LIZ);

    static {
        Covode.recordClassIndex(58360);
    }

    private final C3295LFu LIZJ() {
        return (C3295LFu) this.LIZ.getValue();
    }

    public final boolean LIZ(String str) {
        return OpenChatExt.LIZ(str);
    }

    public final boolean LIZ(Context context, Aweme aweme, int i, 4RU r5) {
        M12.LIZ(context, aweme, r5);
        return C2555Kug.LIZ(context, aweme, i, r5);
    }

    public final void LIZ(Context context, String str, String str2) {
        LIZJ();
        if (!C2553Kue.LIZ(context, str, false)) {
            Intent intent = new Intent(context, CrossPlatformActivity.class);
            if (!TextUtils.isEmpty(str2)) {
                intent.setData(Uri.parse(str2));
                3i8.LIZ(intent, context);
                context.startActivity(intent);
            }
        }
    }

    public final void LIZ(Context context, String str) {
        LIZJ();
        Aweme LIZIZ = AwemeService.LIZIZ().LIZIZ(str);
        Activity LIZ2 = 3jJ.LIZ(context);
        if (LIZ2 != null) {
            IReportService LIZ3 = a.LIZ();
            M12.LIZ(LIZIZ, "landing_page", "ad");
            HashMap hashMap = new HashMap();
            C3296LFv LIZ4 = LG8.LIZ.LIZ(LIZIZ);
            String str2 = null;
            hashMap.put("log_extra", LIZ4 != null ? LIZ4.logExtra : null);
            if (LIZ4 != null) {
                str2 = LIZ4.creativeId;
            }
            hashMap.put("cid", str2);
            Uri.Builder builder = new Uri.Builder();
            String LIZIZ2 = new Gson().LIZIZ(hashMap);
            n.LIZIZ(LIZIZ2, "");
            LIZ3.LIZIZ(LIZ2, 4sH.LIZ(builder, LIZIZ, "landing_page", "ad", LIZIZ2));
        }
    }

    public final void LIZ(String str, Context context, C3296LFv lFv, Aweme aweme, String str2) {
        C3293LFs lFs = new C3293LFs();
        lFs.LIZ(lFv);
        lFs.LIZ(aweme);
        lFs.LJ = true;
        lFs.LIZ(true);
        lFs.LIZ(str);
        if (str2 == null) {
            str2 = "";
        }
        M12.LIZ((Object) str2);
        lFs.LJII = str2;
        C3236LDn.LIZ(context, lFs.LIZ());
    }

    public final void LIZ(AwemeRawAd awemeRawAd) {
        if (awemeRawAd != null) {
            LFW.LIZ.LIZ("click", awemeRawAd.getClickTrackUrlList(), awemeRawAd.getCreativeId(), awemeRawAd.getLogExtra(), (C4950LsD<? super C2624Kvn, ? super Boolean, ? extends C2624Kvn>) new C3292LFr(awemeRawAd));
        }
    }

    public final boolean LIZ(Aweme aweme) {
        M12.LIZ((Object) aweme);
        C3296LFv LIZ2 = LG8.LIZ.LIZ(aweme);
        return LIZ2 != null && LIZ2.linkType == 0;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:14:0x0062, code lost:
        if (r5 != null) goto L_0x0032;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(java.lang.String r10, java.lang.String r11, com.ss.android.ugc.aweme.feed.model.Aweme r12, boolean r13) {
        /*
            r9 = this;
            X.LG8 r0 = X.LG8.LIZ
            r6 = r12
            X.LFv r5 = r0.LIZ(r6)
            if (r5 == 0) goto L_0x0060
            int r0 = r5.linkType
            if (r0 != 0) goto L_0x0060
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            java.lang.String r0 = "enterprise_link_"
            r1.<init>(r0)
            int r0 = r5.saiyanLinkType
            r1.append(r0)
            java.lang.String r2 = r1.toString()
            boolean r0 = X.C3290LFp.LJJJJLI(r6)
            if (r0 == 0) goto L_0x0032
            if (r13 == 0) goto L_0x0032
            X.9EH r0 = X.9EH.LJJIFFI
            android.content.Context r4 = r0.LIZ()
            r7 = 1
            r8 = 0
            java.lang.String r3 = "link_click"
            X.C3236LDn.LIZ((java.lang.String) r3, (android.content.Context) r4, (X.C3296LFv) r5, (com.ss.android.ugc.aweme.feed.model.Aweme) r6, (boolean) r7, (boolean) r8)
        L_0x0032:
            int r1 = r5.linkType
            r0 = 1
            if (r1 != r0) goto L_0x0039
            java.lang.String r2 = "ad_link"
        L_0x0039:
            X.2UX r3 = new X.2UX
            r3.<init>()
            java.lang.String r1 = r6.getAid()
            java.lang.String r0 = "group_id"
            r3.LIZ(r0, r1)
            java.lang.String r0 = "enter_from"
            r3.LIZ(r0, r10)
            java.lang.String r1 = r6.getAuthorUid()
            java.lang.String r0 = "author_id"
            r3.LIZ(r0, r1)
            java.lang.String r0 = "link_type"
            r3.LIZ(r0, r2)
            java.util.Map r0 = r3.LIZ
            X.2nK.LIZ(r11, r0)
            return
        L_0x0060:
            java.lang.String r2 = ""
            if (r5 == 0) goto L_0x0039
            goto L_0x0032
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.commercialize.depend.AdCommentDependImpl.LIZ(java.lang.String, java.lang.String, com.ss.android.ugc.aweme.feed.model.Aweme, boolean):void");
    }

    public final void LIZ(Context context, String str, String str2, String str3) {
        Context context2 = context;
        String str4 = str;
        M12.LIZ(context2, str4, str2, str3);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("refer", str2);
            jSONObject.put("log_extra", str3);
            jSONObject.put("is_ad_event", "1");
        } catch (JSONException e) {
            TSt.LIZ(e);
        }
        C3236LDn.LIZ(context2, "draw_ad", "replay", jSONObject, str4, 0);
    }

    public final String LIZ() {
        LinkPlan linkPlan;
        try {
            MMg LIZ2 = MMg.LIZ();
            n.LIZIZ(LIZ2, "");
            AwemeFEConfigs LJ = LIZ2.LJ();
            if (LJ == null || (linkPlan = LJ.getLinkPlan()) == null) {
                return null;
            }
            return linkPlan.getInfo();
        } catch (4Ek e) {
            0HH.LIZ(e);
            return null;
        }
    }

    public static IAdCommentDepend LIZIZ() {
        MethodCollector.i(1649);
        IAdCommentDepend iAdCommentDepend = (IAdCommentDepend) C4672Lnj.LIZ(IAdCommentDepend.class, false);
        if (iAdCommentDepend != null) {
            MethodCollector.o(1649);
            return iAdCommentDepend;
        }
        Object LIZIZ = C4672Lnj.LIZIZ(IAdCommentDepend.class, false);
        if (LIZIZ != null) {
            IAdCommentDepend iAdCommentDepend2 = (IAdCommentDepend) LIZIZ;
            MethodCollector.o(1649);
            return iAdCommentDepend2;
        }
        if (C4672Lnj.LJLJJI == null) {
            synchronized (IAdCommentDepend.class) {
                try {
                    if (C4672Lnj.LJLJJI == null) {
                        C4672Lnj.LJLJJI = new AdCommentDependImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(1649);
                    throw th;
                }
            }
        }
        AdCommentDependImpl adCommentDependImpl = (AdCommentDependImpl) C4672Lnj.LJLJJI;
        MethodCollector.o(1649);
        return adCommentDependImpl;
    }

    public final Widget LIZ(C4939Ls2<2Pr> ls2) {
        M12.LIZ((Object) ls2);
        return new NewCommentAdWidget(ls2);
    }

    public final Widget LIZIZ(C4939Ls2<2Pr> ls2) {
        M12.LIZ((Object) ls2);
        return new CommentHeaderWidget(ls2);
    }

    public final String LIZIZ(9xA r2) {
        M12.LIZ((Object) r2);
        return CommentServiceImpl.LJI().LIZIZ(r2);
    }

    public final List<TextExtraStruct> LIZ(9xA r2) {
        M12.LIZ((Object) r2);
        return CommentServiceImpl.LJI().LIZ(r2);
    }

    public final void LIZ(Context context, Aweme aweme) {
        C3296LFv LIZ2 = LG8.LIZ.LIZ(aweme);
        if (LIZ2 == null) {
            return;
        }
        if (LIZ2.linkType == 0) {
            C2553Kue.LIZ(context, LIZ2, aweme, true);
        } else if (LIZ2.linkType == 1) {
            C2553Kue.LIZ(context, LIZ2, aweme, true);
        }
    }

    public final void LIZ(Context context, User user) {
        if (user != null && context != null) {
            SmartRoute buildRoute = SmartRouter.buildRoute(context, "aweme://user/profile/");
            buildRoute.withParam("uid", user.getUid());
            buildRoute.withParam("sec_user_id", user.getSecUid());
            buildRoute.withParam("profile_enterprise_type", FKq.LIZ.LIZ(user));
            buildRoute.open();
        }
    }

    public final void LIZ(Context context, C3296LFv lFv, Aweme aweme) {
        LIZJ();
        C2553Kue.LIZ(context, lFv, aweme, true);
    }

    public final List<TextExtraStruct> LIZ(9xA r2, AwemeRawAd awemeRawAd, C4939Ls2<2Pr> ls2) {
        M12.LIZ((Object) r2, (Object) ls2);
        return CommentServiceImpl.LJI().LIZ(r2, awemeRawAd, ls2);
    }

    public final List<TextExtraStruct> LIZ(Context context, Aweme aweme, 9xA r4) {
        M12.LIZ(context, aweme, r4);
        return CommentServiceImpl.LJI().LIZ(context, aweme, r4);
    }

    public final void LIZ(Context context, Aweme aweme, String str) {
        M12.LIZ((Object) context);
        JSONObject LIZ2 = C3236LDn.LIZ(context, aweme, false, (Map<String, String>) null);
        if (!TextUtils.isEmpty(str)) {
            try {
                LIZ2.put("refer", str);
                HashMap hashMap = new HashMap();
                hashMap.put("anchor_id", C3236LDn.LIZIZ(aweme));
                hashMap.put("room_id", C3236LDn.LIZ(aweme));
                LIZ2.put("ad_extra_data", new Gson().LIZIZ(hashMap));
            } catch (JSONException e) {
                TSt.LIZ(e);
            }
        }
        C3236LDn.LIZIZ(context, "comment", aweme, LIZ2);
    }
}
