import Image from "next/image";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Heart } from 'lucide-react';

type UnitCardProps = {
  card: {
    image: string;
    title: string;
    label: string;
    isFavorite: boolean;
    price?: string | number;
    area?: number | string;
    bedrooms?: number | string;
    bathrooms?: number | string;
    isPremium?: boolean,
    subtitle?: string;
  };

  showButtonText?: boolean;
  showPremiumBadge?: boolean;
  showLabel?: boolean;
  action?: () => void;
};

const UnitCard = ({ card, showButtonText = true, showPremiumBadge = true, action, showLabel = true }: UnitCardProps) => {
  return (
    <div className="p-2 border bg-[#F8FAFC] border-[#CAD5E2] rounded-xl">
      <div className="relative w-full h-[230px] rounded-xl overflow-hidden">
        <Image
          src={card.image}
          alt={card.title}
          fill
          className="object-cover"
        />
        <Button
          variant="ghost"
          size="icon"
          className={`absolute top-2 left-2 rounded-full p-2 bg-[#052531]/70 ${card.isFavorite ? 'text-red-500' : 'text-white'}`}
        >
          <Heart className={`h-5 w-5 ${card.isFavorite ? 'fill-red-500' : ''}`} />
        </Button>
      </div>

      <div className="mt-2 flex justify-between">
        <p className="flex itmes-center gap-2 text-[#1D293D] text-sm font-semibold">
          {card.title}
          {card.isPremium && showPremiumBadge && <PremiumIcon />}
        </p>
        {showLabel && (
          <span className="flex items-center rounded-full bg-[#0525311A] text-xs px-2">
            {card.label}
          </span>
        )}
      </div>

      <div className="flex gap-2 mt-4 flex-wrap">
        <div className="flex items-center gap-1 text-xs text-[#45556C] bg-[#E2E8F0] rounded-md py-1 px-2">
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g clipPath="url(#clip0_5919_14178)">
              <path d="M2.91699 5.24996L1.16699 6.99996L2.91699 8.74996" fill="#45556C" />
              <path d="M5.25033 2.91663L7.00033 1.16663L8.75033 2.91663" fill="#45556C" />
              <path d="M8.75033 11.0833L7.00033 12.8333L5.25033 11.0833" fill="#45556C" />
              <path d="M11.0837 5.24996L12.8337 6.99996L11.0837 8.74996" fill="#45556C" />
              <path d="M2.91699 5.24996L1.16699 6.99996M1.16699 6.99996L2.91699 8.74996M1.16699 6.99996H12.8337M5.25033 2.91663L7.00033 1.16663M7.00033 1.16663L8.75033 2.91663M7.00033 1.16663V12.8333M8.75033 11.0833L7.00033 12.8333M7.00033 12.8333L5.25033 11.0833M11.0837 5.24996L12.8337 6.99996M12.8337 6.99996L11.0837 8.74996" stroke="#45556C" strokeWidth="1.1" strokeLinecap="round" strokeLinejoin="round" />
            </g>
            <defs>
              <clipPath id="clip0_5919_14178"><rect width="14" height="14" fill="white" /></clipPath>
            </defs>
          </svg>
          {card.area ?? "-"} م²
        </div>

        <div className="flex items-center gap-1 text-xs text-[#45556C] bg-[#E2E8F0] rounded-md py-1 px-2">
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g clipPath="url(#clip0_5919_14175)">
              <path d="M11.0833 1.16663H2.91667C1.30842 1.16663 0 2.47504 0 4.08329V12.25C0 12.5725 0.261333 12.8333 0.583333 12.8333C0.905333 12.8333 1.16667 12.5725 1.16667 12.25V11.0833H12.8333V12.25C12.8333 12.5725 13.0941 12.8333 13.4167 12.8333C13.7392 12.8333 14 12.5725 14 12.25V4.08329C14 2.47504 12.6916 1.16663 11.0833 1.16663ZM2.91667 2.33329H11.0833C12.0482 2.33329 12.8333 3.11846 12.8333 4.08329V7.58329H11.6667C11.6667 6.29646 10.6202 5.24996 9.33333 5.24996H8.75C8.0535 5.24996 7.42817 5.55679 7 6.04154C6.57183 5.55621 5.9465 5.24996 5.25 5.24996H4.66667C3.37983 5.24996 2.33333 6.29646 2.33333 7.58329H1.16667V4.08329C1.16667 3.11846 1.95183 2.33329 2.91667 2.33329ZM7.58333 7.58329C7.58333 6.93988 8.10658 6.41663 8.75 6.41663H9.33333C9.97675 6.41663 10.5 6.93988 10.5 7.58329H7.58333ZM3.5 7.58329C3.5 6.93988 4.02325 6.41663 4.66667 6.41663H5.25C5.89342 6.41663 6.41667 6.93988 6.41667 7.58329H3.5ZM1.16667 9.91663V8.74996H12.8333V9.91663H1.16667Z" fill="#45556C" />
            </g>
            <defs>
              <clipPath id="clip0_5919_14175"><rect width="14" height="14" fill="white" /></clipPath>
            </defs>
          </svg>
          {card.bedrooms ?? "-"}
        </div>

        <div className="flex items-center gap-1 text-xs text-[#45556C] bg-[#E2E8F0] rounded-md py-1 px-2">
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g clipPath="url(#clip0_5919_14172)">
              <path d="M13.5619 7.59221C13.23 7.21596 12.7517 7.00012 12.25 7.00012H1.16667V2.61462C1.16667 2.12404 1.38833 1.63871 1.80425 1.37796C2.4395 0.979539 3.21533 1.17554 3.61667 1.71104L3.76775 1.91229L3.486 3.52871C3.45217 3.72354 3.49242 3.92421 3.59917 4.09046C3.84708 4.47662 4.37092 4.57112 4.73783 4.29579L6.84133 2.71846C7.17208 2.47054 7.2555 2.00854 7.03208 1.66029L7.0245 1.64804C6.88625 1.43221 6.65117 1.29687 6.39508 1.28521L4.69992 1.20996L4.59842 1.07462C4.21458 0.563039 3.66917 0.175122 3.0415 0.0508723C1.42333 -0.269378 0 0.966122 0 2.52771C0 2.52771 0.00233333 5.85854 0.0035 7.14946C0.0035 7.48546 0.0250833 7.81737 0.0665 8.15104C0.125417 8.62296 0.20475 9.25937 0.20475 9.25937C0.351167 10.429 0.918167 11.4568 1.74183 12.1976L1.47525 13.2768C1.39767 13.5895 1.58842 13.9056 1.90108 13.9832C1.94833 13.9949 1.995 14.0001 2.04167 14.0001C2.30358 14.0001 2.54158 13.8222 2.6075 13.5568L2.76908 12.9029C3.416 13.2319 4.14575 13.4168 4.91342 13.4168H9.24C9.95342 13.4168 10.6342 13.2575 11.2467 12.9705L11.3919 13.5568C11.4573 13.8222 11.6958 14.0001 11.9578 14.0001C12.0044 14.0001 12.0511 13.9943 12.0983 13.9832C12.411 13.9056 12.6018 13.5895 12.5242 13.2768L12.285 12.3085C13.1775 11.5606 13.7964 10.4885 13.9498 9.25996L13.986 8.96771C14.0478 8.46954 13.8938 7.96904 13.5613 7.59279L13.5619 7.59221ZM12.8287 8.82246L12.7925 9.11471C12.5691 10.902 11.0419 12.2501 9.24058 12.2501H4.914C3.11267 12.2501 1.58608 10.902 1.36267 9.11471L1.24425 8.16679H12.25C12.4198 8.16679 12.5755 8.23679 12.6875 8.36396C12.7995 8.49171 12.8497 8.65387 12.8287 8.82246Z" fill="#45556C" />
            </g>
            <defs>
              <clipPath id="clip0_5919_14172"><rect width="14" height="14" fill="white" /></clipPath>
            </defs>
          </svg>
          {card.bathrooms ?? "-"}
        </div>
      </div>

      <div className={`mt-4 bg-[#F1F5F9] rounded-lg p-4 ${!showButtonText ? "flex justify-between" : ""}`}>
        <p className="mb-2 font-medium text-xl flex items-center gap-1">
          {card.price ?? "-"}
          <RiyalIcon />
        </p>
        {showButtonText ? (
          <Button
            className="p-2 w-full text-[#05222D] font-normal bg-[#0525311A] hover:bg-[#05253126] rounded-full"
            onClick={action}
          >
            عرض بيانات الوحدة
            <svg
              width="16"
              height="16"
              viewBox="0 0 16 16"
              fill="none"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                d="M12.6663 8.00004H3.33301M3.33301 8.00004L7.99967 12.6667M3.33301 8.00004L7.99967 3.33337"
                stroke="#05222D"
                strokeWidth="1.3"
                strokeLinecap="round"
                strokeLinejoin="round"
              />
            </svg>
          </Button>
        ) : (
          <Link href="#" className="p-2 bg-[#0525311A] rounded-full">
            <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
              <path d="M14.1663 14.1667L5.83301 5.83333M5.83301 5.83333V14.1667M5.83301 5.83333H14.1663" stroke="#05222D" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
          </Link>
        )}
      </div>
    </div>
  );
};

const RiyalIcon = () => {
  return (
    <svg width="14" height="15" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">
      <g clipPath="url(#clip0_6448_12071)">
        <path d="M8.13811 13.2883C7.90475 13.8194 7.7505 14.3956 7.69141 15L12.6297 13.9226C12.863 13.3917 13.0171 12.8153 13.0764 12.2109L8.13811 13.2883Z" fill="#1D293D" />
        <path d="M12.6302 10.6949C12.8636 10.164 13.0178 9.58759 13.0769 8.98324L9.23018 9.82291V8.20876L12.6301 7.46723C12.8635 6.9363 13.0177 6.35989 13.0768 5.75554L9.23007 6.59449V0.789524C8.64063 1.12919 8.11715 1.58132 7.69162 2.11463V6.93021L6.15318 7.26582V0C5.56375 0.339544 5.04027 0.791792 4.61474 1.32511V7.6013L1.17247 8.35203C0.939118 8.88295 0.78475 9.45936 0.725539 10.0637L4.61474 9.21545V11.2482L0.4467 12.1572C0.213346 12.6881 0.0590948 13.2646 0 13.8689L4.36277 12.9174C4.71793 12.8416 5.02317 12.6261 5.22163 12.3295L6.02173 11.1121V11.1118C6.10479 10.9859 6.15318 10.834 6.15318 10.6705V8.87985L7.69162 8.54424V11.7725L12.6301 10.6947L12.6302 10.6949Z" fill="#1D293D" />
      </g>
      <defs>
        <clipPath id="clip0_6448_12071"><rect width="13.0769" height="15" fill="white" /></clipPath>
      </defs>
    </svg>
  );
};

const PremiumIcon = () => {
  return (
    <svg width="18" height="18" viewBox="0 0 23 23" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M11.5 0.5C17.5751 0.5 22.5 5.42487 22.5 11.5C22.5 17.5751 17.5751 22.5 11.5 22.5C5.42487 22.5 0.5 17.5751 0.5 11.5C0.5 5.42487 5.42487 0.5 11.5 0.5Z" fill="#F0B100" />
      <path d="M11.5 0.5C17.5751 0.5 22.5 5.42487 22.5 11.5C22.5 17.5751 17.5751 22.5 11.5 22.5C5.42487 22.5 0.5 17.5751 0.5 11.5C0.5 5.42487 5.42487 0.5 11.5 0.5Z" stroke="white" />
      <path d="M6.83481 10.5682C6.62138 9.97747 6.51466 9.68212 6.56016 9.49286C6.60994 9.28585 6.75715 9.12446 6.94533 9.07063C7.11737 9.0214 7.385 9.14035 7.92025 9.37825C8.3937 9.58867 8.63042 9.69388 8.85283 9.68803C9.09772 9.68158 9.33329 9.58338 9.52068 9.40962C9.69088 9.2518 9.80504 9.00032 10.0334 8.49735L10.5365 7.38889C10.9568 6.46296 11.167 6 11.4998 6C11.8326 6 12.0428 6.46296 12.4631 7.38889L12.9663 8.49735C13.1946 9.00032 13.3087 9.2518 13.4789 9.40962C13.6663 9.58338 13.9019 9.68158 14.1468 9.68803C14.3692 9.69388 14.6059 9.58867 15.0794 9.37825C15.6146 9.14035 15.8822 9.0214 16.0543 9.07063C16.2425 9.12446 16.3897 9.28585 16.4394 9.49286C16.4849 9.68212 16.3782 9.97747 16.1648 10.5682L15.2474 13.1072C14.8549 14.1933 14.6587 14.7364 14.2481 15.0432C13.8374 15.35 13.3068 15.35 12.2455 15.35H10.7541C9.69283 15.35 9.16218 15.35 8.75154 15.0432C8.3409 14.7364 8.14468 14.1933 7.75223 13.1072L6.83481 10.5682Z" fill="white" stroke="white" />
      <path fillRule="evenodd" clipRule="evenodd" d="M11.5 12.6H11.5049H11.5Z" fill="white" />
      <path d="M11.5 12.6H11.5049" stroke="white" strokeLinecap="round" strokeLinejoin="round" />
      <path d="M8.75 17H14.25" stroke="white" strokeLinecap="round" />
    </svg>
  )
}

export default UnitCard;