"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _react = _interopRequireWildcard(require("react"));

var _axiosClient = _interopRequireDefault(require("../axiosClient"));

var _button = _interopRequireDefault(require("devextreme-react/button"));

var _button2 = _interopRequireDefault(require("devextreme/ui/button"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// import { useSelector } from "react-redux";
// require("./scss/application.scss");
var ComponentSignButton = function ComponentSignButton(_ref) {
  var data = _ref.data,
      _onClick = _ref.onClick,
      user = _ref.user;

  var undoRef = /*#__PURE__*/_react["default"].createRef(); // const userConfiges = useSelector((state) => state.userConfiges);


  var _useState = (0, _react.useState)(false),
      _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
      undoApproveButtonVisibility = _useState2[0],
      setUndoApproveButtonVisibility = _useState2[1];

  var _useState3 = (0, _react.useState)(null),
      _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
      approveBtnIcon = _useState4[0],
      setApproveBtnIcon = _useState4[1];

  var _useState5 = (0, _react.useState)({}),
      _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
      btnStyle = _useState6[0],
      setBtnStyle = _useState6[1];

  var _useState7 = (0, _react.useState)(data.displayName),
      _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
      btnText = _useState8[0],
      setBtnText = _useState8[1];

  var buttonClicked = function buttonClicked(button, status) {
    button.setAttribute('clicked', status);
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "component-sign"
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    className: "CheckButton",
    key: data.id,
    text: btnText,
    style: btnStyle,
    id: "button".concat(data.id),
    name: "button".concat(data.id),
    disabled: data.permissions && data.permissions.findIndex(function (r) {
      return r.key === user.role.id;
    }) >= 0 || data.permissions === undefined || data.permissions.length === 0 ? false : true // icon="check"
    // text={`${userConfiges.auth.currentUser.username}`}
    ,
    hint: "Click to Approve",
    onClick: function onClick(e) {
      _onClick(e, data);

      setBtnText("".concat(data.displayName, " ").concat(user.username));
      buttonClicked(e.element, true);
      setBtnStyle({
        backgroundColor: 'rgba(198, 239, 226, 1)'
      });
      setApproveBtnIcon('check');
      setUndoApproveButtonVisibility(true);
    }
  }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    style: {
      marginLeft: 10
    },
    ref: undoRef,
    id: "undo-".concat(data.id),
    icon: "undo",
    stylingMode: "text",
    visible: undoApproveButtonVisibility,
    hint: "Click to undo the Approve",
    onClick: function onClick(e) {
      var button = _button2["default"].getInstance(document.getElementById('button' + data.id));

      setBtnText(data.displayName);
      buttonClicked(button.element(), false); //setApproveBtnType('normal');

      setBtnStyle({});
      setApproveBtnIcon(null);
      setUndoApproveButtonVisibility(false);
    }
  }));
};

var _default = ComponentSignButton;
exports["default"] = _default;