UNPKG

@salla.sa/twilight-components

Version:
203 lines (202 loc) • 7.61 kB
import { type EventEmitter } from "../../stencil-public-runtime"; import type { IntentType, Country, Region, City, District, Branch, SavedAddress, BulletDeliveryConfirmedEvent, AddressCreatedEvent, NewAddressFormData, HeaderContextUpdateEvent } from "./interfaces"; type ViewMode = "main" | "add-address"; /** * @slot footer - The bottom section of the component for custom actions. */ export declare class SallaBulletDelivery { private modal; private confirmBtn; private confirming; private branchSearchDebounceTimer; private preselectedAddressId?; private preselectedBranchId?; private componentReady; private pendingOpen; private tabChanging; private readonly intentStorageKey; private readonly sessionShownKey; private readonly cartItemAddedEvent; private cartItemAddedHandler; private useCartEventApi; private bulletDeliveryOpenHandler; private closeHandler; private guestLoginSyncHandler; /** True after saved addresses have been loaded (lazy: only when address tab is shown). */ private savedAddressesLoaded; private isRTL; loading: boolean; activeTab: IntentType; isLoggedIn: boolean; viewMode: ViewMode; countries: Country[]; regions: Region[]; cities: City[]; districts: District[]; loadingRegions: boolean; selectedCountry: Country | null; selectedRegion: Region | null; selectedCity: City | null; selectedDistrict: District | null; districtName: string; savedAddresses: SavedAddress[]; selectedSavedAddress: SavedAddress | null; /** True when user selected the session address (guest address from before login, not yet saved) */ selectedSessionAddress: boolean; branches: Branch[]; filteredBranches: Branch[]; selectedBranch: Branch | null; branchSearchQuery: string; loadingCities: boolean; loadingDistricts: boolean; loadingBranches: boolean; loadingNearestBranch: boolean; locationError: string; savingAddress: boolean; loadingSavedAddresses: boolean; showCartWillBeClearedBanner: boolean; /** Shown when scopes/allocation returns 422 (address outside delivery coverage). Only on delivery tab. */ allocationOutOfCoverageMessage: string | null; /** * SA add-address view: 'confirmed' = selected address box + description + confirm, 'full' = all form fields (after Edit). */ private static readonly INITIAL_ADDRESS_FORM; newAddressForm: NewAddressFormData; /** Whether to show delivery + pickup tabs. From store.settings.bullet_delivery.supports_pickup */ private get supportsPickup(); /** The modal opening strategy: 'first_visit' | 'on_cart_click' | 'after_add_to_cart' */ private get openingType(); /** Whether the modal is required (cannot be closed/skipped). From store.settings.bullet_delivery.settings.is_required */ private get isRequired(); /** * Emitted when the user confirms their selection */ bulletDeliveryConfirmed: EventEmitter<BulletDeliveryConfirmedEvent>; /** * Emitted when the modal is closed */ bulletDeliveryClosed: EventEmitter<void>; /** * Emitted when a new address is created */ addressCreated: EventEmitter<AddressCreatedEvent>; /** * Emitted to sync with the global header (Delivering to: [location]) */ headerContextUpdate: EventEmitter<HeaderContextUpdateEvent>; /** * Opens the bullet delivery modal */ open(): Promise<void>; /** * Closes the bullet delivery modal */ close(): Promise<HTMLElement>; private resetState; private getIntentStorage; private getStoredIntent; private setStoredIntent; private removeStoredIntent; /** * Single prefill flow: load geography from stored intent and set selected location + form. * Assumes this.countries is already loaded. No-op if no intent or no city in intent. */ private prefillAddressFromStoredIntent; private updateNewAddressForm; /** Whether allocation completed successfully this session (modal won't auto-open again). */ private hasBeenShownThisSession; /** Mark allocation as completed this session (called only after allocateScope succeeds). */ private markShownThisSession; private loadCountries; private loadCities; private loadDistricts; private findPrefillDistrict; private loadBranches; private filterBranches; /** * Prefill form fields from session storage */ private prefillFromSessionStorage; private loadSavedAddresses; private applyCountryChange; private loadRegions; /** * AC7: Guest-to-Registered Sync * Syncs guest session location to user profile on login */ private handleGuestToRegisteredSync; /** * Set an address as active/last used */ private setAddressAsActive; /** * Create a new address from guest session: only country, city and district IDs (no street, etc.). * Uses address/location API; after fetch we return the newly created address from the list. */ private createAddressFromGuestSession; private emitHeaderContextUpdate; private handleBranchSearch; private loadBranchesWithLocation; /** Locate nearest branch using device geolocation (branches tab only). */ private handleFindNearestBranch; private handleBranchSelect; private handleSavedAddressSelect; private handleSessionAddressSelect; /** Show delete confirmation UI for this address (do not call API yet). */ /** * Switch to add-address form (unified form). Preselects country from session when present. */ private handleAddNewAddress; private handleBackToAddressList; /** * Build address/location payload from guest-form state (same fields as add-address). */ private buildAddressLocationPayload; /** * Submit add-address form: create address via API then switch back to list. */ private handleSubmitAddAddress; private handleTabChange; private isConfirmDisabled; private handleLogin; private buildIntentAddress; private buildIntentAddressFromSaved; private buildIntentBranch; private handleConfirm; private getCartViewConfig; /** Creates the cart view DOM for mounting into cart.items.start hook */ private createCartViewElement; private renderSkeleton; private renderTabs; private renderAlert; private renderAllocationOutOfCoverageAlert; private renderCountrySelect; private renderSelectLoader; private renderLoadingLabel; /** Region select (SA only): shown when SA is selected; city and district disabled until region selected. */ private renderRegionSelect; private renderCityDistrictSelects; private renderSavedAddressesEmptyState; /** * Save session address (guest intent) to user profile. Returns the newly saved address or null. */ private saveSessionAddressToProfile; private renderSavedAddresses; private renderAddressRow; private renderGuestDeliveryForm; private renderDeliveryTab; private renderBranchSearch; private renderBranchList; private renderPickupTab; /** Add-address form: same fields as guest form (country, region, city, district) only. */ private renderAddAddressForm; private renderFooter; private renderMainView; private handleAfterAddToCart; private overrideScopeSwitchUI; componentWillLoad(): Promise<void>; render(): any; componentDidLoad(): void; disconnectedCallback(): void; } export {};