import * as React from 'react';
import { observer, useLocalStore } from 'mobx-react';
import { filter, map, get } from 'lodash';
import { p as i18n$1, ad as apiMediaFunc, ae as OmniMediaViewGetMediaTypeEnum, h as getSignatureUrl, a1 as Input, af as MAP_DRAG_MODEL, i as getOssUrl } from './MapEditView-f6381866.js';
import { useMount } from 'ahooks';
import $ from 'jquery';
import { v4 } from 'uuid';
import 'axios';
import 'maptalks';
import 'mobx';
import 'lz-string';
import 'dayjs';
import 'react-dom';
import 'classnames';
import 'react-is';
import '@loadable/component';
import 'js-beautify';
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 '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';

const i18n = i18n$1.mapEdit;
const prefixCls = 'map-data-model-list';
const DataModelList = observer(({ projectOption }) => {
    const store = useLocalStore(() => {
        return {
            searchText: '',
            renderList: [],
        };
    });
    useMount(() => {
        apiMediaFunc()
            .getOmniMedia(Object.assign({ pageSize: 5000 }, ((projectOption === null || projectOption === void 0 ? void 0 : projectOption.version)
            ? { versionId: projectOption === null || projectOption === void 0 ? void 0 : projectOption.version, targetApp: projectOption === null || projectOption === void 0 ? void 0 : projectOption.targetApp }
            : {})))
            .then((res) => {
            const _res = res.data.result;
            if (_res) {
                const renderList = filter(_res, (li) => li.mediaType === OmniMediaViewGetMediaTypeEnum.Model);
                Promise.all(renderList.map((r) => getSignatureUrl(r === null || r === void 0 ? void 0 : r.preview))).then((urls) => {
                    store.renderList = renderList.map((t, index) => {
                        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                        // @ts-ignore
                        t.displayUrl = urls[index];
                        return t;
                    });
                });
            }
        });
    });
    const { renderList, searchText } = store;
    // 素材库数据
    return (React.createElement("div", { className: prefixCls },
        React.createElement("div", { className: 'mb4' }, i18n.modelList),
        React.createElement(Input, { className: `${prefixCls}-input mb8`, block: true, placeholder: i18n.modelSearch, size: "compact", type: 'assist-bg', value: searchText, onChange: (e) => {
                const target = e.target;
                store.searchText = target.value;
            } }),
        React.createElement("div", { className: `${prefixCls}-list-wrapper` }, map(renderList, (li) => {
            var _a;
            if (searchText) {
                if (((_a = li.name) === null || _a === void 0 ? void 0 : _a.indexOf(searchText)) === -1) {
                    return null;
                }
            }
            return (React.createElement("div", { key: li.id, className: `${prefixCls}-li mb8`, draggable: true, onDragStart: () => {
                    console.log(li, 'li');
                    const node = {
                        name: li.name,
                        id: v4(),
                        url: get(li, 'url') || get(li, 'extra.url'),
                    };
                    const nodeStr = JSON.stringify(node);
                    sessionStorage.setItem(MAP_DRAG_MODEL, nodeStr);
                    $('.dm-map-models-config-li').addClass('can-dragover');
                }, onDragEnd: () => {
                    $('.dm-map-models-config-li').removeClass('can-dragover');
                    $('.dm-map-models-config-li').removeClass('can-dragover');
                } },
                React.createElement("img", { src: getOssUrl(li.displayUrl), alt: li.name }),
                li.name));
        }))));
});
var DataModelList$1 = DataModelList;

export { DataModelList$1 as default };
