package com.bytedance.android.live.wallet;

import X.2fU;
import X.2sR;
import X.86a;
import X.9Y3;
import X.AnonymousClass16F;
import X.AnonymousClass16G;
import X.AnonymousClass16H;
import X.AnonymousClass16I;
import X.AnonymousClass16L;
import X.AnonymousClass16M;
import X.AnonymousClass16N;
import X.AnonymousClass16O;
import X.AnonymousClass16P;
import X.AnonymousClass16Y;
import X.AnonymousClass16Z;
import X.AnonymousClass17B;
import X.AnonymousClass17E;
import X.AnonymousClass17G;
import X.AnonymousClass17H;
import X.AnonymousClass17M;
import X.AnonymousClass1JF;
import X.AnonymousClass1MY;
import X.C10000b0;
import X.C11100cm;
import X.C24850yx;
import X.C270616a;
import X.C270916d;
import X.C271016e;
import X.C271316h;
import X.C271416i;
import X.C271516j;
import X.C272216q;
import X.C38401fi;
import X.C38411fj;
import X.C38421fk;
import X.C38431fl;
import X.C38441fm;
import X.C38451fn;
import X.C38461fo;
import X.C38471fp;
import X.C38481fq;
import X.C38491fr;
import X.C38501fs;
import X.C38591g1;
import X.G2l;
import X.GFy;
import X.GtA;
import X.HEP;
import X.HK2;
import X.HK3;
import X.HV3;
import X.HVJ;
import X.Hzs;
import X.M12;
import X.Ql4;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.android.live.wallet.api.IapApi;
import com.bytedance.android.live.wallet.model.BalanceStruct;
import com.bytedance.android.live.wallet.model.BalanceStructExtra;
import com.bytedance.android.live.wallet.model.RevenueExchange;
import com.bytedance.android.livesdk.livesetting.gift.LiveExchangeConfirmThreshold;
import com.bytedance.android.livesdk.livesetting.wallet.LiveAutoExchangeABTestSetting;
import com.bytedance.android.livesdk.livesetting.wallet.LiveExchangeTaxEnableSetting;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.host.IHostContext;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.HashMap;
import kotlin.h.b.n;

public final class WalletExchange implements IWalletExchange {
    public static final WalletExchange LIZ = new WalletExchange();

    public final void onInit() {
    }

    public final /* synthetic */ void LIZ(DataChannel dataChannel, long j, Boolean bool, int i) {
        String str;
        boolean booleanValue = bool.booleanValue();
        if (i == 1) {
            str = "ug_exchange";
        } else {
            str = "anchor_income";
        }
        M12.LIZ(str);
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        GtA LIZ2 = GtA.LJFF.LIZ("livesdk_balance_exchange_failed");
        LIZ2.LIZ(dataChannel);
        String str2 = null;
        LIZ2.LIZ("anchor_id", String.valueOf(room != null ? Long.valueOf(room.getOwnerUserId()) : null));
        if (room != null) {
            str2 = room.getIdStr();
        }
        LIZ2.LIZ("room_id", String.valueOf(str2));
        LIZ2.LIZ("is_anchor", G2l.LIZJ(dataChannel) ? "1" : "0");
        LIZ2.LIZ("error_code", j);
        LIZ2.LIZ("is_auto", Boolean.valueOf(booleanValue));
        LIZ2.LIZ("charge_reason", str);
        LIZ2.LIZLLL();
    }

    public final boolean LIZ() {
        return !86a.LIZ("0", AnonymousClass16Y.LIZ.LIZ().getString("live_auto_exchange", "0"));
    }

    public final void LIZ(boolean z) {
        AnonymousClass16Y.LIZ.LIZ().edit().putString("live_auto_exchange", z ? "1" : "0").apply();
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).updateAutoExchange(true, 0).LIZ(new Hzs()).LIZ(new C38471fp(str), C38481fq.LIZ);
    }

    public final void LIZ(Context context, C270616a r6, AnonymousClass16Z r7) {
        if (context != null) {
            HK2 hk2 = new HK2(context);
            hk2.LIZLLL = 2131234575;
            hk2.LJIIIZ = false;
            hk2.LIZ(r6.LIZ);
            hk2.LIZIZ = r6.LIZIZ;
            hk2.LIZ(r6.LIZLLL, new AnonymousClass16G(r7), false);
            hk2.LIZIZ(r6.LIZJ, new AnonymousClass16H(r7), false);
            if (r6.LJFF) {
                View LIZ2 = LIZ(LayoutInflater.from(context));
                View findViewById = LIZ2.findViewById(2131363262);
                n.LIZIZ(findViewById, "");
                AnonymousClass1MY r1 = (AnonymousClass1MY) findViewById;
                r1.setText(r6.LJ);
                r1.setOnCheckedChangeListener(new AnonymousClass16I(r7));
                hk2.LJII = LIZ2;
            }
            LIZ(hk2.LIZ());
        }
    }

    public final boolean LIZ(Context context, C271016e r31, C270916d r32) {
        boolean z;
        boolean z2;
        boolean z3;
        Context context2 = context;
        if (context2 == null) {
            return false;
        }
        C271016e r11 = r31;
        if (AnonymousClass16F.LIZ.LIZIZ((long) r11.LIZIZ)) {
            return false;
        }
        C270916d r5 = r32;
        if (AnonymousClass16Y.LIZ(context2, r11, r5)) {
            return true;
        }
        M12.LIZ(r11);
        if (!AnonymousClass16F.LIZ.LIZIZ((long) r11.LIZIZ)) {
            IWalletCenter walletCenter = ((IWalletService) C11100cm.LIZ(IWalletService.class)).walletCenter();
            n.LIZIZ(walletCenter, "");
            long LIZIZ = ((long) r11.LIZIZ) - walletCenter.LIZIZ();
            if (r11.LIZIZ > LiveExchangeConfirmThreshold.INSTANCE.getValue()) {
                z = true;
            } else {
                z = false;
            }
            2sR r2 = GFy.LLJIJIL;
            n.LIZIZ(r2, "");
            if (((Integer) r2.LIZ()).intValue() < 2) {
                z2 = true;
            } else {
                z2 = false;
            }
            IWalletExchange walletExchange = ((IWalletService) C11100cm.LIZ(IWalletService.class)).walletExchange();
            n.LIZIZ(walletExchange, "");
            boolean LIZ2 = walletExchange.LIZ();
            IWalletCenter walletCenter2 = ((IWalletService) C11100cm.LIZ(IWalletService.class)).walletCenter();
            n.LIZIZ(walletCenter2, "");
            BalanceStruct LIZLLL = walletCenter2.LIZLLL();
            BalanceStructExtra exchangeInfo = LIZLLL.getExchangeInfo();
            long coins = exchangeInfo != null ? exchangeInfo.getCoins() : 0;
            if (LIZLLL.getExchangeInfo() != null && LIZLLL.getValidUser() && LIZIZ <= coins && (z2 || LIZ2)) {
                DataChannel dataChannel = r11.LIZ;
                long j = r11.LIZJ;
                if (z || !LIZ2) {
                    AnonymousClass16P.LIZ.LIZ(dataChannel, j, AnonymousClass16Y.LIZ.LIZ(z), "ug_exchange");
                    WalletExchange walletExchange2 = LIZ;
                    String LIZ3 = C10000b0.LIZ(2131828701, Long.valueOf(LIZIZ), ((IWalletService) C11100cm.LIZ(IWalletService.class)).walletExchange().LIZ(LIZIZ), Long.valueOf(LIZIZ));
                    n.LIZIZ(LIZ3, "");
                    2sR r10 = GFy.LLJILJILJ;
                    n.LIZIZ(r10, "");
                    if (((Number) r10.LIZ()).intValue() <= 1 || LIZ2) {
                        z3 = false;
                    } else {
                        z3 = true;
                    }
                    DataChannel dataChannel2 = dataChannel;
                    walletExchange2.LIZ(context2, new C270616a(2131828702, LIZ3, 2131828699, 2131828698, 2131828700, z3), (AnonymousClass16Z) new C38591g1(dataChannel2, j, z, r5, context2, LIZ2, LIZIZ));
                } else {
                    LIZ.LIZ(context2, 1, r5);
                }
                return true;
            }
        }
        r5.LIZJ();
        return true;
    }

    public final void LIZ(String str, String str2, long j) {
        String str3 = str2;
        String str4 = str;
        M12.LIZ(str4, str3);
        ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).getExchangeRatio(str4, str3, 101, j, 2).LIZ(new Hzs()).LIZ(C38491fr.LIZ, C38501fs.LIZ);
    }

    public final void LIZ(Context context, int i, C270916d r9) {
        if (LiveExchangeTaxEnableSetting.INSTANCE.getValue()) {
            LIZ.LIZ(context, i == 2 ? "LIVE_GIFTS" : "UG", "11", true, (AnonymousClass17H) new C38421fk(r9, i));
        } else if (r9 != null) {
            r9.LIZ(i, true, false);
        }
    }

    public final void LIZ(Context context, boolean z, String str, String str2, AnonymousClass17H r11) {
        String str3 = str;
        String str4 = str2;
        M12.LIZ(str3, str4);
        AnonymousClass17H r5 = r11;
        if (!LiveExchangeTaxEnableSetting.INSTANCE.getValue()) {
            r5.LIZ(true, true);
            return;
        }
        LIZ.LIZ(context, str3, str4, z, r5);
    }

    public final void LIZ(Context context, Throwable th) {
        Context context2 = context;
        if (context2 != null) {
            String LIZ2 = C10000b0.LIZ(2131828692);
            if (th instanceof AnonymousClass1JF) {
                AnonymousClass1JF r11 = (AnonymousClass1JF) th;
                r11.getErrorCode();
                LIZ2 = r11.getPrompt();
            }
            String LIZ3 = C10000b0.LIZ(2131830254);
            HV3 hv3 = new HV3(false, "", -1);
            C272216q r2 = C272216q.LIZ;
            n.LIZIZ(LIZ3, "");
            n.LIZIZ(LIZ2, "");
            r2.LIZ(context2, LIZ3, LIZ2, "", "", hv3);
        }
    }

    public final void LIZ(Context context, int i) {
        AnonymousClass16F.LIZ.LIZJ();
        AnonymousClass16F.LIZ.LJI();
        if (i == 2) {
            WalletExchange walletExchange = LIZ;
            if (!walletExchange.LIZIZ()) {
                2sR r0 = GFy.LLJJ;
                n.LIZIZ(r0, "");
                if (((Number) r0.LIZ()).intValue() > 0) {
                    2sR r02 = GFy.LLJJI;
                    n.LIZIZ(r02, "");
                    Object LIZ2 = r02.LIZ();
                    n.LIZIZ(LIZ2, "");
                    if (((Boolean) LIZ2).booleanValue()) {
                        walletExchange.LIZIZ(context, i);
                        GFy.LLJJI.LIZ(false);
                    }
                }
            }
            2sR r1 = GFy.LLJJ;
            n.LIZIZ(r1, "");
            r1.LIZ(Integer.valueOf(((Number) r1.LIZ()).intValue() + 1));
        } else if (i == 1) {
            WalletExchange walletExchange2 = LIZ;
            if (!walletExchange2.LIZ()) {
                2sR r03 = GFy.LLJILJILJ;
                n.LIZIZ(r03, "");
                if (((Number) r03.LIZ()).intValue() > 0) {
                    2sR r04 = GFy.LLJILLL;
                    n.LIZIZ(r04, "");
                    Object LIZ3 = r04.LIZ();
                    n.LIZIZ(LIZ3, "");
                    if (((Boolean) LIZ3).booleanValue()) {
                        walletExchange2.LIZIZ(context, i);
                        GFy.LLJILLL.LIZ(false);
                    }
                }
            }
            2sR r12 = GFy.LLJILJILJ;
            n.LIZIZ(r12, "");
            r12.LIZ(Integer.valueOf(((Number) r12.LIZ()).intValue() + 1));
        }
    }

    public final void LIZ(Context context, AnonymousClass17G r9, AnonymousClass17E r10) {
        if (context != null && r9 != null) {
            C271516j r3 = C271516j.LIZ;
            String LIZ2 = C10000b0.LIZ(2131828720, "6");
            if (86a.LIZ(r9.LIZIZ, "UG")) {
                LIZ2 = C10000b0.LIZ(2131828721, "6");
            }
            HK2 hk2 = new HK2(context);
            hk2.LJIIIZ = false;
            hk2.LIZ = C10000b0.LIZ(2131828722);
            hk2.LIZIZ = LIZ2;
            hk2.LIZ(C10000b0.LIZ(2131829192), new C271316h(r10, r9, context), false);
            hk2.LIZIZ(C10000b0.LIZ(2131828687), new C271416i(r10, r9), false);
            HK3 LIZ3 = hk2.LIZ();
            LIZ3.show();
            2fU.LIZ.LIZ(LIZ3);
            r3.LIZ(r9, "show");
        }
    }

    static {
        Covode.recordClassIndex(10792);
    }

    public final boolean LIZIZ() {
        if (!86a.LIZ("0", AnonymousClass16Y.LIZ.LIZ().getString("live_revenue_auto_exchange", "0"))) {
            return true;
        }
        return false;
    }

    public final void LIZJ() {
        Bundle bundle = new Bundle();
        AnonymousClass16Y.LIZ(bundle);
        int i = bundle.getInt("key_bundle_show_balance", 0);
        String str = "open";
        String str2 = "";
        if (i == -2) {
            str2 = "anchor_income";
        } else if (i == -1) {
            str2 = "ug_exchange";
        } else {
            str = str2;
            if (i == 0) {
                return;
            }
        }
        GtA LIZ2 = GtA.LJFF.LIZ("livesdk_auto_balance_exchange_status");
        LIZ2.LIZ();
        LIZ2.LIZ("status", str);
        LIZ2.LIZ("charge_reason", str2);
        LIZ2.LIZLLL();
    }

    public final boolean LIZ(C271016e r2) {
        return AnonymousClass16Y.LIZ((Context) null, r2, (C270916d) null);
    }

    public static void LIZ(HK3 hk3) {
        hk3.show();
        2fU.LIZ.LIZ(hk3);
    }

    private final String LIZ(double d) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        decimalFormat.setRoundingMode(RoundingMode.CEILING);
        String format = decimalFormat.format(d);
        n.LIZIZ(format, "");
        return format;
    }

    public static View LIZ(LayoutInflater layoutInflater) {
        MethodCollector.i(11093);
        if (9Y3.LIZ(9Y3.LIZ(), true, "tiktok_tux_text_view_opt", false) && layoutInflater != null && layoutInflater.getFactory() == null && layoutInflater.getFactory2() == null) {
            try {
                layoutInflater.setFactory(new Ql4());
            } catch (Exception unused) {
                View inflate = layoutInflater.inflate(2131561532, (ViewGroup) null);
                MethodCollector.o(11093);
                return inflate;
            }
        }
        View inflate2 = layoutInflater.inflate(2131561532, (ViewGroup) null);
        MethodCollector.o(11093);
        return inflate2;
    }

    public final void LIZIZ(String str) {
        M12.LIZ(str);
        ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).updateAutoExchange(true, 1).LIZ(new Hzs()).LIZ(new C38451fn(str), C38461fo.LIZ);
    }

    public final void LIZIZ(boolean z) {
        String str;
        String str2 = "0";
        if (z) {
            str = "1";
        } else {
            str = str2;
        }
        if (LiveAutoExchangeABTestSetting.INSTANCE.getValue()) {
            str2 = str;
        }
        AnonymousClass16Y.LIZ.LIZ().edit().putString("live_revenue_auto_exchange", str2).apply();
    }

    public final String LIZ(long j) {
        WalletCenter walletCenter = AnonymousClass16F.LIZ;
        n.LIZIZ(walletCenter, "");
        return LIZ(j, walletCenter.LIZIZ.getExchangeInfo(), false);
    }

    private void LIZIZ(Context context, int i) {
        RevenueExchange revenueExchange;
        if (i != 0) {
            if (LiveAutoExchangeABTestSetting.INSTANCE.getValue() && i == 2) {
                AnonymousClass16P.LIZ.LIZ("anchor_income");
                IWalletCenter walletCenter = ((IWalletService) C11100cm.LIZ(IWalletService.class)).walletCenter();
                n.LIZIZ(walletCenter, "");
                AnonymousClass17M LJ = walletCenter.LJ();
                if (LJ != null) {
                    revenueExchange = LJ.LIZJ;
                } else {
                    revenueExchange = null;
                }
                int i2 = 2131828269;
                if (revenueExchange != null && revenueExchange.isRevenue()) {
                    i2 = 2131828270;
                }
                HK2 hk2 = new HK2(context);
                hk2.LJIIIZ = false;
                hk2.LIZ(i2);
                hk2.LIZIZ(2131828268);
                hk2.LIZ(2131828705, new AnonymousClass16L(context), false);
                hk2.LIZIZ(2131828699, AnonymousClass16M.LIZ, false);
                LIZ(hk2.LIZ());
            } else if (i == 1) {
                AnonymousClass16P.LIZ.LIZ("ug_exchange");
                HK2 hk22 = new HK2(context);
                hk22.LJIIIZ = false;
                hk22.LIZ(2131828708);
                hk22.LIZIZ(2131828707);
                hk22.LIZ(2131828705, AnonymousClass16N.LIZ, false);
                hk22.LIZIZ(2131828699, AnonymousClass16O.LIZ, false);
                LIZ(hk22.LIZ());
            }
        }
    }

    public final String LIZ(long j, boolean z) {
        WalletCenter walletCenter = AnonymousClass16F.LIZ;
        n.LIZIZ(walletCenter, "");
        AnonymousClass17M r0 = walletCenter.LIZ;
        n.LIZIZ(r0, "");
        return LIZ(j, r0.LIZLLL, z);
    }

    public final void LIZ(AnonymousClass17B r12, HVJ hvj) {
        if (r12 != null) {
            ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).exchangeCoins(r12.LIZ, r12.LIZLLL, r12.LIZJ, r12.LJ, r12.LJFF, r12.LJI, r12.LJII).LIZ(new Hzs()).LIZ(new C38431fl(hvj), new C38441fm(hvj));
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0036, code lost:
        if (r0 != null) goto L_0x006a;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0067, code lost:
        if (r0 != null) goto L_0x006a;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x006a, code lost:
        r3 = r0;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private final java.lang.String LIZ(long r10, com.bytedance.android.live.wallet.model.BalanceStructExtra r12, boolean r13) {
        /*
            r9 = this;
            java.lang.String r3 = ""
            if (r12 == 0) goto L_0x0010
            com.bytedance.android.live.wallet.model.BasePackage r0 = r12.getBasePackage()
            if (r0 == 0) goto L_0x0010
            com.bytedance.android.live.wallet.model.CurrencyInfo r0 = r12.getCurrencyInfo()
            if (r0 != 0) goto L_0x0011
        L_0x0010:
            return r3
        L_0x0011:
            r8 = 0
            com.bytedance.android.live.wallet.model.BasePackage r0 = r12.getBasePackage()
            if (r13 == 0) goto L_0x006c
            if (r0 == 0) goto L_0x001e
            int r8 = r0.getLocalDot()
        L_0x001e:
            r1 = 0
            com.bytedance.android.live.wallet.model.BasePackage r0 = r12.getBasePackage()
            if (r13 == 0) goto L_0x0057
            if (r0 == 0) goto L_0x002c
            long r1 = r0.getLocalPrice()
        L_0x002c:
            com.bytedance.android.live.wallet.model.CurrencyInfo r0 = r12.getLocalCurrencyInfo()
            if (r0 == 0) goto L_0x0038
            java.lang.String r0 = r0.getSymbol()
            if (r0 != 0) goto L_0x006a
        L_0x0038:
            java.lang.StringBuilder r7 = new java.lang.StringBuilder
            r7.<init>()
            r7.append(r3)
            double r3 = (double) r1
            r5 = 4621819117588971520(0x4024000000000000, double:10.0)
            double r0 = (double) r8
            double r0 = java.lang.Math.pow(r5, r0)
            double r3 = r3 / r0
            double r0 = (double) r10
            double r3 = r3 * r0
            java.lang.String r0 = r9.LIZ((double) r3)
            r7.append(r0)
            java.lang.String r0 = r7.toString()
            return r0
        L_0x0057:
            if (r0 == 0) goto L_0x005d
            long r1 = r0.getPrice()
        L_0x005d:
            com.bytedance.android.live.wallet.model.CurrencyInfo r0 = r12.getCurrencyInfo()
            if (r0 == 0) goto L_0x0038
            java.lang.String r0 = r0.getSymbol()
            if (r0 != 0) goto L_0x006a
            goto L_0x0038
        L_0x006a:
            r3 = r0
            goto L_0x0038
        L_0x006c:
            if (r0 == 0) goto L_0x001e
            int r8 = r0.getRealDot()
            goto L_0x001e
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.live.wallet.WalletExchange.LIZ(long, com.bytedance.android.live.wallet.model.BalanceStructExtra, boolean):java.lang.String");
    }

    private void LIZ(Context context, String str, String str2, boolean z, AnonymousClass17H r13) {
        String str3 = str;
        String str4 = str2;
        M12.LIZ(str3, str4);
        HashMap hashMap = new HashMap();
        hashMap.put("app_id", Integer.valueOf(C11100cm.LIZ(IHostContext.class).appId()));
        HashMap hashMap2 = new HashMap();
        hashMap2.put("case_type", 1);
        hashMap2.put("w9", hashMap);
        AnonymousClass17H r3 = r13;
        ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).getTaxInfo(hashMap2).LIZ(new Hzs()).LIZ(new C38401fi(r3, z, str4, str3, context), new C38411fj(r3));
    }
}
