"use client";

import { Label } from "@/components/atoms";
import {
  JapanAddressForm,
  type JapanAddressFormData,
  type JapanAddressFormProps,
} from "@/features/address/components/JapanAddressForm";
import type { AccountFormErrors } from "./types";

interface AddressFieldsProps {
  onAddressChange: (data: JapanAddressFormData, isComplete: boolean) => void;
  initialValues?: JapanAddressFormProps["initialValues"];
  description?: string;
  errors: AccountFormErrors;
  loading: boolean;
}

/**
 * AddressFields - Standalone address form section.
 *
 * Used when an SF-unmapped user has incomplete prefilled address data
 * and needs to provide a full address before account creation.
 * Accepts initialValues to pre-populate from Salesforce (e.g., postcode).
 */
export function AddressFields({
  onAddressChange,
  initialValues,
  description = "Please provide your full address.",
  errors,
  loading,
}: AddressFieldsProps) {
  return (
    <div className="space-y-2">
      <Label>
        Address <span className="text-danger">*</span>
      </Label>
      <p className="text-sm text-muted-foreground">{description}</p>
      <JapanAddressForm
        initialValues={initialValues}
        onChange={onAddressChange}
        disabled={loading}
      />
      {errors.address && <p className="text-sm text-danger">{errors.address}</p>}
    </div>
  );
}
