import { helper } from '@ember/component/helper';

function isItemOpen(item, selectedItem) {
  // The developer can force the item to be open.
  if (item.forceOpen) {
    return true;
  }

  // Of course a selected item is open.
  if (item.id === selectedItem) {
    return true;
  }

  // The item has to be open if it has a child that's open.
  if (item.items) {
    return item.items.some(item => isItemOpen(item, selectedItem));
  }
  return false;
}

/**
 * Retuns wether an item is open taking into account his childs
 *
 * @param { any } ref
 */
function isItemOpenHelper([item, selectedItem]) {
  return isItemOpen(item, selectedItem);
}
var isItemOpen$1 = helper(isItemOpenHelper);

export { isItemOpen$1 as default, isItemOpen, isItemOpenHelper };
//# sourceMappingURL=is-item-open.js.map
