(function (root, factory) {
  if (typeof module === 'object' && module.exports) module.exports = factory;
  else root.createMobileWorkEntry = factory;
})(typeof self !== 'undefined' ? self : this, function createMobileWorkEntry(options) {
  function mode() {
    if (options.isTodayActive()) return 'continue';
    const preparation = options.getPreparationState?.();
    if (preparation?.active) return 'prepare-resume';
    if (preparation?.next && !['today', 'find'].includes(preparation.next)) return 'prepare';
    const recommended = options.queueLauncher && options.queueLauncher.recommend();
    if (recommended && !['today', 'find'].includes(recommended.name)) return recommended.name;
    if (options.getTodayCount() > 0 && options.isTodayResumable()) return 'resume';
    if (options.getTodayCount() > 0) return 'start';
    if (options.getEligibleCount() > 0) return 'plan';
    if (options.shouldActivate?.()) return 'activate';
    return 'find';
  }

  function open() {
    const current = mode();
    if (current === 'continue') options.continueToday();
    else if (['prepare', 'prepare-resume'].includes(current)) options.prepareToday();
    else if (current === 'resume') options.resumeToday();
    else if (current === 'start') options.startToday();
    else if (current === 'plan') options.planToday();
    else if (current === 'activate') options.openActivation();
    else if (current === 'find') options.findWork();
    else options.queueLauncher.open(current);
    return current;
  }

  return {mode, open};
});
