import React from "react";
import {Button, Group, Header, Panel, Select, Text} from "../ui";
import {downloadCSV, inventoryExportFilename, toCSV} from "./inventoryExport";
import {groupFieldsOf, summableFieldsOf} from "./summarize";
const fieldOptions = (fs) => fs.map(f => ({value: f.key, label: f.label}));
/**
* The "Export" tab: explains each export format and provides the action to produce it. CSV is the raw items table,
* generated entirely in the browser. "PDF" opens the print dialog over the hidden printable view (see
* InventoryPrint), which includes a summary table grouped by the field chosen here.
*/
export function InventoryExportPanel({name, fields, items, groupKey, sumKey, onGroupKey, onSumKey}) {
const count = (items || []).length;
const groupFields = groupFieldsOf(fields);
const summableFields = summableFieldsOf(fields);
const exportCSV = () =>
downloadCSV(inventoryExportFilename(name, 'csv'), toCSV(fields, items));
return <>
CSV
A comma-separated spreadsheet of all {count} item{count === 1 ? '' : 's'} and every field, openable
in Excel, Numbers, or Google Sheets. Generated entirely on this device.
PDF
A printable table of the whole inventory, followed by a summary grouped by the field you choose.
This opens your browser's print dialog — choose "Save as PDF" as the destination to get a PDF file,
or print it on paper.
{groupFields.length > 0 &&
Summary group:{' '}
{summableFields.length > 0 &&
Sum:{' '}
}
}
>;
}