<commit_before>import {
  EventSegUiInteractionState,
  VNode,
  DateComponent,
  RefObject,
  CssDimValue,
  h,
  PositionCache,
  Ref,
  memoize,
  addDays,
  RefMap,
  setRef,
  ComponentContext,
  DateRange,
  NowTimer,
  DateMarker,
  DateProfile,
} from '@fullcalendar/core'
import TableSeg, { splitSegsByRow, splitInteractionByRow } from './TableSeg'
import TableRow, { RowMoreLinkArg } from './TableRow'
import { TableCellModel } from './TableCell'
import MorePopover from './MorePopover'


export interface TableProps {
  elRef?: Ref<HTMLDivElement>
  cells: TableCellModel[][] // cells-BY-ROW
  dateProfile: DateProfile
  renderRowIntro?: () => VNode
  colGroupNode: VNode
  tableMinWidth: CssDimValue
  expandRows: boolean
  clientWidth: CssDimValue
  clientHeight: CssDimValue
  businessHourSegs: TableSeg[]
  bgEventSegs: TableSeg[]
  fgEventSegs: TableSeg[]
  dateSelectionSegs: TableSeg[]
  eventSelection: string
  eventDrag: EventSegUiInteractionState | null
  eventResize: EventSegUiInteractionState | null
  eventLimit: boolean | number
  headerAlignElRef?: RefObject<HTMLElement>
}

interface TableState {
  morePopoverState: MorePopoverState | null
}

interface MorePopoverState extends RowMoreLinkArg {
  currentFgEventSegs: TableSeg[]
}


export default class Table extends DateComponent<TableProps, TableState> {

  private splitBusinessHourSegs = memoize(splitSegsByRow)
  private splitBgEventSegs = memoize(splitSegsByRow)
  private splitFgEventSegs = memoize(splitSegsByRow)
  private splitDateSelectionSegs = memoize(splitSegsByRow)
  private splitEventDrag = memoize(splitInteractionByRow)
  private splitEventResize = memoize(splitInteractionByRow)
  private buildBuildMoreLinkText = memoize(buildBuildMoreLinkText)
  private rootEl: HTMLElement
  private rowRefs = new RefMap<TableRow>()
  private rowPositions: PositionCache
  private colPositions: PositionCache


  render(props: TableProps, state: TableState, context: ComponentContext) {
    let { morePopoverState } = state
    let rowCnt = props.cells.length

    let businessHourSegsByRow = this.splitBusinessHourSegs(props.businessHourSegs, rowCnt)
    let bgEventSegsByRow = this.splitBgEventSegs(props.bgEventSegs, rowCnt)
    let fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, rowCnt)
    let dateSelectionSegsByRow = this.splitDateSelectionSegs(props.dateSelectionSegs, rowCnt)
    let eventDragByRow = this.splitEventDrag(props.eventDrag, rowCnt)
    let eventResizeByRow = this.splitEventResize(props.eventResize, rowCnt)
    let buildMoreLinkText = this.buildBuildMoreLinkText(context.options.moreLinkText)

    let classNames = [ 'fc-daygrid-body' ]
    if (props.expandRows && props.eventLimit === true) {
      classNames.push('fc-daygrid-body-balanced')
    }

    return (
      <div class={classNames.join(' ')} ref={this.handleRootEl} style={{
        // these props are important to give this wrapper correct dimensions for interactions
        // TODO: if we set it here, can we avoid giving to inner tables?
        width: props.clientWidth,
        minWidth: props.tableMinWidth
      }}>
        <NowTimer unit='day' content={(nowDate: DateMarker, todayRange: DateRange) => [
          <table
            className='fc-scrollgrid-sync-table'
            style={{
              width: props.clientWidth,
              minWidth: props.tableMinWidth,
              height: props.expandRows ? props.clientHeight : ''
            }}
          >
            {props.colGroupNode}
            <tbody>
              {props.cells.map((cells, row) => (
                <TableRow
                  ref={this.rowRefs.createRef(row)}
                  key={cells[0].date.toISOString() /* best? or put key on cell? or use diff formatter? */}
                  enableNumbers={rowCnt > 1}
                  todayRange={todayRange}
                  dateProfile={props.dateProfile}
                  cells={cells}
                  renderIntro={props.renderRowIntro}
                  businessHourSegs={businessHourSegsByRow[row]}
                  eventSelection={props.eventSelection}
                  bgEventSegs={bgEventSegsByRow[row]}
                  fgEventSegs={fgEventSegsByRow[row]}
                  dateSelectionSegs={dateSelectionSegsByRow[row]}
                  eventDrag={eventDragByRow[row]}
                  eventResize={eventResizeByRow[row]}
                  eventLimit={props.eventLimit}
                  clientWidth={props.clientWidth}
                  buildMoreLinkText={buildMoreLinkText}
                  onMoreClick={this.handleMoreLinkClick}
                />
              ))}
            </tbody>
          </table>,<commit_msg>correct keys for inverse-bg events<commit_after>import {
  EventSegUiInteractionState,
  VNode,
  DateComponent,
  RefObject,
  CssDimValue,
  h,
  PositionCache,
  Ref,
  memoize,
  addDays,
  RefMap,
  setRef,
  ComponentContext,
  DateRange,
  NowTimer,
  DateMarker,
  DateProfile,
} from '@fullcalendar/core'
import TableSeg, { splitSegsByRow, splitInteractionByRow } from './TableSeg'
import TableRow, { RowMoreLinkArg } from './TableRow'
import { TableCellModel } from './TableCell'
import MorePopover from './MorePopover'


export interface TableProps {
  elRef?: Ref<HTMLDivElement>
  cells: TableCellModel[][] // cells-BY-ROW
  dateProfile: DateProfile
  renderRowIntro?: () => VNode
  colGroupNode: VNode
  tableMinWidth: CssDimValue
  expandRows: boolean
  clientWidth: CssDimValue
  clientHeight: CssDimValue
  businessHourSegs: TableSeg[]
  bgEventSegs: TableSeg[]
  fgEventSegs: TableSeg[]
  dateSelectionSegs: TableSeg[]
  eventSelection: string
  eventDrag: EventSegUiInteractionState | null
  eventResize: EventSegUiInteractionState | null
  eventLimit: boolean | number
  headerAlignElRef?: RefObject<HTMLElement>
}

interface TableState {
  morePopoverState: MorePopoverState | null
}

interface MorePopoverState extends RowMoreLinkArg {
  currentFgEventSegs: TableSeg[]
}


export default class Table extends DateComponent<TableProps, TableState> {

  private splitBusinessHourSegs = memoize(splitSegsByRow)
  private splitBgEventSegs = memoize(splitSegsByRow)
  private splitFgEventSegs = memoize(splitSegsByRow)
  private splitDateSelectionSegs = memoize(splitSegsByRow)
  private splitEventDrag = memoize(splitInteractionByRow)
  private splitEventResize = memoize(splitInteractionByRow)
  private buildBuildMoreLinkText = memoize(buildBuildMoreLinkText)
  private rootEl: HTMLElement
  private rowRefs = new RefMap<TableRow>()
  private rowPositions: PositionCache
  private colPositions: PositionCache


  render(props: TableProps, state: TableState, context: ComponentContext) {
    let { morePopoverState } = state
    let rowCnt = props.cells.length

    let businessHourSegsByRow = this.splitBusinessHourSegs(props.businessHourSegs, rowCnt)
    let bgEventSegsByRow = this.splitBgEventSegs(props.bgEventSegs, rowCnt)
    let fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, rowCnt)
    let dateSelectionSegsByRow = this.splitDateSelectionSegs(props.dateSelectionSegs, rowCnt)
    let eventDragByRow = this.splitEventDrag(props.eventDrag, rowCnt)
    let eventResizeByRow = this.splitEventResize(props.eventResize, rowCnt)
    let buildMoreLinkText = this.buildBuildMoreLinkText(context.options.moreLinkText)

    let classNames = [ 'fc-daygrid-body' ]
    if (props.expandRows && props.eventLimit === true) {
      classNames.push('fc-daygrid-body-balanced')
    }

    return (
      <div class={classNames.join(' ')} ref={this.handleRootEl} style={{
        // these props are important to give this wrapper correct dimensions for interactions
        // TODO: if we set it here, can we avoid giving to inner tables?
        width: props.clientWidth,
        minWidth: props.tableMinWidth
      }}>
        <NowTimer unit='day' content={(nowDate: DateMarker, todayRange: DateRange) => [
          <table
            className='fc-scrollgrid-sync-table'
            style={{
              width: props.clientWidth,
              minWidth: props.tableMinWidth,
              height: props.expandRows ? props.clientHeight : ''
            }}
          >
            {props.colGroupNode}
            <tbody>
              {props.cells.map((cells, row) => (
                <TableRow
                  ref={this.rowRefs.createRef(row)}
                  key={
                    cells.length
                      ? cells[0].date.toISOString() /* best? or put key on cell? or use diff formatter? */
                      : row // in case there are no cells (like when resource view is loading)
                  }
                  enableNumbers={rowCnt > 1}
                  todayRange={todayRange}
                  dateProfile={props.dateProfile}
                  cells={cells}
                  renderIntro={props.renderRowIntro}
                  businessHourSegs={businessHourSegsByRow[row]}
                  eventSelection={props.eventSelection}
                  bgEventSegs={bgEventSegsByRow[row]}
                  fgEventSegs={fgEventSegsByRow[row]}
                  dateSelectionSegs={dateSelectionSegsByRow[row]}
                  eventDrag={eventDragByRow[row]}
                  eventResize={eventResizeByRow[row]}
                  eventLimit={props.eventLimit}
                  clientWidth={props.clientWidth}
                  buildMoreLinkText={buildMoreLinkText}
                  onMoreClick={this.handleMoreLinkClick}
                />
              ))}
            </tbody>
          </table>,
{'fraction_non_alphanumeric': 0.0879420715709938, 'fraction_numerical': 0.000419771224682548, 'mean_word_length': 2.9445364238410594, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6863054', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2735, 'n_words': 552}