import * as types from '../constants/actionTypes';

const actions: ActionType = dispatch => ({
  setTotalPage: (page: number): void =>
    dispatch({ type: types.SET_TOTAL_PAGE, payload: page }),
  setCurrentPage: (page: number): void =>
    dispatch({ type: types.SET_CURRENT_PAGE, payload: page }),
  setPdf: (pdf: Record<string, any>): void =>
    dispatch({ type: types.SET_PDF, payload: pdf }),
  setProgress: (progress: ProgressType): void =>
    dispatch({ type: types.SET_PROGRESS, payload: progress }),
  setViewport: (viewport: ViewportType): void =>
    dispatch({ type: types.SET_VIEWPORT, payload: viewport }),
  changeScale: (scale: number | string): void =>
    dispatch({ type: types.CHANGE_SCALE, payload: scale }),
  changeRotate: (rotation: number): void =>
    dispatch({ type: types.CHANGE_ROTATE, payload: rotation }),
  addAnnots: (annotations: AnnotationType[], init = true): void =>
    dispatch({ type: types.ADD_ANNOTS, payload: { annotations, init } }),
  updateAnnots: (annotations: AnnotationType[]): void =>
    dispatch({ type: types.UPDATE_ANNOTS, payload: annotations }),
  updateWatermark: (watermark: WatermarkType): void =>
    dispatch({ type: types.UPDATE_WATERMARK, payload: watermark }),
  setTextDivs: (pageNum: number, elements: HTMLElement[]): void =>
    dispatch({ type: types.SET_TEXT_DIV, payload: { [pageNum]: elements } }),
});

export default actions;
