import { connect } from 'react-redux';

import { fetchProfile, updateProfile } from '../actions/profile.js';
import { getNomDeBid, getProfile, isAllowedToBid } from '../selectors/profile.js';

import Profile from './Profile.js';

const matchStateToProps = (state) => {
  const profile = getProfile(state);

  return {
    hasLinkedApple: profile.get('hasLinkedApple'),
    hasLinkedFacebook: profile.get('hasLinkedFacebook'),
    hasLinkedGoogle: profile.get('hasLinkedGoogle'),
    hasLocalAccount: profile.get('hasLocalAccount'),
    hasRegisteredAcccount: profile.get('hasRegisteredAcccount'),
    id: profile.get('id'),
    isAllowedToBid: isAllowedToBid(state),
    isVerified: profile.get('isVerified'),
    lastName: profile.get('lastName'),
    nomDeBid: getNomDeBid(state),
    organizationIdentifier: profile.get('organizationIdentifier'),
    paymentToken: profile.get('paymentToken'),
  };
};

const mapDispatchToProps = (dispatch) => ({
  fetchProfile: () => dispatch(fetchProfile(dispatch)),
  updateProfile: () => dispatch(updateProfile(dispatch)),
});

export default connect(matchStateToProps, mapDispatchToProps)(Profile);
