import React from 'react';
import { useState, useEffect, useRef } from 'react';
import { ScrollView, StyleSheet, Text, View, Dimensions, Button, Image, TextInput, TouchableOpacity, ActivityIndicator, Alert } from 'react-native';
import Theme from '../../../../components/theme.style.js';
import Assets from '../../../../components/assets.manager.js';
import Icon from '../../../../components/icons';
import DB from '../../../../components/storage';
import REQUEST from '../../../../components/api';
import { Divider } from 'react-native-elements';
import BottomSheet from '@gorhom/bottom-sheet';
import Geolocation from '@react-native-community/geolocation';
import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps';
const styles = {
container: {
flex: 1,
backgroundColor: '#f8f9fa',
alignItems: 'center',
justifyContent: 'center'
},
panel: {
flex: 1,
backgroundColor: 'white',
position: 'relative'
},
panelHeader: {
height: 60,
backgroundColor: Theme.colors.lightGray,
alignItems: 'center',
justifyContent: 'center'
}
}
const { height } = Dimensions.get('window')
const renderStations = (isGuest, data, onPress, onUpdateFavorite) => {
console.log('isGuest:', isGuest);
return data.map((station, index) => {
let stars = [1, 2, 3, 4, 5].map((star, i) => {
let name = station.stars >= star ? "star" : "staro"
let mgn = index > 0 ? 5 : 0
return (
)
})
return (
onPress(station) || null} style={{}}>
{station.name}
{station.address}
{stars}
{
updateFavorite(station, index, onUpdateFavorite)
}}
>
)
})
}
const updateFavorite = async (city, index, callback) => {
let session = await DB.session()
let urlTask = city.favorite ? "station_delete_favorite" : "station_add_favorite"
let method = city.favorite ? "delete" : "get"
REQUEST(urlTask, method, {
Authorization: session.token
}, {
noID: true,
value: city.station_uuid
}, {}, function (res) {
callback(index, city.favorite ? false : true)
}, function (err) {
if (err.message) {
Alert.alert("Information", `\n${err.message}`);
}
}, "Favorite", city.favorite ? "Delete" : "Update")
}
export default function renderStationPanel(props) {
const bottomSheetRef = useRef(null);
const snapPoints = [450, 300, 0];
useEffect(() => {
if (props.visible) {
bottomSheetRef.current?.expand();
} else {
bottomSheetRef.current?.collapse();
}
}, [props.visible]);
return (
{renderStations(props.data, props.onClick, props.onUpdateFavorite)}
{props.error ? "There was an error" : props.loading || props.data.length == 0 ? "Getting Nearby Stations" : "Unioil Stations found: " + props.data.length}
{props.error ?
Try Again
: props.loading || props.data.length == 0 ? : null}
)
}