import { useSelector } from 'react-redux';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { useState, useEffect } from 'react';
import classNames from 'classnames';
import Link from "next/link";

import {
  faBasketShopping,
  faUser,
  faLocationDot,
  faPhone
} from "@fortawesome/free-solid-svg-icons";



//import { Search } from './search';
//import { selectCart } from '../../redux/cart/selectors';


export const Header: React.FC = () => {
  //const { items, totalPrice } = useSelector(selectCart);
  const [showBasketCard, setShowBasketCard] = useState(false);
  const isMounted = React.useRef(false);
  const updateDataHeader = () => {
    setShowBasketCard(true);
    console.log('clik');
  }

  //const totalCount = items.reduce((sum: number, item: any) => sum + item.count, 0);

  React.useEffect(() => {
  //  const pageWidth = document.documentElement.clientWidth
 //   const pageHeight = document.documentElement.scrollHeight
    if (isMounted.current) {
   //   const json = JSON.stringify(items);
     // localStorage.setItem('cart', json);
    }
    isMounted.current = true;
 //   console.log(pageWidth, 'pageWidth');
 //   console.log(pageHeight, 'pageHeight');
  }, [1]);

  return (
    <header>
      <div className={classNames('block logo')}>
        <p>Logo</p>
      </div>
      <div className={classNames('block address')} >
        <div className={"address_box"}>
          <FontAwesomeIcon icon={faLocationDot} className={'icon_address'}/>
          <input type='search' className={"input_address"} placeholder="Введите адресс"/>
        </div>
      </div>
      <div className={classNames('block telephone')} >
        <div className={'description'}>
          <a href="tel:+7(999)-999-99-99">
            <p className={classNames('phone entrance_link')}>8(999)-999-99-99</p>
            <span className={"entrance_link calk"}>Звонок бесплатный</span>
          </a>
        </div>
      </div>
      <div className={classNames('block basket')} >
        <div className={'description'}>
          <i className="icon">
              <FontAwesomeIcon
                icon={faBasketShopping}
                className={'basket'}
              />
            </i>
            <Link href="/?cart" as="/cart" className={classNames('link entrance_link')}>
              Корзина
            </Link>
        </div>
      </div>
      <div className={classNames('block entrance')} >
        <div className={'description'}>
          <a href="admin">
            <i className="icon">
              <FontAwesomeIcon
                icon={faUser}
                className={'basket'}
              />
            </i>
            <p className={classNames('link entrance_link')}>Войти</p>
          </a>
        </div>
      </div>
    </header>
  );
};
