import * as React from 'react';
import classNames from 'classnames';
import { w as appContext, I as Icon, i as __read, a6 as Input, y as IconButton } from './MapEditView-24782753.js';
import { observer } from 'mobx-react';
import { useClickAway } from 'react-use';

var prefixCls$1 = 'dm-map-visual-card-simple-eye';
var SimpleEye = observer(function (props) {
    var _a;
    var _b = props.className, className = _b === void 0 ? '' : _b, onClick = props.onClick, visible = props.visible;
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var customerIcons = routeStore.customerIcons;
    var showIcon = (customerIcons === null || customerIcons === void 0 ? void 0 : customerIcons.showIcon) || 'visibility-on';
    var hideIcon = (customerIcons === null || customerIcons === void 0 ? void 0 : customerIcons.hideIcon) || 'visibility-off';
    return (React.createElement("div", { className: classNames("".concat(className, " ").concat(prefixCls$1), (_a = {},
            _a["".concat(prefixCls$1, "-disable")] = !visible,
            _a)), onClick: onClick }, visible ? React.createElement(Icon, { icon: showIcon, size: 16 }) : React.createElement(Icon, { icon: hideIcon, size: 16 })));
});
SimpleEye.whyDidYouRender = true;
SimpleEye.displayName = 'SimpleEye';

var prefixCls = 'dm-map-visual-list-item';
var useRef = React.useRef, useState = React.useState;
var MapVisualListItem = React.memo(function (props) {
    var _a, _b;
    var _c = props || {}, text = _c.text, onSelect = _c.onSelect, onDelete = _c.onDelete, setName = _c.setName, isSimpleCardsMode = _c.isSimpleCardsMode;
    var _d = __read(useState(false), 2), edit = _d[0], setEdit = _d[1];
    var refTime = useRef();
    var refDiv = useRef(null);
    useClickAway(refDiv, function () {
        setEdit(false);
    });
    var _onSelect = function () {
        refTime.current && clearTimeout(refTime.current);
        refTime.current = window.setTimeout(function () {
            onSelect && onSelect();
        }, 300);
    };
    var _onDoubleClick = function () {
        refTime.current && clearTimeout(refTime.current);
        setEdit(true);
    };
    var _onPressEnter = function (e) {
        var target = e.target;
        var value = target.value;
        setEdit(false);
        setName && setName(value);
    };
    var _onBlur = function (e) {
        var target = e.target;
        var value = target.value;
        setEdit(false);
        setName && setName(value);
    };
    React.useEffect(function () {
        var _a, _b;
        if (edit) {
            (_b = (_a = refDiv.current) === null || _a === void 0 ? void 0 : _a.querySelector('input')) === null || _b === void 0 ? void 0 : _b.select();
        }
    }, [edit]);
    return (React.createElement(React.Fragment, null,
        React.createElement("div", { className: classNames("".concat(prefixCls, "-border"), (_a = {},
                _a["".concat(prefixCls, "-border-detail")] = !isSimpleCardsMode,
                _a)) }),
        React.createElement("div", { className: prefixCls, ref: refDiv },
            React.createElement("div", { className: classNames("".concat(prefixCls, "-text"), (_b = {},
                    _b["".concat(prefixCls, "-text-detail")] = !isSimpleCardsMode,
                    _b)) },
                edit ? (React.createElement(Input, { allowClear: false, className: "".concat(prefixCls, "-input"), type: "menu-bg", placeholder: text, autoFocus: true, defaultValue: text, onPressEnter: _onPressEnter, onBlur: _onBlur })) : (React.createElement("div", { className: "".concat(prefixCls, "-name"), onClick: _onSelect, onDoubleClick: _onDoubleClick }, text)),
                onDelete && (React.createElement(IconButton, { className: "".concat(prefixCls, "-delete-icon"), icon: "close", type: "only-icon", onClick: onDelete }))))));
});

export { MapVisualListItem as M, SimpleEye as S };
