package com.bytedance.android.livesdk.usermanage;

import X.0Uo;
import X.0V3;
import X.0Ys;
import X.0b0;
import X.0c0;
import X.0cm;
import X.0yx;
import X.163;
import X.164;
import X.165;
import X.166;
import X.167;
import X.168;
import X.16A;
import X.2Pr;
import X.86a;
import X.C1420G2b;
import X.C1423G2e;
import X.C1424G2f;
import X.C1429G2k;
import X.C1439G2u;
import X.C1440G2v;
import X.C1441G2w;
import X.C1442G2x;
import X.C1444G2z;
import X.C1831GHw;
import X.C2206GWh;
import X.C2402Gbb;
import X.C2704GgT;
import X.C3028Glh;
import X.C3441GsM;
import X.C3491GtA;
import X.C3499GtI;
import X.C4100H7d;
import X.C5164Hf3;
import X.C6455Hzs;
import X.G30;
import X.G31;
import X.G32;
import X.G3I;
import X.G3J;
import X.G3K;
import X.G3L;
import X.G3M;
import X.G3N;
import X.G3O;
import X.G3R;
import X.G3V;
import X.G99;
import X.GAW;
import X.GSY;
import X.HGR;
import X.LsC;
import X.M12;
import X.Mjy;
import X.Mk2;
import X.Mk3;
import X.PgV;
import X.PgX;
import X.Ph1;
import X.PhE;
import X.PlI;
import android.app.Dialog;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.live.browser.IBrowserService;
import com.bytedance.android.live.browser.IHybridContainerService;
import com.bytedance.android.live.liveinteract.api.IInteractService;
import com.bytedance.android.live.usermanage.IUserManageService;
import com.bytedance.android.livesdk.container.config.base.PopupConfig;
import com.bytedance.android.livesdk.container.config.live.LivePopupConfig;
import com.bytedance.android.livesdk.livesetting.roomfunction.LiveMuteCommentsListSetting;
import com.bytedance.android.livesdk.livesetting.roomfunction.LiveReportOptimizeUrlSetting;
import com.bytedance.android.livesdk.ui.BaseFragment;
import com.bytedance.android.livesdkapi.host.IHostAction;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONObject;

public class UserManageService implements IUserManageService {
    static {
        Covode.recordClassIndex(21288);
    }

    public void onInit() {
    }

    public boolean hasAdminBlockPermission() {
        return C1429G2k.LIZ.LIZ(3);
    }

    public boolean hasAdminMutePermission() {
        return C1429G2k.LIZ.LIZ(2);
    }

    public boolean hasAdminPinMessagePermission() {
        return C1429G2k.LIZ.LIZ(4);
    }

    public PgV<0Ys> getMuteDuration() {
        C3028Glh LIZIZ = C4100H7d.LIZ().LIZIZ();
        n.LIZIZ(LIZIZ, "");
        long LIZJ = LIZIZ.LIZJ();
        0Ys r0 = G3I.LIZ.get(Long.valueOf(LIZJ));
        if (r0 != null) {
            PgV<0Ys> LIZ = PgV.LIZ(r0);
            n.LIZIZ(LIZ, "");
            return LIZ;
        }
        PgV<0Ys> LIZ2 = PgV.LIZ(new G3O(LIZJ)).LIZIZ(0Ys.LIZIZ).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ));
        n.LIZIZ(LIZ2, "");
        return LIZ2;
    }

    public String getReportScene() {
        IInteractService LIZ = 0cm.LIZ(IInteractService.class);
        n.LIZIZ(LIZ, "");
        if (LIZ.isRoomInBattle()) {
            return "manual_pk";
        }
        IInteractService LIZ2 = 0cm.LIZ(IInteractService.class);
        n.LIZIZ(LIZ2, "");
        if (LIZ2.isInCoHost()) {
            return "anchor";
        }
        IInteractService LIZ3 = 0cm.LIZ(IInteractService.class);
        n.LIZIZ(LIZ3, "");
        if (LIZ3.getLinkedGuestNum() > 0) {
            return "audience";
        }
        return "regular";
    }

    public void fetchMuteDurationList(LsC<? super List<0Ys>, 2Pr> lsC) {
        M12.LIZ(lsC);
        M12.LIZ(lsC);
        double[] value = LiveMuteCommentsListSetting.INSTANCE.getValue();
        ArrayList arrayList = new ArrayList(value.length);
        for (double d : value) {
            arrayList.add(new 0Ys((long) d));
        }
        lsC.invoke(arrayList);
    }

    public void setMuteDuration(0Ys r5) {
        M12.LIZ(r5);
        M12.LIZ(r5);
        C3028Glh LIZIZ = C4100H7d.LIZ().LIZIZ();
        n.LIZIZ(LIZIZ, "");
        long LIZJ = LIZIZ.LIZJ();
        if (!n.LIZ(G3I.LIZ.get(Long.valueOf(LIZJ)), r5)) {
            G3I.LIZ.put(Long.valueOf(LIZJ), r5);
            DataChannelGlobal.LIZLLL.LIZJ(HGR.class, r5);
            Ph1.LIZ(new G3J(r5)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(PgX.LJII).LIZIZ();
        }
    }

    public void fetchAdminList(163 r5, long j) {
        String str;
        0Uo LIZ;
        M12.LIZ(r5);
        M12.LIZ(r5);
        WeakReference weakReference = new WeakReference(r5);
        AdminApi adminApi = (AdminApi) 0yx.LIZ().LIZ(AdminApi.class);
        String LIZ2 = C4100H7d.LIZ().LIZIZ().LIZ(j);
        C3028Glh LIZIZ = C4100H7d.LIZ().LIZIZ();
        if (LIZIZ == null || (LIZ = LIZIZ.LIZ()) == null) {
            str = null;
        } else {
            str = LIZ.getSecUid();
        }
        adminApi.fetchAdministrators(j, LIZ2, str).LIZ(new C6455Hzs()).LIZ(new C1424G2f(weakReference), new C1423G2e(weakReference));
    }

    public void report(Context context, G3V g3v) {
        boolean z;
        M12.LIZ(g3v);
        String value = LiveReportOptimizeUrlSetting.INSTANCE.getValue();
        if (TextUtils.isEmpty(value)) {
            C1831GHw LIZLLL = 0V3.LIZ.LIZLLL("ttlive_report_user_error");
            LIZLLL.LIZ("error_code", (Long) -1L);
            LIZLLL.LIZ("error_msg", "live report url is empty");
            LIZLLL.LIZJ = true;
            LIZLLL.LIZ();
            return;
        }
        String LIZ = g3v.LIZ(value);
        IHostAction LIZ2 = 0cm.LIZ(IHostAction.class);
        if (LIZ2 != null) {
            z = LIZ2.hostInterceptSpark(LIZ);
        } else {
            z = false;
        }
        if (context == null) {
            return;
        }
        if (z) {
            n.LIZIZ(LIZ, "");
            handleSparkContainer(LIZ, g3v, context);
            return;
        }
        n.LIZIZ(LIZ, "");
        handleLiveContainer(LIZ, g3v, context);
    }

    public void report(Context context, C2704GgT ggT) {
        String str;
        C2704GgT ggT2 = ggT;
        M12.LIZ(ggT2);
        String LIZ = C2402Gbb.LIZ.LIZ();
        String LIZLLL = C2402Gbb.LIZ.LIZLLL();
        String str2 = ggT2.LJJIIJ;
        if (str2 == null || str2.length() == 0) {
            str = "share";
        } else {
            str = ggT2.LJJIIJ;
        }
        G3V g3v = new G3V(ggT2.LIZJ, ggT2.LIZLLL, ggT2.LIZLLL, ggT2.LJIL, str, LIZ, LIZLLL, C2402Gbb.LIZ.LJ(), "report_anchor", ggT2.LJIJI, new C3441GsM((DataChannel) null, "user_live_duration"));
        g3v.LJIJJLI = ggT2.LJJJI;
        g3v.LJIILIIL = ggT2.LJJJJ;
        report(context, g3v);
    }

    public 166 configUserHelper(BaseFragment baseFragment, DataChannel dataChannel, Mjy mjy) {
        M12.LIZ(baseFragment, dataChannel, mjy);
        return new G99(baseFragment, dataChannel, mjy);
    }

    public void unmuteUser(User user, long j, 168 r14) {
        M12.LIZ(user, r14);
        M12.LIZ(user, r14);
        WeakReference weakReference = new WeakReference(r14);
        long j2 = j;
        ((MuteApi) 0yx.LIZ().LIZ(MuteApi.class)).unmute(j2, user.getId(), user.getSecUid()).LIZ(new C6455Hzs()).LIZ(new G3L(user, weakReference, j2), new G3N(weakReference, j2, user));
    }

    private final void handleSparkContainer(String str, G3V g3v, Context context) {
        int i;
        int LIZLLL;
        C2206GWh LIZIZ = C2206GWh.LIZ.LIZIZ(str);
        C2206GWh unused = LIZIZ.LIZIZ(8, GAW.DP);
        if (g3v.LJ != 0) {
            i = g3v.LJ;
        } else if (g3v.LJIILIIL) {
            i = (int) 0b0.LJ((int) ((((float) 0b0.LIZIZ()) * 1.0f) / 2.0f));
        } else {
            i = -1;
        }
        C2206GWh unused2 = LIZIZ.LIZ(i, GAW.DP);
        if (g3v.LJFF != 0) {
            LIZLLL = g3v.LJFF;
        } else if (g3v.LJIILIIL) {
            LIZLLL = (int) 0b0.LJ(0b0.LIZJ());
        } else {
            LIZLLL = 0b0.LIZLLL(2131166139);
        }
        C2206GWh unused3 = LIZIZ.LIZJ(LIZLLL, GAW.DP);
        LIZIZ.LIZJ("bottom");
        LIZIZ.LIZ(0);
        String uri = LIZIZ.LJIIJ().toString();
        n.LIZIZ(uri, "");
        0cm.LIZ(IHybridContainerService.class).openSparkContainer(context, uri, new GSY(this, str, g3v));
        onContainerShow(str, g3v, true);
    }

    private final void handleLiveContainer(String str, G3V g3v, Context context) {
        int LIZLLL;
        PopupConfig popupConfig = new PopupConfig(new Uri.Builder().scheme("sslocal").authority(C5164Hf3.LIZIZ).appendQueryParameter("url", str).build());
        int i = -1;
        if (n.LIZ(g3v.LJIILJJIL, "report_anchor")) {
            if (g3v.LJ != 0) {
                i = g3v.LJ;
            } else if (g3v.LJIILIIL) {
                i = (int) (((float) 0b0.LIZIZ()) * 0.73f);
            }
            popupConfig.setHeight(i);
            LivePopupConfig livePopupConfig = new LivePopupConfig();
            livePopupConfig.setSoftInputMode("adjustPan");
            popupConfig.setExtraConfig(livePopupConfig);
        } else {
            if (g3v.LJ != 0) {
                i = g3v.LJ;
            } else if (g3v.LJIILIIL) {
                i = (int) ((((float) 0b0.LIZIZ()) * 1.0f) / 2.0f);
            }
            popupConfig.setHeight(i);
        }
        if (g3v.LJFF != 0) {
            LIZLLL = g3v.LJFF;
        } else if (g3v.LJIILIIL) {
            LIZLLL = 0b0.LIZJ();
        } else {
            LIZLLL = 0b0.LIZLLL(2131166136);
        }
        popupConfig.setWidth(LIZLLL);
        String str2 = "center";
        if (!g3v.LJIILIIL || !TextUtils.equals(popupConfig.getGravity(), str2)) {
            if (g3v.LJIILIIL) {
                str2 = "bottom";
            } else {
                str2 = "right";
            }
        }
        popupConfig.setAnimation(str2);
        IBrowserService LIZ = 0cm.LIZ(IBrowserService.class);
        if (LIZ != null) {
            LIZ.openHybridDialog(context, popupConfig);
        } else {
            onReportShowFail(str, g3v, false, "service is null");
        }
        onContainerShow(str, g3v, false);
    }

    private final void onContainerShow(String str, G3V g3v, boolean z) {
        HashMap hashMap = new HashMap();
        String valueOf = String.valueOf(g3v.LIZLLL);
        n.LIZIZ(valueOf, "");
        hashMap.put("to_user_id", valueOf);
        String str2 = g3v.LJII;
        n.LIZIZ(str2, "");
        hashMap.put("request_page", str2);
        hashMap.put("event_page", "live_detail");
        String LIZ = g3v.LIZ();
        n.LIZIZ(LIZ, "");
        hashMap.put("admin_type", LIZ);
        if (n.LIZ(g3v.LJIILLIIL, "3")) {
            hashMap.put("report_type", "report_question");
        } else if (!TextUtils.isEmpty(g3v.LJIILJJIL)) {
            String str3 = g3v.LJIILJJIL;
            n.LIZIZ(str3, "");
            hashMap.put("report_type", str3);
        }
        if (!TextUtils.isEmpty(g3v.LJIILL)) {
            String str4 = g3v.LJIILL;
            if (str4 == null) {
                str4 = "";
            }
            n.LIZIZ(str4, "");
            hashMap.put("report_content", str4);
        }
        if (!TextUtils.isEmpty(g3v.LJIJI)) {
            String str5 = g3v.LJIJI;
            n.LIZIZ(str5, "");
            hashMap.put("video_id", str5);
        }
        C3499GtI LIZ2 = C3499GtI.LIZ();
        n.LIZIZ(LIZ2, "");
        if (!86a.LIZ(LIZ2.LJ())) {
            C3499GtI LIZ3 = C3499GtI.LIZ();
            n.LIZIZ(LIZ3, "");
            String LJ = LIZ3.LJ();
            n.LIZIZ(LJ, "");
            hashMap.put("enter_live_method", LJ);
        }
        hashMap.put("small_picture_order", C2402Gbb.LIZ.LJIIJJI());
        hashMap.put("live_window_mode", C2402Gbb.LIZ.LJIIL());
        if (0b0.LJFF()) {
            hashMap.put("room_orientation", "portrait");
        } else {
            hashMap.put("room_orientation", "landscape");
        }
        hashMap.put("report_click_time", String.valueOf(System.currentTimeMillis()));
        C3491GtA LIZ4 = C3491GtA.LJFF.LIZ("livesdk_live_user_report");
        LIZ4.LIZ((Map<String, String>) hashMap);
        LIZ4.LIZ("scene", g3v.LJIJJLI);
        LIZ4.LIZ();
        LIZ4.LIZ(new C3441GsM("user_live_duration"));
        LIZ4.LIZLLL();
        C1831GHw LIZ5 = 0V3.LIZ.LIZ("ttlive_report_user");
        LIZ5.LIZ("report_url", str);
        LIZ5.LIZ();
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("enter_from", g3v.LJIIIIZZ);
        jSONObject.put("enter_method", g3v.LJIIIZ);
        jSONObject.put("use_spark", z);
        jSONObject.put("report_url", str);
        for (Map.Entry entry : hashMap.entrySet()) {
            jSONObject.put((String) entry.getKey(), entry.getValue());
        }
        0c0.LIZIZ("ttlive_live_report_click", 0, jSONObject);
    }

    public void fetchKickOutList(164 r11, long j, int i, int i2) {
        String str;
        0Uo LIZ;
        M12.LIZ(r11);
        M12.LIZ(r11);
        WeakReference weakReference = new WeakReference(r11);
        r11.LIZ();
        KickOutApi kickOutApi = (KickOutApi) 0yx.LIZ().LIZ(KickOutApi.class);
        C3028Glh LIZIZ = C4100H7d.LIZ().LIZIZ();
        if (LIZIZ == null || (LIZ = LIZIZ.LIZ()) == null) {
            str = null;
        } else {
            str = LIZ.getSecUid();
        }
        long j2 = j;
        kickOutApi.getKickedOutList(j2, i2, i, str).LIZ(new C6455Hzs()).LIZ(new C1441G2w(weakReference), new C1442G2x(weakReference));
    }

    public void fetchMuteList(165 r11, long j, int i, int i2) {
        String str;
        0Uo LIZ;
        M12.LIZ(r11);
        M12.LIZ(r11);
        WeakReference weakReference = new WeakReference(r11);
        r11.LIZLLL();
        MuteApi muteApi = (MuteApi) 0yx.LIZ().LIZ(MuteApi.class);
        C3028Glh LIZIZ = C4100H7d.LIZ().LIZIZ();
        if (LIZIZ == null || (LIZ = LIZIZ.LIZ()) == null) {
            str = null;
        } else {
            str = LIZ.getSecUid();
        }
        long j2 = j;
        muteApi.getMuteList(j2, i2, i, str).LIZ(new C6455Hzs()).LIZ(new C1439G2u(weakReference), new C1440G2v(weakReference));
    }

    public void kickOut(164 r16, boolean z, long j, long j2) {
        164 r0 = r16;
        M12.LIZ(r0);
        M12.LIZ(r0);
        WeakReference weakReference = new WeakReference(r0);
        long j3 = j;
        long j4 = j2;
        boolean z2 = z;
        if (z2) {
            ((KickOutApi) 0yx.LIZ().LIZ(KickOutApi.class)).kickOut(j3, j4).LIZ(new C6455Hzs()).LIZ(new G31(weakReference, z2, j3, j4), new C1444G2z(weakReference, z2, j3, j4));
        } else {
            ((KickOutApi) 0yx.LIZ().LIZ(KickOutApi.class)).unKickOut(j3, j4).LIZ(new C6455Hzs()).LIZ(new G32(weakReference, false, j3, j4), new G30(weakReference, false, j3, j4));
        }
    }

    public void muteUser(User user, long j, 0Ys r21, 168 r22) {
        long j2;
        0Ys r2 = r21;
        168 r1 = r22;
        User user2 = user;
        M12.LIZ(user2, r2, r1);
        M12.LIZ(user2, r2, r1);
        if (n.LIZ(r2, 0Ys.LIZIZ)) {
            j2 = 0;
        } else {
            j2 = 1;
        }
        WeakReference weakReference = new WeakReference(r1);
        long j3 = j;
        ((MuteApi) 0yx.LIZ().LIZ(MuteApi.class)).mute(j3, user2.getId(), j2, user2.getSecUid(), r2.LIZ).LIZ(new C6455Hzs()).LIZ(new G3K(user2, weakReference, j3), new G3M(weakReference, j3, user2));
    }

    public final void onReportShowFail(String str, G3V g3v, boolean z, String str2) {
        HashMap hashMap = new HashMap();
        String valueOf = String.valueOf(g3v.LIZLLL);
        n.LIZIZ(valueOf, "");
        hashMap.put("to_user_id", valueOf);
        String str3 = g3v.LJII;
        n.LIZIZ(str3, "");
        hashMap.put("request_page", str3);
        hashMap.put("event_page", "live_detail");
        String LIZ = g3v.LIZ();
        n.LIZIZ(LIZ, "");
        hashMap.put("admin_type", LIZ);
        if (n.LIZ(g3v.LJIILLIIL, "3")) {
            hashMap.put("report_type", "report_question");
        } else if (!TextUtils.isEmpty(g3v.LJIILJJIL)) {
            String str4 = g3v.LJIILJJIL;
            n.LIZIZ(str4, "");
            hashMap.put("report_type", str4);
        }
        if (!TextUtils.isEmpty(g3v.LJIJI)) {
            String str5 = g3v.LJIJI;
            n.LIZIZ(str5, "");
            hashMap.put("video_id", str5);
        }
        C3499GtI LIZ2 = C3499GtI.LIZ();
        n.LIZIZ(LIZ2, "");
        if (!86a.LIZ(LIZ2.LJ())) {
            C3499GtI LIZ3 = C3499GtI.LIZ();
            n.LIZIZ(LIZ3, "");
            String LJ = LIZ3.LJ();
            n.LIZIZ(LJ, "");
            hashMap.put("enter_live_method", LJ);
        }
        hashMap.put("small_picture_order", C2402Gbb.LIZ.LJIIJJI());
        hashMap.put("live_window_mode", C2402Gbb.LIZ.LJIIL());
        if (0b0.LJFF()) {
            hashMap.put("room_orientation", "portrait");
        } else {
            hashMap.put("room_orientation", "landscape");
        }
        JSONObject jSONObject = new JSONObject();
        for (Map.Entry entry : hashMap.entrySet()) {
            jSONObject.put((String) entry.getKey(), entry.getValue());
        }
        jSONObject.put("enter_from", g3v.LJIIIIZZ);
        jSONObject.put("enter_method", g3v.LJIIIZ);
        jSONObject.put("use_spark", z);
        jSONObject.put("report_url", str);
        jSONObject.put("fail_reason", str2);
        0c0.LIZIZ("ttlive_live_report_load_fail", 0, jSONObject);
    }

    public Dialog getEnsureKickOutDialog(Context context, long j, long j2, long j3, 167 r17) {
        return new G3R(context, j, j2, j3, r17);
    }

    public void updateAdmin(163 r10, boolean z, 16A r12, long j, long j2, String str) {
        163 r1 = r10;
        M12.LIZ(r1);
        long j3 = j;
        C1420G2b.LIZ.LIZ(r1, z, r12, j3, j2, str);
    }

    public void updateAdmin(163 r11, boolean z, User user, long j, long j2, String str) {
        163 r2 = r11;
        M12.LIZ(r2);
        C1420G2b g2b = C1420G2b.LIZ;
        M12.LIZ(r2);
        if (user != null) {
            long j3 = j;
            g2b.LIZ(r2, z, 16A.LJIIIIZZ.LIZ(user), j3, j2, str);
        }
    }
}
