"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { MapPin } from "lucide-react";
import { Input } from "./input";
import { Label } from "./label";
import { Card, CardContent } from "./card";
import { cn } from "../../lib/utils";
function AddressInput({
  value = {
    street: "",
    city: "",
    state: "",
    zipCode: "",
    country: ""
  },
  onChange,
  disabled = false,
  className,
  layout = "stacked",
  showFullAddress = true
}) {
  const updateField = (field, fieldValue) => {
    const newAddress = { ...value, [field]: fieldValue };
    if (showFullAddress && field !== "fullAddress") {
      newAddress.fullAddress = [
        newAddress.street,
        newAddress.city,
        newAddress.state,
        newAddress.zipCode,
        newAddress.country
      ].filter(Boolean).join(", ");
    }
    onChange(newAddress);
  };
  const handleFullAddressChange = (fullAddress) => {
    const parts = fullAddress.split(",").map((part) => part.trim());
    const newAddress = {
      ...value,
      fullAddress
    };
    if (parts.length >= 1) newAddress.street = parts[0] || "";
    if (parts.length >= 2) newAddress.city = parts[1] || "";
    if (parts.length >= 3) newAddress.state = parts[2] || "";
    if (parts.length >= 4) newAddress.zipCode = parts[3] || "";
    if (parts.length >= 5) newAddress.country = parts[4] || "";
    onChange(newAddress);
  };
  if (layout === "inline") {
    return /* @__PURE__ */ jsxs("div", { className: cn("space-y-4", className), children: [
      showFullAddress && /* @__PURE__ */ jsxs("div", { className: "relative", children: [
        /* @__PURE__ */ jsx(MapPin, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            placeholder: "Direcci\xF3n completa...",
            value: value.fullAddress || "",
            onChange: (e) => handleFullAddressChange(e.target.value),
            disabled,
            className: "pl-9"
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3", children: [
        /* @__PURE__ */ jsx(
          Input,
          {
            placeholder: "Calle",
            value: value.street,
            onChange: (e) => updateField("street", e.target.value),
            disabled
          }
        ),
        /* @__PURE__ */ jsx(
          Input,
          {
            placeholder: "Ciudad",
            value: value.city,
            onChange: (e) => updateField("city", e.target.value),
            disabled
          }
        ),
        /* @__PURE__ */ jsx(
          Input,
          {
            placeholder: "Estado/Provincia",
            value: value.state,
            onChange: (e) => updateField("state", e.target.value),
            disabled
          }
        ),
        /* @__PURE__ */ jsx(
          Input,
          {
            placeholder: "C\xF3digo Postal",
            value: value.zipCode,
            onChange: (e) => updateField("zipCode", e.target.value),
            disabled
          }
        )
      ] }),
      /* @__PURE__ */ jsx(
        Input,
        {
          placeholder: "Pa\xEDs",
          value: value.country,
          onChange: (e) => updateField("country", e.target.value),
          disabled
        }
      )
    ] });
  }
  return /* @__PURE__ */ jsx(Card, { className, children: /* @__PURE__ */ jsxs(CardContent, { className: "p-4 space-y-4", children: [
    showFullAddress && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
      /* @__PURE__ */ jsx(Label, { htmlFor: "full-address", children: "Direcci\xF3n Completa" }),
      /* @__PURE__ */ jsxs("div", { className: "relative", children: [
        /* @__PURE__ */ jsx(MapPin, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "full-address",
            placeholder: "Ingresa la direcci\xF3n completa...",
            value: value.fullAddress || "",
            onChange: (e) => handleFullAddressChange(e.target.value),
            disabled,
            className: "pl-9"
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
      /* @__PURE__ */ jsxs("div", { className: "space-y-2 md:col-span-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "street", children: "Calle y N\xFAmero" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "street",
            placeholder: "Ej: Av. Corrientes 1234",
            value: value.street,
            onChange: (e) => updateField("street", e.target.value),
            disabled
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "city", children: "Ciudad" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "city",
            placeholder: "Ej: Buenos Aires",
            value: value.city,
            onChange: (e) => updateField("city", e.target.value),
            disabled
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "state", children: "Estado/Provincia" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "state",
            placeholder: "Ej: CABA",
            value: value.state,
            onChange: (e) => updateField("state", e.target.value),
            disabled
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "zipCode", children: "C\xF3digo Postal" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "zipCode",
            placeholder: "Ej: C1043",
            value: value.zipCode,
            onChange: (e) => updateField("zipCode", e.target.value),
            disabled
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "country", children: "Pa\xEDs" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "country",
            placeholder: "Ej: Argentina",
            value: value.country,
            onChange: (e) => updateField("country", e.target.value),
            disabled
          }
        )
      ] })
    ] })
  ] }) });
}
export {
  AddressInput
};
