import React from "react";

function IconLocation() {
  return (
    <svg width="17" height="24" viewBox="0 0 17 24" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M8.5 0C4.41068 0 1 3.32656 1 7.57392C1 9.18978 1.48082 10.6307 2.40359 11.9808L7.92605 20.683C8.19395 21.1061 8.80659 21.1052 9.07396 20.683L14.6204 11.9512C15.5233 10.6622 16 9.14869 16 7.57392C16 3.39766 12.6355 0 8.5 0ZM8.5 11.0166C6.62032 11.0166 5.09091 9.47212 5.09091 7.57392C5.09091 5.67571 6.62032 4.13123 8.5 4.13123C10.3797 4.13123 11.9091 5.67571 11.9091 7.57392C11.9091 9.47212 10.3797 11.0166 8.5 11.0166Z" fill="#053F31" />
      <path d="M12.93 16L10.0766 21.6466C9.33799 23.1041 7.6579 23.0993 6.92285 21.6479L4.06481 16.0015C1.55017 16.7374 0 18.0855 0 19.6965C0 22.492 4.3795 24 8.5 24C12.6205 24 17 22.492 17 19.6965C17 18.0843 15.4477 16.7355 12.93 16Z" fill="#053F31" />
    </svg>

  );
}

function IconEmail() {
  return (
    <svg width="24" height="16" viewBox="0 0 24 16" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M23.9781 1.6092C23.9781 1.58354 23.997 1.55857 23.9958 1.5332L16.6719 8.13615L23.987 14.5282C23.9913 14.4825 23.9781 14.4365 23.9781 14.3898V1.6092Z" fill="#053F31" />
      <path d="M15.5582 9.15234L12.5683 11.8439C12.417 11.9801 12.2216 12.0484 12.0261 12.0484C11.8347 12.0484 11.6433 11.983 11.493 11.852L8.51132 9.25225L1.14844 15.8927C1.32747 15.9529 1.51964 15.9996 1.72088 15.9996H22.3315C22.6303 15.9996 22.9106 15.9144 23.1543 15.7874L15.5582 9.15234Z" fill="#053F31" />
      <path d="M12.0186 10.3095L23.1959 0.23522C22.9428 0.0944393 22.6482 0 22.3325 0H1.7219C1.31076 0 0.934039 0.149366 0.640625 0.377172L12.0186 10.3095Z" fill="#053F31" />
      <path d="M0 1.85547V14.3905C0 14.5344 0.0353473 14.6732 0.0737185 14.8058L7.34526 8.25393L0 1.85547Z" fill="#053F31" />
    </svg>

  );
}

function IconPhone() {
  return (
    <svg width="19" height="19" viewBox="0 0 19 19" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M14.4446 12.5689C13.8239 11.9561 13.049 11.9561 12.4322 12.5689C11.9617 13.0355 11.4912 13.502 11.0286 13.9764C10.9021 14.1069 10.7954 14.1346 10.6412 14.0476C10.3367 13.8816 10.0125 13.7471 9.71998 13.5653C8.35597 12.7073 7.21337 11.6042 6.20123 10.3628C5.69912 9.74597 5.25235 9.0857 4.94002 8.34241C4.87676 8.19217 4.88862 8.09332 5.01118 7.97076C5.48167 7.51608 5.94029 7.04954 6.40287 6.583C7.04731 5.9346 7.04731 5.17548 6.39891 4.52312C6.03122 4.15147 5.66353 3.78773 5.29584 3.41608C4.91629 3.03653 4.5407 2.65302 4.15719 2.27741C3.53647 1.6725 2.76156 1.6725 2.14479 2.28137C1.67035 2.74791 1.21568 3.2263 0.733333 3.68493C0.286571 4.10798 0.0612129 4.62592 0.0137691 5.23084C-0.0613503 6.21531 0.179822 7.14443 0.519836 8.04983C1.21568 9.92389 2.27526 11.5884 3.56019 13.1145C5.29585 15.1784 7.36756 16.8113 9.79114 17.9895C10.8824 18.5193 12.0131 18.9265 13.2427 18.9937C14.0888 19.0411 14.8241 18.8276 15.4132 18.1674C15.8165 17.7167 16.2712 17.3055 16.6982 16.8745C17.3308 16.234 17.3347 15.4591 16.7061 14.8265C15.9549 14.0713 15.1997 13.3201 14.4446 12.5689Z" fill="#053F31" />
      <path d="M13.6842 9.41905L15.1431 9.16997C14.9138 7.82966 14.2812 6.61587 13.3205 5.65117C12.3044 4.63506 11.0194 3.99456 9.60403 3.79688L9.39844 5.2637C10.4936 5.4179 11.4899 5.91211 12.2767 6.6989C13.02 7.4422 13.5063 8.38318 13.6842 9.41905Z" fill="#053F31" />
      <path d="M15.967 3.07599C14.2828 1.39171 12.1518 0.328158 9.79934 0L9.59375 1.46683C11.6259 1.75149 13.4683 2.67271 14.9233 4.12372C16.3031 5.50357 17.2085 7.24715 17.5366 9.1647L18.9955 8.91562C18.612 6.69363 17.5643 4.67724 15.967 3.07599Z" fill="#053F31" />
    </svg>

  );
}

function IconBilling() {
  return (
    <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
      <g clipPath="url(#clip0_1420_27226)">
        <path d="M36.3873 0.149734C36.2497 0.0647145 36.0911 0.0196348 35.9293 0.0195312H9.81965C7.57499 0.0195312 5.74873 1.8279 5.74873 4.04424L5.59529 26.5286H0.876785C0.392537 26.5286 0 26.9211 0 27.4054V31.4561C0.00306875 34.4306 2.41353 36.8411 5.38811 36.8445C5.44843 36.8445 5.50902 36.8384 5.56829 36.8261H27.3526C27.4824 36.8353 27.6133 36.8414 27.7451 36.8414C30.766 36.836 33.212 34.3864 33.2131 31.3657V18.2221H39.1231C39.6074 18.2221 39.9999 17.8296 39.9999 17.3453V4.3299C39.9893 2.23692 38.4566 0.463097 36.3873 0.149734ZM1.75357 31.4564V28.2825H22.2772V31.366C22.2761 32.7397 22.7931 34.0633 23.7249 35.0725H5.26825C5.22678 35.0728 5.18575 35.076 5.14498 35.0821C3.23762 34.9523 1.75594 33.3682 1.75357 31.4564ZM31.4595 4.3299V31.3657C31.4579 32.3456 31.0684 33.285 30.3761 33.9786C29.7135 34.6585 28.8132 35.0552 27.8643 35.0855C27.8169 35.0773 27.7689 35.0731 27.7208 35.0728H27.4125C25.5029 34.8848 24.0435 33.2854 24.0308 31.3664V27.4054C24.0308 26.9214 23.6383 26.5286 23.154 26.5286H7.34886L7.5023 4.05046C7.51502 2.78246 8.55138 1.76355 9.81965 1.7731H32.3304C31.7655 2.50567 31.4593 3.40483 31.4595 4.3299ZM38.2463 16.4685H33.213V4.3299C33.2359 2.95615 34.3559 1.85499 35.7296 1.85499C37.1034 1.85499 38.2233 2.95615 38.2463 4.3299V16.4685Z" fill="#053F31" />
        <path d="M11.2596 9.5192H19.5636C20.048 9.5192 20.4404 9.12675 20.4404 8.64241C20.4404 8.15816 20.048 7.76562 19.5636 7.76562H11.2596C10.7753 7.76562 10.3828 8.15816 10.3828 8.64241C10.3828 9.12675 10.7753 9.5192 11.2596 9.5192ZM26.7499 14.0346H11.2596C10.7753 14.0346 10.3828 14.4272 10.3828 14.9114C10.3828 15.3954 10.7753 15.7882 11.2596 15.7882H26.7499C27.2342 15.7882 27.6267 15.3954 27.6267 14.9114C27.6267 14.4272 27.2342 14.0346 26.7499 14.0346ZM26.7499 20.3034H11.2596C10.7753 20.3034 10.3828 20.6962 10.3828 21.1802C10.3828 21.6644 10.7753 22.057 11.2596 22.057H26.7499C27.2342 22.057 27.6267 21.6644 27.6267 21.1802C27.6267 20.6962 27.2342 20.3034 26.7499 20.3034Z" fill="#053F31" />
      </g>
      <defs>
        <clipPath id="clip0_1420_27226">
          <rect width="40" height="40" fill="white" />
        </clipPath>
      </defs>
    </svg>

  );
}

function IconPackage() {
  return (
    <svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M37.7794 10.6909L20.2794 1.94092C20.1926 1.89757 20.097 1.875 20 1.875C19.903 1.875 19.8074 1.89757 19.7206 1.94092L2.22063 10.6909C2.11674 10.7428 2.02936 10.8227 1.96832 10.9215C1.90727 11.0203 1.87496 11.1341 1.87501 11.2503V28.7503C1.87437 28.867 1.90641 28.9815 1.96749 29.0809C2.02857 29.1803 2.11626 29.2606 2.22063 29.3128L19.7206 38.0628C19.8074 38.1061 19.903 38.1287 20 38.1287C20.097 38.1287 20.1926 38.1061 20.2794 38.0628L37.7794 29.3128C37.8838 29.2606 37.9714 29.1803 38.0325 29.0809C38.0936 28.9815 38.1256 28.867 38.125 28.7503V11.2503C38.1251 11.1341 38.0928 11.0203 38.0317 10.9215C37.9707 10.8227 37.8833 10.7428 37.7794 10.6909ZM20 19.3015L15.1144 16.8584L30.7306 8.56279L36.1056 11.2503L20 19.3015ZM10.1144 14.3584L25.7306 6.06279L29.3556 7.87529L13.7413 16.1722L10.1144 14.3584ZM9.37501 15.3865L13.125 17.2615V22.2415L11.6919 20.8084C11.5747 20.6912 11.4158 20.6253 11.25 20.6253H9.37501V15.3865ZM20 3.19904L24.3575 5.37529L8.74126 13.6722L3.89751 11.2503L20 3.19904ZM3.12501 12.2615L8.12501 14.7615V21.2503C8.12501 21.4161 8.19086 21.575 8.30807 21.6922C8.42528 21.8094 8.58425 21.8753 8.75001 21.8753H10.9913L13.3081 24.1922C13.3955 24.2795 13.5069 24.3391 13.6281 24.3632C13.7493 24.3873 13.875 24.3749 13.9892 24.3276C14.1034 24.2803 14.201 24.2002 14.2696 24.0975C14.3383 23.9947 14.375 23.8739 14.375 23.7503V17.8865L19.375 20.3865V36.489L3.12501 28.364V12.2615ZM20.625 36.489V20.3865L36.875 12.2615V28.364L20.625 36.489Z" fill="#053F31" />
    </svg>

  );
}

type InfoCardProps = {
  title: string;
  companyName: string;
  companySubText: string;
  taxId?: string;
  address: string;
  email: string;
  phone: string;
  icon: React.ReactNode;
  isActive?: boolean;
};

const InfoCard = ({
  title,
  companyName,
  companySubText,
  taxId,
  address,
  email,
  phone,
  icon,
  isActive = false,
}: InfoCardProps) => {
  return (
    <article
      className={`relative flex-1 rounded-[24px] bg-[#F7FAF8] p-[15px_30px] border transition-all duration-200 hover:border-[#053F31] hover:border-b-[3px] 
        ${isActive ? "border-[#053F31]/10" : "border-[#DAE6DC]"}`}
    >
      <h4 className="font-outfit font-semibold mb-[10px]">
        {title}
      </h4>

      <div className="border-t border-[#000000]/10 pt-[10px]">
        <div className="flex items-start gap-4 md:gap-6">
          <div className="flex h-[72px] w-[72px] md:h-[91px] md:w-[91px] shrink-0 items-center justify-center rounded-[18px] bg-[#DAE6DC]">
            {icon}
          </div>

          <div className="pt-1">
            <p className="font-outfit !text-[16px] font-light  text-[#757575] mb-1">
              {companySubText}
            </p>
            <p className="font-outfit text-[18px] md:text-[20px] font-normal text-[#141414]">
              {companyName}
            </p>
            {taxId && (
              <p className="font-outfit text-[18px] md:text-[20px] font-bold  text-[#141414]">
                {taxId}
              </p>
            )}
            <p className="mt-3 flex items-start gap-2 font-outfit text-[16px] md:text-[18px] leading-[150%] text-[#666666]">
              <span className="mt-1 shrink-0">
                <IconLocation />
              </span>
              <span className="font-light">{address}</span>
            </p>
          </div>
        </div>
      </div>

      <div className="mt-[10px] border-t border-[#000000]/10 pt-[10px]">
        <div className="flex flex-col gap-3">
          <a
            href={`mailto:${email}`}
            className="group flex items-center gap-3 font-outfit text-[18px] md:text-[20px] font-medium text-[#0F3F32]  transition-opacity"
          >
            <IconEmail />
            <span>{email}</span>
          </a>
          <a
            href={`tel:${phone.replace(/\s/g, "")}`}
            className="group flex items-center gap-3 font-outfit text-[18px] md:text-[20px] font-medium text-[#0F3F32]  transition-opacity"
          >
            <IconPhone />
            <span>{phone}</span>
          </a>
        </div>
      </div>
    </article>
  );
};

const DEFAULT_BILLING = {
  title: "Billing Information",
  companySubText: "Organic Farms SA",
  companyName: "VAT: ESB12345678",
  taxId: undefined as string | undefined,
  address: "Calle de las Flores 12328016 Madrid, Spain",
  email: "info@biomket.com",
  phone: "1345678905",
};

const DEFAULT_DELIVERY = {
  title: "Delivery/Service Location",
  companySubText: "Organic Farms SA - Main Facility",
  companyName: "Madrid Region",
  taxId: undefined as string | undefined,
  address: "Camino KM 12 28850 Torrejón de Ardoz Madrid, Spain",
  email: "info@biomket.com",
  phone: "1345678905",
};

export type BillingLocationCardFields = {
  title?: string;
  companySubText?: string;
  companyName?: string;
  taxId?: string;
  address?: string;
  email?: string;
  phone?: string;
};

export type BillingInfoDeliveryLocationCardsProps = {
  billing?: BillingLocationCardFields;
  delivery?: BillingLocationCardFields;
};

export default function BillingInfoDeliveryLocationCards({
  billing,
  delivery,
}: BillingInfoDeliveryLocationCardsProps) {
  const b = { ...DEFAULT_BILLING, ...billing };
  const d = { ...DEFAULT_DELIVERY, ...delivery };

  return (
    <section>
      <div className="xl:max-w-[1240px] 2xl:max-w-[1440px] sm:mx-auto flex flex-col lg:flex-row gap-6 md:gap-8">
        <InfoCard
          title={b.title}
          companySubText={b.companySubText}
          companyName={b.companyName}
          taxId={b.taxId}
          address={b.address}
          email={b.email}
          phone={b.phone}
          icon={<IconBilling />}
        />

        <InfoCard
          title={d.title}
          companySubText={d.companySubText}
          companyName={d.companyName}
          taxId={d.taxId}
          address={d.address}
          email={d.email}
          phone={d.phone}
          icon={<IconPackage />}
          isActive={true}
        />
      </div>
    </section>
  );
}
