import * as React from 'react';
import { isNumber, isString, map } from 'lodash';
import { P as PackageWrapper } from './PackageWrapper-a88fc0ff.js';
import { ai as NameHelp, a3 as Input, t as toastApi, aj as LazyLoad, v as i18n$1, s as __assign, ak as DraggableWrap, al as LabelSelect, am as LinkButton, an as Button, w as appContext, ah as MAP_DRAG_MODEL, ao as Tooltip } from './MapEditView-67426f04.js';
import $ from 'jquery';
import { observer, useLocalStore } from 'mobx-react';
import { S as SliderInput } from './SliderInput-de0cf600.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 '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 './Slider-6a70ba99.js';
import 'rc-align';

var prefixCls$2 = 'dm-map-base-label-input';
var LabelInput = function (props) {
    var className = props.className, text = props.text, help = props.help, _a = props.value, value = _a === void 0 ? '' : _a, onPressEnter = props.onPressEnter;
    var _changeValue = function (value) {
        var _value = Number(value);
        if (isNumber(_value)) {
            onPressEnter && onPressEnter(_value);
        }
        else {
            toastApi.warning('Illegal number');
        }
    };
    var _onPressEnter = function (e) {
        var target = e.target;
        _changeValue(target.value);
    };
    var _onBlur = function (e) {
        var target = e.target;
        _changeValue(target.value);
    };
    var _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 })));
};

var JsonCodeEditor = LazyLoad(function () { return import('./index-181ce188.js'); });
var prefixCls$1 = 'dm-map-model-setting';
var i18n = i18n$1.mapEdit.modelSetting;
var MapModelSetting = observer(function (props) {
    var onCancel = props.onCancel, onOk = props.onOk, modelInfo = props.modelInfo;
    var _modelInfo = useLocalStore(function () {
        return __assign({}, modelInfo);
    });
    var scale = _modelInfo.scale, rotation = _modelInfo.rotation;
    var _handleOk = function () {
        console.log(_modelInfo, '_modelInfo');
        try {
            JSON.parse(_modelInfo.info);
            onOk && onOk(_modelInfo);
            onCancel && onCancel();
        }
        catch (e) {
            console.log(e);
        }
    };
    var ModelScale = function () { return (React.createElement(SliderInput, { min: 0, max: 1, step: 0.001, value: scale[0], onChange: function (scale) {
            _modelInfo.scale = [scale, scale, scale];
        } })); };
    var ModelRotation = function () { return (React.createElement(SliderInput, { min: 0, max: 360, step: 0.01, value: rotation, onChange: function (rotation) {
            _modelInfo.rotation = rotation;
        } })); };
    return (React.createElement(DraggableWrap, { bounds: false },
        React.createElement("div", { className: prefixCls$1 },
            React.createElement("div", { className: "".concat(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: function (value) {
                        _modelInfo.position.x = value;
                    } }),
                React.createElement(LabelInput, { text: i18n.latitude, value: _modelInfo.position.y, className: "mb8", onPressEnter: function (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: "".concat(194, "px"), onChange: function (value) {
                        console.log(value, 'value');
                        _modelInfo.info = value;
                    }, value: isString(_modelInfo.info) ? _modelInfo.info : '{}' })),
            React.createElement(LinkButton, { className: "mt8", onClick: function () {
                    onOk && onOk(_modelInfo);
                } }, i18n.refreshStatus),
            React.createElement("div", { className: "".concat(prefixCls$1, "-button mt20") },
                React.createElement(Button, { onClick: onCancel }, i18n$1.mapEdit.cancelText),
                React.createElement(Button, { type: "primary", onClick: _handleOk }, i18n$1.mapEdit.okText)))));
});

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