import { v as i18n$2, w as appContext, x as Popconfirm, I as Icon, y as IconButton, s as __assign, F as FieldItem, z as useStaticCallback, A as MAP_DRAG_PACKAGE, G as GEO_TYPES, B as GeometryType, D as DataSource, C as SortList, H as CheckList, J as Scrollbar, K as MapStateSet } from './MapEditView-24782753.js';
import * as React from 'react';
import { size, map, get } from 'lodash';
import { observer } from 'mobx-react';
import { P as PackageWrapper } from './PackageWrapper-02d516e3.js';
import 'classnames';
import 'perfect-scrollbar';
import $ from 'jquery';
import { useUpdate } from 'ahooks';
import 'maptalks';
import 'uuid';
import 'mobx';
import 'lz-string';
import 'dayjs';
import 'react-dom';
import 'react-is';
import '@loadable/component';
import 'js-beautify';
import 'axios';
import 'superstruct';
import '@tanem/react-nprogress';
import 'chroma-js';
import 'js-cookie';
import 'is-email';
import 'is-uuid';
import 'is-url';
import 'anymatch';
import 'perf-request';
import '@syncpoint/wkx';
import 'buffer';
import '@turf/turf';
import '@mapbox/polylabel';
import 'turf-multipolygon';
import 'turf-polygon';
import 'gcoord';
import 'eventemitter2';
import 'geobuf';
import 'localforage';
import 'rc-menu';
import 'jszip';
import 'file-saver';
import 'screenfull';
import 'sql-formatter-fork';
import 'array-move';
import 'turf-multilinestring';
import 'copy-to-clipboard';
import 'maptalks.three';
import 'ajv';
import 'spark-md5';
import 'react-draggable';
import 'react-virtualized';
import 'turf-point';
import 'decamelize';
import 'rbush';
import 'qs';
import 'maptalks.snap';
import 'react-use';
import 'react-rnd';
import 'react-beautiful-dnd';

var i18n$1 = i18n$2.mapEdit.packageConfig;
var prefixCls$1 = 'map-package-config-header';
var MapPackageConfigHeader = observer(function () {
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var SuppFiltersStore = routeStore.SuppFiltersStore, GeoFiltersStore = routeStore.GeoFiltersStore, onClearAll = routeStore.onClearAll, MapSettingStore = routeStore.MapSettingStore, onSearch = routeStore.onSearch;
    var changePackageConfigShow = MapSettingStore.changePackageConfigShow;
    var suppFilters = SuppFiltersStore.suppFilters;
    var geoFilters = GeoFiltersStore.geoFilters;
    var hasData = React.useMemo(function () {
        return !!(size(suppFilters) || size(geoFilters));
    }, [suppFilters, geoFilters]);
    return (React.createElement("div", { className: "".concat(prefixCls$1, "-flex") },
        React.createElement("div", { className: "".concat(prefixCls$1, "-title") },
            React.createElement("span", { className: "".concat(prefixCls$1, "-data-title") }, i18n$1.dataTitle),
            size(suppFilters) > 0 && (React.createElement("div", { className: "".concat(prefixCls$1, "-search") },
                i18n$1.click,
                React.createElement("div", { onClick: onSearch, className: "".concat(prefixCls$1, "-search-click") }, i18n$2.mapEdit.startAnalysis),
                i18n$1.addToMap))),
        hasData && (React.createElement(React.Fragment, null,
            React.createElement(Popconfirm, { placement: "bottomRight", okText: i18n$2.mapEdit.okText, cancelText: i18n$2.mapEdit.cancelText, message: "".concat(i18n$2.mapEdit.confirmClearData).concat(i18n$2.mapEdit.questionMark), trigger: "click", emotion: 'help-2', onConfirm: onClearAll },
                React.createElement("div", { className: "flex_center" },
                    React.createElement(Icon, { icon: "delete-2", className: "".concat(prefixCls$1, "-clear-icon"), size: 12 }),
                    React.createElement("div", { className: "".concat(prefixCls$1, "-clear-text mr12") }, i18n$1.clearText))))),
        React.createElement(IconButton, { icon: "close", type: "only-icon", onClick: changePackageConfigShow })));
});

var useCallback = React.useCallback;
var prefixCls = 'dm-map-packages-config';
var removeClass = function (target) {
    $(target).removeClass("".concat(prefixCls, "-success-border"));
    $(target).removeClass("".concat(prefixCls, "-warning-border"));
};
var _onDragLeave = function (event) {
    var target = event.currentTarget;
    if ($(target).hasClass('geo-filters') || $(target).hasClass('supp-filters')) {
        removeClass(target);
    }
};
var i18n = i18n$2.mapEdit.packageConfig;
var MapGeoPackageTitle = observer(function () {
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var GeoFiltersStore = routeStore.GeoFiltersStore;
    var geoFilters = GeoFiltersStore.geoFilters;
    return (React.createElement("div", { className: "".concat(prefixCls, "-flex mt12") },
        React.createElement("div", { className: "".concat(prefixCls, "-title") },
            React.createElement("span", { className: "".concat(prefixCls, "-fence-title") }, i18n.fenceTitle),
            size(geoFilters) > 0 && React.createElement("div", { className: "".concat(prefixCls, "-search") }, i18n.afterAdd))));
});
var MapPackageConfig = observer(function () {
    var _a, _b, _c;
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var SuppFiltersStore = routeStore.SuppFiltersStore, GeoFiltersStore = routeStore.GeoFiltersStore, MapStatusStore = routeStore.MapStatusStore;
    var setColAlias = SuppFiltersStore.setColAlias, deleteSuppFilter = SuppFiltersStore.deleteSuppFilter, aliasSuppFilter = SuppFiltersStore.aliasSuppFilter, setSuppFilters = SuppFiltersStore.setSuppFilters, pushSuppFilter = SuppFiltersStore.pushSuppFilter, currentSuppFilter = SuppFiltersStore.currentSuppFilter, setCurrentSuppFilter = SuppFiltersStore.setCurrentSuppFilter, 
    // getColList: getSuppColList,
    // getColSelectedList: getSuppColSelectedList,
    setSuppColSelectedList = SuppFiltersStore.setColSelectedList, getSuppColUuid = SuppFiltersStore.getColUuid, getSuppColClassification = SuppFiltersStore.getColClassification, getColAlias = SuppFiltersStore.getColAlias, getSuppPackage = SuppFiltersStore.getSuppPackage;
    var suppFilters = (_a = SuppFiltersStore === null || SuppFiltersStore === void 0 ? void 0 : SuppFiltersStore.suppFilters) === null || _a === void 0 ? void 0 : _a.slice();
    var deleteGeoFilter = GeoFiltersStore.deleteGeoFilter, setGeoFilters = GeoFiltersStore.setGeoFilters, aliasGeoFilter = GeoFiltersStore.aliasGeoFilter, pushGeoFilter = GeoFiltersStore.pushGeoFilter, currentGeoFilter = GeoFiltersStore.currentGeoFilter, setCurrentGeoFilter = GeoFiltersStore.setCurrentGeoFilter, getGeoColList = GeoFiltersStore.getColList, getGeoColClassification = GeoFiltersStore.getColClassification; GeoFiltersStore.getColSelectedList; var setGeoColSelectedList = GeoFiltersStore.setColSelectedList, getGeoColUuid = GeoFiltersStore.getColUuid, getGeoPackage = GeoFiltersStore.getGeoPackage;
    var update = useUpdate();
    var setMapState = MapStatusStore.setMapState;
    var geoFilters = (_b = GeoFiltersStore === null || GeoFiltersStore === void 0 ? void 0 : GeoFiltersStore.geoFilters) === null || _b === void 0 ? void 0 : _b.slice();
    var currentSuppPackage = getSuppPackage(currentSuppFilter);
    var currentGeoPackage = getGeoPackage(currentGeoFilter);
    // 当前supp数据包 Columns
    var suppColList = ((currentSuppPackage === null || currentSuppPackage === void 0 ? void 0 : currentSuppPackage._getColList) || {}).list;
    // 当前geo数据包 Columns
    ((currentGeoPackage === null || currentGeoPackage === void 0 ? void 0 : currentGeoPackage._getColList) || {}).list;
    console.log(suppColList, 'suppColList');
    var currentSuppColumns = map(suppColList, function (i) {
        return {
            label: i,
            value: i,
            type: getSuppColClassification({ uuid: currentSuppFilter, col: i }),
        };
    });
    var currentGeoColumns = (_c = getGeoColList({ uuid: currentGeoFilter })) === null || _c === void 0 ? void 0 : _c.map(function (i) { return ({
        label: i,
        value: i,
        type: getGeoColClassification({ uuid: currentGeoFilter, col: i }),
    }); }).filter(function (i) { return i.type === 'text'; });
    var currentSuppSelected = currentSuppPackage === null || currentSuppPackage === void 0 ? void 0 : currentSuppPackage.getColSelectedList;
    var currentGeoSelected = currentGeoPackage === null || currentGeoPackage === void 0 ? void 0 : currentGeoPackage.getColSelectedList;
    var geoFilterRender = useCallback(function (provided, item, index) {
        var _a = item, geometryType = _a.geometryType, objectType = _a.objectType, uuid = _a.uuid, alias = _a.alias;
        var _onClick = function () {
            setCurrentGeoFilter(uuid);
            setMapState(MapStateSet.FENCE_SELECT);
        };
        var _deleteGeoFilter = function () {
            deleteGeoFilter(uuid);
        };
        var _aliasGeoFilter = function (alias) {
            aliasGeoFilter(uuid, alias);
        };
        return (React.createElement("div", __assign({ ref: provided.innerRef }, provided.draggableProps, { key: index }),
            React.createElement(PackageWrapper, { isCurrent: uuid === currentGeoFilter, key: index, type: geometryType, text: objectType, alias: alias, onClick: _onClick, onDelete: _deleteGeoFilter, onChangeText: _aliasGeoFilter, provided: provided })));
    }, [currentGeoFilter, setCurrentGeoFilter, setMapState, deleteGeoFilter, aliasGeoFilter]);
    var suppFilterRender = useCallback(function (provided, item, index) {
        var _a = item, geometryType = _a.geometryType, objectType = _a.objectType, uuid = _a.uuid, alias = _a.alias;
        var _onClick = function () {
            setCurrentSuppFilter(uuid);
        };
        var _deleteSuppFilter = function () {
            deleteSuppFilter(uuid);
        };
        var _aliasSuppFilter = function (alias) {
            aliasSuppFilter(uuid, alias);
        };
        return (React.createElement("div", __assign({ ref: provided.innerRef }, provided.draggableProps, { key: index }),
            React.createElement(PackageWrapper, { isCurrent: uuid === currentSuppFilter, key: index, type: geometryType, text: objectType, alias: alias, onClick: _onClick, onDelete: _deleteSuppFilter, onChangeText: _aliasSuppFilter, deleteTitle: i18n.deleteTitle, provided: provided })));
    }, [currentSuppFilter, setCurrentSuppFilter, deleteSuppFilter, aliasSuppFilter]);
    var suppFiledItemRender = useCallback(function (provided, item, index) {
        var _a = item, type = _a.type, value = _a.value;
        var _onClose = function () {
            currentSuppSelected.splice(index, 1);
            setSuppColSelectedList({
                uuid: currentSuppFilter,
                selected: currentSuppSelected,
            });
        };
        var changeAlias = function (value) {
            setColAlias({
                uuid: currentSuppFilter,
                colUuid: get(item, 'uuid'),
                columnAlias: value,
            }).then(function () {
                requestAnimationFrame(function () {
                    update();
                });
            });
        };
        return (React.createElement("div", __assign({ ref: provided.innerRef }, provided.draggableProps, { key: index }),
            React.createElement("div", { style: { display: 'flex', alignItems: 'center', marginBottom: 4, width: 180 } },
                React.createElement(IconButton, __assign({ type: "only-icon", icon: "drag-handle", className: "".concat(prefixCls, "-drag-handle") }, provided === null || provided === void 0 ? void 0 : provided.dragHandleProps)),
                React.createElement(FieldItem, { key: index, type: type, name: get(item, 'label') || value, checked: true, onClose: _onClose, editable: true, changeAlias: changeAlias }))));
    }, [currentSuppFilter, currentSuppSelected, setColAlias, setSuppColSelectedList, update]);
    var geoFiledItemRender = useCallback(function (provided, item, index) {
        var _a = item, type = _a.type, value = _a.value;
        var _onClose = function () {
            currentGeoSelected.splice(index, 1);
            setGeoColSelectedList({
                uuid: currentGeoFilter,
                selected: currentGeoSelected,
            });
        };
        return (React.createElement("div", __assign({ ref: provided.innerRef }, provided.draggableProps, { key: index }),
            React.createElement("div", { style: { display: 'flex', alignItems: 'center', marginBottom: 4, width: 180 } },
                React.createElement(IconButton, __assign({ type: "only-icon", icon: "drag-handle", className: "".concat(prefixCls, "-drag-handle") }, provided === null || provided === void 0 ? void 0 : provided.dragHandleProps)),
                React.createElement(FieldItem, { key: index, type: type, name: value, checked: true, onClose: _onClose }))));
    }, [currentGeoFilter, currentGeoSelected, setGeoColSelectedList]);
    var _changeSuppColumnsSelect = useStaticCallback(function (selected) {
        setSuppColSelectedList({ uuid: currentSuppFilter, selected: selected });
    });
    var _changeGeoColumnsSelect = useStaticCallback(function (selected) {
        setGeoColSelectedList({ uuid: currentGeoFilter, selected: selected });
    });
    var _suppValue = function () {
        return map(currentSuppSelected, function (value) {
            var uuid = getSuppColUuid({ uuid: currentSuppFilter, col: value });
            var type = getSuppColClassification({ uuid: currentSuppFilter, col: value });
            var alias = getColAlias({ uuid: currentSuppFilter, col: value });
            return {
                label: alias,
                value: value,
                uuid: uuid,
                type: type,
            };
        });
    };
    var suppValue = _suppValue();
    var _geoValue = function () {
        return map(currentGeoSelected, function (value) {
            var uuid = getGeoColUuid({ uuid: currentGeoFilter, col: value });
            var type = getGeoColClassification({ uuid: currentGeoFilter, col: value });
            return {
                label: value,
                value: value,
                uuid: uuid,
                type: type,
            };
        });
    };
    var geoValue = _geoValue();
    var _changeSuppQuotes = useStaticCallback(function (arr) {
        var selected = map(arr, function (a) {
            return getSuppColUuid({ uuid: currentSuppFilter, col: a.value });
        });
        setSuppColSelectedList({ uuid: currentSuppFilter, selected: selected, direct: true });
    });
    var _changeGeoQuotes = useStaticCallback(function (arr) {
        var selected = map(arr, function (a) {
            return getGeoColUuid({ uuid: currentGeoFilter, col: a.label });
        });
        setGeoColSelectedList({ uuid: currentGeoFilter, selected: selected, direct: true });
    });
    return (React.createElement("div", { className: prefixCls },
        React.createElement("div", { className: "".concat(prefixCls, "-content") },
            React.createElement(MapPackageConfigHeader, null),
            React.createElement("div", { className: "".concat(prefixCls, "-list") },
                React.createElement("div", { "data-test": "map-supp-pkg-filter-drop-target", className: "".concat(prefixCls, "-list-wrapper supp-filters"), onDrop: function (event) {
                        var target = event.currentTarget;
                        $(target).removeClass("".concat(prefixCls, "-success-border"));
                        var item = event.dataTransfer.getData(MAP_DRAG_PACKAGE);
                        if (!item)
                            return;
                        if (item)
                            item = JSON.parse(item);
                        if ($(target).hasClass('supp-filters')) {
                            removeClass(target);
                            var source = item.source, packageUuid = item.packageUuid, geometryType = item.geometryType, geoType = item.geoType, objectType = item.objectType;
                            if ((geometryType || geoType) === GEO_TYPES[GeometryType.polygon] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.pointToPoint] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.line] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.point]) {
                                pushSuppFilter({
                                    source: source === DataSource.private ? DataSource.market : source,
                                    packageUuid: packageUuid,
                                    objectType: objectType,
                                    geometryType: geometryType || geoType,
                                });
                            }
                        }
                    }, onDragOver: function (event) {
                        event.preventDefault();
                        var target = event.currentTarget;
                        var item = sessionStorage.getItem(MAP_DRAG_PACKAGE);
                        if (!item) {
                            return;
                        }
                        var _item = JSON.parse(item);
                        var geometryType = _item.geometryType, geoType = _item.geoType;
                        if ($(target).hasClass('supp-filters')) {
                            if ((geometryType || geoType) === GEO_TYPES[GeometryType.polygon] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.pointToPoint] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.line] ||
                                (geometryType || geoType) === GEO_TYPES[GeometryType.point]) {
                                $(target).addClass("".concat(prefixCls, "-success-border"));
                            }
                            else {
                                $(target).addClass("".concat(prefixCls, "-warning-border"));
                            }
                        }
                    }, onDragLeave: _onDragLeave },
                    React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper-auto") },
                        React.createElement(SortList, { list: suppFilters, renderItem: suppFilterRender, onChange: setSuppFilters, valueKey: "uuid" })),
                    size(suppFilters) === 0 && React.createElement("div", { className: "".concat(prefixCls, "-no-data") }, i18n.noSupp)),
                (size(currentSuppColumns) > 0 || size(suppFilters) > 0) && (React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper"), "data-test": "map-supp-pkg-col-check-list" },
                    React.createElement(CheckList, { mode: "plain", dynamicRowHeight: true, size: "compact", text: i18n$2.mapEdit.selectFieldsToBeAddedToMapFilter, listDescriptionClassName: "".concat(prefixCls, "-list-wrapper-checklist-title"), flexHeight: true, rowHeight: 30, options: currentSuppColumns, value: currentSuppSelected, onChange: _changeSuppColumnsSelect }))),
                size(suppValue) > 0 && (React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper"), key: Date.now() },
                    React.createElement("div", { style: { height: '100%' }, "data-test": "map-supp-pkg-col-sort-list" },
                        React.createElement(Scrollbar, null,
                            React.createElement(SortList, { list: suppValue, renderItem: suppFiledItemRender, onChange: _changeSuppQuotes, valueKey: "uuid" }))))))),
        React.createElement("div", { className: "".concat(prefixCls, "-content") },
            React.createElement(MapGeoPackageTitle, null),
            React.createElement("div", { className: "".concat(prefixCls, "-list") },
                React.createElement("div", { "data-test": "map-geo-pkg-filter-drop-target", className: "".concat(prefixCls, "-list-wrapper geo-filters"), onDrop: function (event) {
                        var target = event.currentTarget;
                        $(target).removeClass("".concat(prefixCls, "-success-border"));
                        var item = event.dataTransfer.getData(MAP_DRAG_PACKAGE);
                        if (!item)
                            return;
                        var _item = JSON.parse(item);
                        if ($(target).hasClass('geo-filters')) {
                            removeClass(target);
                            var source = _item.source, packageUuid = _item.packageUuid, geometryType = _item.geometryType, geoType = _item.geoType, objectType = _item.objectType;
                            if (source !== 'sql' &&
                                ((geometryType || geoType) === GEO_TYPES[GeometryType.polygon] ||
                                    (geometryType || geoType) === GEO_TYPES[GeometryType.pointToPolygon])) {
                                pushGeoFilter({
                                    source: source === DataSource.private ? DataSource.market : source,
                                    packageUuid: packageUuid,
                                    objectType: objectType,
                                    geometryType: geometryType || geoType,
                                });
                            }
                        }
                    }, onDragOver: function (event) {
                        event.preventDefault();
                        var target = event.currentTarget;
                        var item = sessionStorage.getItem(MAP_DRAG_PACKAGE);
                        if (!item) {
                            return;
                        }
                        var _item = JSON.parse(item);
                        var geometryType = _item.geometryType, geoType = _item.geoType, source = _item.source;
                        if ($(target).hasClass('geo-filters')) {
                            if (source !== 'sql' &&
                                ((geometryType || geoType) === GEO_TYPES[GeometryType.polygon] ||
                                    (geometryType || geoType) === GEO_TYPES[GeometryType.pointToPolygon])) {
                                $(target).addClass("".concat(prefixCls, "-success-border"));
                            }
                            else {
                                $(target).addClass("".concat(prefixCls, "-warning-border"));
                            }
                        }
                    }, onDragLeave: _onDragLeave },
                    React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper-auto") },
                        React.createElement(SortList, { list: geoFilters, renderItem: geoFilterRender, onChange: setGeoFilters, valueKey: "uuid" })),
                    size(geoFilters) === 0 && React.createElement("div", { className: "".concat(prefixCls, "-no-data") }, i18n.noGeo)),
                (size(currentGeoColumns) > 0 || size(geoFilters) > 0) && (React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper"), "data-test": "map-geo-pkg-col-check-list" },
                    React.createElement(CheckList, { mode: "plain", dynamicRowHeight: true, size: "compact", text: i18n$2.mapEdit.selectFieldsToBeAddedToMapFilter, listDescriptionClassName: "".concat(prefixCls, "-list-wrapper-checklist-title"), flexHeight: true, rowHeight: 30, options: currentGeoColumns, value: currentGeoSelected, onChange: _changeGeoColumnsSelect }))),
                size(geoValue) > 0 && (React.createElement("div", { className: "".concat(prefixCls, "-list-wrapper") },
                    React.createElement("div", { style: { height: '100%' }, "data-test": "map-geo-pkg-col-sort-list" },
                        React.createElement(Scrollbar, null,
                            React.createElement(SortList, { list: geoValue, renderItem: geoFiledItemRender, onChange: _changeGeoQuotes, valueKey: "uuid" })))))))));
});
MapPackageConfig.whyDidYouRender = true;
MapPackageConfig.displayName = 'MapPackageConfig';
var MapPackageConfig$1 = MapPackageConfig;

export { MapPackageConfig$1 as default };
