import React from 'react';

export type SubCell = 'date' | 'time';

interface SubCellClickTracker {
  /** Read the last clicked sub-cell. Cleared (returns null) after read. */
  consume: () => SubCell | null;
  /** Record which sub-cell the user just mousedowned on. */
  record: (sub: SubCell) => void;
}

const NOOP_TRACKER: SubCellClickTracker = {
  consume: () => null,
  record: () => {},
};

export const SubCellClickContext =
  React.createContext<SubCellClickTracker>(NOOP_TRACKER);

export const useSubCellClickTracker = (): SubCellClickTracker =>
  React.useContext(SubCellClickContext);
