var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import Icon from "../../../icon";
import map from 'lodash/map';
import { Dropdown } from "../../../dropdown";
import classNames from 'classnames';
import { ICON_GEOMETRY_TRY_MAP } from "../../constants";
export var prefixCls = "dmc-global-filter-sf";

var PackageDropDown = function PackageDropDown(_a) {
  var currentPackage = _a.currentPackage,
      packages = _a.packages,
      changeCurrentPackage = _a.changeCurrentPackage;

  var _b = currentPackage !== null && currentPackage !== void 0 ? currentPackage : {},
      objectType = _b.objectType,
      _c = _b.geometryType,
      geometryType = _c === void 0 ? 'point' : _c,
      packageUuid = _b.packageUuid;

  var overlay = React.useCallback(function () {
    return _jsx("ul", __assign({
      className: "dmc-menu dmc-menu-vertical",
      role: "menu"
    }, {
      children: map(packages, function (item) {
        var _a;

        var _b;

        var itemCls = classNames('dmc-dropmenu-menu-item', (_a = {}, _a["dmc-dropmenu-menu-item-actived"] = packageUuid === item.packageUuid, _a));

        var onClick = function onClick() {
          changeCurrentPackage && changeCurrentPackage(item);
        };

        return _jsx("li", __assign({
          className: "dmc-menu-item",
          role: "menuitem",
          onClick: onClick
        }, {
          children: _jsxs("div", __assign({
            className: itemCls
          }, {
            children: [_jsx(Icon, {
              icon: "done-check",
              className: "dmc-dropmenu-drop-icon"
            }, void 0), _jsx(Icon, {
              icon: ICON_GEOMETRY_TRY_MAP[(_b = item.geometryType) !== null && _b !== void 0 ? _b : 'point'],
              size: 16
            }, void 0), item.objectType]
          }), void 0)
        }), void 0);
      })
    }), void 0);
  }, [changeCurrentPackage, packageUuid, packages]);
  return currentPackage ? _jsxs(React.Fragment, {
    children: [_jsx(Dropdown, __assign({
      trigger: "click",
      placement: "bottomLeft",
      overlay: overlay
    }, {
      children: _jsx("div", __assign({
        style: {
          flexShrink: 0
        }
      }, {
        children: _jsxs("div", __assign({
          className: prefixCls + "-item"
        }, {
          children: [_jsx(Icon, {
            icon: ICON_GEOMETRY_TRY_MAP[geometryType]
          }, void 0), _jsx("div", __assign({
            className: prefixCls + "-item-text"
          }, {
            children: objectType
          }), void 0), _jsx(Icon, {
            icon: "chevron-down",
            size: 12
          }, void 0)]
        }), void 0)
      }), void 0)
    }), void 0), _jsx("div", {
      className: prefixCls + "-item-split-line"
    }, void 0)]
  }, void 0) : null;
};

export default PackageDropDown;

