export const OOXML_PATHS = {
    contentTypes: "[Content_Types].xml",
    rootRels: "_rels/.rels",
    docPropsApp: "docProps/app.xml",
    docPropsCore: "docProps/core.xml",
    xlWorkbook: "xl/workbook.xml",
    xlWorkbookRels: "xl/_rels/workbook.xml.rels",
    xlSharedStrings: "xl/sharedStrings.xml",
    xlStyles: "xl/styles.xml",
    xlTheme1: "xl/theme/theme1.xml",
    xlFeaturePropertyBag: "xl/featurePropertyBag/featurePropertyBag.xml"
};
const worksheetXmlRegex = /^xl\/worksheets\/sheet(\d+)[.]xml$/;
const worksheetRelsXmlRegex = /^xl\/worksheets\/_rels\/sheet(\d+)[.]xml[.]rels$/;
const themeXmlRegex = /^xl\/theme\/[a-zA-Z0-9]+[.]xml$/;
const mediaFilenameRegex = /^xl\/media\/([a-zA-Z0-9]+[.][a-zA-Z0-9]{3,4})$/;
const drawingXmlRegex = /^xl\/drawings\/(drawing\d+)[.]xml$/;
const drawingRelsXmlRegex = /^xl\/drawings\/_rels\/(drawing\d+)[.]xml[.]rels$/;
const vmlDrawingRegex = /^xl\/drawings\/(vmlDrawing\d+)[.]vml$/;
const commentsXmlRegex = /^xl\/comments(\d+)[.]xml$/;
const tableXmlRegex = /^xl\/tables\/(table\d+)[.]xml$/;
const pivotTableXmlRegex = /^xl\/pivotTables\/(pivotTable\d+)[.]xml$/;
const pivotTableRelsXmlRegex = /^xl\/pivotTables\/_rels\/(pivotTable\d+)[.]xml[.]rels$/;
const pivotCacheDefinitionXmlRegex = /^xl\/pivotCache\/(pivotCacheDefinition\d+)[.]xml$/;
const pivotCacheDefinitionRelsXmlRegex = /^xl\/pivotCache\/_rels\/(pivotCacheDefinition\d+)[.]xml[.]rels$/;
const pivotCacheRecordsXmlRegex = /^xl\/pivotCache\/(pivotCacheRecords\d+)[.]xml$/;
export function normalizeZipPath(path) {
    return path.startsWith("/") ? path.slice(1) : path;
}
export function getWorksheetNoFromWorksheetPath(path) {
    const match = worksheetXmlRegex.exec(path);
    if (!match) {
        return undefined;
    }
    return parseInt(match[1], 10);
}
export function getWorksheetNoFromWorksheetRelsPath(path) {
    const match = worksheetRelsXmlRegex.exec(path);
    if (!match) {
        return undefined;
    }
    return parseInt(match[1], 10);
}
export function isMediaPath(path) {
    return path.startsWith("xl/media/");
}
export function getMediaFilenameFromPath(path) {
    const match = mediaFilenameRegex.exec(path);
    return match ? match[1] : undefined;
}
export function isThemePath(path) {
    return themeXmlRegex.test(path);
}
export function getThemeNameFromPath(path) {
    const match = /^xl\/theme\/([a-zA-Z0-9]+)[.]xml$/.exec(path);
    return match ? match[1] : undefined;
}
export function isBinaryEntryPath(path) {
    // Media and themes should be treated as binary in the legacy buffer-based reader.
    // Everything else is parsed as text XML.
    return isMediaPath(path) || isThemePath(path);
}
export function getDrawingNameFromPath(path) {
    const match = drawingXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getDrawingNameFromRelsPath(path) {
    const match = drawingRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getVmlDrawingNameFromPath(path) {
    const match = vmlDrawingRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getCommentsIndexFromPath(path) {
    const match = commentsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getTableNameFromPath(path) {
    const match = tableXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getPivotTableNameFromPath(path) {
    const match = pivotTableXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getPivotTableNameFromRelsPath(path) {
    const match = pivotTableRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getPivotCacheDefinitionNameFromPath(path) {
    const match = pivotCacheDefinitionXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getPivotCacheDefinitionNameFromRelsPath(path) {
    const match = pivotCacheDefinitionRelsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function getPivotCacheRecordsNameFromPath(path) {
    const match = pivotCacheRecordsXmlRegex.exec(path);
    return match ? match[1] : undefined;
}
export function toContentTypesPartName(zipPath) {
    // ContentTypes uses leading slash PartName (e.g. "/xl/workbook.xml").
    return zipPath.startsWith("/") ? zipPath : `/${zipPath}`;
}
export function themePath(themeName) {
    return `xl/theme/${themeName}.xml`;
}
export function mediaPath(filename) {
    return `xl/media/${filename}`;
}
export function worksheetPath(sheetId) {
    return `xl/worksheets/sheet${sheetId}.xml`;
}
export function worksheetRelsPath(sheetId) {
    return `xl/worksheets/_rels/sheet${sheetId}.xml.rels`;
}
export function worksheetRelTarget(sheetId) {
    return `worksheets/sheet${sheetId}.xml`;
}
export function commentsPath(sheetId) {
    return `xl/comments${sheetId}.xml`;
}
export function commentsPathFromName(commentName) {
    // For comments when the caller already has the logical name (e.g. "comments1").
    return `xl/${commentName}.xml`;
}
export function vmlDrawingPath(sheetId) {
    return `xl/drawings/vmlDrawing${sheetId}.vml`;
}
export function tablePath(target) {
    return `xl/tables/${target}`;
}
export function drawingPath(drawingName) {
    return `xl/drawings/${drawingName}.xml`;
}
export function drawingRelsPath(drawingName) {
    return `xl/drawings/_rels/${drawingName}.xml.rels`;
}
export function pivotCacheDefinitionPath(n) {
    return `xl/pivotCache/pivotCacheDefinition${n}.xml`;
}
export function pivotCacheDefinitionRelsPath(n) {
    return `xl/pivotCache/_rels/pivotCacheDefinition${n}.xml.rels`;
}
export function pivotCacheRecordsPath(n) {
    return `xl/pivotCache/pivotCacheRecords${n}.xml`;
}
export function pivotCacheRecordsRelTarget(n) {
    return `pivotCacheRecords${n}.xml`;
}
export function pivotTablePath(n) {
    return `xl/pivotTables/pivotTable${n}.xml`;
}
export function pivotTableRelsPath(n) {
    return `xl/pivotTables/_rels/pivotTable${n}.xml.rels`;
}
export function pivotCacheDefinitionRelTargetFromPivotTable(n) {
    return `../pivotCache/pivotCacheDefinition${n}.xml`;
}
export const OOXML_REL_TARGETS = {
    // Targets inside xl/_rels/workbook.xml.rels (base: xl/)
    workbookStyles: "styles.xml",
    workbookSharedStrings: "sharedStrings.xml",
    workbookTheme1: "theme/theme1.xml",
    workbookFeaturePropertyBag: "featurePropertyBag/featurePropertyBag.xml"
};
export function pivotCacheDefinitionRelTargetFromWorkbook(n) {
    // Target inside xl/_rels/workbook.xml.rels (base: xl/)
    return `pivotCache/pivotCacheDefinition${n}.xml`;
}
export function commentsRelTargetFromWorksheet(sheetId) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../comments${sheetId}.xml`;
}
export function vmlDrawingRelTargetFromWorksheet(sheetId) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../drawings/vmlDrawing${sheetId}.vml`;
}
export function drawingRelTargetFromWorksheet(drawingName) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../drawings/${drawingName}.xml`;
}
export function vmlDrawingRelTargetFromWorksheetName(vmlName) {
    // For VML drawings when the caller already has the logical name (e.g. "vmlDrawing1").
    return `../drawings/${vmlName}.vml`;
}
export function commentsRelTargetFromWorksheetName(commentName) {
    // For comments when the caller already has the logical name (e.g. "comments1").
    return `../${commentName}.xml`;
}
export function pivotTableRelTargetFromWorksheet(n) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../pivotTables/pivotTable${n}.xml`;
}
export function pivotTableRelTargetFromWorksheetName(pivotName) {
    // For pivot tables when the caller already has the logical name (e.g. "pivotTable1").
    return `../pivotTables/${pivotName}.xml`;
}
export function tableRelTargetFromWorksheet(target) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../tables/${target}`;
}
export function tableRelTargetFromWorksheetName(name) {
    return `../tables/${name}.xml`;
}
export function mediaRelTargetFromRels(filename) {
    // Target from a rels file located under xl/*/_rels (base is one level deeper than xl/)
    return `../media/${filename}`;
}
// Form Control (ctrlProps) path functions
export function ctrlPropPath(id) {
    return `xl/ctrlProps/ctrlProp${id}.xml`;
}
export function ctrlPropRelTargetFromWorksheet(id) {
    // Target inside xl/worksheets/_rels/sheetN.xml.rels (base: xl/worksheets/)
    return `../ctrlProps/ctrlProp${id}.xml`;
}
