"use client";

import React from 'react';
import AddressForm from './AddressForm';
import SavedAddresses from './SavedAddresses';

interface DeliveryAddressProps {
  sameAddress: boolean;
  guestId: string | null;
  onAddressToggle: (value: boolean) => void;
  onAddressChange: (data: any) => void;
  onSavedAddressSelect: (addressId: string) => void;
  errors: any;
}

const DeliveryAddress = ({ 
  sameAddress, 
  guestId, 
  onAddressToggle, 
  onAddressChange,
  onSavedAddressSelect,
  errors 
}: DeliveryAddressProps) => {
  return (
    <div className="card">
      <div className="card-body">
        <div className="section-heading">
          <h2>Delivery Address</h2>
        </div>
        
        {!guestId && (
          <div className="radio-custom">
            <div className="customRadio">
              <input
                type="radio"
                id="newAddr"
                name="ship_addr"
                value="1"
                checked={!sameAddress}
                onChange={() => onAddressToggle(false)}
              />
              <label htmlFor="newAddr">Create a new address</label>
            </div>

            <div className="customRadio">
              <input
                type="radio"
                id="oldAddr"
                name="ship_addr"
                value="2"
                checked={sameAddress}
                onChange={() => onAddressToggle(true)}
              />
              <label htmlFor="oldAddr">Use saved address</label>
            </div>
          </div>       
        )}

        {sameAddress ? (
          <SavedAddresses 
            onAddressSelect={onSavedAddressSelect}
            errors={errors}
          />
        ) : (
          <AddressForm 
            onAddressChange={onAddressChange}
            errors={errors}
          />
        )}
      </div>
    </div>
  );
};

export default DeliveryAddress;