import { useState } from 'react';
import { 
  Calendar, 
  Clock, 
  Activity, 
  Check, 
  Plus,
  Pencil,
  Trash2
} from "lucide-react";
import Button from "@/components/common/button";
import StatCard from "@/components/common/dashStatCard";
import { roomData, scheduleData } from '@/constants/constant';
import { Card } from '@/components/common/cardWrapper';
import { CardHeader } from '@/components/common/cardHeader';

// Your Card Comp

export default function MeetingRoomPortal() {
  return (
    <div className="my-15 text-slate-100 font-sans">
      {/* --- HEADER SECTION --- */}
      <div className="flex flex-col md:flex-row md:items-start md:justify-between gap-4 mb-6">
        <div>
          <div className="flex items-center gap-2 text-[10px] font-bold tracking-widest text-slate-500 uppercase font-mono">
            <span className="text-teal-400">Apple One — HQ Tower</span>
            <span>•</span>
            <span>WORKPLACE</span>
            <span>•</span>
            <span>MEETING ROOMS</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-1">
            Meeting room booking
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-1 max-w-xl leading-relaxed">
            Real-time availability, calendar-synced reservations, room services and utilization analytics.
          </p>
        </div>

        {/* --- HEADER BUTTONS --- */}
        <div className="flex items-center gap-2.5 self-start md:mt-6">
          <Button className="bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 text-xs px-3.5 py-2 rounded-lg flex items-center gap-2 font-semibold transition-colors">
            <Calendar className="w-4 h-4 text-slate-300" />
            <span>Sync calendar</span>
          </Button>

          <Button className="bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 text-xs px-3.5 py-2 rounded-lg flex items-center gap-2 font-semibold transition-colors">
            <Plus className="w-4 h-4 text-slate-300" />
            <span>Add room</span>
          </Button>

          <Button className="bg-teal-400 hover:bg-teal-300 text-slate-950 font-bold text-xs px-4 py-2 rounded-lg flex items-center gap-1.5 transition-colors">
            <Plus className="w-4 h-4 stroke-[3]" />
            <span>Book room</span>
          </Button>
        </div>
      </div>

      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Available now */}
        <StatCard
          variant="icon"
          title="Available now"
          value="3"
          icon={Calendar}
          badgeText="of 6 rooms"
          badgeClassName="text-emerald-400 lowercase font-mono"
          iconContainerClassName="bg-emerald-950/40 border-emerald-800/30 text-emerald-400"
        />

        {/* In use now */}
        <StatCard
          variant="icon"
          title="In use now"
          value="2"
          icon={Clock}
          badgeText="live"
          badgeClassName="text-rose-400 lowercase font-mono"
          iconContainerClassName="bg-rose-950/40 border-rose-900/30 text-rose-400"
        />

        {/* Utilization */}
        <StatCard
          variant="icon"
          title="Utilization"
          value="50%"
          icon={Activity}
          badgeText="today"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-blue-950/50 border-blue-800/30 text-blue-400"
        />

        {/* Bookings today */}
        <StatCard
          variant="icon"
          title="Bookings today"
          value="5"
          icon={Check}
          badgeText="scheduled"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-500"
        />
      </div>

      {/* --- MAIN CONTENT UI (ADDED BELOW STAT CARDS) --- */}
      <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
        {/* Room List (Left 2 Columns) */}
        <div className="lg:col-span-2 grid grid-cols-1 md:grid-cols-2 gap-4">
          {roomData.map((room) => (
            <Card key={room.id} className="min-h-[170px]">
              <div>
                {/* Header info inside room card */}
                <div className="flex justify-between items-start mb-1">
                  <div>
                    <h3 className="text-white font-semibold text-base">{room.name}</h3>
                    <p className="text-xs text-slate-400 font-mono mt-0.5">{room.location}</p>
                  </div>
                  <span className={`flex items-center gap-1.5 px-2 py-0.5 rounded text-[10px] font-mono font-bold border ${room.statusColor}`}>
                    <span className={`w-1.5 h-1.5 rounded-full ${room.dotColor}`} />
                    {room.status}
                  </span>
                </div>

                {/* Feature Tags */}
                <div className="flex flex-wrap gap-1.5 my-3">
                  {room.tags.map((tag, idx) => (
                    <span key={idx} className="bg-[#12233a] border border-[#1d3554] text-slate-300 text-[11px] px-2 py-0.5 rounded">
                      {tag}
                    </span>
                  ))}
                </div>
              </div>

              {/* Bottom Info & Action Buttons */}
              <div className="flex items-center justify-between border-t border-[#162942]/60 pt-3 mt-2">
                <span className="text-xs text-slate-400">{room.subtitle}</span>
                <div className="flex items-center gap-1.5">
                  <button className="bg-[#12233a] hover:bg-[#1a3252] border border-[#1d3554] text-slate-200 text-xs font-semibold px-3 py-1.5 rounded transition-colors">
                    {room.actionType === "book" ? "Book" : "View"}
                  </button>
                  <button className="bg-[#12233a] hover:bg-[#1a3252] border border-[#1d3554] text-slate-400 hover:text-slate-200 p-1.5 rounded transition-colors">
                    <Pencil className="w-3.5 h-3.5" />
                  </button>
                  <button className="bg-[#12233a] hover:bg-[#1a3252] border border-[#1d3554] text-slate-400 hover:text-rose-400 p-1.5 rounded transition-colors">
                    <Trash2 className="w-3.5 h-3.5" />
                  </button>
                </div>
              </div>
            </Card>
          ))}
        </div>

        {/* Today's Schedule Timeline (Right 1 Column) */}
        <div>
          <Card className="h-full justify-start">
            <CardHeader title="Today’s schedule" subtitle="Apple One — HQ Tower" />
            <div className="mt-4 space-y-6 relative before:absolute before:inset-0 before:left-[7px] before:w-[2px] before:bg-[#1d3554] pl-6">
              {scheduleData.map((item, idx) => (
                <div key={idx} className="relative">
                  {/* Timeline dot */}
                  <span className="absolute -left-[23px] top-1 w-3.5 h-3.5 rounded-full border-2 border-[#0a1526] bg-teal-400 ring-2 ring-teal-400/20" />
                  
                  {/* Event Details */}
                  <h4 className="text-sm font-semibold text-white leading-tight">
                    {item.room} <span className="text-slate-400 font-normal">• {item.title}</span>
                  </h4>
                  <p className="text-xs text-slate-500 font-mono mt-1">
                    {item.time} <span className="text-slate-600">•</span> {item.status}
                  </p>
                </div>
              ))}
            </div>
          </Card>
        </div>
      </div>
    </div>
  );
}