import { n as iconsUtil, i as __read, w as appContext, v as i18n, h as __spreadArray, G as GEO_TYPES, B as GeometryType, br as getCustomGeoMenuOpts, bm as getDesText, bq as TextShave, I as Icon, bc as getIcon, bs as Dropdown, bp as MapMenuCustom, s as __assign, bt as TYPE_VISUAL, bu as NUMBER_VISUAL } from './MapEditView-24782753.js';
import * as React from 'react';
import { observer } from 'mobx-react';
import { find, size, map, forEach } from 'lodash';
import { M as MapVisualGeoIcon } from './MapVisualGeoIcon-fdf6d163.js';
import { useClickAway } from 'react-use';
import { T as TextColorSegmentation, N as NumberColorSegmentation } from './TextColorSegmentation-321ebe99.js';
import { M as MapTypeSetting, D as DataGroupby } from './DataGroupby-1192d469.js';
import 'maptalks';
import 'uuid';
import 'mobx';
import 'lz-string';
import 'dayjs';
import 'react-dom';
import 'classnames';
import 'react-is';
import '@loadable/component';
import 'js-beautify';
import 'axios';
import 'superstruct';
import '@tanem/react-nprogress';
import 'jquery';
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 'perfect-scrollbar';
import 'ahooks';
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-rnd';
import 'react-beautiful-dnd';
import './index-ae07a940.js';
import './MapColorPicker-41ec1c5c.js';
import './index-f58067b3.js';
import './index-3fbe476f.js';
import './useDataValue-8bdb351c.js';
import './Transfer-f55a5877.js';
import 'simple-statistics';
import 'echarts';

var prefixCls = 'dm-map-visual-geo-card';
var useState = React.useState, useRef = React.useRef;
var MapVisualGeoCard = observer(function () {
    var iconCache = iconsUtil.iconCache, getIconUrl = iconsUtil.getIconUrl, getIconColorPref = iconsUtil.getIconColorPref;
    var _a = __read(useState(false), 2), popupVisible = _a[0], setPopupVisible = _a[1];
    var ref = useRef(null);
    var refWrap = useRef(null);
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var GeoFiltersStore = routeStore.GeoFiltersStore, defaultIcon = routeStore.defaultIcon, customIconPrefInfo = routeStore.customIconPrefInfo, EmitStore = routeStore.EmitStore, getPopupContainer = routeStore.getPopupContainer;
    var geoFilters = GeoFiltersStore.geoFilters, currentGeoFilter = GeoFiltersStore.currentGeoFilter, geoDataCount = GeoFiltersStore.geoDataCount, geoDataPointCount = GeoFiltersStore.geoDataPointCount, updateRenderCurrentGeo = GeoFiltersStore.updateRenderCurrentGeo;
    var zoomToCurrentGeo = EmitStore.zoomToCurrentGeo;
    var geoPackage = find(geoFilters, { uuid: currentGeoFilter });
    var i18nMenu = i18n.mapEdit.menu;
    var i18nCards = i18n.mapEdit.cards;
    if (!geoPackage) {
        return null;
    }
    var _b = geoPackage, geometryType = _b.geometryType, objectType = _b.objectType, alias = _b.alias, getColListByType = _b.getColListByType, 
    // allColumns,
    updateHoverVisual = _b.updateHoverVisual, updateLabelVisual = _b.updateLabelVisual, getColUuid = _b.getColUuid, 
    // setColSelectedList,
    addTypeVisual = _b.addTypeVisual, typeVisual = _b.typeVisual, numberVisual = _b.numberVisual, addNumberVisual = _b.addNumberVisual, getColumnValueById = _b.getColumnValueById, getCol = _b.getCol, changeVisualColor = _b.changeVisualColor, 
    // getAllColValue,
    // getColumnValueNameList,
    setColumnValue = _b.setColumnValue, getColumnIdByValue = _b.getColumnIdByValue, updateTypeVisual = _b.updateTypeVisual, updateNumberVisual = _b.updateNumberVisual, setNoVisual = _b.setNoVisual, defaultStyle = _b.defaultStyle, updateDefaultStyle = _b.updateDefaultStyle;
    var iconInfo = React.useMemo(function () { return ({
        defaultIcon: defaultIcon,
        iconList: __spreadArray(__spreadArray([], __read(iconCache.customIconList.map(function (i) { return ({
            // label: getIconLabel(i),
            name: i,
            url: getIconUrl(i),
            originalColor: getIconColorPref(i),
        }); })), false), __read(iconCache.defaultIconList.map(function (i) { return ({
            // label: getIconLabel(i),
            name: i,
            url: getIconUrl(i),
            originalColor: getIconColorPref(i),
        }); })), false),
        customIconPrefInfo: customIconPrefInfo,
    }); }, [
        defaultIcon,
        iconCache.customIconList,
        iconCache.defaultIconList,
        customIconPrefInfo,
        getIconUrl,
        getIconColorPref,
    ]);
    // const { fenceSetting } = FenceSettingStore;
    // const { defaultFence } = fenceSetting;
    var count = 0;
    if (geometryType === GEO_TYPES[GeometryType.polygon]) {
        count = geoDataCount;
    }
    else if (geometryType === GEO_TYPES[GeometryType.pointToPolygon]) {
        count = geoDataPointCount;
    }
    var isCurrentTypeVisual = size(typeVisual) > 0;
    var isCurrentNumberVisual = size(numberVisual) > 0;
    var _currentVisualConfig = function () {
        var currentVisualDetail = isCurrentTypeVisual ? typeVisual : numberVisual; //find(visual, { fieldId });
        var currentVisualField = getCol({ fieldId: currentVisualDetail === null || currentVisualDetail === void 0 ? void 0 : currentVisualDetail.fieldId });
        var currentVisualType = isCurrentTypeVisual ? TYPE_VISUAL : NUMBER_VISUAL;
        return {
            currentVisualDetail: currentVisualDetail,
            currentVisualType: currentVisualType,
            currentVisualField: currentVisualField,
        };
    };
    var _c = _currentVisualConfig(), currentVisualDetail = _c.currentVisualDetail, currentVisualType = _c.currentVisualType, currentVisualField = _c.currentVisualField;
    var _d = __read(getColListByType(), 2), _numberCols = _d[0], _textCols = _d[1];
    var numberCols = map(_numberCols, function (c) {
        return {
            id: c,
            value: c,
        };
    });
    var textCols = map(_textCols, function (c) {
        return {
            id: c,
            value: c,
        };
    });
    var defaultOpts = getCustomGeoMenuOpts({ geometryType: geometryType, numberCols: numberCols, textCols: textCols });
    var _menuClick = function (info) {
        var key = info.key, keyPath = info.keyPath;
        setPopupVisible(false);
        if (key === i18nMenu.removeVisualization) {
            setNoVisual();
            updateRenderCurrentGeo();
        }
        else if (key === i18nMenu.moveTo) {
            zoomToCurrentGeo();
        }
        if (keyPath.indexOf(i18nMenu.hoverInteraction) > -1) {
            var colId = getColUuid({ col: key });
            // setColSelectedList({ selected: [key] });
            var fields = colId ? [colId] : [];
            updateHoverVisual({ fields: fields });
            updateRenderCurrentGeo();
        }
        else if (keyPath.indexOf(i18nMenu.displayField) > -1) {
            var colId = getColUuid({ col: key });
            // setColSelectedList({ selected: [key] });
            var fields = colId ? [colId] : [];
            updateLabelVisual({ fields: fields });
            updateRenderCurrentGeo();
        }
        else if (keyPath.indexOf(i18nMenu.classificationVisualization) > -1) {
            addTypeVisual(key).then(function () {
                updateRenderCurrentGeo();
            });
        }
        else if (keyPath.indexOf(i18nMenu.numericalVisualization) > -1) {
            addNumberVisual(key).then(function () {
                updateRenderCurrentGeo();
            });
        }
    };
    var _setPopupVisible = function () {
        setPopupVisible(!popupVisible);
    };
    var getMenuTip = function () {
        return (React.createElement("div", { ref: refWrap },
            React.createElement(MapMenuCustom, { options: defaultOpts, onClick: _menuClick, getTooltipPopupContainer: getPopupContainer })));
    };
    useClickAway(ref, function (e) {
        var isWrap = !!(refWrap.current && refWrap.current.contains(e.target));
        if (!isWrap) {
            // todo 优化 报错
            setTimeout(function () {
                setPopupVisible && setPopupVisible(false);
            }, 200);
        }
    });
    var _getCurrentBreaks = function () {
        var currentBreaks = [];
        if (isCurrentTypeVisual) {
            // const col = getCol({ fieldId: typeVisual.fieldId });
            forEach(typeVisual === null || typeVisual === void 0 ? void 0 : typeVisual.breaks, function (b) {
                var data = getColumnValueById({ col: currentVisualField, id: b });
                currentBreaks.push(data === null || data === void 0 ? void 0 : data.value);
            });
        }
        return currentBreaks;
    };
    var _changeVisualColor = function (_a) {
        var color = _a.color, index = _a.index;
        var type = isCurrentNumberVisual ? NUMBER_VISUAL : TYPE_VISUAL;
        changeVisualColor({
            color: color,
            index: index,
            type: type,
        });
        updateRenderCurrentGeo();
    };
    // const _getCurrentValueNameList = () => {
    //   // const col = getCol({ fieldId: typeVisual.fieldId });
    //   // const resp = getAllColValue({ col: currentVisualField });
    //   const data = getColumnValueNameList({ col: currentVisualField });
    //   return data;
    // };
    // todo _changeTypeVisual
    var _changeTypeVisual = function (result) {
        setColumnValue({ col: currentVisualField, values: result === null || result === void 0 ? void 0 : result.breaks });
        var breaks = map(result === null || result === void 0 ? void 0 : result.breaks, function (b) {
            var column = getColumnIdByValue({ col: currentVisualField, value: b });
            return column === null || column === void 0 ? void 0 : column.uuid;
        });
        var typeVisual = __assign(__assign(__assign({}, currentVisualDetail), result), { breaks: breaks });
        updateTypeVisual({ typeVisual: typeVisual });
        updateRenderCurrentGeo();
    };
    var _changeNumberVisual = function (result) {
        var breaks = (result || {}).breaks;
        var numberVisual = __assign(__assign({}, currentVisualDetail), { breaks: breaks });
        updateNumberVisual({ numberVisual: numberVisual });
        updateRenderCurrentGeo();
    };
    var currentDesText = getDesText(currentVisualType);
    var currentVisualDes = function (field, text) {
        return (React.createElement("div", { className: "".concat(prefixCls, "-visual-des") },
            "\u6309\u201C ",
            React.createElement("span", null, field || currentVisualField),
            " \u201D",
            text || currentDesText));
    };
    var _updateStyle = function (style) {
        updateDefaultStyle({ defaultStyle: style });
        updateRenderCurrentGeo();
    };
    return (React.createElement("div", { className: prefixCls, "data-test": "dm-map-visual-geo-card" },
        React.createElement("div", { className: "".concat(prefixCls, "-title") }, i18nMenu.visualizationBottomFence),
        React.createElement("div", { className: "".concat(prefixCls, "-content") },
            React.createElement(MapVisualGeoIcon, { className: "".concat(prefixCls, "-icon"), type: geometryType, 
                // isHeat={isHeat}
                style: defaultStyle, updateStyle: _updateStyle }),
            React.createElement("div", { style: { paddingTop: 8, paddingRight: 8, flex: 1 } },
                React.createElement("div", { className: "".concat(prefixCls, "-text") },
                    React.createElement(TextShave, null, alias ? alias : objectType)),
                React.createElement("div", { className: "".concat(prefixCls, "-count") },
                    count,
                    i18nCards.data),
                isCurrentNumberVisual ||
                    (isCurrentTypeVisual && (React.createElement("div", { className: "".concat(prefixCls, "-visual") },
                        React.createElement("div", { className: "".concat(prefixCls, "-visual-line") },
                            currentVisualDes(),
                            isCurrentTypeVisual && (React.createElement(MapTypeSetting, { breaks: _getCurrentBreaks(), visual: typeVisual, packageInfo: geoPackage, col: getCol({ fieldId: typeVisual === null || typeVisual === void 0 ? void 0 : typeVisual.fieldId }), 
                                // getValue={_getCurrentValueNameList}
                                changeTypeVisual: _changeTypeVisual },
                                React.createElement(Icon, { icon: "edit", className: "".concat(prefixCls, "-edit-icon") }))),
                            isCurrentNumberVisual && (React.createElement(DataGroupby, { breaks: currentVisualDetail === null || currentVisualDetail === void 0 ? void 0 : currentVisualDetail.breaks, data: currentVisualDetail === null || currentVisualDetail === void 0 ? void 0 : currentVisualDetail.breaks, onOk: _changeNumberVisual },
                                React.createElement(Icon, { icon: "edit", className: "".concat(prefixCls, "-edit-icon") })))),
                        isCurrentTypeVisual && (React.createElement(TextColorSegmentation, { icons: [getIcon(geometryType)], breaks: _getCurrentBreaks(), colors: typeVisual === null || typeVisual === void 0 ? void 0 : typeVisual.colors, changeVisualColor: _changeVisualColor, iconInfo: iconInfo })),
                        isCurrentNumberVisual && (React.createElement(NumberColorSegmentation, { icons: [], breaks: numberVisual === null || numberVisual === void 0 ? void 0 : numberVisual.breaks, colors: numberVisual === null || numberVisual === void 0 ? void 0 : numberVisual.colors, changeVisualColor: _changeVisualColor, iconInfo: iconInfo, getPopupContainer: getPopupContainer }))))),
                React.createElement("div", { className: "".concat(prefixCls, "-action") },
                    React.createElement(Dropdown, { placement: "bottomRight", open: popupVisible, dropdownRender: getMenuTip, getPopupContainer: getPopupContainer },
                        React.createElement("div", { ref: ref, className: "default-menu", onClick: _setPopupVisible },
                            React.createElement(Icon, { icon: "more", size: 16 }))))))));
});
var MapVisualGeoCard$1 = MapVisualGeoCard;

export { MapVisualGeoCard$1 as default };
