import { j as __rest, aR as dialogApi, s as __assign, ap as LinkButton, X as map, bF as size, a4 as Tag, aI as drawerApi, $ as find, aC as Select, y as IconButton, at as Icon } from './MapEditView-24782753.js';
import { observer } from 'mobx-react';
import React__default from 'react';
import { t as thumbListContext, a as i18n, b as prefixCls, U as UserManager, C as ConditionPermissionEnum, c as ConditionItemTable, F as FilterOperator } from './index-3505e026.js';
import 'react-dom';
import 'react-dnd-html5-backend';
import classNames from 'classnames';
import 'perfect-scrollbar';
import 'react-virtualized';
import 'maptalks';
import 'lodash';
import 'uuid';
import 'mobx';
import 'lz-string';
import 'dayjs';
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 '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 'turf-point';
import 'decamelize';
import 'rbush';
import 'qs';
import 'maptalks.snap';
import 'react-use';
import 'react-rnd';
import 'react-beautiful-dnd';
import 'react-contextmenu';
import 'coordtransform';
import './compact-6f8b3541.js';
import './useDataValue-8bdb351c.js';
import 'ali-react-table-fork';
import './Transfer-f55a5877.js';
import 'ismobilejs';

var UserItem = observer(function (_a) {
    var _b;
    var _c = _a.users, users = _c === void 0 ? [] : _c, title = _a.title, _d = _a.emotion, emotion = _d === void 0 ? 'success' : _d, restProps = __rest(_a, ["users", "title", "emotion"]);
    var Context = thumbListContext.getContext();
    var value = React__default.useContext(Context);
    var deleteUserUuids = restProps.conditionStore.deleteUserUuids;
    var addUser = React__default.useCallback(function () {
        dialogApi.open({
            title: i18n.collaboration.addMember,
            className: "".concat(prefixCls, "-user-manager-dialog"),
        }, function (onClose) {
            return (React__default.createElement(Context.Provider, { value: value },
                React__default.createElement(UserManager, __assign({ onClose: onClose }, restProps))));
        });
    }, [Context, restProps, value]);
    var tipCls = classNames("".concat(prefixCls, "-condition-item-user-top-tip"), (_b = {},
        _b["".concat(prefixCls, "-condition-item-user-top-tip-").concat(emotion)] = emotion,
        _b));
    return (React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-user") },
        React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-user-top") },
            React__default.createElement("div", null,
                i18n.collaboration.followUser,
                React__default.createElement("span", { className: tipCls }, title),
                i18n.collaboration.theData),
            React__default.createElement(LinkButton, { onClick: addUser, disabled: restProps.permission === ConditionPermissionEnum.editable }, i18n.collaboration.addUser)),
        React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-user-bottom") }, users.length > 0
            ? map(users, function (user) {
                return size(user.children) > 0 ? (React__default.createElement(Tag, { "data-value": user.key, tag: user.title, closable: true, color: 'blue-700' })) : (React__default.createElement(Tag, { tag: user.title, closable: true, onClickClose: function () {
                        deleteUserUuids(user.key + '', restProps.permission);
                    } }));
            })
            : i18n.collaboration.addUser)));
});
UserItem.displayName = 'UserItem';

var ConditionItem = observer(function (_a) {
    var conditionStore = _a.conditionStore, isLast = _a.isLast, index = _a.index;
    var Context = thumbListContext.getContext();
    var value = React__default.useContext(Context);
    var store = value.store;
    var addCondition = store.addCondition, allOptionMap = store.allOptionMap, splitFields = store.splitFields, 
    // usedValMap,
    fieldLoading = store.fieldLoading, deleteConditionStore = store.deleteConditionStore;
    var _b = conditionStore.showRead, showRead = _b === void 0 ? false : _b, _c = conditionStore.items, items = _c === void 0 ? [] : _c, updateItems = conditionStore.updateItems, _d = conditionStore.updateUsers, updateUsers = _d === void 0 ? [] : _d, openShowRead = conditionStore.openShowRead, _e = conditionStore.readUsers, readUsers = _e === void 0 ? [] : _e;
    var onPreview = React__default.useCallback(function () {
        drawerApi.open(function (onClose) {
            return (React__default.createElement(Context.Provider, { value: value },
                React__default.createElement(ConditionItemTable, { conditionStore: conditionStore, onClose: onClose })));
        }, {
            width: 917,
            maskClosable: true,
        });
    }, [Context, value, conditionStore]);
    var canPreview = conditionStore.hasValItems.length > 0;
    var deleteSelf = React__default.useCallback(function () {
        deleteConditionStore(index);
    }, [deleteConditionStore, index]);
    return (React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item"), id: "".concat(prefixCls, "-condition-item-").concat(index) },
        React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header") },
            React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-items") }, map(splitFields, function (sf) {
                var _a;
                var conditionItem = find(items, { column: sf });
                //TODO 暂不支持disabled，打算先去除掉
                // const options = map(allOptionMap[sf], (it) => {
                //   return {
                //     label: it,
                //     value: it,
                //     disabled: usedValMap[sf]?.includes(it) && !conditionItem?.value.includes(it),
                //   };
                // });
                var options = map(
                // filter(allOptionMap[sf], (it) => {
                //   const disabled =
                //     usedValMap[sf]?.includes(it) && !conditionItem?.values?.includes(it);
                //   return !disabled;
                // }),
                allOptionMap[sf], function (it) { return ({
                    label: it,
                    value: it,
                }); });
                return (React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-item"), key: sf },
                    React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-top") },
                        "\u5F53 ",
                        React__default.createElement("span", null, sf),
                        " ="),
                    React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-bottom") },
                        React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-left") },
                            React__default.createElement(Select, { placeholder: i18n.collaboration.selectPh, mode: "multiple", showSearch: true, options: options, 
                                // createAble
                                loading: fieldLoading, getNewOptionTemp: function (value) { return "".concat(i18n.collaboration.create, "\u201C").concat(value, "\u201D"); }, value: (_a = conditionItem === null || conditionItem === void 0 ? void 0 : conditionItem.values) !== null && _a !== void 0 ? _a : [], onChange: function (values) {
                                    var item = { column: sf, values: values, operator: FilterOperator.equal };
                                    updateItems(item, 'add');
                                } }),
                            "\u65F6"))));
            })),
            React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-header-icons") },
                React__default.createElement(IconButton, { icon: canPreview ? 'visibility-on' : 'visibility-off', type: "only-icon", onClick: canPreview ? onPreview : undefined, disabled: !canPreview }),
                React__default.createElement(IconButton, { icon: "delete-2", type: "only-icon", onClick: deleteSelf }))),
        React__default.createElement("div", { className: "".concat(prefixCls, "-condition-item-content") },
            React__default.createElement(UserItem, { title: i18n.collaboration.editable, users: updateUsers, permission: ConditionPermissionEnum.editable, conditionStore: conditionStore }),
            showRead ? (React__default.createElement(UserItem, { title: i18n.collaboration.onlyView, users: readUsers, permission: ConditionPermissionEnum.onlyView, emotion: "warning", conditionStore: conditionStore })) : (React__default.createElement(LinkButton, { className: "".concat(prefixCls, "-condition-add-prvi"), onClick: openShowRead },
                React__default.createElement(Icon, { icon: "add", size: 16 }),
                i18n.collaboration.addPrivilegeGroup))),
        isLast && (React__default.createElement(LinkButton, { className: "".concat(prefixCls, "-condition-add"), onClick: addCondition },
            React__default.createElement(Icon, { icon: "add", size: 16 }),
            i18n.collaboration.addCondition))));
});
ConditionItem.displayName = 'ConditionItem';

export { ConditionItem as default };
