package l5;

import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
import androidx.slice.SliceItem;
import androidx.slice.SliceSpec;
import com.google.firebase.messaging.Constants;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import k5.a;
import s3.e;

/* loaded from: classes.dex */
public class c extends d implements l5.a {

    /* renamed from: d, reason: collision with root package name */
    private List f27475d;

    /* renamed from: e, reason: collision with root package name */
    private Set f27476e;

    /* renamed from: f, reason: collision with root package name */
    private Slice f27477f;

    /* renamed from: g, reason: collision with root package name */
    private boolean f27478g;

    /* renamed from: h, reason: collision with root package name */
    private boolean f27479h;

    /* renamed from: i, reason: collision with root package name */
    private boolean f27480i;

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

    /* loaded from: classes.dex */
    public static class a extends d {

        /* renamed from: d, reason: collision with root package name */
        private SliceItem f27482d;

        /* renamed from: e, reason: collision with root package name */
        private SliceItem f27483e;

        /* renamed from: f, reason: collision with root package name */
        private SliceItem f27484f;

        /* renamed from: g, reason: collision with root package name */
        private k5.b f27485g;

        /* renamed from: h, reason: collision with root package name */
        private CharSequence f27486h;

        a(c cVar) {
            super(cVar.h(), null);
        }

        private void m(CharSequence charSequence) {
            this.f27486h = charSequence;
        }

        private void n(int i10) {
            i().e(i10, "layout_direction", new String[0]);
        }

        private void o(k5.b bVar) {
            this.f27485g = bVar;
        }

        private void p(CharSequence charSequence, boolean z10) {
            SliceItem sliceItem = new SliceItem(charSequence, "text", null, new String[0]);
            this.f27483e = sliceItem;
            if (z10) {
                sliceItem.a("partial");
            }
        }

        private void q(CharSequence charSequence, boolean z10) {
            SliceItem sliceItem = new SliceItem(charSequence, "text", null, new String[]{"summary"});
            this.f27484f = sliceItem;
            if (z10) {
                sliceItem.a("partial");
            }
        }

        private void r(CharSequence charSequence, boolean z10) {
            SliceItem sliceItem = new SliceItem(charSequence, "text", null, new String[]{"title"});
            this.f27482d = sliceItem;
            if (z10) {
                sliceItem.a("partial");
            }
        }

        @Override // l5.d
        public void f(Slice.a aVar) {
            SliceItem sliceItem = this.f27482d;
            if (sliceItem != null) {
                aVar.f(sliceItem);
            }
            SliceItem sliceItem2 = this.f27483e;
            if (sliceItem2 != null) {
                aVar.f(sliceItem2);
            }
            SliceItem sliceItem3 = this.f27484f;
            if (sliceItem3 != null) {
                aVar.f(sliceItem3);
            }
            CharSequence charSequence = this.f27486h;
            if (charSequence != null) {
                aVar.j(charSequence, "content_description", new String[0]);
            }
            k5.b bVar = this.f27485g;
            if (bVar != null) {
                bVar.e(aVar);
            }
            if (this.f27483e == null && this.f27482d == null) {
                throw new IllegalStateException("Header requires a title or subtitle to be set.");
            }
        }

        void l(a.C0530a c0530a) {
            if (c0530a.g() != null) {
                k(new Slice.a(c0530a.g()));
            }
            o(c0530a.c());
            if (c0530a.b() != -1) {
                n(c0530a.b());
            }
            if (c0530a.f() != null || c0530a.j()) {
                r(c0530a.f(), c0530a.j());
            }
            if (c0530a.d() != null || c0530a.h()) {
                p(c0530a.d(), c0530a.h());
            }
            if (c0530a.e() != null || c0530a.i()) {
                q(c0530a.e(), c0530a.i());
            }
            if (c0530a.a() != null) {
                m(c0530a.a());
            }
        }
    }

    /* loaded from: classes.dex */
    public static class b extends d {

        /* renamed from: d, reason: collision with root package name */
        private k5.b f27487d;

        /* renamed from: e, reason: collision with root package name */
        private SliceItem f27488e;

        /* renamed from: f, reason: collision with root package name */
        private SliceItem f27489f;

        /* renamed from: g, reason: collision with root package name */
        private Slice f27490g;

        /* renamed from: h, reason: collision with root package name */
        private ArrayList f27491h;

        /* renamed from: i, reason: collision with root package name */
        private CharSequence f27492i;

        b(Slice.a aVar) {
            super(aVar, null);
            this.f27491h = new ArrayList();
        }

        private void m(IconCompat iconCompat, int i10, boolean z10) {
            ArrayList arrayList = new ArrayList();
            if (i10 != 0) {
                arrayList.add("no_tint");
            }
            if (i10 == 2) {
                arrayList.add("large");
            }
            if (z10) {
                arrayList.add("partial");
            }
            Slice.a c10 = new Slice.a(i()).c(iconCompat, null, arrayList);
            if (z10) {
                c10.b("partial");
            }
            this.f27491h.add(c10.l());
        }

        private void n(k5.b bVar, boolean z10) {
            Slice.a aVar = new Slice.a(i());
            if (z10) {
                aVar.b("partial");
            }
            this.f27491h.add(bVar.a(aVar));
        }

        private void q(CharSequence charSequence) {
            this.f27492i = charSequence;
        }

        private void r(int i10) {
            i().e(i10, "layout_direction", new String[0]);
        }

        private void s(k5.b bVar) {
            this.f27487d = bVar;
        }

        private void t(CharSequence charSequence, boolean z10) {
            SliceItem sliceItem = new SliceItem(charSequence, "text", null, new String[0]);
            this.f27489f = sliceItem;
            if (z10) {
                sliceItem.a("partial");
            }
        }

        private void u(CharSequence charSequence, boolean z10) {
            SliceItem sliceItem = new SliceItem(charSequence, "text", null, new String[]{"title"});
            this.f27488e = sliceItem;
            if (z10) {
                sliceItem.a("partial");
            }
        }

        private void v(long j10) {
            this.f27490g = new Slice.a(i()).k(j10, null, new String[0]).b("title").l();
        }

        private void w(IconCompat iconCompat, int i10, boolean z10) {
            ArrayList arrayList = new ArrayList();
            if (i10 != 0) {
                arrayList.add("no_tint");
            }
            if (i10 == 2) {
                arrayList.add("large");
            }
            if (z10) {
                arrayList.add("partial");
            }
            Slice.a c10 = new Slice.a(i()).c(iconCompat, null, arrayList);
            if (z10) {
                c10.b("partial");
            }
            this.f27490g = c10.b("title").l();
        }

        private void x(k5.b bVar, boolean z10) {
            Slice.a b10 = new Slice.a(i()).b("title");
            if (z10) {
                b10.b("partial");
            }
            this.f27490g = bVar.a(b10);
        }

        @Override // l5.d
        public void f(Slice.a aVar) {
            Slice slice = this.f27490g;
            if (slice != null) {
                aVar.h(slice);
            }
            SliceItem sliceItem = this.f27488e;
            if (sliceItem != null) {
                aVar.f(sliceItem);
            }
            SliceItem sliceItem2 = this.f27489f;
            if (sliceItem2 != null) {
                aVar.f(sliceItem2);
            }
            for (int i10 = 0; i10 < this.f27491h.size(); i10++) {
                aVar.h((Slice) this.f27491h.get(i10));
            }
            CharSequence charSequence = this.f27492i;
            if (charSequence != null) {
                aVar.j(charSequence, "content_description", new String[0]);
            }
            k5.b bVar = this.f27487d;
            if (bVar != null) {
                bVar.e(aVar);
            }
        }

        protected void l(long j10) {
            this.f27491h.add(new Slice.a(i()).k(j10, null, new String[0]).l());
        }

        void o(a.b bVar) {
            if (bVar.m() != null) {
                k(new Slice.a(bVar.m()));
            }
            s(bVar.f());
            if (bVar.e() != -1) {
                r(bVar.e());
            }
            if (bVar.j() != null || bVar.o()) {
                x(bVar.j(), bVar.o());
            } else if (bVar.k() != null || bVar.p()) {
                w(bVar.k(), bVar.l(), bVar.p());
            } else if (bVar.h() != -1) {
                v(bVar.h());
            }
            if (bVar.i() != null || bVar.q()) {
                u(bVar.i(), bVar.q());
            }
            if (bVar.g() != null || bVar.n()) {
                t(bVar.g(), bVar.n());
            }
            if (bVar.a() != null) {
                q(bVar.a());
            }
            List b10 = bVar.b();
            List d10 = bVar.d();
            List c10 = bVar.c();
            for (int i10 = 0; i10 < b10.size(); i10++) {
                int intValue = ((Integer) d10.get(i10)).intValue();
                if (intValue == 0) {
                    l(((Long) b10.get(i10)).longValue());
                } else if (intValue == 1) {
                    e eVar = (e) b10.get(i10);
                    m((IconCompat) eVar.f35408a, ((Integer) eVar.f35409b).intValue(), ((Boolean) c10.get(i10)).booleanValue());
                } else if (intValue == 2) {
                    n((k5.b) b10.get(i10), ((Boolean) c10.get(i10)).booleanValue());
                }
            }
        }

        boolean p() {
            return (this.f27488e == null && this.f27489f == null) ? false : true;
        }
    }

    public c(Slice.a aVar, SliceSpec sliceSpec, j5.a aVar2) {
        super(aVar, sliceSpec, aVar2);
    }

    private void m(boolean z10, boolean z11) {
        if (this.f27479h) {
            return;
        }
        this.f27479h = true;
        this.f27480i = z10;
        this.f27481j = z11;
    }

    @Override // l5.a
    public void a(boolean z10) {
        this.f27478g = z10;
    }

    @Override // l5.a
    public void b(int i10) {
        i().e(i10, "color", new String[0]);
    }

    @Override // l5.a
    public void c(long j10) {
        i().k(j10 != -1 ? j().currentTimeMillis() + j10 : -1L, "millis", "ttl");
    }

    @Override // l5.a
    public void d(a.C0530a c0530a) {
        this.f27480i = true;
        this.f27481j = true;
        this.f27479h = true;
        a aVar = new a(this);
        aVar.l(c0530a);
        this.f27477f = aVar.g();
    }

    @Override // l5.a
    public void e(a.b bVar) {
        b bVar2 = new b(h());
        bVar2.o(bVar);
        m(true, bVar2.p());
        l(bVar2);
    }

    @Override // l5.d
    public void f(Slice.a aVar) {
        aVar.g(j().currentTimeMillis(), "millis", "last_updated");
        Slice slice = this.f27477f;
        if (slice != null) {
            aVar.h(slice);
        }
        if (this.f27475d != null) {
            Slice.a aVar2 = new Slice.a(aVar);
            for (int i10 = 0; i10 < this.f27475d.size(); i10++) {
                aVar2.h((Slice) this.f27475d.get(i10));
            }
            aVar.h(aVar2.b("actions").l());
        }
        if (this.f27478g) {
            aVar.b(Constants.IPC_BUNDLE_KEY_SEND_ERROR);
        }
        if (this.f27476e != null) {
            Slice.a aVar3 = new Slice.a(i());
            Iterator it = this.f27476e.iterator();
            while (it.hasNext()) {
                aVar3.j((String) it.next(), null, new String[0]);
            }
            i().h(aVar3.b("keywords").l());
        }
    }

    @Override // l5.d
    public Slice g() {
        Slice g10 = super.g();
        boolean z10 = n5.e.d(g10, null, "partial", null) != null;
        boolean z11 = n5.e.d(g10, "slice", "list_item", null) == null;
        String[] strArr = {"shortcut", "title"};
        SliceItem e10 = n5.e.e(g10, "action", strArr, null);
        List f10 = n5.e.f(g10, "slice", strArr, null);
        if (!z10 && !z11 && e10 == null && (f10 == null || f10.isEmpty())) {
            throw new IllegalStateException("A slice requires a primary action; ensure one of your builders has called #setPrimaryAction with a valid SliceAction.");
        }
        boolean z12 = this.f27479h;
        if (z12 && !this.f27480i) {
            throw new IllegalStateException("A slice cannot have the first row be constructed from a GridRowBuilder, consider using #setHeader.");
        }
        if (!z12 || this.f27481j) {
            return g10;
        }
        throw new IllegalStateException("A slice requires the first row to have some text.");
    }

    public void l(b bVar) {
        m(true, bVar.p());
        bVar.i().b("list_item");
        i().h(bVar.g());
    }
}
