package jxl.biff.drawing;

import common.Logger;
import d.b.a.a.a;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;

/* JADX INFO: loaded from: classes.dex */
public class Opt extends EscherAtom {
    public static /* synthetic */ Class class$jxl$biff$drawing$Opt;
    private static Logger logger;
    private byte[] data;
    private int numProperties;
    private ArrayList properties;

    static {
        Class clsClass$ = class$jxl$biff$drawing$Opt;
        if (clsClass$ == null) {
            clsClass$ = class$("jxl.biff.drawing.Opt");
            class$jxl$biff$drawing$Opt = clsClass$;
        }
        logger = Logger.getLogger(clsClass$);
    }

    public Opt(EscherRecordData escherRecordData) {
        super(escherRecordData);
        this.numProperties = getInstance();
        readProperties();
    }

    public static /* synthetic */ Class class$(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException e2) {
            throw new NoClassDefFoundError(e2.getMessage());
        }
    }

    private void readProperties() {
        this.properties = new ArrayList();
        byte[] bytes = getBytes();
        int i2 = 0;
        for (int i3 = 0; i3 < this.numProperties; i3++) {
            int i4 = IntegerHelper.getInt(bytes[i2], bytes[i2 + 1]);
            int i5 = i4 & 16383;
            int i6 = IntegerHelper.getInt(bytes[i2 + 2], bytes[i2 + 3], bytes[i2 + 4], bytes[i2 + 5]);
            boolean z = true;
            boolean z2 = (i4 & 16384) != 0;
            if ((i4 & 32768) == 0) {
                z = false;
            }
            i2 += 6;
            this.properties.add(new Property(i5, z2, z, i6));
        }
        for (Property property : this.properties) {
            if (property.complex) {
                property.stringValue = StringHelper.getUnicodeString(bytes, property.value / 2, i2);
                i2 += property.value;
            }
        }
    }

    public void addProperty(int i2, boolean z, boolean z2, int i3) {
        this.properties.add(new Property(i2, z, z2, i3));
    }

    @Override // jxl.biff.drawing.EscherAtom, jxl.biff.drawing.EscherRecord
    public byte[] getData() {
        String str;
        int size = this.properties.size();
        this.numProperties = size;
        setInstance(size);
        this.data = new byte[this.numProperties * 6];
        int i2 = 0;
        for (Property property : this.properties) {
            int i3 = property.id & 16383;
            if (property.blipId) {
                i3 |= 16384;
            }
            if (property.complex) {
                i3 |= 32768;
            }
            IntegerHelper.getTwoBytes(i3, this.data, i2);
            IntegerHelper.getFourBytes(property.value, this.data, i2 + 2);
            i2 += 6;
        }
        for (Property property2 : this.properties) {
            if (property2.complex && (str = property2.stringValue) != null) {
                byte[] bArr = new byte[a.H(str, 2, this.data.length)];
                byte[] bArr2 = this.data;
                System.arraycopy(bArr2, 0, bArr, 0, bArr2.length);
                StringHelper.getUnicodeBytes(property2.stringValue, bArr, this.data.length);
                this.data = bArr;
            }
        }
        return setHeaderData(this.data);
    }

    public Property getProperty(int i2) {
        Iterator it = this.properties.iterator();
        boolean z = false;
        Property property = null;
        while (it.hasNext() && !z) {
            property = (Property) it.next();
            if (property.id == i2) {
                z = true;
            }
        }
        if (z) {
            return property;
        }
        return null;
    }

    public void addProperty(int i2, boolean z, boolean z2, int i3, String str) {
        this.properties.add(new Property(i2, z, z2, i3, str));
    }

    public Opt() {
        super(EscherRecordType.OPT);
        this.properties = new ArrayList();
        setVersion(3);
    }

    public static final class Property {
        public boolean blipId;
        public boolean complex;
        public int id;
        public String stringValue;
        public int value;

        public Property(int i2, boolean z, boolean z2, int i3) {
            this.id = i2;
            this.blipId = z;
            this.complex = z2;
            this.value = i3;
        }

        public Property(int i2, boolean z, boolean z2, int i3, String str) {
            this.id = i2;
            this.blipId = z;
            this.complex = z2;
            this.value = i3;
            this.stringValue = str;
        }
    }
}
