package com.ss.android.ugc.aweme.commercialize.preview.manager;

import X.0CB;
import X.0CH;
import X.0CN;
import X.2cN;
import X.325;
import X.3Cl;
import X.4Dd;
import X.6Is;
import X.C4179Lfm;
import X.C4180Lfn;
import X.C4181Lfo;
import X.C4182Lfp;
import X.C4184Lfr;
import X.C4186Lft;
import X.Mjy;
import X.PhE;
import X.Pkb;
import X.PlI;
import com.bytedance.covode.number.Covode;
import com.bytedance.keva.Keva;
import com.ss.android.ugc.aweme.commercialize.preview.api.AdsPreviewApi;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class AdsPreviewStateManager implements 6Is {
    public static List<String> LJFF;
    public static List<String> LJI;
    public static final C4182Lfp LJII = new C4182Lfp((byte) 0);
    public final Pkb<C4184Lfr> LIZ;
    public final Mjy LIZIZ = new Mjy();
    public C4186Lft LIZJ;
    public String LIZLLL = "";
    public String LJ = "";
    public final Keva LJIIIIZZ = Keva.getRepo("ads_preview_keva");

    static {
        Covode.recordClassIndex(59358);
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            dispose();
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void dispose() {
        this.LIZIZ.dispose();
    }

    public AdsPreviewStateManager() {
        Pkb<C4184Lfr> pkb = new Pkb<>();
        n.LIZIZ(pkb, "");
        this.LIZ = pkb;
    }

    public final void LIZ() {
        2cN LIZ2 = ((AdsPreviewApi) 325.LIZ.LIZ(AdsPreviewApi.class, 3Cl.LIZ)).sendAdsPreviewRequest(this.LIZLLL, this.LJ).LIZJ(new C4181Lfo(this)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(new C4180Lfn(this), new C4179Lfm(this));
        n.LIZIZ(LIZ2, "");
        4Dd.LIZ(LIZ2, this.LIZIZ);
    }

    public final void LIZ(C4184Lfr lfr) {
        this.LIZ.onNext(lfr);
    }

    public static final /* synthetic */ C4186Lft LIZ(AdsPreviewStateManager adsPreviewStateManager) {
        C4186Lft lft = adsPreviewStateManager.LIZJ;
        if (lft == null) {
            n.LIZ("");
        }
        return lft;
    }

    public final void LIZ(List<String> list, List<String> list2) {
        boolean z;
        LJFF = list;
        LJI = list2;
        if (list == null || list.isEmpty()) {
            z = true;
        } else {
            z = false;
        }
        if (!z) {
            this.LJIIIIZZ.storeLong("preview_timestamp", System.currentTimeMillis());
            Keva keva = this.LJIIIIZZ;
            Object[] array = list.toArray(new String[0]);
            Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
            keva.storeStringArray("preview_adids", (String[]) array);
        }
        if (list2 != null && !list2.isEmpty()) {
            this.LJIIIIZZ.storeLong("preview_timestamp", System.currentTimeMillis());
            Keva keva2 = this.LJIIIIZZ;
            Object[] array2 = list2.toArray(new String[0]);
            Objects.requireNonNull(array2, "null cannot be cast to non-null type kotlin.Array<T>");
            keva2.storeStringArray("preview_cids", (String[]) array2);
        }
    }
}
