/**
 * This JS file was auto-generated via Terser.
 *
 * Contributors should avoid editing this file, but instead edit the associated
 * non minified file file. For more information, check out our engineering docs
 * on how we handle JS minification in our engineering docs.
 *
 * @see: https://evnt.is/dev-docs-minification
 */

tribe.events=tribe.events||{},tribe.events.views=tribe.events.views||{},tribe.events.views.monthGrid={},function($,obj){"use strict";var $document=$(document);obj.selectors={grid:'[data-js="tribe-events-month-grid"]',row:'[data-js="tribe-events-month-grid-row"]',cell:'[data-js="tribe-events-month-grid-cell"]',focusable:"[tabindex]",focused:'[tabindex="0"]'},obj.keyCode={END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40},obj.isValidCell=function(grid,row,col){return!isNaN(row)&&!isNaN(col)&&row>=0&&col>=0&&grid&&grid.length&&row<grid.length&&col<grid[row].length},obj.getNextCell=function(grid,currentRow,currentCol,directionX,directionY){var row=currentRow+directionY,col=currentCol+directionX;return obj.isValidCell(grid,row,col)?{row:row,col:col}:{row:currentRow,col:currentCol}},obj.setFocusPointer=function($grid,row,col){var state=$grid.data("tribeEventsState");return!!obj.isValidCell(state.grid,row,col)&&(state.grid[state.currentRow][state.currentCol].attr("tabindex","-1"),state.grid[row][col].attr("tabindex","0"),state.currentRow=row,state.currentCol=col,$grid.data("tribeEventsState",state),!0)},obj.focusCell=function($grid,row,col){obj.setFocusPointer($grid,row,col)&&$grid.data("tribeEventsState").grid[row][col].focus()},obj.handleKeydown=function(event){var nextCell,$grid=event.data.grid,state=$grid.data("tribeEventsState"),key=event.which||event.keyCode,row=state.currentRow,col=state.currentCol;switch(key){case obj.keyCode.UP:row=(nextCell=obj.getNextCell(state.grid,row,col,0,-1)).row,col=nextCell.col;break;case obj.keyCode.DOWN:row=(nextCell=obj.getNextCell(state.grid,row,col,0,1)).row,col=nextCell.col;break;case obj.keyCode.LEFT:row=(nextCell=obj.getNextCell(state.grid,row,col,-1,0)).row,col=nextCell.col;break;case obj.keyCode.RIGHT:row=(nextCell=obj.getNextCell(state.grid,row,col,1,0)).row,col=nextCell.col;break;case obj.keyCode.HOME:event.ctrlKey&&(row=0),col=0;break;case obj.keyCode.END:event.ctrlKey&&(row=state.grid.length-1),col=state.grid[state.currentRow].length-1;break;default:return}obj.focusCell($grid,row,col),event.preventDefault()},obj.handleClick=function(event){for(var $grid=event.data.grid,state=$grid.data("tribeEventsState"),$clickedCell=$(event.target).closest(obj.selectors.focusable),row=0;row<state.grid.length;row++)for(var col=0;col<state.grid[row].length;col++)if(state.grid[row][col].is($clickedCell))return void obj.focusCell($grid,row,col)},obj.initState=function($grid){$grid.data("tribeEventsState",{grid:[],currentRow:0,currentCol:0})},obj.setupGrid=function($grid){var state=$grid.data("tribeEventsState");$grid.find(obj.selectors.row).each((function(rowIndex,row){var gridRow=[];$(row).find(obj.selectors.cell).each((function(colIndex,cell){var $cell=$(cell);if($cell.is(obj.selectors.focusable))$cell.is(obj.selectors.focused)&&(state.currentRow=state.grid.length,state.currentCol=gridRow.length),gridRow.push($cell);else{var $focusableCell=$cell.find(obj.selectors.focusable);$focusableCell.is(obj.selectors.focusable)&&($cell.is(obj.selectors.focused)&&(state.currentRow=state.grid.length,state.currentCol=gridRow.length),gridRow.push($focusableCell))}})),gridRow.length&&state.grid.push(gridRow)})),$grid.data("tribeEventsState",state)},obj.unbindEvents=function($grid){$grid.off()},obj.bindEvents=function($grid){$grid.on("keydown",{grid:$grid},obj.handleKeydown).on("click",{grid:$grid},obj.handleClick)},obj.deinit=function(event,jqXHR,settings){var $container=event.data.container,$grid=$container.find(obj.selectors.grid);obj.unbindEvents($grid),$container.off("beforeAjaxSuccess.tribeEvents",obj.deinit)},obj.init=function(event,index,$container,data){var $grid=$container.find(obj.selectors.grid);if($grid.length){obj.initState($grid),obj.setupGrid($grid);var state=$grid.data("tribeEventsState");obj.setFocusPointer($grid,state.currentRow,state.currentCol),obj.bindEvents($grid),$container.on("beforeAjaxSuccess.tribeEvents",{container:$container},obj.deinit)}},obj.ready=function(){$document.on("afterSetup.tribeEvents",tribe.events.views.manager.selectors.container,obj.init)},$(obj.ready)}(jQuery,tribe.events.views.monthGrid);