// withHooks
import { EventHeader } from 'esoftplay/cache/event/header/import';
import { LibCurl } from 'esoftplay/cache/lib/curl/import';
import { LibDialog } from 'esoftplay/cache/lib/dialog/import';
import { LibIcon } from 'esoftplay/cache/lib/icon/import';
import { LibLoading } from 'esoftplay/cache/lib/loading/import';
import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
import { LibStyle } from 'esoftplay/cache/lib/style/import';
import { UseMap } from 'esoftplay/cache/use/map/import';
import esp from 'esoftplay/esp';
import useSafeState from 'esoftplay/state';

import React, { useEffect } from 'react';
import { Pressable, ScrollView, Text, View } from 'react-native';


export interface EventTms_gate_resultArgs {
  type: "gate" | "hall",
  event_id: number | string,
}
export interface EventTms_gate_resultProps {

}
export default function m(props: EventTms_gate_resultProps): any {

  const { event_id, type } = LibNavigation.getArgsAll(props)

  const backResult = LibNavigation.useBackResult(props)

  const [data, setData] = useSafeState<any>()

  useEffect(() => {
    if (type == "gate") {
      new LibCurl('event_gate', { event_id: event_id }, (res, msg) => {
        if (res.length == 1) {
          backResult(res[0])
        }
        setData(res)
      }, (error) => {
        LibDialog.warning(esp.lang("event/tms_gate", "warning_load"), error?.message)
        LibNavigation.back()
      }, 1)
    } else if (type == "hall") {
      new LibCurl('event_hall', { event_id: event_id }, (res, msg) => {
        if (res.length == 1) {
          backResult(res[0])
        }
        setData(res)
      }, (error) => {
        LibDialog.warning(esp.lang("event/tms_gate", "warning_loadhall"), error?.message)
        LibNavigation.back()
      }, 1)
    }
  }, [])


  if (!data) {
    return <LibLoading />
  }

  return (
    <View style={{ flex: 1 }}>
      <EventHeader title={type == "gate" ? esp.lang("event/tms_gate", "header_title1") : esp.lang("event/tms_gate", "header_title2")} subtitle={esp.lang("event/tms_gate", "gate_sub")} />
      <ScrollView style={{}}>
        <Text allowFontScaling={false} style={{ margin: 20, marginBottom: 10, fontFamily: "Arial", fontSize: 16, fontWeight: "bold", fontStyle: "normal", letterSpacing: 0, paddingLeft: 3, paddingRight: 3 }}>{esp.lang("event/tms_gate", "text_select", type == "gate" ? esp.lang("event/tms_gate", "gate") : esp.lang("event/tms_gate", "hall"))}</Text>
        <UseMap
          data={data}
          renderItem={(item) => (
            <Pressable onPress={() => {
              backResult(item)
            }} style={{ flexDirection: 'row', alignContent: 'center', alignItems: 'center', backgroundColor: '#fff', ...LibStyle.elevation(2), padding: 16, marginBottom: 10, marginHorizontal: 15, borderRadius: 5, flex: 1 }}>
              <LibIcon name={"chevron-right"} size={18} color={"#3ea4dc"} />
              <Text allowFontScaling={false} style={{ marginLeft: 10, fontSize: 17, fontWeight: "normal", fontStyle: "normal", letterSpacing: 0, textAlign: "center", color: '#9e9e9e', paddingLeft: 3, paddingRight: 3 }}>{item.name}</Text>
            </Pressable>
          )}
        />
      </ScrollView>
    </View>
  )
}