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 Theme from '../../../../components/theme.style.js';
import Icon from '../../../../components/icons';
import DB from '../../../../components/storage';
import REQUEST from '../../../../components/api';
import BottomSheet from 'reanimated-bottom-sheet';
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 renderStationPanel = (props) => {
const [panel, setpanel] = useState(null)
const [updateFavorite, setUpdateFavorite] = useState(0)
const [updateFavoriteVal, setUpdateFavoriteVal] = useState(false)
const nvapp = useRef();
useEffect(() => {
if(props.visible){
panel.show()
}
return setpanel(null)
}, [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) {
console.log('Cant handle url')
alert("Call Not Supported")
} else {
Alert.alert("Call Customer Service", "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)} style={{flex: 0, justifyContent: 'center'}}>
:
updateFavoriteCall(props.stationId, station, props.onload)} style={{flex: 0, justifyContent: 'center'}}>
}
{/*
Fuel Prices
Last Update: {station.latest_update}
{
[1,2,3,4,5].map((data, index) => {
return (
{station.fuel_prices[index] ? station.fuel_prices[index].fuel_name : ''}
{station.fuel_prices[index] ? (
₱ {station.fuel_prices[index].price}
) : null}
)
})
}
*/}
)
}
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(error){
onload(false)
})
}
return (
{
return renderStationDetails(props.data, props.onClick)
}}
enabledBottomInitialAnimation={true}
enabledInnerScrolling={true}
initialSnap={0}
renderHeader={() => {
console.log(props.data.address)
return (
{props.data.name}
{}} activeOpacity={1} style={{top: -20}}>
{(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:'',lon:'',action: actions.navigateByAddress, travelMode:googleMapsTravelModes.driving}} // specific settings for google maps
maps={{ address: props.data.address, lat:'', lon:'',action: actions.navigateByAddress, travelMode:mapsTravelModes.driving}} // specific settings for maps
/> : null}
Directions
)
}}/>
);
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(renderStationPanel);