package o8;

import android.R;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import ca.canadapost.core.data.model.CoreConstants;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.lang.ref.WeakReference;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import v4.j;

/* loaded from: classes.dex */
public class l implements j.c {

    /* renamed from: a, reason: collision with root package name */
    private final ca.canadapost.core.common.navigation.ui.b f31043a;

    /* renamed from: b, reason: collision with root package name */
    private final d0 f31044b;

    /* renamed from: c, reason: collision with root package name */
    private Set f31045c;

    /* renamed from: d, reason: collision with root package name */
    private WeakReference f31046d;

    /* renamed from: e, reason: collision with root package name */
    private k.b f31047e;

    /* renamed from: f, reason: collision with root package name */
    private ValueAnimator f31048f;

    public l(ca.canadapost.core.common.navigation.ui.b activity, d0 navViewModel, y4.d configuration) {
        kotlin.jvm.internal.t.g(activity, "activity");
        kotlin.jvm.internal.t.g(navViewModel, "navViewModel");
        kotlin.jvm.internal.t.g(configuration, "configuration");
        this.f31043a = activity;
        this.f31044b = navViewModel;
        this.f31045c = configuration.c();
        configuration.b();
        this.f31046d = null;
    }

    private final boolean b(v4.o oVar, Set set) {
        do {
            kotlin.jvm.internal.t.d(oVar);
            if (set.contains(Integer.valueOf(oVar.D()))) {
                return true;
            }
            oVar = oVar.G();
        } while (oVar != null);
        return false;
    }

    private final void c(boolean z10) {
        boolean z11;
        if (this.f31047e == null) {
            k.b bVar = new k.b(this.f31043a);
            this.f31047e = bVar;
            bVar.d(androidx.core.content.res.h.d(this.f31043a.getResources(), R.color.white, this.f31043a.getTheme()));
            z11 = false;
        } else {
            z11 = true;
        }
        d(this.f31047e, z10 ? h7.l.G0 : h7.l.F0);
        float f10 = BitmapDescriptorFactory.HUE_RED;
        float f11 = z10 ? 0.0f : 1.0f;
        if (!z11) {
            k.b bVar2 = this.f31047e;
            if (bVar2 == null) {
                return;
            }
            bVar2.setProgress(f11);
            return;
        }
        k.b bVar3 = this.f31047e;
        if (bVar3 != null) {
            f10 = bVar3.a();
        }
        ValueAnimator valueAnimator = this.f31048f;
        if (valueAnimator != null) {
            valueAnimator.cancel();
        }
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.f31047e, "progress", f10, f11);
        this.f31048f = ofFloat;
        if (ofFloat != null) {
            ofFloat.start();
        }
    }

    private final void d(Drawable drawable, int i10) {
        i.a E = this.f31043a.E();
        if (drawable == null) {
            if (E != null) {
                E.u(false);
            }
        } else {
            if (E != null) {
                E.u(true);
            }
            i.b D = this.f31043a.D();
            if (D != null) {
                D.b(drawable, i10);
            }
        }
    }

    private final void e(CharSequence charSequence) {
        i.a E = this.f31043a.E();
        if (E == null) {
            return;
        }
        E.A(charSequence);
    }

    @Override // v4.j.c
    public void a(v4.j controller, v4.o destination, Bundle bundle) {
        kotlin.jvm.internal.t.g(controller, "controller");
        kotlin.jvm.internal.t.g(destination, "destination");
        if (destination instanceof v4.d) {
            return;
        }
        WeakReference weakReference = this.f31046d;
        if (weakReference != null) {
            android.support.v4.media.session.b.a(weakReference.get());
        }
        if (this.f31046d != null) {
            controller.e0(this);
            return;
        }
        CharSequence E = destination.E();
        if (E != null) {
            StringBuffer stringBuffer = new StringBuffer();
            Matcher matcher = Pattern.compile("\\{(.+?)\\}").matcher(E);
            while (matcher.find()) {
                String group = matcher.group(1);
                if (bundle == null || !bundle.containsKey(group)) {
                    throw new IllegalArgumentException("Could not find " + group + " in " + bundle + " to fill label " + ((Object) E));
                }
                matcher.appendReplacement(stringBuffer, "");
                stringBuffer.append(String.valueOf(bundle.get(group)));
            }
            matcher.appendTail(stringBuffer);
            e(stringBuffer);
        }
        boolean z10 = bundle != null ? bundle.getBoolean(CoreConstants.DISPLAY_CLOSE_ICON) : false;
        boolean z11 = bundle != null ? bundle.getBoolean("displayProfileIcon") : false;
        boolean w02 = this.f31044b.w0(this.f31043a.d());
        boolean b10 = b(destination, this.f31045c);
        rm.v vVar = z10 ? new rm.v(androidx.core.content.res.h.f(this.f31043a.getResources(), h7.h.f21027w, this.f31043a.getTheme()), 0) : z11 ? new rm.v(androidx.core.content.res.h.f(this.f31043a.getResources(), h7.h.f20998h0, this.f31043a.getTheme()), Integer.valueOf(h7.l.f21155i1)) : new rm.v(null, 0);
        Drawable drawable = (Drawable) vVar.a();
        int intValue = ((Number) vVar.b()).intValue();
        if (!b10) {
            if (z10) {
                d(drawable, intValue);
                return;
            } else {
                c(false);
                return;
            }
        }
        if ((z11 && w02) || z10) {
            d(drawable, intValue);
        } else if (w02) {
            d(null, 0);
        } else {
            c(false);
        }
    }
}
