"use client";

import { useCallback } from "react";
import { accountService } from "@/features/account/services/account.service";
import {
  addressFormSchema,
  addressFormToRequest,
  type AddressFormData,
} from "@customer-portal/domain/customer";
import { useZodForm } from "@customer-portal/validation";

export function useAddressEdit(initial: AddressFormData) {
  const handleSave = useCallback(async (formData: AddressFormData) => {
    const requestData = addressFormToRequest(formData);
    await accountService.updateAddress(requestData);
  }, []);

  return useZodForm({
    schema: addressFormSchema,
    initialValues: initial,
    onSubmit: handleSave,
  });
}
