ods.
 */
class _TabGroupState {
  /**
   * Collect data related to a single tab group, synchronously.
   *
   * @param {MozTabbrowserTabGroup} tabGroup
   *   Tab group browser element
   * @returns {TabGroupStateData}
   *   Serialized tab group data
   */
  collect(tabGroup) {
    return {
      id: tabGroup.id,
      name: tabGroup.label,
      color: tabGroup.color,
      collapsed: tabGroup.collapsed,
      saveOnWindowClose: tabGroup.saveOnWindowClose,
    };
  }

  /**
   * Create initial state for a tab group that is about to close inside of an
   * open window.
   *
   * The caller is responsible for hydrating closed tabs data into `tabs`
   * using the `TabState` class.
   *
   * @param {MozTabbrowserTabGroup} tabGroup
   * @param {string} sourceWindowId
   *   `window.__SSi` window ID of the open window where the tab group is closing.
   * @returns {ClosedTabGroupStateData}
   */
  closed(tabGroup, sourceWindowId) {
    let closedData = this.collect(tabGroup);
    closedData.closedAt = Date.now();
    closedData.sourceWindowId = sourceWindowId;
    closedData.tabs = [];
    return closedData;
  }

  /**
   * Create initial state for a tab group that is about to be explicitly saved
   * by the user inside of an open window.
   *
   * The caller is responsible for hydrating closed tabs data into `tabs`
   * using the `TabState` class.
   *
   * @param {MozTabbrowserTabGroup} tabGroup
   * @param {string} sourceWindowId
   *   `window.__SSi` window ID of the open window where the tab group
   *   is being saved.
   * @returns {SavedTabGroupStateData}
   */
  savedInOpenWindow(tabGroup, sourceWindowId) {
    let savedData = this.closed(tabGroup, sourceWindowId);
    savedData.saved = true;
    return savedData;
  }

  /**
   * Convert an existing tab group's state to saved tab group state. The input
   * tab group state should come from a closing/closed window; if you need the
   * state of a tab group that still exists in the browser, use `savedInOpenWindow`
   * instead. This should be used when a tab group is being saved automatically
   * due to a user closing a window containing some tab groups.
   *
   * The caller is responsible for hydrating closed tabs data into `tabs`
   * using the `TabState` class.
   *
   * @param {TabGroupStateData} tabGroupState
   * @param {number} windowClosedId
   *   `WindowStateData.closedId` of the closed window from which this tab group
   *   should be automatically saved.
   */
  savedInClosedWindow(tabGroupState, windowClosedId) {
    let savedData = tabGroupState;
    savedData.saved = true;
    savedData.closedAt = Date.now();
    savedData.windowClosedId = windowClosedId;
    savedData.tabs = [];
    return savedData;
  }

  /**
   * In cases where we surface tab group metadata to external callers, we may want
   * to provide an abbreviated set of metadata. This can help hide internal details
   * from browser code or from extensions. Hiding those details can make the public
   * session APIs simpler and more stable.
   *
   * @param {TabGroupStateData} tabGroupState
   * @returns {TabGroupStateData}
   */
  abbreviated(tabGroupState) {
    let abbreviatedData = {
      id: tabGroupState.id,
      name: tabGroupState.name,
      color: tabGroupState.color,
      collapsed: tabGroupState.collapsed,
    };
    return abbreviatedData;
  }
}

export const TabGroupState = new _TabGroupState();
PK