/* ObsiGate — XLSX command bar builder (Sheets-like ribbon).
*
* Pure string builder for the spreadsheet shell (sheet tabs + grouped action
* buttons + status pills). Extracted from frontend/js/viewer.js so the markup
* is testable and the viewer only wires behaviour.
*
* Order follows Google Sheets: search, undo/redo, print, paint, zoom, number
* formats, font size, B/I/S/U, colours, borders, merge, alignments, wrap,
* rotation, overflow menu — then the ObsiGate-specific groups (structure,
* format, view, gridlines) kept with their stable ids. File outputs
* (Download / CSV / Markdown / HTML / Print) moved to the **Fichier** menu of
* the menu bar (#185, frontend/js/xlsx/menus.js); only Save stays on the
* sheet-tab strip, pinned at its right end.
*/
import { t } from '../i18n.js';
import { escapeHtml } from '../utils.js';
const IC = (name) => ``;
/**
* @param {object} ctx
* @param {Array<{name: string}>} ctx.sheets
* @param {boolean} ctx.isCsv
* @param {boolean} ctx.readOnly
* @param {boolean} ctx.editable - not a CSV and not read-only
* @returns {{ tabs: string, actionsHtml: string, statusBar: string, fileHtml: string }}
*/
export function buildCommandBar({ sheets, isCsv, readOnly, editable }) {
// Sheet tabs are always rendered (even for a single sheet) so the strip reads
// as a real affordance; an editable workbook gets an explicit “+” button.
const tabs = isCsv
? ""
: `
`;
// Status pills make the viewer's limits visible up front (#180: the
// "formulas computed locally" pill is gone — local computation is the
// normal behaviour, not a limit worth a badge).
const statusPills = [
readOnly
? `${escapeHtml(t("xlsx.readonly_badge"))}`
: "",
].filter(Boolean).join("");
const statusBar = statusPills ? `
${statusPills}
` : "";
// Command groups, separated by thin rules (Sheets order).
const actionGroups = [];
actionGroups.push(``);
if (!readOnly) {
actionGroups.push(``);
}
actionGroups.push(``);
if (editable) {
actionGroups.push(``);
actionGroups.push(``);
actionGroups.push(``);
// #183 — colour commands open the Sheets-like panel built by
// xlsx/color-picker.js (the native is kept hidden and
// only driven by the panel's « + » / crayon buttons).
const colourPick = (id, label, iconName, swatchId) =>
``
+ ``
+ ``
+ ``;
actionGroups.push(`
${colourPick("xs-fgcolor", t("xlsx.format_font_color"), "font", "xs-fgcolor")}
${colourPick("xs-bgcolor", t("xlsx.format_fill_color"), "fill", "xs-bgcolor")}
`);
actionGroups.push(``);
}
if (!readOnly) {
actionGroups.push(``);
}
if (editable) {
actionGroups.push(``);
actionGroups.push(``);
}
// #185 — the ribbon now reads like Google Sheets': flat icon buttons, no
// chrome, grouped by thin vertical rules. The gridline switch belongs to it
// (the View ▸ Show menu toggles the very same state).
actionGroups.push(``);
const actionsHtml = actionGroups.join('');
// #185 — file outputs moved to the **Fichier** menu of the menu bar
// (frontend/js/xlsx/menus.js), which keeps the `#xlsx-download-btn` /
// `#xlsx-csv-btn` ids and the `[data-xlsx-export]` markers. Only **Save**
// stays on the sheet-tab strip, pinned at its right end.
const fileHtml =
``;
return { tabs, actionsHtml, statusBar, fileHtml };
}