import { cloneFilterRecord, cloneSortKeyRecord, cloneSortRecord, filterKey, sortKey } from './workbook-metadata-records.js';
import { canonicalWorkbookFilterRangeOnSheet, canonicalWorkbookRangeOnSheet } from './workbook-metadata-service-helpers.js';
export function setWorkbookFilterRecord(metadata, sheetName, range) {
    const storedRange = canonicalWorkbookFilterRangeOnSheet(sheetName, range);
    const record = { sheetName, range: storedRange };
    metadata.filters.set(filterKey(sheetName, storedRange), record);
    return cloneFilterRecord(record);
}
export function getWorkbookFilterRecord(metadata, sheetName, range) {
    const record = metadata.filters.get(filterKey(sheetName, range));
    return record ? cloneFilterRecord(record) : undefined;
}
export function deleteWorkbookFilterRecord(metadata, sheetName, range) {
    return metadata.filters.delete(filterKey(sheetName, range));
}
export function listWorkbookFilterRecords(metadata, sheetName) {
    return [...metadata.filters.values()]
        .filter((record) => record.sheetName === sheetName)
        .toSorted((left, right) => filterKey(left.sheetName, left.range).localeCompare(filterKey(right.sheetName, right.range)))
        .map(cloneFilterRecord);
}
export function setWorkbookSortRecord(metadata, sheetName, range, keys) {
    const storedRange = canonicalWorkbookRangeOnSheet(sheetName, range);
    const record = {
        sheetName,
        range: storedRange,
        keys: keys.map(cloneSortKeyRecord),
    };
    metadata.sorts.set(sortKey(sheetName, storedRange), record);
    return cloneSortRecord(record);
}
export function getWorkbookSortRecord(metadata, sheetName, range) {
    const record = metadata.sorts.get(sortKey(sheetName, range));
    return record ? cloneSortRecord(record) : undefined;
}
export function deleteWorkbookSortRecord(metadata, sheetName, range) {
    return metadata.sorts.delete(sortKey(sheetName, range));
}
export function listWorkbookSortRecords(metadata, sheetName) {
    return [...metadata.sorts.values()]
        .filter((record) => record.sheetName === sheetName)
        .toSorted((left, right) => sortKey(left.sheetName, left.range).localeCompare(sortKey(right.sheetName, right.range)))
        .map(cloneSortRecord);
}
//# sourceMappingURL=workbook-metadata-sheet-range-records.js.map