import React, { useCallback } from 'react';
import { Box, Text } from '@wix/design-system';
import { AddressInput } from '@wix/patterns-fields';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { classes } from './Edit.st.css.js';
/**
 * Bridges patterns-fields AddressInput into EditableTable. State seeding,
 * popover focus handling, and Enter-to-select are owned by AddressInput;
 * here we only forward the cell-framework callbacks.
 */
export const AddressEdit = ({ value, onChange, onCommit, onCancel, inputRef, editTrigger, typeConfig, }) => {
    const { atlasService } = typeConfig ?? {};
    const { translate: t } = useWixPatternsContainer();
    const initialSearchText = editTrigger &&
        typeof editTrigger === 'object' &&
        editTrigger.kind === 'type' &&
        editTrigger.key.length === 1
        ? editTrigger.key
        : undefined;
    const handleKeyDownCapture = useCallback((e) => {
        if (e.key === 'Escape') {
            e.preventDefault();
            onCancel();
        }
    }, [onCancel]);
    const handleBlur = useCallback((e) => {
        if (e.currentTarget.contains(e.relatedTarget)) {
            return;
        }
        onCommit();
    }, [onCommit]);
    return (React.createElement("div", { onKeyDownCapture: handleKeyDownCapture, onBlur: handleBlur, onClick: (e) => e.stopPropagation(), onMouseDown: (e) => e.stopPropagation(), className: classes.addressInput },
        React.createElement(AddressInput, { ref: (instance) => {
                if (inputRef) {
                    inputRef.current = instance;
                }
            }, value: value, onChange: onChange, onSelectAddress: onCommit, atlasService: atlasService, initialSearchText: initialSearchText, size: "small", border: "none", popoverProps: { appendTo: 'window', moveBy: { y: 4 } }, noResultsText: React.createElement(Box, { padding: "SP1", align: "center" },
                React.createElement(Text, { light: true, secondary: true }, t('EditableTable.fields.no_addresses_found'))) })));
};
//# sourceMappingURL=Edit.js.map