import { mdiChartTimelineVariant } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement } from 'react'
import CardBox from '../components/CardBox'
import LayoutAuthenticated from '../layouts/Authenticated'
import SectionMain from '../components/SectionMain'
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton'
import { getPageTitle } from '../config'
import ActivityFeed from '../components/ActivityFeed'
import { useAppSelector } from '../stores/hooks'

const Dashboard = () => {
  const { currentUser } = useAppSelector((state) => state.auth)

  return (
    <>
      <Head>
        <title>{getPageTitle('Trial Tracker')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={`Welcome ${currentUser?.firstName || ''}`} main>
          {''}
        </SectionTitleLineWithButton>

        <div className="grid grid-cols-1 gap-6 lg:grid-cols-3 mb-6">
          <CardBox className="bg-gradient-to-br from-pavitra-500 to-pavitra-600 border-none shadow-lg">
            <div className="flex items-center justify-between text-white">
              <div>
                <p className="text-sm font-medium opacity-80 mb-1">Total Projects</p>
                <h3 className="text-3xl font-bold">12</h3>
              </div>
              <div className="bg-white/20 p-3 rounded-lg">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
                </svg>
              </div>
            </div>
            <p className="text-white/60 text-sm mt-4">+2 since last month</p>
          </CardBox>

          <CardBox className="bg-gradient-to-br from-blue-500 to-blue-600 border-none shadow-lg">
            <div className="flex items-center justify-between text-white">
              <div>
                <p className="text-sm font-medium opacity-80 mb-1">Active Trials</p>
                <h3 className="text-3xl font-bold">48</h3>
              </div>
              <div className="bg-white/20 p-3 rounded-lg">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z" />
                </svg>
              </div>
            </div>
            <p className="text-white/60 text-sm mt-4">+12 from last week</p>
          </CardBox>

          <CardBox className="bg-gradient-to-br from-green-500 to-green-600 border-none shadow-lg">
            <div className="flex items-center justify-between text-white">
              <div>
                <p className="text-sm font-medium opacity-80 mb-1">Completed Trials</p>
                <h3 className="text-3xl font-bold">156</h3>
              </div>
              <div className="bg-white/20 p-3 rounded-lg">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
              </div>
            </div>
            <p className="text-white/60 text-sm mt-4">98% success rate</p>
          </CardBox>
        </div>

        <div className="mb-6 max-w-4xl mx-auto">
          <div className="flex items-center justify-between mb-4">
            <h3 className="text-xl font-bold text-gray-800 dark:text-white">Recent Activities</h3>
            <div className="flex gap-2">
              <span className="text-sm text-gray-500">Filter by:</span>
              <select className="text-sm border-none bg-transparent font-medium text-pavitra-600 focus:ring-0 cursor-pointer">
                <option>All Activities</option>
                <option>Images</option>
                <option>Updates</option>
              </select>
            </div>
          </div>
          <ActivityFeed />
        </div>
      </SectionMain>
    </>
  )
}

Dashboard.getLayout = function getLayout(page: ReactElement) {
  return <LayoutAuthenticated>{page}</LayoutAuthenticated>
}

export default Dashboard