/**
 * Item lists for the file trees' right-click menus.
 *
 * Pure on purpose: every action arrives as a callback, so the composition can
 * be asserted without mounting RepoPanel and its four context providers.
 */

/**
 * The menu for a right-click on empty tree space.
 *
 * Empty space acts on the tree's container, never on a selection — FileTree
 * has already cleared the selection by the time this menu opens, so nothing
 * selection-scoped (Pull Latest, Submit, Checkout, Delete, Revert) belongs
 * here. With an empty selection those actions are either inert or, in Pull
 * Latest's case, merely a help popup.
 */
export function buildEmptyMenuItems({
  tab,
  isTauri,
  hasWorkspace,
  fileManagerLabel,
  canRefresh,
  canNewFolder,
  onNewFolder,
  onReveal,
  onCopyPath,
  onSelectAll,
  onExpandAll,
  onCollapseAll,
  onRefresh,
}) {
  const items = [];

  // Workspace only: Cambium stores no empty directories, so a folder created
  // on the Server tree would have nothing to represent until a file landed in
  // it. Native only — there is no filesystem to create it on in the browser.
  if (tab === 'workspace' && isTauri && hasWorkspace) {
    items.push({
      key: 'newFolder',
      label: 'New Folder…',
      icon: 'assets/circle_add.svg',
      disabled: !canNewFolder,
      onClick: onNewFolder,
    });
    items.push({ key: 'sep0', separator: true });
  }

  if (isTauri) {
    items.push({
      key: 'reveal',
      label: fileManagerLabel,
      icon: 'assets/folder.svg',
      disabled: !hasWorkspace,
      onClick: onReveal,
    });
  }
  items.push({ key: 'copyPath', label: 'Copy Path', onClick: onCopyPath });
  items.push(
    { key: 'sep1', separator: true },
    { key: 'selectAll', label: 'Select All', onClick: onSelectAll },
    { key: 'expandAll', label: 'Expand All', onClick: onExpandAll },
    { key: 'collapseAll', label: 'Collapse All', onClick: onCollapseAll },
    { key: 'sep2', separator: true },
    {
      key: 'refresh',
      label: 'Refresh',
      icon: 'assets/refresh.svg',
      disabled: !canRefresh,
      onClick: onRefresh,
    }
  );

  return items;
}
