package dc;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import ca.canadapost.core.data.findrate.model.FindRateResponseItem;
import ca.canadapost.core.data.findrate.model.Product;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.material.chip.Chip;
import dc.r0;
import java.util.Date;
import java.util.List;
import org.joda.time.DateTime;

/* loaded from: classes4.dex */
public final class r0 extends RecyclerView.h {

    /* renamed from: d, reason: collision with root package name */
    private final dn.l f16166d;

    /* renamed from: e, reason: collision with root package name */
    private final ca.a f16167e;

    /* renamed from: f, reason: collision with root package name */
    private final Context f16168f;

    /* renamed from: g, reason: collision with root package name */
    private final Integer f16169g;

    /* renamed from: h, reason: collision with root package name */
    private final DateTime f16170h;

    /* renamed from: i, reason: collision with root package name */
    private final List f16171i;

    /* renamed from: j, reason: collision with root package name */
    private final boolean f16172j;

    /* renamed from: k, reason: collision with root package name */
    private List f16173k;

    /* loaded from: classes4.dex */
    public final class a extends RecyclerView.e0 {
        private final ec.o J;
        final /* synthetic */ r0 K;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public a(r0 r0Var, ec.o binding) {
            super(binding.x());
            kotlin.jvm.internal.t.g(binding, "binding");
            this.K = r0Var;
            this.J = binding;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void Q(r0 this$0, FindRateResponseItem item, View view) {
            kotlin.jvm.internal.t.g(this$0, "this$0");
            kotlin.jvm.internal.t.g(item, "$item");
            this$0.f16166d.invoke(item);
        }

        private final String R(FindRateResponseItem findRateResponseItem, int i10, int i11) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append(this.K.f16168f.getString(h0.T0));
            sb2.append(this.K.f16168f.getString(h0.A0));
            boolean z10 = true;
            sb2.append(i10 + 1);
            sb2.append(this.K.f16168f.getString(h0.f16072c1));
            sb2.append(i11);
            String P = this.K.P(findRateResponseItem);
            if (!(P == null || P.length() == 0)) {
                sb2.append(this.K.P(findRateResponseItem));
            }
            String Q = this.K.Q(findRateResponseItem);
            if (!(Q == null || Q.length() == 0)) {
                sb2.append(this.K.Q(findRateResponseItem));
                sb2.append(" ");
            }
            String N = this.K.N(findRateResponseItem);
            if (N != null && N.length() != 0) {
                z10 = false;
            }
            if (!z10) {
                sb2.append(this.K.N(findRateResponseItem));
                if (this.K.O(findRateResponseItem) == 0) {
                    sb2.append(this.K.f16168f.getString(h0.f16107p0));
                }
            }
            if (this.K.T(findRateResponseItem)) {
                sb2.append(this.K.f16168f.getString(h0.H0));
            }
            if (this.K.R(findRateResponseItem)) {
                sb2.append(this.K.f16168f.getString(h0.P));
            }
            String sb3 = sb2.toString();
            kotlin.jvm.internal.t.f(sb3, "toString(...)");
            return sb3;
        }

        public final void P(final FindRateResponseItem item, int i10, int i11) {
            kotlin.jvm.internal.t.g(item, "item");
            this.J.H.setText(this.K.P(item));
            this.J.G.setText(this.K.Q(item));
            String N = this.K.N(item);
            if (N == null || N.length() == 0) {
                this.J.B.setVisibility(8);
                this.J.D.setVisibility(8);
            } else {
                this.J.C.setText(N);
                this.J.B.setVisibility(0);
                this.J.D.setVisibility(this.K.O(item));
            }
            if (this.K.T(item)) {
                Chip mostFuelEfficient = this.J.F;
                kotlin.jvm.internal.t.f(mostFuelEfficient, "mostFuelEfficient");
                w8.d0.r(mostFuelEfficient);
            } else {
                Chip mostFuelEfficient2 = this.J.F;
                kotlin.jvm.internal.t.f(mostFuelEfficient2, "mostFuelEfficient");
                w8.d0.o(mostFuelEfficient2);
            }
            this.J.A.setText(this.K.f16172j ? this.K.f16168f.getString(h0.P) : this.K.f16168f.getString(h0.M));
            if (this.K.R(item)) {
                Chip carbonNeutral = this.J.A;
                kotlin.jvm.internal.t.f(carbonNeutral, "carbonNeutral");
                w8.d0.r(carbonNeutral);
            } else {
                Chip carbonNeutral2 = this.J.A;
                kotlin.jvm.internal.t.f(carbonNeutral2, "carbonNeutral");
                w8.d0.o(carbonNeutral2);
            }
            this.J.x().setContentDescription(R(item, i10, i11));
            View x10 = this.J.x();
            kotlin.jvm.internal.t.f(x10, "getRoot(...)");
            final r0 r0Var = this.K;
            w8.d0.p(x10, new View.OnClickListener() { // from class: dc.q0
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    r0.a.Q(r0.this, item, view);
                }
            });
        }
    }

    public r0(dn.l onItemClickListener, ca.a languageService, Context context, Integer num, DateTime dateTime, List list, boolean z10) {
        List k10;
        kotlin.jvm.internal.t.g(onItemClickListener, "onItemClickListener");
        kotlin.jvm.internal.t.g(languageService, "languageService");
        kotlin.jvm.internal.t.g(context, "context");
        this.f16166d = onItemClickListener;
        this.f16167e = languageService;
        this.f16168f = context;
        this.f16169g = num;
        this.f16170h = dateTime;
        this.f16171i = list;
        this.f16172j = z10;
        k10 = sm.u.k();
        this.f16173k = k10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String N(FindRateResponseItem findRateResponseItem) {
        boolean U;
        if (S() && this.f16169g != null && this.f16170h != null) {
            List list = this.f16171i;
            boolean z10 = false;
            if (list != null) {
                List list2 = list;
                Product product = findRateResponseItem.getProduct();
                U = sm.c0.U(list2, product != null ? product.getId() : null);
                if (U) {
                    z10 = true;
                }
            }
            if (z10) {
                return this.f16168f.getString(h0.f16113s0, qa.d.d(new Date(this.f16170h.getMillis()), this.f16167e.d()));
            }
        }
        if (findRateResponseItem.getMaxDays() > 0) {
            return (findRateResponseItem.getMaxDays() == 1 && findRateResponseItem.getAmDelivery()) ? this.f16168f.getString(h0.F) : this.f16168f.getResources().getQuantityString(g0.f16061a, findRateResponseItem.getMaxDays(), Integer.valueOf(findRateResponseItem.getMaxDays()));
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int O(FindRateResponseItem findRateResponseItem) {
        if (findRateResponseItem.getGuaranteed()) {
            if (findRateResponseItem.getOversizeFee() == BitmapDescriptorFactory.HUE_RED) {
                return 0;
            }
        }
        return 8;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String P(FindRateResponseItem findRateResponseItem) {
        String str;
        Product product = findRateResponseItem.getProduct();
        List<String> names = product != null ? product.getNames() : null;
        if (this.f16167e.b()) {
            if (names == null || (str = names.get(0)) == null) {
                return "";
            }
        } else if (names == null || (str = names.get(1)) == null) {
            return "";
        }
        return str;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean R(FindRateResponseItem findRateResponseItem) {
        Boolean carbonNeutral;
        Product product = findRateResponseItem.getProduct();
        if (product == null || (carbonNeutral = product.getCarbonNeutral()) == null) {
            return false;
        }
        return carbonNeutral.booleanValue();
    }

    private final boolean S() {
        return false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean T(FindRateResponseItem findRateResponseItem) {
        Boolean mostFuelEfficient;
        Product product = findRateResponseItem.getProduct();
        if (product == null || (mostFuelEfficient = product.getMostFuelEfficient()) == null) {
            return false;
        }
        return mostFuelEfficient.booleanValue();
    }

    public final String Q(FindRateResponseItem rateItem) {
        kotlin.jvm.internal.t.g(rateItem, "rateItem");
        String string = this.f16168f.getString(h0.R, Float.valueOf(rateItem.getTotal()));
        kotlin.jvm.internal.t.f(string, "getString(...)");
        return string;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    /* renamed from: U, reason: merged with bridge method [inline-methods] */
    public void u(a holder, int i10) {
        kotlin.jvm.internal.t.g(holder, "holder");
        holder.P((FindRateResponseItem) this.f16173k.get(i10), i10, g());
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    /* renamed from: V, reason: merged with bridge method [inline-methods] */
    public a w(ViewGroup parent, int i10) {
        kotlin.jvm.internal.t.g(parent, "parent");
        ec.o U = ec.o.U(LayoutInflater.from(parent.getContext()), parent, false);
        kotlin.jvm.internal.t.f(U, "inflate(...)");
        return new a(this, U);
    }

    public final void W(List list) {
        if (list == null) {
            list = sm.u.k();
        }
        this.f16173k = list;
        l();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    public int g() {
        return this.f16173k.size();
    }
}
