package com.bytedance.tux.sheet.sheet;

import X.0AA;
import X.0AP;
import X.0HH;
import X.AnonymousClass3S8;
import X.AnonymousClass3Y8;
import X.AnonymousClass3YA;
import X.AnonymousClass3YC;
import X.AnonymousClass3YE;
import X.C16832uR;
import X.C18942xq;
import X.C213133z;
import X.C29983aY;
import X.C30013ab;
import X.C30933c5;
import X.HxD;
import X.LnI;
import X.Lrq;
import X.M12;
import X.Qen;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewStub;
import android.view.Window;
import android.widget.RelativeLayout;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.tux.sheet.BaseSheet;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import java.util.Objects;
import kotlin.h.b.n;

public final class TuxSheet extends BaseSheet {
    public static final AnonymousClass3S8 LJIJI = new AnonymousClass3S8((byte) 0);
    public View LIZ;
    public Fragment LIZIZ;
    public boolean LIZJ = true;
    public C16832uR LIZLLL;
    public int LJ;
    public int LJFF = -1;
    public int LJI = -1;
    public int LJII = -1;
    public boolean LJIIIIZZ = true;
    public boolean LJIIIZ;
    public boolean LJIIJ = true;
    public boolean LJIIJJI = true;
    public C30933c5 LJIIL;
    public HxD LJIILIIL;
    public AnonymousClass3YE LJIILJJIL;
    public Integer LJIILL;
    public BottomSheetBehavior<?> LJIILLIIL;
    public Boolean LJIIZILJ;
    public boolean LJIJ = true;
    public final AnonymousClass3Y8 LJJIIJ = new AnonymousClass3Y8(this);
    public SparseArray LJJIIJZLJL;

    static {
        Covode.recordClassIndex(39294);
    }

    public final void LIZ() {
        SparseArray sparseArray = this.LJJIIJZLJL;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        LIZ();
    }

    public final void LIZIZ() {
        0AA childFragmentManager = getChildFragmentManager();
        n.LIZIZ(childFragmentManager, "");
        if (childFragmentManager.LJ() > 0) {
            getChildFragmentManager().LIZLLL();
        } else if (this.LJIIJ) {
            LJIJI.LIZ(getDialog(), (C30013ab) C29983aY.LIZ);
            onCancel(getDialog());
            dismissAllowingStateLoss();
        }
    }

    public final void onActivityCreated(Bundle bundle) {
        TuxSheet.super.onActivityCreated(bundle);
        getChildFragmentManager().LIZ(new AnonymousClass3YC(this), false);
    }

    public final Dialog onCreateDialog(Bundle bundle) {
        Dialog onCreateDialog = super.onCreateDialog(bundle);
        onCreateDialog.setOnKeyListener(new C213133z(new AnonymousClass3YA(this)));
        Integer num = this.LJIILL;
        if (num != null) {
            int intValue = num.intValue();
            Window window = onCreateDialog.getWindow();
            if (window != null) {
                window.setSoftInputMode(intValue);
            }
        }
        return onCreateDialog;
    }

    public final void LIZ(C16832uR r7) {
        ViewGroup.LayoutParams layoutParams;
        if (this.LJ == 2 && r7 != null) {
            C30933c5 r0 = this.LJIIL;
            Lrq lrq = null;
            if (r0 != null) {
                layoutParams = r0.getLayoutParams();
            } else {
                layoutParams = null;
            }
            Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.widget.RelativeLayout.LayoutParams");
            RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) layoutParams;
            Resources system = Resources.getSystem();
            n.LIZIZ(system, "");
            layoutParams2.topMargin = LnI.LIZ(TypedValue.applyDimension(1, 14.0f, system.getDisplayMetrics()));
            C30933c5 r02 = this.LJIIL;
            if (r02 != null) {
                r02.setLayoutParams(layoutParams2);
            }
            AnonymousClass3YE r03 = this.LJIILJJIL;
            if (r03 != null) {
                lrq = r03.getHandleView();
            }
            C30933c5 r04 = this.LJIIL;
            if (r04 != null) {
                r04.LIZ();
            }
            C30933c5 r05 = this.LJIIL;
            if (r05 != null) {
                int currentNavBarBackgroundColor = r05.getCurrentNavBarBackgroundColor();
                if (lrq != null) {
                    lrq.setBackgroundColor(currentNavBarBackgroundColor);
                }
            }
            C30933c5 r06 = this.LJIIL;
            if (r06 != null) {
                r06.getCurrentNavBarBackgroundColor();
            }
        }
    }

    public final void LIZ(Fragment fragment, boolean z) {
        M12.LIZ(fragment);
        0AA childFragmentManager = getChildFragmentManager();
        n.LIZIZ(childFragmentManager, "");
        String concat = "sheet_content_fragment".concat(String.valueOf(childFragmentManager.LJ() + 1));
        0AP LIZ2 = getChildFragmentManager().LIZ();
        n.LIZIZ(LIZ2, "");
        Context context = getContext();
        if (context == null || !Qen.LIZ(context)) {
            LIZ2.LIZ(2130772149, 2130772150, 2130772148, 2130772151);
        } else {
            LIZ2.LIZ(2130772148, 2130772151, 2130772149, 2130772150);
        }
        LIZ2.LIZIZ(2131370259, fragment, concat);
        LIZ2.LIZ(concat);
        LIZ2.LIZJ();
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        int i;
        MethodCollector.i(16787);
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131558424, viewGroup, false);
        this.LJIILIIL = LIZ2.findViewById(2131369236);
        AnonymousClass3YE r1 = (AnonymousClass3YE) LIZ2.findViewById(2131370258);
        this.LJIILJJIL = r1;
        r1.setFixedHeightPx(this.LJFF);
        r1.setDynamicPeekHeightPx(this.LJI);
        r1.setDynamicMaxHeightPx(this.LJII);
        r1.setVariant(this.LJ);
        r1.setHideable(this.LJIIJJI);
        r1.setDismissFunc(new C18942xq(this));
        r1.setBehavior(this.LJIILLIIL);
        r1.setBottomSheetCallback(this.LJJIIJ);
        ViewStub viewStub = (ViewStub) LIZ2.findViewById(2131370260);
        n.LIZIZ(viewStub, "");
        if (this.LJIIIIZZ) {
            i = 2131558426;
        } else {
            i = 2131558427;
        }
        viewStub.setLayoutResource(i);
        View inflate = viewStub.inflate();
        if (n.LIZ(this.LJIIZILJ, true)) {
            n.LIZIZ(inflate, "");
            ViewGroup.LayoutParams layoutParams = inflate.getLayoutParams();
            if (layoutParams != null) {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
                Resources system = Resources.getSystem();
                n.LIZIZ(system, "");
                marginLayoutParams.topMargin = LnI.LIZ(TypedValue.applyDimension(1, 14.0f, system.getDisplayMetrics()));
                inflate.setLayoutParams(marginLayoutParams);
            } else {
                NullPointerException nullPointerException = new NullPointerException("null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
                MethodCollector.o(16787);
                throw nullPointerException;
            }
        }
        if (this.LJIIIZ) {
            ViewGroup viewGroup2 = (ViewGroup) LIZ2.findViewById(2131370259);
            n.LIZIZ(viewGroup2, "");
            ViewGroup.LayoutParams layoutParams2 = viewGroup2.getLayoutParams();
            layoutParams2.height = -1;
            viewGroup2.setLayoutParams(layoutParams2);
        }
        View view = this.LIZ;
        if (view != null) {
            view.setTag(2131363900, this);
            ViewParent parent = view.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(view);
            }
            ((ViewGroup) LIZ2.findViewById(2131370259)).addView(view);
        }
        Fragment fragment = this.LIZIZ;
        if (fragment != null) {
            0AP LIZ3 = getChildFragmentManager().LIZ();
            LIZ3.LIZIZ(2131370259, fragment, "sheet_content_fragment");
            LIZ3.LIZJ();
        }
        C30933c5 r12 = (C30933c5) LIZ2.findViewById(2131370269);
        this.LJIIL = r12;
        if (r12 != null) {
            r12.setNavActions(this.LIZLLL);
        }
        LIZ(this.LIZLLL);
        if (this.LIZJ) {
            Dialog dialog = getDialog();
            n.LIZIZ(dialog, "");
            Window window = dialog.getWindow();
            if (window != null) {
                window.addFlags(2);
            }
            Dialog dialog2 = getDialog();
            n.LIZIZ(dialog2, "");
            Window window2 = dialog2.getWindow();
            if (window2 != null) {
                window2.setDimAmount(0.5f);
            }
        } else {
            Dialog dialog3 = getDialog();
            n.LIZIZ(dialog3, "");
            Window window3 = dialog3.getWindow();
            if (window3 != null) {
                window3.clearFlags(2);
            }
        }
        MethodCollector.o(16787);
        return LIZ2;
    }
}
