package x3;

import B0.i0;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import java.util.BitSet;
import java.util.Objects;
import l6.C1139a;
import r3.C1493a;
import w3.C1704a;

/* JADX INFO: loaded from: classes.dex */
public class g extends Drawable implements u {

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public static final Paint f18603M = new Paint(1);

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final Region f18604A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final Region f18605B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public k f18606C;
    public final Paint D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final Paint f18607E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final C1704a f18608F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final C1139a f18609G;
    public final i0 H;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public PorterDuffColorFilter f18610I;

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public PorterDuffColorFilter f18611J;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public final RectF f18612K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public final boolean f18613L;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public f f18614q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final s[] f18615r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final s[] f18616s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final BitSet f18617t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public boolean f18618u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final Matrix f18619v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final Path f18620w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final Path f18621x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final RectF f18622y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final RectF f18623z;

    public g() {
        this(new k());
    }

    public final void a(RectF rectF, Path path) {
        f fVar = this.f18614q;
        this.H.b(fVar.f18588a, fVar.i, rectF, this.f18609G, path);
        if (this.f18614q.f18595h != 1.0f) {
            Matrix matrix = this.f18619v;
            matrix.reset();
            float f3 = this.f18614q.f18595h;
            matrix.setScale(f3, f3, rectF.width() / 2.0f, rectF.height() / 2.0f);
            path.transform(matrix);
        }
        path.computeBounds(this.f18612K, true);
    }

    public final int b(int i) {
        f fVar = this.f18614q;
        float fMin = 0.0f;
        float f3 = fVar.f18599m + 0.0f + fVar.f18598l;
        C1493a c1493a = fVar.f18589b;
        if (c1493a == null || !c1493a.f16435a || F.a.d(i, 255) != c1493a.f16437c) {
            return i;
        }
        if (c1493a.f16438d > 0.0f && f3 > 0.0f) {
            fMin = Math.min(((((float) Math.log1p(f3 / r4)) * 4.5f) + 2.0f) / 100.0f, 1.0f);
        }
        return F.a.d(W2.g.z(fMin, F.a.d(i, 255), c1493a.f16436b), Color.alpha(i));
    }

    public final void c(Canvas canvas) {
        if (this.f18617t.cardinality() > 0) {
            Log.w("g", "Compatibility shadow requested but can't be drawn for all operations in this shape.");
        }
        int i = this.f18614q.f18601o;
        Path path = this.f18620w;
        C1704a c1704a = this.f18608F;
        if (i != 0) {
            canvas.drawPath(path, c1704a.f18303a);
        }
        for (int i5 = 0; i5 < 4; i5++) {
            s sVar = this.f18615r[i5];
            int i8 = this.f18614q.f18600n;
            Matrix matrix = s.f18664a;
            sVar.a(matrix, c1704a, i8, canvas);
            this.f18616s[i5].a(matrix, c1704a, this.f18614q.f18600n, canvas);
        }
        if (this.f18613L) {
            double d8 = 0;
            int iSin = (int) (Math.sin(Math.toRadians(d8)) * ((double) this.f18614q.f18601o));
            int iCos = (int) (Math.cos(Math.toRadians(d8)) * ((double) this.f18614q.f18601o));
            canvas.translate(-iSin, -iCos);
            canvas.drawPath(path, f18603M);
            canvas.translate(iSin, iCos);
        }
    }

    public final void d(Canvas canvas, Paint paint, Path path, k kVar, RectF rectF) {
        if (!kVar.d(rectF)) {
            canvas.drawPath(path, paint);
        } else {
            float fA = kVar.f18641f.a(rectF) * this.f18614q.i;
            canvas.drawRoundRect(rectF, fA, fA, paint);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        Paint paint;
        Paint paint2 = this.D;
        paint2.setColorFilter(this.f18610I);
        int alpha = paint2.getAlpha();
        int i = this.f18614q.f18597k;
        paint2.setAlpha(((i + (i >>> 7)) * alpha) >>> 8);
        Paint paint3 = this.f18607E;
        paint3.setColorFilter(this.f18611J);
        paint3.setStrokeWidth(this.f18614q.f18596j);
        int alpha2 = paint3.getAlpha();
        int i5 = this.f18614q.f18597k;
        paint3.setAlpha(((i5 + (i5 >>> 7)) * alpha2) >>> 8);
        boolean z8 = this.f18618u;
        Path path = this.f18621x;
        Path path2 = this.f18620w;
        RectF rectF = this.f18623z;
        if (z8) {
            float f3 = -(f() ? paint3.getStrokeWidth() / 2.0f : 0.0f);
            k kVar = this.f18614q.f18588a;
            j jVarE = kVar.e();
            InterfaceC1715c c1714b = kVar.f18640e;
            if (!(c1714b instanceof h)) {
                c1714b = new C1714b(f3, c1714b);
            }
            jVarE.f18629e = c1714b;
            InterfaceC1715c c1714b2 = kVar.f18641f;
            if (!(c1714b2 instanceof h)) {
                c1714b2 = new C1714b(f3, c1714b2);
            }
            jVarE.f18630f = c1714b2;
            InterfaceC1715c c1714b3 = kVar.f18643h;
            if (!(c1714b3 instanceof h)) {
                c1714b3 = new C1714b(f3, c1714b3);
            }
            jVarE.f18632h = c1714b3;
            InterfaceC1715c c1714b4 = kVar.f18642g;
            if (!(c1714b4 instanceof h)) {
                c1714b4 = new C1714b(f3, c1714b4);
            }
            jVarE.f18631g = c1714b4;
            k kVarA = jVarE.a();
            this.f18606C = kVarA;
            float f7 = this.f18614q.i;
            rectF.set(e());
            float strokeWidth = f() ? paint3.getStrokeWidth() / 2.0f : 0.0f;
            rectF.inset(strokeWidth, strokeWidth);
            this.H.b(kVarA, f7, rectF, null, path);
            a(e(), path2);
            this.f18618u = false;
        }
        f fVar = this.f18614q;
        fVar.getClass();
        if (fVar.f18600n > 0) {
            int i8 = Build.VERSION.SDK_INT;
            if (!this.f18614q.f18588a.d(e()) && !path2.isConvex() && i8 < 29) {
                canvas.save();
                double d8 = 0;
                canvas.translate((int) (((double) this.f18614q.f18601o) * Math.sin(Math.toRadians(d8))), (int) (Math.cos(Math.toRadians(d8)) * ((double) this.f18614q.f18601o)));
                if (this.f18613L) {
                    RectF rectF2 = this.f18612K;
                    int iWidth = (int) (rectF2.width() - getBounds().width());
                    int iHeight = (int) (rectF2.height() - getBounds().height());
                    if (iWidth < 0 || iHeight < 0) {
                        throw new IllegalStateException("Invalid shadow bounds. Check that the treatments result in a valid path.");
                    }
                    Bitmap bitmapCreateBitmap = Bitmap.createBitmap((this.f18614q.f18600n * 2) + ((int) rectF2.width()) + iWidth, (this.f18614q.f18600n * 2) + ((int) rectF2.height()) + iHeight, Bitmap.Config.ARGB_8888);
                    Canvas canvas2 = new Canvas(bitmapCreateBitmap);
                    float f8 = (getBounds().left - this.f18614q.f18600n) - iWidth;
                    float f9 = (getBounds().top - this.f18614q.f18600n) - iHeight;
                    canvas2.translate(-f8, -f9);
                    c(canvas2);
                    canvas.drawBitmap(bitmapCreateBitmap, f8, f9, (Paint) null);
                    bitmapCreateBitmap.recycle();
                    canvas.restore();
                } else {
                    c(canvas);
                    canvas.restore();
                }
            }
        }
        f fVar2 = this.f18614q;
        Paint.Style style = fVar2.f18602p;
        if (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.FILL) {
            d(canvas, paint2, path2, fVar2.f18588a, e());
        }
        if (f()) {
            k kVar2 = this.f18606C;
            rectF.set(e());
            float strokeWidth2 = f() ? paint3.getStrokeWidth() / 2.0f : 0.0f;
            rectF.inset(strokeWidth2, strokeWidth2);
            paint = paint3;
            d(canvas, paint, path, kVar2, rectF);
        } else {
            paint = paint3;
        }
        paint2.setAlpha(alpha);
        paint.setAlpha(alpha2);
    }

    public final RectF e() {
        RectF rectF = this.f18622y;
        rectF.set(getBounds());
        return rectF;
    }

    public final boolean f() {
        Paint.Style style = this.f18614q.f18602p;
        return (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.STROKE) && this.f18607E.getStrokeWidth() > 0.0f;
    }

    public final void g(Context context) {
        this.f18614q.f18589b = new C1493a(context);
        l();
    }

    @Override // android.graphics.drawable.Drawable
    public final Drawable.ConstantState getConstantState() {
        return this.f18614q;
    }

    @Override // android.graphics.drawable.Drawable
    public int getOpacity() {
        return -3;
    }

    @Override // android.graphics.drawable.Drawable
    public void getOutline(Outline outline) {
        this.f18614q.getClass();
        if (this.f18614q.f18588a.d(e())) {
            outline.setRoundRect(getBounds(), this.f18614q.f18588a.f18640e.a(e()) * this.f18614q.i);
            return;
        }
        RectF rectFE = e();
        Path path = this.f18620w;
        a(rectFE, path);
        if (path.isConvex() || Build.VERSION.SDK_INT >= 29) {
            try {
                outline.setConvexPath(path);
            } catch (IllegalArgumentException unused) {
            }
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean getPadding(Rect rect) {
        Rect rect2 = this.f18614q.f18594g;
        if (rect2 == null) {
            return super.getPadding(rect);
        }
        rect.set(rect2);
        return true;
    }

    @Override // android.graphics.drawable.Drawable
    public final Region getTransparentRegion() {
        Rect bounds = getBounds();
        Region region = this.f18604A;
        region.set(bounds);
        RectF rectFE = e();
        Path path = this.f18620w;
        a(rectFE, path);
        Region region2 = this.f18605B;
        region2.setPath(path, region);
        region.op(region2, Region.Op.DIFFERENCE);
        return region;
    }

    public final void h(float f3) {
        f fVar = this.f18614q;
        if (fVar.f18599m != f3) {
            fVar.f18599m = f3;
            l();
        }
    }

    public final void i(ColorStateList colorStateList) {
        f fVar = this.f18614q;
        if (fVar.f18590c != colorStateList) {
            fVar.f18590c = colorStateList;
            onStateChange(getState());
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void invalidateSelf() {
        this.f18618u = true;
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public boolean isStateful() {
        if (super.isStateful()) {
            return true;
        }
        ColorStateList colorStateList = this.f18614q.f18592e;
        if (colorStateList != null && colorStateList.isStateful()) {
            return true;
        }
        this.f18614q.getClass();
        ColorStateList colorStateList2 = this.f18614q.f18591d;
        if (colorStateList2 != null && colorStateList2.isStateful()) {
            return true;
        }
        ColorStateList colorStateList3 = this.f18614q.f18590c;
        return colorStateList3 != null && colorStateList3.isStateful();
    }

    public final boolean j(int[] iArr) {
        boolean z8;
        Paint paint;
        int color;
        int colorForState;
        Paint paint2;
        int color2;
        int colorForState2;
        if (this.f18614q.f18590c == null || color2 == (colorForState2 = this.f18614q.f18590c.getColorForState(iArr, (color2 = (paint2 = this.D).getColor())))) {
            z8 = false;
        } else {
            paint2.setColor(colorForState2);
            z8 = true;
        }
        if (this.f18614q.f18591d == null || color == (colorForState = this.f18614q.f18591d.getColorForState(iArr, (color = (paint = this.f18607E).getColor())))) {
            return z8;
        }
        paint.setColor(colorForState);
        return true;
    }

    public final boolean k() {
        PorterDuffColorFilter porterDuffColorFilter;
        PorterDuffColorFilter porterDuffColorFilter2 = this.f18610I;
        PorterDuffColorFilter porterDuffColorFilter3 = this.f18611J;
        f fVar = this.f18614q;
        ColorStateList colorStateList = fVar.f18592e;
        PorterDuff.Mode mode = fVar.f18593f;
        Paint paint = this.D;
        if (colorStateList == null || mode == null) {
            int color = paint.getColor();
            int iB = b(color);
            porterDuffColorFilter = iB != color ? new PorterDuffColorFilter(iB, PorterDuff.Mode.SRC_IN) : null;
        } else {
            porterDuffColorFilter = new PorterDuffColorFilter(b(colorStateList.getColorForState(getState(), 0)), mode);
        }
        this.f18610I = porterDuffColorFilter;
        this.f18614q.getClass();
        this.f18611J = null;
        this.f18614q.getClass();
        return (Objects.equals(porterDuffColorFilter2, this.f18610I) && Objects.equals(porterDuffColorFilter3, this.f18611J)) ? false : true;
    }

    public final void l() {
        f fVar = this.f18614q;
        float f3 = fVar.f18599m + 0.0f;
        fVar.f18600n = (int) Math.ceil(0.75f * f3);
        this.f18614q.f18601o = (int) Math.ceil(f3 * 0.25f);
        k();
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final Drawable mutate() {
        f fVar = this.f18614q;
        f fVar2 = new f();
        fVar2.f18590c = null;
        fVar2.f18591d = null;
        fVar2.f18592e = null;
        fVar2.f18593f = PorterDuff.Mode.SRC_IN;
        fVar2.f18594g = null;
        fVar2.f18595h = 1.0f;
        fVar2.i = 1.0f;
        fVar2.f18597k = 255;
        fVar2.f18598l = 0.0f;
        fVar2.f18599m = 0.0f;
        fVar2.f18600n = 0;
        fVar2.f18601o = 0;
        fVar2.f18602p = Paint.Style.FILL_AND_STROKE;
        fVar2.f18588a = fVar.f18588a;
        fVar2.f18589b = fVar.f18589b;
        fVar2.f18596j = fVar.f18596j;
        fVar2.f18590c = fVar.f18590c;
        fVar2.f18591d = fVar.f18591d;
        fVar2.f18593f = fVar.f18593f;
        fVar2.f18592e = fVar.f18592e;
        fVar2.f18597k = fVar.f18597k;
        fVar2.f18595h = fVar.f18595h;
        fVar2.f18601o = fVar.f18601o;
        fVar2.i = fVar.i;
        fVar2.f18598l = fVar.f18598l;
        fVar2.f18599m = fVar.f18599m;
        fVar2.f18600n = fVar.f18600n;
        fVar2.f18602p = fVar.f18602p;
        if (fVar.f18594g != null) {
            fVar2.f18594g = new Rect(fVar.f18594g);
        }
        this.f18614q = fVar2;
        return this;
    }

    @Override // android.graphics.drawable.Drawable
    public final void onBoundsChange(Rect rect) {
        this.f18618u = true;
        super.onBoundsChange(rect);
    }

    @Override // android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        boolean z8 = j(iArr) || k();
        if (z8) {
            invalidateSelf();
        }
        return z8;
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i) {
        f fVar = this.f18614q;
        if (fVar.f18597k != i) {
            fVar.f18597k = i;
            super.invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        this.f18614q.getClass();
        super.invalidateSelf();
    }

    @Override // x3.u
    public final void setShapeAppearanceModel(k kVar) {
        this.f18614q.f18588a = kVar;
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final void setTint(int i) {
        setTintList(ColorStateList.valueOf(i));
    }

    @Override // android.graphics.drawable.Drawable
    public void setTintList(ColorStateList colorStateList) {
        this.f18614q.f18592e = colorStateList;
        k();
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setTintMode(PorterDuff.Mode mode) {
        f fVar = this.f18614q;
        if (fVar.f18593f != mode) {
            fVar.f18593f = mode;
            k();
            super.invalidateSelf();
        }
    }

    public g(Context context, AttributeSet attributeSet, int i, int i5) {
        this(k.b(context, attributeSet, i, i5).a());
    }

    public g(k kVar) {
        f fVar = new f();
        fVar.f18590c = null;
        fVar.f18591d = null;
        fVar.f18592e = null;
        fVar.f18593f = PorterDuff.Mode.SRC_IN;
        fVar.f18594g = null;
        fVar.f18595h = 1.0f;
        fVar.i = 1.0f;
        fVar.f18597k = 255;
        fVar.f18598l = 0.0f;
        fVar.f18599m = 0.0f;
        fVar.f18600n = 0;
        fVar.f18601o = 0;
        fVar.f18602p = Paint.Style.FILL_AND_STROKE;
        fVar.f18588a = kVar;
        fVar.f18589b = null;
        this(fVar);
    }

    public g(f fVar) {
        i0 i0Var;
        this.f18615r = new s[4];
        this.f18616s = new s[4];
        this.f18617t = new BitSet(8);
        this.f18619v = new Matrix();
        this.f18620w = new Path();
        this.f18621x = new Path();
        this.f18622y = new RectF();
        this.f18623z = new RectF();
        this.f18604A = new Region();
        this.f18605B = new Region();
        Paint paint = new Paint(1);
        this.D = paint;
        Paint paint2 = new Paint(1);
        this.f18607E = paint2;
        this.f18608F = new C1704a();
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            i0Var = l.f18647a;
        } else {
            i0Var = new i0();
        }
        this.H = i0Var;
        this.f18612K = new RectF();
        this.f18613L = true;
        this.f18614q = fVar;
        paint2.setStyle(Paint.Style.STROKE);
        paint.setStyle(Paint.Style.FILL);
        Paint paint3 = f18603M;
        paint3.setColor(-1);
        paint3.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        k();
        j(getState());
        this.f18609G = new C1139a(this);
    }
}
