function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React from 'react';
import { Dropdown } from 'antd';
import { Button, Icon, Tag } from '@pisell/materials';
import { DeleteOutlined, DisconnectOutlined, EditOutlined, MoreOutlined, PlayCircleOutlined } from '@ant-design/icons';
var PeripheralConnectionCard = function PeripheralConnectionCard(_ref) {
  var model = _ref.model,
    getText = _ref.getText,
    onEdit = _ref.onEdit,
    onRemove = _ref.onRemove,
    onRequestDisconnect = _ref.onRequestDisconnect,
    onOpenUsageSelect = _ref.onOpenUsageSelect,
    onTest = _ref.onTest,
    onOpenPhysicalSelect = _ref.onOpenPhysicalSelect,
    onConnect = _ref.onConnect;
  var renderStatusTag = function renderStatusTag() {
    var color = model.status === 'connected' ? 'green' : model.status === 'connecting' ? 'gold' : 'red';
    return /*#__PURE__*/React.createElement(Tag, {
      color: color
    }, getText("pisell2.saas.app-peripheral.status.".concat(model.status)));
  };
  var getActionItems = function getActionItems() {
    return [{
      key: 'edit',
      icon: /*#__PURE__*/React.createElement(EditOutlined, null),
      label: getText('pisell2.saas.app-peripheral.edit'),
      onClick: function onClick() {
        return onEdit(model.connection);
      }
    }].concat(_toConsumableArray(model.canDisconnect ? [{
      key: 'disconnect',
      icon: /*#__PURE__*/React.createElement(DisconnectOutlined, null),
      label: getText('pisell2.saas.app-peripheral.disconnect'),
      onClick: function onClick() {
        return onRequestDisconnect(model.connection);
      }
    }] : []), [{
      key: 'remove',
      icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
      danger: true,
      label: getText('pisell2.saas.app-peripheral.remove'),
      onClick: function onClick() {
        return onRemove(model.connection);
      }
    }]);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card"
  }, /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-icon"
  }, /*#__PURE__*/React.createElement(Icon, {
    type: model.icon
  })), /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-main"
  }, /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-title-row"
  }, /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-title"
  }, model.title), renderStatusTag()), /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-subtitle"
  }, model.subtitle), /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__meta"
  }, /*#__PURE__*/React.createElement("span", null, getText('pisell2.saas.app-peripheral.model'), ":\xA0", model.modelName), /*#__PURE__*/React.createElement("span", {
    className: "saas-app-peripheral__tag"
  }, model.connectionTypeLabel), model.connectionDetail ? /*#__PURE__*/React.createElement("span", {
    className: "saas-app-peripheral__tag"
  }, model.connectionDetail) : null), model.profileLabels.length ? /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__meta"
  }, /*#__PURE__*/React.createElement("span", null, getText('pisell2.saas.app-peripheral.profiles'), ":"), model.profileLabels.map(function (label) {
    return /*#__PURE__*/React.createElement("span", {
      key: String(label),
      className: "saas-app-peripheral__tag"
    }, label);
  })) : null), /*#__PURE__*/React.createElement("div", {
    className: "saas-app-peripheral__card-actions"
  }, model.canTest ? /*#__PURE__*/React.createElement(Button, {
    icon: /*#__PURE__*/React.createElement(PlayCircleOutlined, null),
    onClick: onTest
  }, getText('pisell2.saas.app-peripheral.test')) : model.canConnect ? /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "ApiOutlined"
    }),
    disabled: model.actionDisabled,
    onClick: function onClick() {
      if (model.isUsageAction) {
        onOpenUsageSelect();
        return;
      }
      if (model.isSelectAction) {
        onOpenPhysicalSelect();
        return;
      }
      onConnect();
    }
  }, model.actionText) : null, /*#__PURE__*/React.createElement(Dropdown, {
    menu: {
      items: getActionItems()
    },
    trigger: ['click'],
    placement: "bottomRight"
  }, /*#__PURE__*/React.createElement(Button, {
    type: "text",
    icon: /*#__PURE__*/React.createElement(MoreOutlined, null)
  }))));
};
export default PeripheralConnectionCard;