import React, { useState, useEffect } from 'react';
import Image from 'next/image';
import Link from "next/link";
import { Modal, Button } from '../../../../../UI';
import classNames from 'classnames';
import axios from 'axios';
import pickBy from 'lodash/pickBy';
import identity from 'lodash/identity';

type Props = {
  id: string | string[];
 };
const title='dddd',
feature='feature',
description='description',
sum=33, types=[0,1], sizes=[30,40, 50];

const typeNames = ['традиционное тесто','тонкое тесто'];

const addBasket = () => {
  console.log('add');
}

export const PizzaCard: React.FC<Props> = ({id}) => {
  const [activeType, setActiveType] = useState(0);
  const [activeSize, setActiveSize] = useState(0);
  const [rows, setRows] = useState([]);
  useEffect(() => {
    const getData = async () => {
        const { data } = await axios.get('/api/loadingPizzaInformation/'+id);
        setRows(data);
    };
    getData();
    console.log(rows);
  }, [id]);
  return (
    <Modal styles={'modal_product'} position={'position_product'}>
      <div className='modal_body_left'>
        <div className='modal_img'>
          <Image
            src={'/assets/img/'+id+'.jpg'}
            alt={'pizza'}
            width={400}
            height={400}
            />
        </div>
      </div>
      <div className='modal_body_right'>
        <div className="modal_header">
          <h3 className="modal_title">{title}</h3>
          <p className="modal_feature">{feature}</p>
          <p className="modal_description">{description}</p>
          <div className="pizza-block__selector">
            <ul>
              {types.map((typeId) => (
                <li
                  key={typeId}
                  onClick={() => setActiveType(typeId)}
                  className={activeType === typeId ? classNames('active type') : classNames('type')}>
                  {typeNames[typeId]}
                </li>
              ))}
            </ul>
            <ul>
              {sizes.map((size, i) => (
                <li
                  key={size}
                  onClick={() => setActiveSize(i)}
                  className={activeSize === i ? classNames('active size') : classNames('size')}>
                  {size} см
                </li>
              ))}
            </ul>
          </div>
          <div className='modal_footer'>
            <Button styles={'yellow button_size_48'} align={'button_align_center'}
              onClick={addBasket}>В корзину за {sum} р</Button>
            <Link href={"/"} as={"/"} scroll={false}>
              <button className={classNames('yelow button_size_32')}>Закрыть </button>
            </Link>
          </div>
        </div>
      </div>
    </Modal>
  );
};