import { useQuery } from '@tanstack/react-query'
import React from 'react'
import { productData } from '../../services/services'
import queryKeys from '../../services/queryKeys'
import productPath from "../../utils/productpath";
import { Link } from 'react-router-dom';
export default function Products() {

    const {data, isFetching, isError, error} = useQuery({
        queryKey: queryKeys.product,
        queryFn: () => productData()
    })
/*
   {
      "banner": "p1.jpg",
      "description": "Your personal professional web presence",
      "id": 1,
      "name": "Personal Website",
      "product_id": "A000001",
      "product_uid": "e92282b4-3ee1-4026-92ac-12cfd214b43a",
      "status": 5,
      "status_text": "Activate Now"
    },
 */
    //const products = data?.data?.products_list?.products
    const products = data?.data?.products_list

  return (
    <>
        <div className="card card-statistics h-100 mb-0 panel_round_c1">
            <div className="card-header">
                <h4 className="card-title">My Products</h4>
            </div>
            <div className="card-body pb-0">
            {isFetching ? 
                <>
                    <div className="row">
                        <div className="col-12">
                            <p className='text-mute'>Loading...</p>
                        </div>
                    </div>
                </>
                : isError ?
                <div className="row">
                    <div className="col-12">
                        <p className='text-danger'>{error.message}</p>
                    </div>
                </div>
                :
                <div className="row m-b-20">
                    {products && products.map((product, index) => (
                        <div key={product.uid+index} className="col-xxs-6 col-xl-4 col-xxl-6 mb-2 mb-xxl-0 ">
                            <Link to={productPath(product?.product_id)}  >
                                <div className="d-flex align-items-center extraProductCard">
                                    <div className="icon-container img-icon m-r-20 bg-light-gray rounded">
                                        <i className="fa fa-cart-plus text-primary"></i>
                                    </div>
                                    <div className="report-details">
                                        <p>{product?.status_text}</p>
                                        <h4>{product?.name}</h4>
                                    </div>
                                </div>
                            </Link>

                        </div>
                    ))}
                </div>
            }
                <div className="apexchart-wrapper">
                    <div id="ecommerce5" className="chart-fit"></div>
                </div>
            </div>
        </div>
    </>
  )
}
