import * as React from 'react';
import { isNumber, isString, map } from 'lodash';
import { P as PackageWrapper } from './PackageWrapper-2f19b461.js';
import { ag as NameHelp, a1 as Input, t as toastApi, ah as LazyLoad, p as i18n$1, ai as DraggableWrap, aj as LabelSelect, ak as LinkButton, al as Button, q as appContext, af as MAP_DRAG_MODEL, am as Tooltip } from './MapEditView-f6381866.js';
import $ from 'jquery';
import { observer, useLocalStore } from 'mobx-react';
import { S as SliderInput } from './SliderInput-12f1ae97.js';
import classNames from 'classnames';
import 'react-use';
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 '@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';

const prefixCls$2 = 'dm-map-base-label-input';
const LabelInput = (props) => {
    const { className, text, help, value = '', onPressEnter } = props;
    const _changeValue = (value) => {
        const _value = Number(value);
        if (isNumber(_value)) {
            onPressEnter && onPressEnter(_value);
        }
        else {
            toastApi.warning('Illegal number');
        }
    };
    const _onPressEnter = (e) => {
        const target = e.target;
        _changeValue(target.value);
    };
    const _onBlur = (e) => {
        const target = e.target;
        _changeValue(target.value);
    };
    const _value = value === null || value === void 0 ? void 0 : value.toString();
    return (React.createElement("div", { className: classNames(prefixCls$2, className) },
        React.createElement(NameHelp, { name: text, help: help, width: 84 }),
        React.createElement(Input, { size: "compact", type: "menu-bg", block: true, allowClear: false, defaultValue: _value, onPressEnter: _onPressEnter, onBlur: _onBlur })));
};

const JsonCodeEditor = LazyLoad(() => import('./index-5d31e445.js'));
const prefixCls$1 = 'dm-map-model-setting';
const i18n = i18n$1.mapEdit.modelSetting;
const MapModelSetting = observer((props) => {
    const { onCancel, onOk, modelInfo } = props;
    const _modelInfo = useLocalStore(() => {
        return Object.assign({}, modelInfo);
    });
    const { scale, rotation } = _modelInfo;
    const _handleOk = () => {
        console.log(_modelInfo, '_modelInfo');
        try {
            JSON.parse(_modelInfo.info);
            onOk && onOk(_modelInfo);
            onCancel && onCancel();
        }
        catch (e) {
            console.log(e);
        }
    };
    const ModelScale = () => (React.createElement(SliderInput, { min: 0, max: 1, step: 0.001, value: scale[0], onChange: (scale) => {
            _modelInfo.scale = [scale, scale, scale];
        } }));
    const ModelRotation = () => (React.createElement(SliderInput, { min: 0, max: 360, step: 0.01, value: rotation, onChange: (rotation) => {
            _modelInfo.rotation = rotation;
        } }));
    return (React.createElement(DraggableWrap, { bounds: false },
        React.createElement("div", { className: prefixCls$1 },
            React.createElement("div", { className: `${prefixCls$1}-scroll` },
                React.createElement(LabelSelect, { className: `mb8`, text: '缩放大小', noSelect: true }),
                React.createElement(ModelScale, null),
                React.createElement(LabelInput, { text: i18n.longitude, className: `mb8 mt8`, value: _modelInfo.position.x, onPressEnter: (value) => {
                        _modelInfo.position.x = value;
                    } }),
                React.createElement(LabelInput, { text: i18n.latitude, value: _modelInfo.position.y, className: `mb8`, onPressEnter: (value) => {
                        _modelInfo.position.y = value;
                    } }),
                React.createElement(LabelSelect, { className: `mb8`, text: i18n.rotationAngle, noSelect: true }),
                React.createElement(ModelRotation, null),
                React.createElement(LabelSelect, { className: `mb8`, help: i18n.help1, text: i18n.help2, noSelect: true }),
                React.createElement(JsonCodeEditor
                // height={`${194}px`}
                , { 
                    // height={`${194}px`}
                    width: `${194}px`, onChange: (value) => {
                        console.log(value, 'value');
                        _modelInfo.info = value;
                    }, value: isString(_modelInfo.info) ? _modelInfo.info : '{}' })),
            React.createElement(LinkButton, { className: `mt8`, onClick: () => {
                    onOk && onOk(_modelInfo);
                } }, i18n.refreshStatus),
            React.createElement("div", { className: `${prefixCls$1}-button mt20` },
                React.createElement(Button, { onClick: onCancel }, i18n$1.mapEdit.cancelText),
                React.createElement(Button, { type: "primary", onClick: _handleOk }, i18n$1.mapEdit.okText)))));
});

const prefixCls = 'dm-map-models-config';
const MapModelsConfig = observer(() => {
    const { routeStore } = React.useContext(appContext.getContext());
    const { MapSettingStore: { modelList = [], pushModelList, deleteModelById, updateModel }, } = routeStore;
    const store = useLocalStore(() => {
        return {
            showIndex: -1,
        };
    });
    const closeEdit = () => {
        store.showIndex = -1;
    };
    return (React.createElement("div", { className: prefixCls },
        React.createElement("div", { className: `${prefixCls}-list`, onDrop: (event) => {
                const target = event.currentTarget;
                const item = sessionStorage.getItem(MAP_DRAG_MODEL);
                if (item) {
                    const node = JSON.parse(item);
                    // const id = node.id;
                    console.log(node, 'node');
                    pushModelList(node);
                }
                $(target).removeClass(`${prefixCls}-success-border`);
            }, onDragOver: (event) => {
                event.preventDefault();
                const target = event.currentTarget;
                const item = sessionStorage.getItem(MAP_DRAG_MODEL);
                // console.log(item, 'item');
                if (item) {
                    $(target).addClass(`${prefixCls}-success-border`);
                }
            }, onDragLeave: (event) => {
                const target = event.currentTarget;
                $(target).removeClass(`${prefixCls}-success-border`);
            } }, map(modelList.slice(), (current, index) => {
            const { name, id } = current;
            return (React.createElement("div", { key: id, style: { position: 'relative' } },
                React.createElement(PackageWrapper, { type: "model", text: name, onEdit: () => {
                        if (store.showIndex === -1) {
                            store.showIndex = index;
                        }
                        else {
                            closeEdit();
                        }
                    }, onDelete: () => {
                        deleteModelById(id);
                    } }),
                React.createElement(Tooltip, { arrowContent: null, overlayClassName: `${prefixCls}-popup`, trigger: "click", visible: store.showIndex === index, destroyTooltipOnHide: true, overlay: () => (React.createElement(MapModelSetting, { onCancel: closeEdit, onOk: updateModel, modelInfo: current })), placement: "rightTop" },
                    React.createElement("div", { style: { position: 'absolute', top: 0, right: 0 } }))));
        }))));
});
var MapModelsConfig$1 = MapModelsConfig;

export { MapModelsConfig$1 as default };
