function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React from 'react';
import { Spin, Tag } from 'antd';
import { Icon, PisellModal } from '@pisell/materials';
import { ExclamationCircleFilled } from '@ant-design/icons';
import classNames from 'classnames';
import "./index.less";
var DeleteProfileModal = function DeleteProfileModal(_ref) {
  var open = _ref.open,
    loading = _ref.loading,
    submitting = _ref.submitting,
    profileName = _ref.profileName,
    linkedDevices = _ref.linkedDevices,
    translation = _ref.translation,
    getText = _ref.getText,
    onClose = _ref.onClose,
    onConfirm = _ref.onConfirm,
    _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? 'desktop' : _ref$variant;
  var isPhoneVariant = variant === 'phone';
  var hasLinked = linkedDevices.length > 0;
  var renderConfirmBody = function renderConfirmBody() {
    var tpl = getText('pisell2.saas.device-profile.delete.confirm.content');
    var _tpl$split = tpl.split('{ProfileName}'),
      _tpl$split2 = _slicedToArray(_tpl$split, 2),
      before = _tpl$split2[0],
      after = _tpl$split2[1];
    return /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__body"
    }, /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__confirm-text"
    }, before, /*#__PURE__*/React.createElement("strong", null, profileName), after));
  };
  var renderLinkedBody = function renderLinkedBody() {
    var tpl = getText('pisell2.saas.device-profile.delete.linked.content');
    var text = tpl.replace('{ProfileName}', '__PROFILE__').replace('{N}', String(linkedDevices.length));
    var _text$split = text.split('__PROFILE__'),
      _text$split2 = _slicedToArray(_text$split, 2),
      before = _text$split2[0],
      after = _text$split2[1];
    return /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__body"
    }, /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__warning"
    }, /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__warning-title"
    }, /*#__PURE__*/React.createElement(ExclamationCircleFilled, {
      className: "delete-profile-modal__warning-icon"
    }), getText('pisell2.saas.device-profile.delete.linked.title')), /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__warning-content"
    }, before, /*#__PURE__*/React.createElement("strong", null, profileName), after)), /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__devices-label"
    }, getText('pisell2.saas.device-profile.delete.linked.devicesLabel')), /*#__PURE__*/React.createElement("div", {
      className: "delete-profile-modal__devices-list"
    }, linkedDevices.map(function (d) {
      var _d$workarea, _d$workarea2;
      return /*#__PURE__*/React.createElement("div", {
        key: d.id,
        className: "delete-profile-modal__device-row"
      }, /*#__PURE__*/React.createElement("div", {
        className: "delete-profile-modal__device-name"
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "DesktopOutlined"
      }), /*#__PURE__*/React.createElement("span", null, translation(d.name))), d.workarea ? /*#__PURE__*/React.createElement(Tag, {
        key: d === null || d === void 0 || (_d$workarea = d.workarea) === null || _d$workarea === void 0 ? void 0 : _d$workarea.id
      }, translation((_d$workarea2 = d.workarea) === null || _d$workarea2 === void 0 ? void 0 : _d$workarea2.name)) : null);
    })));
  };
  return /*#__PURE__*/React.createElement(PisellModal, {
    open: open,
    onCancel: onClose,
    headerDivider: false,
    footerDivider: false,
    title: getText('pisell2.saas.device-profile.delete.title'),
    okVisible: !hasLinked,
    cancelButtonProps: {
      disabled: submitting
    },
    okButtonProps: {
      danger: true,
      loading: submitting,
      onClick: onConfirm
    },
    cancelText: getText(hasLinked ? 'pisell2.saas.device-profile.delete.button.close' : 'pisell2.saas.device-profile.delete.button.cancel'),
    okText: getText('pisell2.saas.device-profile.delete.button.delete'),
    footer: loading ? null : undefined,
    closable: true,
    width: 520,
    destroyOnClose: true,
    maskClosable: false,
    platform: isPhoneVariant ? 'h5' : undefined,
    mobileModalHeight: isPhoneVariant ? 'auto' : undefined,
    className: classNames('delete-profile-modal', "delete-profile-modal--".concat(variant))
  }, /*#__PURE__*/React.createElement("div", null, loading ? /*#__PURE__*/React.createElement("div", {
    className: "delete-profile-modal__loading"
  }, /*#__PURE__*/React.createElement(Spin, null)) : hasLinked ? renderLinkedBody() : renderConfirmBody()));
};
export default DeleteProfileModal;