import React from 'react';
import { Renderer, RendererProps } from '../factory';

import { SchemaObject, BaseSchema } from '../Schema';
import CalendarComp from '../components/Schedule/calendar';
import { isMobile } from '../utils/helper';
import { IScopedContext, ScopedContext } from '../Scoped';
// import CalendarComp from '../components/Schedule/toast';
// import {DateControlRenderer} from './Form/InputDate';


interface scheduleItem {
  startTime: string;
  endTime: string;
  content: any;
  className?: string;
}

export interface CalendarSchema extends BaseSchema {
  /**
   * 指定为日历选择控件
   */
  type: 'calendar';

  /**
   * 日程
   */
  schedules?: Array<scheduleItem> | string;

  /**
   * 日程显示颜色自定义
   */
  scheduleClassNames?: Array<string>;

  /**
   * 日程点击展示
   */
  scheduleAction?: SchemaObject;
}
interface CalendarProps extends RendererProps {

}
export class Calendar extends React.Component<CalendarProps> {
  // wrapperRef: React.RefObject<HTMLDivElement> = React.createRef();
  receive(values) {
    this.setState({
      receiveData: values
    });
  }
  render() {
    return (
      <div>
        <CalendarComp isMobile={isMobile()} calendarType={this.state.calendarType} {...this.props} context={this.context} receiveData={this.state.receiveData}></CalendarComp>
      </div>
    )
  }
}
@Renderer({
  type: 'calendar'
})
export class CalendarRenderer extends Calendar {
  static contextType = ScopedContext;
  constructor(props, context: IScopedContext) {
    super(props as any);
    const { mode } = props;
    const scoped = context;
    scoped.registerComponent(this);
    this.state = { calendarType: mode ?? 'attendance', receiveData: {} }

  }
  componentWillUnmount(): void {
    // super.componentWillUnmount();
    const scoped = this.context as IScopedContext;
    scoped.unRegisterComponent(this);
  }
  receive(values: any, subPath?: string) {
    const scoped = this.context as IScopedContext;
    if (subPath) {
      return scoped.send(subPath, values);
    }

    return super.receive(values);
  }
}
