import { aP as createI18n, aQ as LANGUAGE, j as __rest, au as Checkbox, s as __assign, am as LazyLoad, i as __read, lj as ColorPanel, b as __awaiter, c as __generator, lk as setFavorColorsPref, ll as initFavoriteColorPref, lm as getFavoriteColorPref } from './MapEditView-24782753.js';
import * as React from 'react';
import React__default from 'react';
import 'maptalks';
import 'lodash';
import 'uuid';
import 'mobx';
import 'lz-string';
import 'dayjs';
import 'react-dom';
import 'classnames';
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 'perfect-scrollbar';
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 'react-virtualized';
import 'turf-point';
import 'mobx-react';
import 'decamelize';
import 'rbush';
import 'qs';
import 'maptalks.snap';
import 'react-use';
import 'react-rnd';
import 'react-beautiful-dnd';

var cn = {
    themeColorPicker: {
        themeLabel: '跟随主题色',
    },
};

var en = {
    themeColorPicker: {
        themeLabel: 'Follow theme',
    },
};

var localeMap = {
    'zh-CN': cn,
    'en-US': en,
};
var locale = localeMap[LANGUAGE];
var i18n = createI18n({
    defaultLocale: { key: LANGUAGE, values: locale },
    // loader: (name) => import(`../../languages/${name}`),
});
i18n._.locale(LANGUAGE);

/** Custom Theme Footer */
var Footer = function (props) {
    var prefixCls = props.prefixCls, restProps = __rest(props, ["prefixCls"]);
    return (React__default.createElement(React__default.Fragment, null,
        React__default.createElement("div", { className: "".concat(prefixCls, "-divider") }),
        React__default.createElement(Checkbox, __assign({}, restProps, { className: "".concat(prefixCls, "-checkbox"), title: i18n.themeColorPicker.themeLabel }))));
};

var ColorPicker = LazyLoad(function () { return import('./index-9909b609.js'); });
var prefixCls = 'dm-theme-color-picker';
var ThemeColorPicker = function (props) {
    var color = props.color, _a = props.showfollowTheme, showfollowTheme = _a === void 0 ? false : _a, _b = props.defaultFollowThemeValue, defaultFollowThemeValue = _b === void 0 ? false : _b, followThemeValue = props.followThemeValue, onFollowThemeChange = props.onFollowThemeChange, restProps = __rest(props, ["color", "showfollowTheme", "defaultFollowThemeValue", "followThemeValue", "onFollowThemeChange"]);
    var _c = __read(React__default.useState(defaultFollowThemeValue), 2), _ftv = _c[0], _setFtv = _c[1];
    var _onFtvChange = React__default.useCallback(function (checked) {
        var isControlled = typeof followThemeValue === 'undefined';
        if (isControlled) {
            _setFtv(checked);
        }
        if (onFollowThemeChange) {
            onFollowThemeChange(isControlled ? checked : !checked, color);
        }
    }, [color, onFollowThemeChange, followThemeValue]);
    return (React__default.createElement(ColorPicker, __assign({}, restProps, { color: color, footer: function () {
            return showfollowTheme ? (React__default.createElement(Footer, { prefixCls: prefixCls, checked: _ftv, onChange: _onFtvChange })) : null;
        }, disabledPanel: showfollowTheme && _ftv })));
};

var useFavors = function (onChangeColors) {
    var _a = __read(React.useState([]), 2), favors = _a[0], setFavors = _a[1];
    // Init Favor from apis
    var _getFavorColorsPref = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
        var res;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    initFavoriteColorPref();
                    return [4 /*yield*/, getFavoriteColorPref()];
                case 1:
                    res = _a.sent();
                    setFavors(res);
                    return [2 /*return*/];
            }
        });
    }); }, []);
    // set Favor to apis
    var _onChangeColors = React.useCallback(function (colors) {
        setFavorColorsPref(colors).then(function () {
            setFavors(colors);
        });
        onChangeColors && onChangeColors(colors);
    }, [onChangeColors]);
    React.useEffect(function () {
        _getFavorColorsPref();
    }, [_getFavorColorsPref]);
    return {
        favors: favors,
        onChangeColors: _onChangeColors,
    };
};
var ColorPickerWrapper = function (props) {
    var onChangeColorsProps = props.onChangeColors, colorPickerProps = __rest(props, ["onChangeColors"]);
    var _a = useFavors(onChangeColorsProps), favors = _a.favors, onChangeColors = _a.onChangeColors;
    return React.createElement(ThemeColorPicker, __assign({}, colorPickerProps, { favors: favors, onChangeColors: onChangeColors }));
};
var ColorPanelWrapper = function (props) {
    var onChangeColorsProps = props.onChangeColors, colorPanelProps = __rest(props, ["onChangeColors"]);
    var _a = useFavors(onChangeColorsProps), favors = _a.favors, onChangeColors = _a.onChangeColors;
    return React.createElement(ColorPanel, __assign({}, colorPanelProps, { favors: favors, onChangeColors: onChangeColors }));
};

export { ColorPanelWrapper, ColorPickerWrapper as default };
