package jxl.write.biff;

import com.seewo.sdk.model.SDKKeyboardCode;
import jxl.SheetSettings;
import jxl.biff.BuiltInName;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.read.biff.NameRecord;

/* JADX INFO: loaded from: classes.dex */
public class NameRecord extends WritableRecordData {
    private static final int areaReference = 59;
    private static final int cellReference = 58;
    private static final int subExpression = 41;
    private static final int union = 16;
    private BuiltInName builtInName;
    private byte[] data;
    private int index;
    private String name;
    private NameRange[] ranges;
    private int sheetRef;

    public NameRecord(jxl.read.biff.NameRecord nameRecord, int i2) {
        super(Type.NAME);
        int i3 = 0;
        this.sheetRef = 0;
        this.data = nameRecord.getData();
        this.name = nameRecord.getName();
        this.sheetRef = nameRecord.getSheetRef();
        this.index = i2;
        NameRecord.NameRange[] ranges = nameRecord.getRanges();
        this.ranges = new NameRange[ranges.length];
        while (true) {
            NameRange[] nameRangeArr = this.ranges;
            if (i3 >= nameRangeArr.length) {
                return;
            }
            nameRangeArr[i3] = new NameRange(ranges[i3]);
            i3++;
        }
    }

    @Override // jxl.biff.WritableRecordData
    public byte[] getData() {
        byte[] bArr = this.data;
        if (bArr != null) {
            return bArr;
        }
        byte[] bArr2 = new byte[(this.builtInName != null ? 1 : this.name.length()) + 26];
        this.data = bArr2;
        IntegerHelper.getTwoBytes(this.builtInName != null ? 32 : 0, bArr2, 0);
        byte[] bArr3 = this.data;
        bArr3[2] = 0;
        if (this.builtInName != null) {
            bArr3[3] = 1;
        } else {
            bArr3[3] = (byte) this.name.length();
        }
        IntegerHelper.getTwoBytes(11, this.data, 4);
        IntegerHelper.getTwoBytes(this.sheetRef, this.data, 6);
        IntegerHelper.getTwoBytes(this.sheetRef, this.data, 8);
        BuiltInName builtInName = this.builtInName;
        if (builtInName != null) {
            this.data[15] = (byte) builtInName.getValue();
        } else {
            StringHelper.getBytes(this.name, this.data, 15);
        }
        int length = this.builtInName != null ? 16 : this.name.length() + 15;
        this.data[length] = SDKKeyboardCode.FUNCTION_KEY_BOARD_F2;
        byte[] data = this.ranges[0].getData();
        System.arraycopy(data, 0, this.data, length + 1, data.length);
        return this.data;
    }

    public int getIndex() {
        return this.index;
    }

    public String getName() {
        return this.name;
    }

    public NameRange[] getRanges() {
        return this.ranges;
    }

    public int getSheetRef() {
        return this.sheetRef;
    }

    public void setSheetRef(int i2) {
        this.sheetRef = i2;
        IntegerHelper.getTwoBytes(i2, this.data, 8);
    }

    public class NameRange {
        private int columnFirst;
        private int columnLast;
        private int externalSheet;
        private int rowFirst;
        private int rowLast;

        public NameRange(NameRecord.NameRange nameRange) {
            this.columnFirst = nameRange.getFirstColumn();
            this.rowFirst = nameRange.getFirstRow();
            this.columnLast = nameRange.getLastColumn();
            this.rowLast = nameRange.getLastRow();
            this.externalSheet = nameRange.getExternalSheet();
        }

        public byte[] getData() {
            byte[] bArr = new byte[10];
            IntegerHelper.getTwoBytes(this.externalSheet, bArr, 0);
            IntegerHelper.getTwoBytes(this.rowFirst, bArr, 2);
            IntegerHelper.getTwoBytes(this.rowLast, bArr, 4);
            IntegerHelper.getTwoBytes(this.columnFirst & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT, bArr, 6);
            IntegerHelper.getTwoBytes(this.columnLast & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT, bArr, 8);
            return bArr;
        }

        public int getExternalSheet() {
            return this.externalSheet;
        }

        public int getFirstColumn() {
            return this.columnFirst;
        }

        public int getFirstRow() {
            return this.rowFirst;
        }

        public int getLastColumn() {
            return this.columnLast;
        }

        public int getLastRow() {
            return this.rowLast;
        }

        public NameRange(int i2, int i3, int i4, int i5, int i6) {
            this.columnFirst = i5;
            this.rowFirst = i3;
            this.columnLast = i6;
            this.rowLast = i4;
            this.externalSheet = i2;
        }
    }

    public NameRecord(String str, int i2, int i3, int i4, int i5, int i6, int i7, boolean z) {
        super(Type.NAME);
        this.sheetRef = 0;
        this.name = str;
        this.index = i2;
        this.sheetRef = z ? 0 : i2 + 1;
        this.ranges = new NameRange[]{new NameRange(i3, i4, i5, i6, i7)};
    }

    public NameRecord(BuiltInName builtInName, int i2, int i3, int i4, int i5, int i6, int i7, boolean z) {
        super(Type.NAME);
        this.sheetRef = 0;
        this.builtInName = builtInName;
        this.index = i2;
        this.sheetRef = z ? 0 : i2 + 1;
        this.ranges = new NameRange[]{new NameRange(i3, i4, i5, i6, i7)};
    }
}
