package com.bytedance.adsdk.ugeno.fm;

import android.text.TextUtils;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.bytedance.adsdk.ugeno.fm.lb;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes.dex */
public class yz {
    public static int fm(int i10) {
        if (i10 < 0) {
            return -1;
        }
        if (i10 == 0) {
            return Integer.MIN_VALUE;
        }
        return i10 - 1;
    }

    public static boolean lb(String str) {
        JSONArray jSONArrayFm = com.bytedance.adsdk.ugeno.wsy.ro.fm(str, (JSONArray) null);
        return jSONArrayFm != null && jSONArrayFm.length() > 0;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0032  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Interpolator ro(String str) {
        byte b10;
        switch (str.hashCode()) {
            case -1965072618:
                b10 = !str.equals("ease_in") ? (byte) -1 : (byte) 0;
                break;
            case -1102672091:
                if (str.equals("linear")) {
                    b10 = 3;
                    break;
                }
                break;
            case -787702915:
                if (str.equals("ease_out")) {
                    b10 = 2;
                    break;
                }
                break;
            case 1065009829:
                if (str.equals("ease_in_out")) {
                    b10 = 1;
                    break;
                }
                break;
        }
        return b10 != 0 ? b10 != 1 ? b10 != 2 ? new LinearInterpolator() : new DecelerateInterpolator() : new AccelerateDecelerateInterpolator() : new AccelerateInterpolator();
    }

    private static String yz(String str, JSONObject jSONObject) {
        String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(str, jSONObject);
        return lb(strFm) ? Arrays.toString(ro(strFm, jSONObject)) : com.bytedance.adsdk.ugeno.lb.ro.fm(strFm, jSONObject);
    }

    public static List<lb> fm(String str, JSONObject jSONObject) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        try {
            JSONArray jSONArray = new JSONArray(str);
            if (jSONArray.length() <= 0) {
                return null;
            }
            for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                JSONObject jSONObjectOptJSONObject = jSONArray.optJSONObject(i10);
                if (jSONObjectOptJSONObject != null) {
                    arrayList.add(fm(jSONObjectOptJSONObject, jSONObject));
                }
            }
            return arrayList;
        } catch (JSONException e10) {
            throw new RuntimeException(e10);
        }
    }

    public static lb.fm lb(String str, JSONObject jSONObject) {
        JSONArray jSONArrayFm;
        if (TextUtils.isEmpty(str) || (jSONArrayFm = com.bytedance.adsdk.ugeno.wsy.ro.fm(str, (JSONArray) null)) == null || jSONArrayFm.length() != 2) {
            return null;
        }
        lb.fm fmVar = new lb.fm();
        fmVar.fm = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONArrayFm.optString(0), jSONObject);
        fmVar.ro = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONArrayFm.optString(1), jSONObject);
        return fmVar;
    }

    public static float[] ro(String str, JSONObject jSONObject) {
        float[] fArr = {0.0f, 0.0f};
        JSONArray jSONArrayFm = com.bytedance.adsdk.ugeno.wsy.ro.fm(str, (JSONArray) null);
        if (jSONArrayFm != null && jSONArrayFm.length() == 2) {
            fArr[0] = (float) com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONArrayFm.optString(0), jSONObject), 0.0d);
            fArr[1] = (float) com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONArrayFm.optString(1), jSONObject), 0.0d);
        }
        return fArr;
    }

    public static lb fm(JSONObject jSONObject, JSONObject jSONObject2) {
        if (jSONObject == null) {
            return null;
        }
        lb lbVar = new lb();
        lbVar.ro(com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("delay"), jSONObject2), 0L));
        lbVar.lb(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("name"), jSONObject2));
        lbVar.ro(com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("playState"), jSONObject2), 1));
        lbVar.fm(Math.max(com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("duration"), jSONObject2), 0L), 0L));
        lbVar.fm(com.bytedance.adsdk.ugeno.wsy.lb.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("playCount"), jSONObject2), 1));
        lbVar.fm(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("playDirection"), jSONObject2));
        lbVar.fm(lb(jSONObject.optString("transformOrigin"), jSONObject2));
        lbVar.ro(com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObject.optString("timingFunction", "linear"), jSONObject2));
        lbVar.fm(jSONObject.optJSONObject("effect"));
        lbVar.fm(fm(jSONObject.optJSONArray("keyframes"), jSONObject2));
        return lbVar;
    }

    public static Map<String, TreeMap<Float, String>> fm(JSONArray jSONArray, JSONObject jSONObject) {
        if (jSONArray == null || jSONArray.length() <= 0) {
            return null;
        }
        HashMap map = new HashMap();
        for (int i10 = 0; i10 < jSONArray.length(); i10++) {
            JSONObject jSONObjectOptJSONObject = jSONArray.optJSONObject(i10);
            if (jSONObjectOptJSONObject != null) {
                float fOptDouble = (float) jSONObjectOptJSONObject.optDouble(IjkMediaPlayer.OnNativeInvokeListener.ARG_OFFSET);
                Iterator<String> itKeys = jSONObjectOptJSONObject.keys();
                while (itKeys.hasNext()) {
                    String next = itKeys.next();
                    if (!TextUtils.equals(next, IjkMediaPlayer.OnNativeInvokeListener.ARG_OFFSET)) {
                        TreeMap treeMap = (TreeMap) map.get(next);
                        if (treeMap == null) {
                            treeMap = new TreeMap();
                            map.put(next, treeMap);
                        }
                        treeMap.put(Float.valueOf(fOptDouble), yz(jSONObjectOptJSONObject.optString(next), jSONObject));
                    }
                }
            }
        }
        return map;
    }

    public static int fm(String str) {
        int iHashCode = str.hashCode();
        if (iHashCode == -1408024454) {
            return str.equals("alternate") ? 2 : 1;
        }
        if (iHashCode != -1039745817) {
            return 1;
        }
        str.equals("normal");
        return 1;
    }

    public static int fm(String str, int i10) {
        int i11 = i10 / 2;
        if (TextUtils.isEmpty(str)) {
            return i11;
        }
        str.getClass();
        switch (str) {
            case "bottom":
            case "right":
                return i10;
            case "center":
                return i11;
            case "top":
            case "left":
                return 0;
            default:
                if (str.endsWith("%")) {
                    try {
                        return (int) ((i10 * Float.parseFloat(str.substring(0, str.length() - 1))) / 100.0f);
                    } catch (NumberFormatException unused) {
                        return i11;
                    }
                }
                try {
                    return Integer.parseInt(str);
                } catch (NumberFormatException unused2) {
                    return i11;
                }
        }
    }
}
