import React from 'react';
import {Platform, ViewProps} from 'react-native';
import RtnCalendarView from './RtnCalendarViewNativeComponent';

export interface IEventItem {
  id: string;
  start: Date;
  duration?: number;
  name: string;
  priorityText?: 'none' | 'low' | 'medium' | 'high' | 'urgent';
  priority?: number;
  isAllDay?: boolean;
}

export interface IEventDayItem {
  id: string;
  date: Date;
  events: IEventItem[];
}

export interface IViewTypeChange {
  type: 'day' | 'month';
}

export interface IDateChange {
  date: Date;
}

interface RtnCalendarProps extends ViewProps {
  events?: IEventDayItem[];
  onEventPress?: (event: IEventItem) => void;
  onDateChange?: (event: IDateChange) => void;
  onViewTypeChange?: (event: IViewTypeChange) => void;
  initDate?: Date;
  viewType?: 'day' | 'month';
}

const App = ({
  events,
  initDate,
  viewType,
  onEventPress,
  onDateChange,
  onViewTypeChange,
  ...props
}: RtnCalendarProps) => {
  return Platform.OS === 'ios' ? (
    <></>
  ) : (
    <RtnCalendarView
      style={{flex: 1, height: '100%', width: '100%'}}
      initDate={initDate?.toJSON()}
      viewType={viewType}
      events={events?.map(day => ({
        id: day.id,
        date: day.date.toJSON(),
        events: day.events.map(event => ({
          id: event.id,
          start: event.start.toJSON(),
          duration: event.duration ?? 10,
          name: event.name,
          priority: event.priority ?? 1,
          priorityText: event.priorityText ?? 'low',
          isAllDay: event.isAllDay ?? false,
        })),
      }))}
      {...props}
    />
  );
};

export default App;
