import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import _extends from '@babel/runtime/helpers/extends';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import React__default, { useMemo, useState } from 'react';
import classnames from 'classnames';
import { useLangDirection } from '../../utils/useLangDirection.js';
import Button from '../Button/Button.js';
import Card from '../Card/Card.js';
import { getUpdatedCardSize, getResizeHandles } from '../../utils/cardUtilityFunctions.js';
import { CARD_SIZES, CARD_ACTIONS } from '../../constants/LayoutConstants.js';
import { CardPropTypes, MapCardPropTypes } from '../../constants/CardPropTypes.js';
import { settings } from '../../constants/Settings.js';
import { mergeRefs } from '../../utils/DragAndDropUtils.js';
import Legend from './Legend.js';
import ZoomControl from './ZoomControl.js';
import MapControls from './MapControls.js';
import { Maximize, Close } from '@carbon/icons-react';

var _excluded = ["children", "mapContainerRef", "availableActions", "size", "mapControls", "isResizable", "isExpanded", "i18n", "id", "isLegendFullWidth", "onZoomIn", "onZoomOut", "stops", "options", "layeredControls", "onCardAction", "isSettingPanelOpen", "settingsContent", "dropRef", "testID", "testId"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = settings.iotPrefix;
var propTypes = _objectSpread(_objectSpread({}, CardPropTypes), MapCardPropTypes);
var defaultProps = {
  isLegendFullWidth: false,
  isSettingPanelOpen: false,
  i18n: {
    cardTitle: 'Card Title',
    zoomIn: 'Zoom In',
    zoomOut: 'Zoom out',
    configurationTitle: 'Map configuration',
    closeSettingsIconText: 'Close',
    expandLabel: 'Expand',
    layerTriggerIconDescription: 'Layered controls',
    legendTitle: 'Legend',
    hideLegend: 'Hide legend',
    showLegend: 'Show legend',
    scrollUp: 'Scroll up',
    scrollDown: 'Scroll down'
  },
  layeredControls: [],
  mapControls: [],
  size: CARD_SIZES.LARGEWIDE,
  stops: [],
  testId: 'map-card'
};
var MapCard = function MapCard(_ref) {
  var children = _ref.children,
    mapContainerRef = _ref.mapContainerRef,
    availableActions = _ref.availableActions,
    size = _ref.size,
    mapControls = _ref.mapControls,
    isResizable = _ref.isResizable,
    isExpanded = _ref.isExpanded,
    i18n = _ref.i18n,
    id = _ref.id,
    isLegendFullWidth = _ref.isLegendFullWidth,
    onZoomIn = _ref.onZoomIn,
    onZoomOut = _ref.onZoomOut,
    stops = _ref.stops;
    _ref.options;
    var layeredControls = _ref.layeredControls,
    onCardAction = _ref.onCardAction,
    isSettingPanelOpen = _ref.isSettingPanelOpen,
    SettingsContent = _ref.settingsContent,
    dropRef = _ref.dropRef,
    testID = _ref.testID,
    testId = _ref.testId,
    others = _objectWithoutProperties(_ref, _excluded);
  var mergedI18n = useMemo(function () {
    return _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  }, [i18n]);
  var langDir = useLangDirection();
  // Checks size property against new size naming convention and reassigns to closest supported size if necessary.
  var newSize = getUpdatedCardSize(size);
  var BASE_CLASS_NAME = "".concat(iotPrefix, "--map");
  var resizeHandles = useMemo(function () {
    return isResizable ? getResizeHandles(children) : [];
  }, [children, isResizable]);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isLegendCollapsed = _useState2[0],
    setIsLegendCollapsed = _useState2[1];
  var tooltipPosition = React__default.useMemo(function () {
    return langDir === 'ltr' ? 'left' : 'right';
  }, [langDir]);
  var controls = mapControls.length || layeredControls.length ? /*#__PURE__*/React__default.createElement(MapControls
  // TODO: remove deprecated 'testID' in v3.
  , {
    testId: "".concat(testID || testId, "-map-controls"),
    controls: mapControls,
    layeredControls: layeredControls,
    tooltipPosition: tooltipPosition,
    i18n: mergedI18n,
    isExpandedMode: isExpanded
  }) : null;
  var myAvailableActions = _objectSpread(_objectSpread({}, availableActions), {}, {
    settings: isExpanded && (availableActions === null || availableActions === void 0 ? void 0 : availableActions.settings)
  });
  return /*#__PURE__*/React__default.createElement(Card, _extends({
    title: mergedI18n.cardTitle,
    size: newSize,
    availableActions: myAvailableActions,
    isResizable: isResizable,
    isExpanded: isExpanded,
    resizeHandles: resizeHandles,
    i18n: mergedI18n,
    id: id,
    renderExpandIcon: Maximize,
    onCardAction: onCardAction,
    contentClassName: "".concat(BASE_CLASS_NAME, "-card-content"),
    className: "".concat(BASE_CLASS_NAME)
    // TODO: remove deprecated 'testID' in v3.
    ,
    testId: testID || testId
  }, others), /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
    ref: mergeRefs(mapContainerRef, dropRef),
    className: classnames("".concat(BASE_CLASS_NAME, "__container"), _defineProperty({}, "".concat(BASE_CLASS_NAME, "__container--open"), isSettingPanelOpen))
  }, children, /*#__PURE__*/React__default.createElement("div", {
    className: classnames("".concat(BASE_CLASS_NAME, "-controls"), _defineProperty(_defineProperty({}, "".concat(BASE_CLASS_NAME, "-controls--has-fullwidth-legend"), isLegendFullWidth && !isLegendCollapsed), "".concat(BASE_CLASS_NAME, "-controls--has-increased-margins"), isExpanded))
  }, controls, /*#__PURE__*/React__default.createElement(ZoomControl
  // TODO: remove deprecated 'testID' in v3.
  , {
    testId: "".concat(testID || testId, "-zoom-control"),
    i18n: {
      zoomIn: mergedI18n.zoomIn,
      zoomOut: mergedI18n.zoomOut
    },
    onZoomIn: onZoomIn,
    onZoomOut: onZoomOut,
    tooltipPosition: tooltipPosition,
    smallButtons: !isExpanded
  })), /*#__PURE__*/React__default.createElement(Legend
  // TODO: remove deprecated 'testID' in v3.
  , {
    testId: "".concat(testID || testId, "-legend"),
    hideLegendText: mergedI18n.hideLegend,
    showLegendText: mergedI18n.showLegend,
    titleText: mergedI18n.legendTitle,
    stops: stops,
    isFullWidth: isLegendFullWidth,
    isCollapsed: isLegendCollapsed,
    increasedMargin: isExpanded,
    onCollapsToggle: function onCollapsToggle() {
      setIsLegendCollapsed(!isLegendCollapsed);
    }
  })), /*#__PURE__*/React__default.createElement("div", {
    "data-testid": "".concat(testID || testId, "-settings"),
    className: classnames("".concat(BASE_CLASS_NAME, "-settings"), _defineProperty({}, "".concat(BASE_CLASS_NAME, "-settings--open"), isSettingPanelOpen))
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(BASE_CLASS_NAME, "-settings-header")
  }, /*#__PURE__*/React__default.createElement("h3", {
    className: "".concat(BASE_CLASS_NAME, "-settings-header__title")
  }, mergedI18n.configurationTitle), /*#__PURE__*/React__default.createElement(Button, {
    className: "".concat(BASE_CLASS_NAME, "-settings-close-btn"),
    kind: "ghost",
    size: "sm",
    hasIconOnly: true,
    renderIcon: Close,
    iconDescription: mergedI18n.closeSettingsIconText,
    onClick: function onClick() {
      onCardAction(id, CARD_ACTIONS.ON_SETTINGS_CLICK);
    }
  })), /*#__PURE__*/React__default.createElement(SettingsContent, null))));
};
MapCard.propTypes = propTypes;
MapCard.defaultProps = defaultProps;
MapCard.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "MapCard",
  "props": {
    "isLegendFullWidth": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "required": false
    },
    "isSettingPanelOpen": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  cardTitle: 'Card Title',\n  zoomIn: 'Zoom In',\n  zoomOut: 'Zoom out',\n  configurationTitle: 'Map configuration',\n  closeSettingsIconText: 'Close',\n  expandLabel: 'Expand',\n  layerTriggerIconDescription: 'Layered controls',\n  legendTitle: 'Legend',\n  hideLegend: 'Hide legend',\n  showLegend: 'Show legend',\n  scrollUp: 'Scroll up',\n  scrollDown: 'Scroll down',\n}",
        "computed": false
      },
      "required": false
    },
    "layeredControls": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "required": false
    },
    "mapControls": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "CARD_SIZES.LARGEWIDE",
        "computed": true
      },
      "required": false
    },
    "stops": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'map-card'",
        "computed": false
      },
      "required": false
    }
  },
  "composes": ["../../constants/CardPropTypes"]
};
var MapCard$1 = MapCard;

export { MapCard$1 as default };
