import React, {useState} from 'react'
import { Link } from 'react-router-dom'
import RecentActivityTable from './WalletComponent/RecentActivityTable'
import PurchasesTable from './WalletComponent/PurchasesTable'
import CouponTable from './WalletComponent/CouponTable'
import LoadingSpinner from '../Spinners/LoadingSpinner'

function Balance({wallet, coupon}) {
    return (
        <div className="content-wrapper">
            {/* heading */}
            <div className="sm:flex justify-between items-center mb-6">
                <div className="mb-5 sm:mb-0">
                    <h1 className="text-26 font-bold   text-dark-gray dark:text-white">
                        Wallet
                    </h1>
                </div>
                <div className="slider-btns flex space-x-4">

                </div>
            </div>
            <div className='w-full lg:flex xl:space-x-8 lg:space-x-4 bottomMargin'>
                {/* WALLET SECTION */}
                <div className="lg:w-4/4 w-full mb-10 lg:mb-0">
                    <div className="wallet w-full  md:p-8 p-4 h-full bg-white dark:bg-dark-white rounded-2xl shadow min-h-[520px]">
                        <div className='flex items-baseline justify-between'>
                            {/*<h2 className='text-slate-900 dark:text-white text-xl lg:text-2xl font-medium'>Wallet</h2>*/}
                            {/*<p className='text-base text-slate-500 dark:text-white'>Add New Wallet</p>*/}
                        </div>
                        {/* wallet balance */}
                        {wallet.loading ?
                        <LoadingSpinner size='16' color='sky-blue' />
                        :
                        wallet.data.length ?
                        wallet.data.map((item, index)=> (
                        <div key={index} className="md:flex items-center flex-wrap my-3 border-t-2 border-slate-400 wallet-box">
                                <div className='text-slate-900 w-full md:w-1/2 flex space-x-3 items-start justify-start'>
                                    <div className='balance-info bal-col1'>
                                        <p className='py-2'></p>
                                        <span className='text-xl text-dark-gray dark:text-white'><b>{item.description}</b></span>
                                        <p className='text-base text-slate-500'>{item.symbol}</p>
                                    </div>
                                    <div className='balance-info'>
                                        <p className='py-2'>Balance</p>
                                        <span className='py-1 px-2 bg-green-100 text-green-500 rounded-lg'>{item.symbol}{(item.amount*0.01).toFixed(2)}</span>
                                    </div>
                                    <div className='balance-info'>
                                        <p className='py-2'>Escrow</p>
                                        <span className='py-1 px-2 bg-red-100 text-red-500 rounded-lg'>{item.symbol}{(item.escrow*0.01).toFixed(2)}</span>
                                    </div>
                                </div>

                                <div className='w-full my-2 md:my-0 md:w-1/2 flex space-x-2 items-center justify-start md:justify-end'>
                                    {
                                        item.action_type != 'AC_AD_FD_ONLY' ?
                                            <Link to='transfer-fund' className='lg:flex hidden user-balance cursor-pointer lg:w-[152px] w-[150px] h-[48px]
                                                                   items-center rounded-full relative  bg-purple pr-1.5 pl-4 lg:text-xl text-lg font-bold text-white'>Transfer</Link>:''
                                    }
                                    <Link to='add-fund' className='lg:flex hidden user-balance cursor-pointer lg:w-[162px] w-[180px] h-[48px]
                                                                   items-center rounded-full relative  bg-green pr-1.5 pl-4 lg:text-xl text-lg font-bold text-white'>
                                    <span className="lg:block">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="38"
                                             height="38" viewBox="0 0 42 42" fill="none"><path
                                            d="M21 0C16.8466 0 12.7865 1.23163 9.33303 3.53914C5.8796 5.84665 3.18798 9.1264 1.59854 12.9636C0.00909901 16.8009 -0.406771 21.0233 0.403518 25.0969C1.21381 29.1705 3.21386 32.9123 6.15077 35.8492C9.08767 38.7861 12.8295 40.7862 16.9031 41.5965C20.9767 42.4068 25.1991 41.9909 29.0364 40.4015C32.8736 38.812 36.1534 36.1204 38.4609 32.667C40.7684 29.2135 42 25.1534 42 21C41.994 15.4323 39.7796 10.0944 35.8426 6.15741C31.9056 2.22045 26.5677 0.00602189 21 0ZM28 22.75H22.75V28C22.75 28.4641 22.5656 28.9092 22.2374 29.2374C21.9093 29.5656 21.4641 29.75 21 29.75C20.5359 29.75 20.0908 29.5656 19.7626 29.2374C19.4344 28.9092 19.25 28.4641 19.25 28V22.75H14C13.5359 22.75 13.0908 22.5656 12.7626 22.2374C12.4344 21.9092 12.25 21.4641 12.25 21C12.25 20.5359 12.4344 20.0907 12.7626 19.7626C13.0908 19.4344 13.5359 19.25 14 19.25H19.25V14C19.25 13.5359 19.4344 13.0908 19.7626 12.7626C20.0908 12.4344 20.5359 12.25 21 12.25C21.4641 12.25 21.9093 12.4344 22.2374 12.7626C22.5656 13.0908 22.75 13.5359 22.75 14V19.25H28C28.4641 19.25 28.9093 19.4344 29.2374 19.7626C29.5656 20.0907 29.75 20.5359 29.75 21C29.75 21.4641 29.5656 21.9092 29.2374 22.2374C28.9093 22.5656 28.4641 22.75 28 22.75Z"
                                            fill="white"></path>
                                        </svg>
                                    </span>
                                        Add Credit</Link>
                                </div>
                        </div>
                        ))
                        :
                        wallet.error ? 
                        (
                        <div className="md:flex items-center flex-wrap mt-3">
                            <p className='text-base'>Opps! An Error occurred, please try again</p>
                        </div>
                        )
                        :
                        (
                        <div className="md:flex items-center flex-wrap mt-3">
                            <p className='text-base'>No Wallets Found!</p>
                        </div>
                        )
                        }
                        {/* end of wallet balance */}
                    </div>
                </div>
                {/* END OF WALLET SECTION */}



            </div>

            {/*<div className='w-full lg:flex xl:space-x-8 lg:space-x-4 bottomMargin'>*/}

            {/*    /!* COUPON SECTION *!/*/}
            {/*    <div className="lg:w-3/4 w-full mb-10 lg:mb-0">*/}
            {/*        <div className="wallet w-full  md:p-8 p-4 h-full max-h-[500px] bg-white dark:bg-dark-white overflow-y-auto rounded-2xl shadow">*/}
            {/*            <h2 className='text-slate-900 dark:text-white text-xl lg:text-2xl font-medium'>Coupons</h2>*/}
            {/*            {coupon.loading ?*/}
            {/*                <LoadingSpinner size='16' color='sky-blue' />*/}
            {/*                :*/}
            {/*                <CouponTable coupon={coupon} />*/}
            {/*            }*/}
            {/*        </div>*/}
            {/*    </div>*/}
            {/*    /!* END OF COUPON SECTION *!/*/}

            {/*</div>*/}
        </div>
      )
}

export default Balance