// withHooks
import { EventHeader } from 'esoftplay/cache/event/header/import';
import { LibCurl } from 'esoftplay/cache/lib/curl/import';
import { LibLoading } from 'esoftplay/cache/lib/loading/import';
import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
import { LibPicture } from 'esoftplay/cache/lib/picture/import';
import { LibStyle } from 'esoftplay/cache/lib/style/import';
import { LibToastProperty } from 'esoftplay/cache/lib/toast/import';
import { LibVideoProperty } from 'esoftplay/cache/lib/video/import';
import { LibWebview } from 'esoftplay/cache/lib/webview/import';
import esp from 'esoftplay/esp';
import useSafeState from 'esoftplay/state';
import { useEffect } from 'react';

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


export interface EventSchedule2Args {

}
export interface EventSchedule2Props {

}
function m(props: EventSchedule2Props): any {
  const { url } = LibNavigation.getArgsAll(props)

  const [result, setResult] = useSafeState()

  useEffect(() => {
    loadData()
  }, [])

  function loadData() {
    new LibCurl(url, null, (res, msg) => {
      setResult(res)
    }, (err) => {
      LibToastProperty.show(err?.message)
    })
  }

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

  function renderArtist(item: any, i: number) {
    return (
      <View key={i} style={{ margin: 15 }}>
        {
          item?.image != "" &&
          <LibPicture source={{ uri: item?.image }} style={{ height: LibStyle.width * 9 / 16, width: LibStyle.width, marginTop: -15, marginLeft: -15, resizeMode: 'cover' }} />
        }
        <Text allowFontScaling={false} style={{ marginTop: 10, fontFamily: "Arial", fontSize: 16, fontWeight: "bold", fontStyle: "normal", letterSpacing: 0, marginBottom: 7 }}>{item?.name || ""}</Text>
        <View style={{ borderRadius: 10, overflow: 'hidden' }}>
          {
            item?.description != "" &&
            <LibWebview source={{ html: item?.description }} onFinishLoad={() => { }} style={{ marginLeft: -20 }} />
          }
        </View>
        {
          item?.video != "" &&
          <>
            <Text allowFontScaling={false} style={{ marginLeft: 0, marginHorizontal: 20, marginTop: 10, fontFamily: "Arial", fontSize: 13, fontWeight: "bold", fontStyle: "normal", lineHeight: 22, letterSpacing: 0, color: "#4a4a4a" }} >{esp.lang("event/schedule", "text_vide")}</Text>
            <TouchableOpacity style={{ borderRadius: 10, overflow: 'hidden' }} onPress={() => LibNavigation.navigate('lib/video', { code: item?.video })} >
              <LibPicture source={{ uri: LibVideoProperty.getUrlThumbnail(item?.video) }} style={{ height: LibStyle.width * 9 / 16, width: LibStyle.width - 30, marginLeft: 0, marginHorizontal: 20, resizeMode: 'cover' }} />
            </TouchableOpacity>
          </>
        }
      </View>
    )
  }

  return (
    <View style={{ flex: 1, backgroundColor: LibStyle.colorBgGrey }}>
      <EventHeader />

      <ScrollView>
        {
          result?.length > 0 && result?.map?.(renderArtist)
        }

      </ScrollView>

    </View>
  )
}