/**
 * amis v3.5.1
 * build time: 2023-11-02
 * Copyright 2018-2023 baidu
 */

import { __extends, __assign, __decorate, __metadata } from 'tslib';
import React from 'react';
import { isMobile, Overlay, PopOver, filter, autobind, FormItem } from 'amis-core';
import { Icon, BaiduMapPicker, Alert2, LocationPicker } from 'amis-ui';
import { supportStatic } from './StaticHoc.js';

var LocationControl = /** @class */ (function (_super) {
    __extends(LocationControl, _super);
    function LocationControl() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.domRef = React.createRef();
        _this.state = {
            isOpened: false
        };
        return _this;
    }
    LocationControl.prototype.close = function () {
        this.setState({
            isOpened: false
        });
    };
    LocationControl.prototype.open = function () {
        this.setState({
            isOpened: true
        });
    };
    LocationControl.prototype.handleClick = function () {
        this.state.isOpened ? this.close() : this.open();
    };
    LocationControl.prototype.getParent = function () {
        var _a;
        return (_a = this.domRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
    };
    LocationControl.prototype.getTarget = function () {
        return this.domRef.current;
    };
    LocationControl.prototype.renderStatic = function (displayValue) {
        var _a;
        if (displayValue === void 0) { displayValue = '-'; }
        var _b = this.props, cx = _b.classnames, value = _b.value, vendor = _b.vendor, ak = _b.ak, coordinatesType = _b.coordinatesType, popOverContainer = _b.popOverContainer;
        var __ = this.props.translate;
        if (!value) {
            return React.createElement(React.Fragment, null, displayValue);
        }
        return (React.createElement("div", { className: this.props.classnames('LocationControl', {
                'is-mobile': isMobile()
            }), ref: this.domRef },
            React.createElement("span", null, value.address),
            React.createElement("a", { className: cx('LocationPicker-toggler', 'ml-1'), onClick: this.handleClick },
                React.createElement(Icon, { icon: "location", className: "icon" })),
            React.createElement(Overlay, { target: this.getTarget, container: popOverContainer || this.getParent, rootClose: false, show: this.state.isOpened },
                React.createElement(PopOver, { className: cx('LocationPicker-popover'), onHide: this.close, overlay: true, style: { width: (_a = this.getTarget()) === null || _a === void 0 ? void 0 : _a.offsetWidth } }, vendor === 'baidu' ? (React.createElement(BaiduMapPicker, { ak: ak, value: value, coordinatesType: coordinatesType })) : (React.createElement(Alert2, null, __('{{vendor}} 地图控件不支持', { vendor: vendor })))))));
    };
    LocationControl.prototype.render = function () {
        this.props.style;
        return (React.createElement("div", { className: this.props.classnames('LocationControl', {
                'is-mobile': isMobile()
            }) },
            React.createElement(LocationPicker, __assign({}, this.props, { ak: filter(this.props.ak, this.props.data) }))));
    };
    LocationControl.defaultProps = {
        vendor: 'baidu',
        coordinatesType: 'bd09'
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "close", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "open", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "handleClick", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "getParent", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "getTarget", null);
    __decorate([
        supportStatic(),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], LocationControl.prototype, "render", null);
    return LocationControl;
}(React.Component));
/** @class */ ((function (_super) {
    __extends(LocationRenderer, _super);
    function LocationRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    LocationRenderer = __decorate([
        FormItem({
            type: 'location-picker'
        })
    ], LocationRenderer);
    return LocationRenderer;
})(LocationControl));

export { LocationControl };
window.amisVersionInfo={version:'3.5.1',buildTime:'2023-11-02'};
