import React from "react";
import { View, Text, Button } from "react-native";
import { createStructuredSelector } from "reselect";

import {
  selectBodyshop,
  selectCurrentUser,
} from "../redux/user/user.selectors";
import { emailSignInStart } from "../redux/user/user.actions";
import { connect } from "react-redux";

const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop,
  currentUser: selectCurrentUser,
});

const mapDispatchToProps = (dispatch) => ({
  emailSignInStart: (email, password) =>
    dispatch(emailSignInStart({ email, password })),
});

export function SignIn({ bodyshop, currentUser, emailSignInStart }) {
  return (
    <View>
      <Text>The secondary view</Text>
      <Text>{JSON.stringify(currentUser)}</Text>
      <Button title="Testing." onPress={() => console.log("test")} />
      <Button
        title="Sign In"
        onPress={() => emailSignInStart("patrick@imex.dev", "patrick")}
      />
    </View>
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(SignIn);
