import React from 'react';
import { Loader } from '@wix/design-system';
import { defineCellType } from '../../types';
import { AddressCellView } from './View';
const addressEditFactory = () => import(/* webpackChunkName: "EditableTableAddressEdit" */ './Edit').then((m) => ({ default: m.AddressEdit }));
if (typeof process !== 'undefined' &&
    process.env.STORYBOOK_VISUAL_E2E !== 'true') {
    addressEditFactory();
}
const LazyAddressEdit = React.lazy(addressEditFactory);
const AddressEdit = (props) => (React.createElement(React.Suspense, { fallback: React.createElement(Loader, { size: "tiny" }) },
    React.createElement(LazyAddressEdit, { ...props })));
export { AddressCellView };
export const addressCellType = defineCellType({
    type: 'address',
    ViewComponent: AddressCellView,
    EditComponent: AddressEdit,
    serialize: (value) => (value ? JSON.stringify(value) : ''),
    deserialize: (raw) => {
        if (!raw) {
            return undefined;
        }
        try {
            const parsed = JSON.parse(raw);
            if (parsed && typeof parsed.formatted === 'string') {
                return parsed;
            }
        }
        catch { }
        return undefined;
    },
    validate: (value) => {
        if (!value) {
            return null;
        }
        if (typeof value === 'object' &&
            typeof value.formatted === 'string' &&
            value.formatted.length > 0) {
            return null;
        }
        return 'Invalid address';
    },
    editable: true,
    clearable: true,
    // Type-to-edit clears the cell so the user starts a fresh search query.
    onTypeToEdit: () => ({ value: undefined }),
});
//# sourceMappingURL=index.js.map