import { MonthOrYearComponents , pageName , RangeStatus , RangeType , State , } from '../../types/store' ; import { RangeClickEvent } from '../../types/components' ; import { _EventListener , DynamicStyle } from '../../types/utils' ; import { getNext , getPre , transformDateToArray } from '../../utils/date' ; import { visible } from '../../utils/element' ; import { Sub } from '../../types/observer' ; const rangeClickEvent = { complete : { plt : 'start' , status : 'selecting' , } , selecting : { plt : 'end' , status : 'complete' , } , } ; export function handleRange ( state ) { return [ { name : 'click' , handler ( ) { const { range } = this ; const current = rangeClickEvent [ range . status as RangeStatus ] ; range [ current . plt ] = state . date ; range . status = current . status ; } , } , { name : 'mouseenter' , handler ( ) { const { range } = this ; if ( range . status === 'selecting' ) { range . end = state . date ; } } , } , ] ; } export function nextYear ( type ) { const num = this . page === 'year' ? 10 : 1 ; this [ type ] . year += num ; } export function preYear ( ) { const num = this . page === 'year' ? 10 : 1 ; this . start . year -= num ; } export function nextMonth ( type ) { const child = this [ type ] ; [ child . month , child . year ] = getNext ( child ) ; } export function preMonth ( ) { const child = this . start ; [ child . month , child . year ] = getPre ( child ) ; } export function toMonthPage ( state ) { const { date } = state ; if ( date ) [ this . start . year ] = transformDateToArray ( date ) ; this . page = 'month' ; } export function selectYM ( state , name ) { const { date } = state ; this . start [ name ] = transformDateToArray ( date ) [ name === 'year' ? 0 : 1 ] ; this . start . date = date ; this . visible = false ; } export function toDayPage ( state ) { this . start . month = transformDateToArray ( state . date ) [ 1 ] ; this . page = 'date' ; } export function toYearPage ( ) { this . page = 'year' ; } export function canIShow ( state , name = 'day' ) { return ( ) => visible ( state . page === name ) ; }