import { AddressForm, IkasCustomerAddress } from "../../../../storefront-models/src"; /** * Initializes an address form with default or existing address values, loads location data, and configures field settings. * * Also resolves `addressForm.addressFormat` for the selected country. That is an * `AddressFormItem[][]` describing which fields the country uses and how they group into rows * (outer array = rows, inner array = fields sharing a row), and it is the only correct source * for laying out an address form -- a hardcoded field list will be wrong for most countries. * It is empty until this promise resolves, and `setAddressFormCountry` re-resolves it, so * render from it rather than copying it into local state. * * @ai-category Address, Form, Initialization, Checkout * @ai-related submitAddressForm, setAddressFormCountry, setAddressFormState, setAddressFormCity * * @param addressForm - The address form instance to initialize. * @param address - An optional existing customer address to pre-populate the form with. * @returns A promise that resolves once the form is fully initialized, including country/state/city lists, field settings, checkout settings, and shipping zones. * * @example * ```tsx * import { useEffect, useState } from "preact/hooks"; * import { * type AddressForm, * type AddressFormItem, * initAddressForm, * setAddressFormFirstName, * setAddressFormLastName, * setAddressFormIdentityNumber, * setAddressFormAddressLine1, * setAddressFormAddressLine2, * setAddressFormPostalCode, * setAddressFormPhone, * } from "@ikas/bp-storefront"; * * // Initialize an empty address form * await initAddressForm(addressForm); * * // Initialize with an existing customer address for editing * await initAddressForm(addressForm, existingAddress); * * // addressFormat is empty until init resolves, so gate the render on it. * const [isLoading, setIsLoading] = useState(true); * useEffect(() => { * initAddressForm(addressForm, address).then(() => setIsLoading(false)); * }, []); * * // Every addressFormat key has a matching setter, each taking (addressForm, value). * // The location keys (country, state, city, district, region) are omitted here: they * // render as selects fed by addressForm.countryOptions / stateOptions / cityOptions / * // districtOptions / regionOptions, and must fall back to a text input when the field * // isFreeText or has no options. * const SETTERS: Partial void>> = { * firstName: setAddressFormFirstName, * lastName: setAddressFormLastName, * identityNumber: setAddressFormIdentityNumber, * addressLine1: setAddressFormAddressLine1, * addressLine2: setAddressFormAddressLine2, * postalCode: setAddressFormPostalCode, * phone: setAddressFormPhone, * }; * * // Render the country's own layout: outer array = rows, inner array = fields in that row. * (addressForm.addressFormat ?? []).map((row) => { * // A field the country does not use is absent from the form object entirely. * const keys = row.filter((key) => addressForm[key] != null); * if (!keys.length) return null; * * return ( *
* {keys.map((key) => { * // Each entry is an IkasFormItem: value, label, placeholder, hasError, message. * const field = addressForm[key]; * if (!field) return null; // already guaranteed by the filter above; narrows the type * return ( * * ); * })} *
* ); * }) * ``` */ export declare function initAddressForm(addressForm: AddressForm, address?: IkasCustomerAddress): Promise; /** * Sets the title field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormFirstName, setAddressFormLastName * * @param addressForm - The address form instance to update. * @param value - The title value to set (e.g., "Home", "Work"). * @returns void * * @example * ```typescript * import { setAddressFormTitle } from "@ikas/bp-storefront"; * * setAddressFormTitle(addressForm, "Home Address"); * ``` */ export declare function setAddressFormTitle(addressForm: AddressForm, value: string): void; /** * Sets the first name field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormLastName, setAddressFormTitle * * @param addressForm - The address form instance to update. * @param value - The first name value to set. * @returns void * * @example * ```typescript * import { setAddressFormFirstName } from "@ikas/bp-storefront"; * * setAddressFormFirstName(addressForm, "John"); * ``` */ export declare function setAddressFormFirstName(addressForm: AddressForm, value: string): void; /** * Sets the last name field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormFirstName, setAddressFormTitle * * @param addressForm - The address form instance to update. * @param value - The last name value to set. * @returns void * * @example * ```typescript * import { setAddressFormLastName } from "@ikas/bp-storefront"; * * setAddressFormLastName(addressForm, "Doe"); * ``` */ export declare function setAddressFormLastName(addressForm: AddressForm, value: string): void; /** * Sets the identity number field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormFirstName, setAddressFormLastName * * @param addressForm - The address form instance to update. * @param value - The identity number value to set (e.g., national ID or tax ID). * @returns void * * @example * ```typescript * import { setAddressFormIdentityNumber } from "@ikas/bp-storefront"; * * setAddressFormIdentityNumber(addressForm, "12345678901"); * ``` */ export declare function setAddressFormIdentityNumber(addressForm: AddressForm, value: string): void; /** * Sets the primary address line field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormAddressLine2, setAddressFormPostalCode * * @param addressForm - The address form instance to update. * @param value - The primary address line value to set (e.g., street address). * @returns void * * @example * ```typescript * import { setAddressFormAddressLine1 } from "@ikas/bp-storefront"; * * setAddressFormAddressLine1(addressForm, "123 Main Street"); * ``` */ export declare function setAddressFormAddressLine1(addressForm: AddressForm, value: string): void; /** * Sets the secondary address line field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormAddressLine1, setAddressFormPostalCode * * @param addressForm - The address form instance to update. * @param value - The secondary address line value to set (e.g., apartment or suite number). * @returns void * * @example * ```typescript * import { setAddressFormAddressLine2 } from "@ikas/bp-storefront"; * * setAddressFormAddressLine2(addressForm, "Apt 4B"); * ``` */ export declare function setAddressFormAddressLine2(addressForm: AddressForm, value: string): void; /** * Sets the postal code field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormAddressLine1, setAddressFormCountry * * @param addressForm - The address form instance to update. * @param value - The postal code value to set. * @returns void * * @example * ```typescript * import { setAddressFormPostalCode } from "@ikas/bp-storefront"; * * setAddressFormPostalCode(addressForm, "34000"); * ``` */ export declare function setAddressFormPostalCode(addressForm: AddressForm, value: string): void; /** * Sets the country field of an address form, resets dependent location fields (state, city, district), refreshes the state list, and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation, Location * @ai-related initAddressForm, setAddressFormState, setAddressFormCity, setAddressFormDistrict * * @param addressForm - The address form instance to update. * @param value - The country ID to set. * @returns void * * @example * ```typescript * import { setAddressFormCountry } from "@ikas/bp-storefront"; * * setAddressFormCountry(addressForm, "country-id-123"); * ``` */ export declare function setAddressFormCountry(addressForm: AddressForm, value: string): void; /** * Sets the state field of an address form, resets dependent city and district fields (unless they are free-text), refreshes the city list, and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation, Location * @ai-related initAddressForm, setAddressFormCountry, setAddressFormCity, setAddressFormDistrict * * @param addressForm - The address form instance to update. * @param value - The state ID to set. * @returns void * * @example * ```typescript * import { setAddressFormState } from "@ikas/bp-storefront"; * * setAddressFormState(addressForm, "state-id-456"); * ``` */ export declare function setAddressFormState(addressForm: AddressForm, value: string): void; /** * Sets the city field of an address form, resets the district and district options, refreshes the district list (unless district is free-text), and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation, Location * @ai-related initAddressForm, setAddressFormState, setAddressFormDistrict, setAddressFormCountry * * @param addressForm - The address form instance to update. * @param value - The city ID to set. * @returns void * * @example * ```typescript * import { setAddressFormCity } from "@ikas/bp-storefront"; * * setAddressFormCity(addressForm, "city-id-789"); * ``` */ export declare function setAddressFormCity(addressForm: AddressForm, value: string): void; /** * Sets the district field of an address form, resets the region field and region options, and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation, Location * @ai-related initAddressForm, setAddressFormCity, setAddressFormRegion, setAddressFormState * * @param addressForm - The address form instance to update. * @param value - The district ID to set. * @returns void * * @example * ```typescript * import { setAddressFormDistrict } from "@ikas/bp-storefront"; * * setAddressFormDistrict(addressForm, "district-id-012"); * ``` */ export declare function setAddressFormDistrict(addressForm: AddressForm, value: string): void; /** * Sets the region field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation, Location * @ai-related initAddressForm, setAddressFormDistrict, setAddressFormCity, submitAddressForm * * @param addressForm - The address form instance to update. * @param value - The region ID to set. * @returns void * * @example * ```typescript * import { setAddressFormRegion } from "@ikas/bp-storefront"; * * setAddressFormRegion(addressForm, "region-id-345"); * ``` */ export declare function setAddressFormRegion(addressForm: AddressForm, value: string): void; /** * Sets the phone number field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormFirstName, setAddressFormCompany * * @param addressForm - The address form instance to update. * @param value - The phone number value to set. * @returns void * * @example * ```typescript * import { setAddressFormPhone } from "@ikas/bp-storefront"; * * setAddressFormPhone(addressForm, "+905551234567"); * ``` */ export declare function setAddressFormPhone(addressForm: AddressForm, value: string): void; /** * Sets the company name field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormTaxOffice, setAddressFormTaxNumber * * @param addressForm - The address form instance to update. * @param value - The company name value to set. * @returns void * * @example * ```typescript * import { setAddressFormCompany } from "@ikas/bp-storefront"; * * setAddressFormCompany(addressForm, "Acme Corp"); * ``` */ export declare function setAddressFormCompany(addressForm: AddressForm, value: string): void; /** * Sets the tax office field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormCompany, setAddressFormTaxNumber * * @param addressForm - The address form instance to update. * @param value - The tax office name value to set. * @returns void * * @example * ```typescript * import { setAddressFormTaxOffice } from "@ikas/bp-storefront"; * * setAddressFormTaxOffice(addressForm, "Istanbul Tax Office"); * ``` */ export declare function setAddressFormTaxOffice(addressForm: AddressForm, value: string): void; /** * Sets the tax number field of an address form and re-validates if the form has been submitted. * * @ai-category Address, Form, Validation * @ai-related initAddressForm, submitAddressForm, setAddressFormCompany, setAddressFormTaxOffice * * @param addressForm - The address form instance to update. * @param value - The tax number value to set. * @returns void * * @example * ```typescript * import { setAddressFormTaxNumber } from "@ikas/bp-storefront"; * * setAddressFormTaxNumber(addressForm, "1234567890"); * ``` */ export declare function setAddressFormTaxNumber(addressForm: AddressForm, value: string): void; /** * Validates and submits the address form, saving the address to the customer's profile as either a new entry or an update to an existing address. * * @ai-category Address, Form, Validation, Checkout, Submission * @ai-related initAddressForm, setAddressFormTitle, setAddressFormFirstName, setAddressFormCountry * * @param addressForm - The address form instance to validate and submit. * @returns A promise that resolves to `true` if the address was saved successfully, or `false` if validation failed or the save operation encountered an error. * * @example * ```typescript * import { submitAddressForm } from "@ikas/bp-storefront"; * * const success = await submitAddressForm(addressForm); * if (success) { * console.log("Address saved successfully"); * } else { * console.log("Address save failed:", addressForm.responseMessage); * } * ``` */ export declare function submitAddressForm(addressForm: AddressForm): Promise;