import React from 'react';
import {View, StyleSheet, Text, ScrollView} from 'react-native';
import { AppAuctionItem } from '../components/auction_item.component';
import { AppContainer } from '../container/container';
import themeColors from '../assets/colors';
import { AuctionBottomTab } from '../Navigations/AuctionBottomTab';

const  AuctionListScreen =  ({navigation}) => {
  const [auctions, setAuctions] = useState([]);
  useEffect(() => {
    axios.get("http://127.0.0.1:8085/auctions")
      .then( async function (response) {
        setAuctions(response.data);
      })
      .catch(function (error) {
        console.log(error);
      })

  }, [])
  return (
    <View style={styles.container}>
      <AppContainer>
        <Text style={styles.auctionHeading}>Auctions</Text>
        <ScrollView>
          <View>
          {auctions.map((auction) => {
              return(
                <AppAuctionItem label={auction.name} expire={auction.expire_date} onPress = {() =>
                  navigation.navigate("AuctionDetailScreen", {
                  auctionObject: auction})
                }/>
              )
            })}
          </View>
      </ScrollView>
      </AppContainer>
      <AuctionBottomTab/>
    </View>
  );
};
export default AuctionListScreen;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffffff'
  },
  header: {
    height: '35%',
    marginBottom: 25,
    backgroundColor : themeColors.PRIMARY_COLOR
  },
  btnRowContainer: {
    maxHeight: 100
  },
  contentContainer: {
    flex: 1,
    flexDirection: 'row',
    margin: 20
  },
  auctionHeading: {
    fontSize: 24,
    fontWeight: 'bold',
    color: themeColors.SECONDARY_COLOR
  }
})