import React, { useContext } from "react";
import style from "./Robot.module.css";
import { appContext, appSetStateContext } from "../AppState";
import {withAddToCart} from './AddToCart'
export interface Robotprops {
  id: number;
  name: string;
  email: string;
  addToCart:(id,name)=>void
}
const Robot: React.FC<Robotprops> = ({ id, name, email,addToCart }) => {
  const value = useContext(appContext);

  return (
    <>
      <div className={style.cardContainer}>
        <img src={`https://robohash.org/${id}`} alt="root" />
        <h2>{name}</h2>
        <p>{email}</p>
        <p>{value.username}</p>
        <button onClick={()=>addToCart(id,name)}>加入购物车</button>
      </div>
    </>
  );
};
export default withAddToCart(Robot);
