import { d as __rest, aM as dialogApi, ak as LinkButton, O as map, bz as size, $ as Tag, aD as drawerApi, U as find, aw as Select, s as IconButton, ao as Icon } from './MapEditView-f6381866.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-0b8bebb4.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 '@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-f89fbdd0.js';
import './useDataValue-6bd3790f.js';
import 'ali-react-table-fork';
import './Transfer-b219601e.js';
import 'ismobilejs';

const UserItem = observer((_a) => {
    var { users = [], title, emotion = 'success' } = _a, restProps = __rest(_a, ["users", "title", "emotion"]);
    const Context = thumbListContext.getContext();
    const value = React__default.useContext(Context);
    const { deleteUserUuids } = restProps.conditionStore;
    const addUser = React__default.useCallback(() => {
        dialogApi.open({
            title: i18n.collaboration.addMember,
            className: `${prefixCls}-user-manager-dialog`,
        }, (onClose) => {
            return (React__default.createElement(Context.Provider, { value: value },
                React__default.createElement(UserManager, Object.assign({ onClose: onClose }, restProps))));
        });
    }, [Context, restProps, value]);
    const tipCls = classNames(`${prefixCls}-condition-item-user-top-tip`, {
        [`${prefixCls}-condition-item-user-top-tip-${emotion}`]: emotion,
    });
    return (React__default.createElement("div", { className: `${prefixCls}-condition-item-user` },
        React__default.createElement("div", { className: `${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: `${prefixCls}-condition-item-user-bottom` }, users.length > 0
            ? map(users, (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: () => {
                        deleteUserUuids(user.key + '', restProps.permission);
                    } }));
            })
            : i18n.collaboration.addUser)));
});
UserItem.displayName = 'UserItem';

const ConditionItem = observer(({ conditionStore, isLast, index }) => {
    const Context = thumbListContext.getContext();
    const value = React__default.useContext(Context);
    const { store } = value;
    const { addCondition, allOptionMap, splitFields, 
    // usedValMap,
    fieldLoading, deleteConditionStore, } = store;
    const { showRead = false, items = [], updateItems, updateUsers = [], openShowRead, readUsers = [], } = conditionStore;
    const onPreview = React__default.useCallback(() => {
        drawerApi.open((onClose) => {
            return (React__default.createElement(Context.Provider, { value: value },
                React__default.createElement(ConditionItemTable, { conditionStore: conditionStore, onClose: onClose })));
        }, {
            width: 917,
            maskClosable: true,
        });
    }, [Context, value, conditionStore]);
    const canPreview = conditionStore.hasValItems.length > 0;
    const deleteSelf = React__default.useCallback(() => {
        deleteConditionStore(index);
    }, [deleteConditionStore, index]);
    return (React__default.createElement("div", { className: `${prefixCls}-condition-item`, id: `${prefixCls}-condition-item-${index}` },
        React__default.createElement("div", { className: `${prefixCls}-condition-item-header` },
            React__default.createElement("div", { className: `${prefixCls}-condition-item-header-items` }, map(splitFields, (sf) => {
                var _a;
                const 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),
                //   };
                // });
                const options = map(
                // filter(allOptionMap[sf], (it) => {
                //   const disabled =
                //     usedValMap[sf]?.includes(it) && !conditionItem?.values?.includes(it);
                //   return !disabled;
                // }),
                allOptionMap[sf], (it) => ({
                    label: it,
                    value: it,
                }));
                return (React__default.createElement("div", { className: `${prefixCls}-condition-item-header-item`, key: sf },
                    React__default.createElement("div", { className: `${prefixCls}-condition-item-header-top` },
                        "\u5F53 ",
                        React__default.createElement("span", null, sf),
                        " ="),
                    React__default.createElement("div", { className: `${prefixCls}-condition-item-header-bottom` },
                        React__default.createElement("div", { className: `${prefixCls}-condition-item-header-left` },
                            React__default.createElement(Select, { placeholder: i18n.collaboration.selectPh, mode: "multiple", showSearch: true, options: options, 
                                // createAble
                                loading: fieldLoading, getNewOptionTemp: (value) => `${i18n.collaboration.create}“${value}”`, value: (_a = conditionItem === null || conditionItem === void 0 ? void 0 : conditionItem.values) !== null && _a !== void 0 ? _a : [], onChange: (values) => {
                                    const item = { column: sf, values, operator: FilterOperator.equal };
                                    updateItems(item, 'add');
                                } }),
                            "\u65F6"))));
            })),
            React__default.createElement("div", { className: `${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: `${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: `${prefixCls}-condition-add-prvi`, onClick: openShowRead },
                React__default.createElement(Icon, { icon: "add", size: 16 }),
                i18n.collaboration.addPrivilegeGroup))),
        isLast && (React__default.createElement(LinkButton, { className: `${prefixCls}-condition-add`, onClick: addCondition },
            React__default.createElement(Icon, { icon: "add", size: 16 }),
            i18n.collaboration.addCondition))));
});
ConditionItem.displayName = 'ConditionItem';

export { ConditionItem as default };
