// withHooks

import { EventHeader } from 'esoftplay/cache/event/header/import';
import { EventMessage } from 'esoftplay/cache/event/message/import';
import { LibCurl } from 'esoftplay/cache/lib/curl/import';
import { LibDialog } from 'esoftplay/cache/lib/dialog/import';
import { LibInfinite } from 'esoftplay/cache/lib/infinite/import';
import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
import { EventVisitor_history_item } from 'esoftplay/cache/event/visitor_history_item/import';
import esp from 'esoftplay/esp';

import moment from 'esoftplay/moment';
import React from 'react';
import { View } from 'react-native';


export interface EventVisitor_historyProps {

}
export default function m(): any {
  moment().locale('id')
  const url = 'event_history_history'

  function doAction(url: string, type: string, data: any): void {
    new LibCurl(url, null, (res, msg) => {
      if (type == '2') {
        LibNavigation.navigate('event/visitor_input', { data: res })
      } else if (type == '3') {
        if (res.image == '') {
          LibNavigation.navigate('event/visitor_edit', { data: res })
        } else {
          LibNavigation.navigate('staff/id_card', { data: res, })
        }
      } else {
        LibNavigation.navigate('event/order_detail', { url: url })
      }
    }, (error) => {
      LibDialog.warning(esp.lang("event/visitor_history", "err"), error?.message)
    })
  }

  function renderItem(item: any) {
    return (
      <EventVisitor_history_item item={item} doAction={() => doAction(item.url, item.type, item)} />
    )
  }

  return (
    <View style={{ flex: 1, backgroundColor: '#fff' }}>
      <EventHeader title={/*history_title*/"History Staff/PIC/Exhibitor"} />
      <LibInfinite
        errorView={(err: any) => (
          <EventMessage message={err} />
        )}
        url={url}

        renderItem={renderItem}
      />
    </View>
  )
}