import React from 'react';
import { useState, useEffect, useRef } from 'react';
import { connect } from 'react-redux';
import {
Text,
View,
TouchableOpacity,
Linking,
Platform,
Alert
} from 'react-native';
import {
NavigationApps,
actions,
googleMapsTravelModes,
mapsTravelModes
} from "../../../../components/navigationapps";
import { AdjustableText } from '../../../../components/text';
import Theme from '../../../../components/theme.style.js';
import Icon from '../../../../components/icons';
import DB from '../../../../components/storage';
import REQUEST from '../../../../components/api';
import BottomSheet from '@gorhom/bottom-sheet';
import { ScrollView } from 'react-native-gesture-handler';
const styles = {
container: {
flex: 1,
backgroundColor: '#f8f9fa',
alignItems: 'center',
justifyContent: 'center'
},
panel: {
flex: 1,
backgroundColor: 'white',
position: 'relative'
},
panelHeader: {
height: 90,
backgroundColor: Theme.colors.lightGray,
alignItems: 'center',
justifyContent: 'center'
}
}
const renderStationPanel = (props) => {
const [updateFavorite, setUpdateFavorite] = useState(0)
const [updateFavoriteVal, setUpdateFavoriteVal] = useState(false)
const bottomSheetRef = useRef(null);
const snapPoints = ['50%', '60%'];
useEffect(() => {
if (props.visible) {
bottomSheetRef.current?.expand();
} else {
bottomSheetRef.current?.collapse();
}
}, [props.visible]);
const renderStationDetails = (station, onPress) => {
let stars = [1, 2, 3, 4, 5].map((star, i) => {
let name = station.stars >= star ? "star" : "staro"
let mgn = i > 0 ? 5 : 0
return (
)
})
return (
{station.address}
Contact:
{station.contact_numbers.map((num, i) => {
return (
{
let url = Platform.OS == 'ios' ? 'telprompt:' : 'tel:'
Linking.canOpenURL(url).then(supported => {
if (!supported) {
alert("Call Not Supported")
} else {
Alert.alert("Call Customer Service", '\n' + "You will be redirected to the dialer to call Unioil Customer Service", [
{
text: 'Cancel',
style: 'cancel',
}, {
text: 'OK', onPress: () => Linking.openURL(`${url}${num}`)
}
],
{ cancelable: true })
return true
}
}).catch(err => {
console.error('An error occurred', err)
})
}}>
{num}
)
})}
{stars}
{updateFavorite == 0 ?
{
updateFavoriteCall(props.stationId, station, props.onload)
}}
>
:
updateFavoriteCall(props.stationId, station, props.onload)} style={{ flex: 0, justifyContent: 'center' }}>
}
Fuel Prices
Last Update: {station.latest_update}
{
station.fuel_prices.map((data, index) => {
return (
{data ? data.fuel_name : ''}
₱ {data.price}
)
})
}
)
}
const updateFavoriteCall = async (id, city, onload) => {
let session = await DB.session()
let urlTask;
let method;
if (updateFavorite == 0) {
urlTask = city.favorite ? "station_delete_favorite" : "station_add_favorite"
method = city.favorite ? "delete" : "get"
} else {
urlTask = updateFavoriteVal ? "station_delete_favorite" : "station_add_favorite"
method = updateFavoriteVal ? "delete" : "get"
}
onload(true)
REQUEST(urlTask, method, {
Authorization: session.token
}, {
noID: true,
value: id
}, {}, function (res) {
setUpdateFavorite(1)
onload(false)
if (updateFavorite == 0) {
setUpdateFavoriteVal(city.favorite ? false : true)
} else {
setUpdateFavoriteVal(updateFavoriteVal ? false : true)
}
}, function (err) {
Alert.alert("Information", `\n${err.message}`);
onload(false)
}, "Favorite", city.favorite ? "Delete" : "Update")
}
return (
{props.data.name}
{ }} activeOpacity={1}>
{(props.data && props.data.address != undefined && props.data.address != "") ?
}
actionSheetTitle="Choose an application to view the route"
address={props.data.address} // address to navigate by for all apps
waze={{ address: props.data.address, lat: props.data.latitude, lon: props.data.longitude, action: actions.navigateByLatAndLon }} // specific settings for waze
googleMaps={{ address: props.data.address, lat: props.data.latitude, lon: props.data.longitude, action: actions.navigateByAddress, travelMode: googleMapsTravelModes.driving }} // specific settings for google maps
maps={{ address: props.data.address, lat: props.data.latitude, lon: props.data.longitude, action: actions.navigateByAddress, travelMode: mapsTravelModes.driving }} // specific settings for maps
/> : null}
Directions
{renderStationDetails(props.data, props.onClick)}
);
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(renderStationPanel);