import React from 'react';
import { connect } from 'react-redux';
import {ScrollView, SafeAreaView, Text, View, TouchableOpacity, Platform} from 'react-native';
import {Divider} from 'react-native-elements';
import Theme from '../../components/theme.style.js';
import CustomHeader from '../../components/header.js';
import SearchFragment from './fragments/searchbar.js';
import CustomSafeArea from '../../components/safeArea.component.js';
class PayatpumpStationSearch extends React.Component {
constructor(props) {
super(props)
}
state = {
searchValue: this.props.route.params.value || "",
cities: "",
cityDropDown: this.props.route.params.stations
}
search = (value) => {
if(value) {
let newValue = this.state.cityDropDown.filter(city => city.storeName.toUpperCase().includes(this.state.searchValue.toUpperCase()));
this.setState({ searchValue: value, cityDropDown: newValue })
return;
}
this.setState({ searchValue: value, cityDropDown: this.props.route.params.stations })
}
renderDropDown = () => {
if(this.state.cityDropDown.length === 0) {
return this.renderNoSearchFound();
}
return this.state.cityDropDown.map((city, i) => {
return (
{
this.props.route.params.navigate(city);
}} key={i} style={{flex: 1}}>
{city.storeName.toUpperCase()}
)
})
}
renderNoSearchFound = () => {
return (
No search found
)
}
render() {
return (
this.props.navigation.goBack()} navigation={this.props.navigation} />
this.search(value)}
onClear={() => this.setState({ searchValue: "", cityDropDown: [] })}/>
{this.renderDropDown()}
)
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(PayatpumpStationSearch)