import React from "react";
import classNames from "classnames";
import { makeStyles } from "@material-ui/core/styles";
import Select from 'react-select';

import Button from "components/CustomButtons/Button.js";
import Icon from "@material-ui/core/Icon";
import styles from "assets/jss/nextjs-material-kit/pages/componentsSections/notificationsStyles.js";
import Card from "components/Card/Card.js";
import CardBody from "components/Card/CardBody.js";
import GridContainer from "components/Grid/GridContainer.js";
import GridItem from "components/Grid/GridItem.js";

const useStyles = makeStyles(styles);

const DataAccessories = function ({ selected, handleName, backend, accessories, ...props }) {
    const classes = useStyles();
    const { ...rest } = props;
    const imageClasses = classNames(
        classes.imgRaised,
        classes.imgRoundedCircle,
        classes.imgFluid
    );
    const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
    const ProductAccessories = accessories.map((data) => {
        return (      
            <div style={{padding:"40px"}}>
                <img
                alt="..."
                style={{ height: "150px", display: "block" }}
                src={`${backend}${data.img["url"]}`}
                className={navImageClasses}
                />
                <div align="center">
                <h3>{data.name}</h3>
                <h4>Rp.{data.price}</h4>
                <Button 
                    color="info" round
                    href={"/yamaha/product/accessories_details?s="+data.id}
                >
                    <Icon className={classes.icons}>open_in_new</Icon>Detail Product
                </Button>
                </div>
            </div>
        );
    })
    return (
        <div>
        <Card className={classes.textCenter} align="center" style={{padding:"5px"}}>
            <CardBody>
            <div align="center" style={{marginTop:"-50px"}}>
                <h2>Yamaha Accessories</h2>
                <Select
                    value={(selected)?accessories.filter((i)=>i.id==selected):null} 
                    getOptionLabel={option => `${option.name}`}
                    getOptionValue={option => option.id}
                    options={accessories}
                    isMulti
                    instanceId="name"
                    placeholder="filter by Nama Part"
                    onChange={values => handleName(values)}
                />
                <br></br>
                <GridContainer justify="center" style={{padding:"40px", marginTop:"-50px"}}>
                    {ProductAccessories}
                    {ProductAccessories}
                </GridContainer>
            </div> 
            </CardBody>
        </Card>
        </div>
    );
}

export default DataAccessories;