package androidx.slice;

import android.app.PendingIntent;
import android.net.Uri;
import androidx.core.graphics.drawable.IconCompat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import s3.i;

/* loaded from: classes.dex */
public final class Slice implements w5.a {

    /* renamed from: a, reason: collision with root package name */
    SliceSpec f5593a;

    /* renamed from: b, reason: collision with root package name */
    SliceItem[] f5594b;

    /* renamed from: c, reason: collision with root package name */
    String[] f5595c;

    /* renamed from: d, reason: collision with root package name */
    String f5596d;

    Slice(ArrayList arrayList, String[] strArr, Uri uri, SliceSpec sliceSpec) {
        this.f5594b = new SliceItem[0];
        this.f5595c = strArr;
        this.f5594b = (SliceItem[]) arrayList.toArray(new SliceItem[arrayList.size()]);
        this.f5596d = uri.toString();
        this.f5593a = sliceSpec;
    }

    public static void a(StringBuilder sb2, String[] strArr) {
        if (strArr == null || strArr.length == 0) {
            return;
        }
        sb2.append('(');
        int length = strArr.length - 1;
        for (int i10 = 0; i10 < length; i10++) {
            sb2.append(strArr[i10]);
            sb2.append(", ");
        }
        sb2.append(strArr[length]);
        sb2.append(")");
    }

    static boolean f(IconCompat iconCompat) {
        if (iconCompat == null) {
            return false;
        }
        if (iconCompat.f3734a != 2 || iconCompat.f() != 0) {
            return true;
        }
        throw new IllegalArgumentException("Failed to add icon, invalid resource id: " + iconCompat.f());
    }

    public List b() {
        return Arrays.asList(this.f5595c);
    }

    public List c() {
        return Arrays.asList(this.f5594b);
    }

    public SliceSpec d() {
        return this.f5593a;
    }

    public Uri e() {
        return Uri.parse(this.f5596d);
    }

    public String g(String str) {
        StringBuilder sb2 = new StringBuilder();
        sb2.append(str);
        sb2.append("Slice ");
        String[] strArr = this.f5595c;
        if (strArr.length > 0) {
            a(sb2, strArr);
            sb2.append(' ');
        }
        sb2.append('[');
        sb2.append(this.f5596d);
        sb2.append("] {\n");
        String str2 = str + "  ";
        int i10 = 0;
        while (true) {
            SliceItem[] sliceItemArr = this.f5594b;
            if (i10 >= sliceItemArr.length) {
                sb2.append(str);
                sb2.append('}');
                return sb2.toString();
            }
            sb2.append(sliceItemArr[i10].o(str2));
            i10++;
        }
    }

    public String toString() {
        return g("");
    }

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

        /* renamed from: a, reason: collision with root package name */
        private final Uri f5597a;

        /* renamed from: b, reason: collision with root package name */
        private ArrayList f5598b = new ArrayList();

        /* renamed from: c, reason: collision with root package name */
        private ArrayList f5599c = new ArrayList();

        /* renamed from: d, reason: collision with root package name */
        private SliceSpec f5600d;

        /* renamed from: e, reason: collision with root package name */
        private int f5601e;

        public a(Uri uri) {
            this.f5597a = uri;
        }

        private Uri m() {
            Uri.Builder appendPath = this.f5597a.buildUpon().appendPath("_gen");
            int i10 = this.f5601e;
            this.f5601e = i10 + 1;
            return appendPath.appendPath(String.valueOf(i10)).build();
        }

        public a a(PendingIntent pendingIntent, Slice slice, String str) {
            i.g(pendingIntent);
            i.g(slice);
            this.f5598b.add(new SliceItem(pendingIntent, slice, "action", str, (String[]) slice.b().toArray(new String[slice.b().size()])));
            return this;
        }

        public a b(String... strArr) {
            this.f5599c.addAll(Arrays.asList(strArr));
            return this;
        }

        public a c(IconCompat iconCompat, String str, List list) {
            i.g(iconCompat);
            return Slice.f(iconCompat) ? d(iconCompat, str, (String[]) list.toArray(new String[list.size()])) : this;
        }

        public a d(IconCompat iconCompat, String str, String... strArr) {
            i.g(iconCompat);
            if (Slice.f(iconCompat)) {
                this.f5598b.add(new SliceItem(iconCompat, "image", str, strArr));
            }
            return this;
        }

        public a e(int i10, String str, String... strArr) {
            this.f5598b.add(new SliceItem(Integer.valueOf(i10), "int", str, strArr));
            return this;
        }

        public a f(SliceItem sliceItem) {
            this.f5598b.add(sliceItem);
            return this;
        }

        public a g(long j10, String str, String... strArr) {
            this.f5598b.add(new SliceItem(Long.valueOf(j10), "long", str, strArr));
            return this;
        }

        public a h(Slice slice) {
            i.g(slice);
            return i(slice, null);
        }

        public a i(Slice slice, String str) {
            i.g(slice);
            this.f5598b.add(new SliceItem(slice, "slice", str, (String[]) slice.b().toArray(new String[slice.b().size()])));
            return this;
        }

        public a j(CharSequence charSequence, String str, String... strArr) {
            this.f5598b.add(new SliceItem(charSequence, "text", str, strArr));
            return this;
        }

        public a k(long j10, String str, String... strArr) {
            this.f5598b.add(new SliceItem(Long.valueOf(j10), "long", str, strArr));
            return this;
        }

        public Slice l() {
            ArrayList arrayList = this.f5598b;
            ArrayList arrayList2 = this.f5599c;
            return new Slice(arrayList, (String[]) arrayList2.toArray(new String[arrayList2.size()]), this.f5597a, this.f5600d);
        }

        public a n(SliceSpec sliceSpec) {
            this.f5600d = sliceSpec;
            return this;
        }

        public a(a aVar) {
            this.f5597a = aVar.m();
        }
    }

    public Slice() {
        this.f5594b = new SliceItem[0];
        this.f5595c = new String[0];
    }
}
