"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _ = require("../..");
var _TextButtonCard = _interopRequireDefault(require("./TextButtonCard"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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; }
var AbsoluteFlexbox = (0, _styledComponents.default)(_.Flexbox).withConfig({
  displayName: "CheckListStep__AbsoluteFlexbox",
  componentId: "sc-12u0g75-0"
})(["border-radius:", "px;background:", ";padding:", "px;position:absolute;left:0;right:0;top:0;bottom:0;"], function (t) {
  return t.theme.spacing.unit(1);
}, function (t) {
  return t.theme.colorTokens.neutral.background_default;
}, function (t) {
  return t.theme.spacing.unit(3);
});
var StyledButton = (0, _styledComponents.default)(_.Button).withConfig({
  displayName: "CheckListStep__StyledButton",
  componentId: "sc-12u0g75-1"
})(["background-color:", ";"], function (t) {
  return t.theme.colorTokens.error.background_default;
});
var TwoButtonBox = _styledComponents.default.div.withConfig({
  displayName: "CheckListStep__TwoButtonBox",
  componentId: "sc-12u0g75-2"
})(["align-items:center;display:flex;flex-basis:", "px;flex-grow:1;gap:", "px;justify-content:flex-end;padding-left:", "px;& button,& a{flex-basis:50%;flex-shrink:0;}"], function (t) {
  return t.theme.spacing.unit(55);
}, function (t) {
  return t.theme.spacing.unit(3);
}, function (t) {
  return t.theme.spacing.unit(3);
});
var CheckListStep = function CheckListStep(_ref) {
  var task = _ref.task,
    taskInfo = _ref.taskInfo,
    _ref$dismissLabel = _ref.dismissLabel,
    dismissLabel = _ref$dismissLabel === void 0 ? 'Dismiss' : _ref$dismissLabel,
    _ref$dismissQuestion = _ref.dismissQuestion,
    dismissQuestion = _ref$dismissQuestion === void 0 ? 'Dismiss?' : _ref$dismissQuestion,
    _ref$dismissCancelLab = _ref.dismissCancelLabel,
    dismissCancelLabel = _ref$dismissCancelLab === void 0 ? 'Cancel' : _ref$dismissCancelLab,
    _ref$dismissConfirmLa = _ref.dismissConfirmLabel,
    dismissConfirmLabel = _ref$dismissConfirmLa === void 0 ? 'Confirm' : _ref$dismissConfirmLa,
    displayMode = _ref.displayMode;
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    dismissMode = _useState2[0],
    setDismissMode = _useState2[1];
  var isDrawer = displayMode === 'DRAWER';
  var isMobile = (0, _.useMedia)(function (theme) {
    return theme.media.lessThan(theme.breakpoints.sm);
  });
  var isCompleted = task.taskState === 'COMPLETED' || task.taskState === 'DISMISSED';
  var taskState = task.taskState,
    percentage = task.percentage;
  var _ref2 = taskInfo || {},
    onDismiss = _ref2.onDismiss,
    startAction = _ref2.startAction,
    icon = _ref2.icon,
    title = _ref2.title,
    description = _ref2.description,
    customPercentage = _ref2.customPercentage;
  var getPercentage = percentage || customPercentage;
  var buttons = isDrawer && taskState !== 'COMPLETED' && taskState !== 'DISMISSED' && _react.default.createElement(TwoButtonBox, null, _react.default.createElement(_.Button, {
    variant: "neutral",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    },
    size: "m",
    fullWidth: true,
    onClick: function onClick() {
      return setDismissMode(true);
    }
  }, dismissLabel), startAction && _react.default.createElement(_.Button.Pill, _extends({
    variant: "secondary",
    size: "m",
    fullWidth: true
  }, startAction), startAction.label));
  var dialog = isDrawer && dismissMode && _react.default.createElement(AbsoluteFlexbox, {
    container: true,
    wrap: "wrap",
    gap: 3,
    alignContent: "center",
    alignItems: "center"
  }, _react.default.createElement(_.Flexbox, {
    item: true,
    container: true,
    justifyContent: "center",
    alignItems: "center",
    shrink: 0,
    grow: 1,
    basis: "320px"
  }, _react.default.createElement(_.Typography, {
    type: "primary",
    weight: "bold"
  }, dismissQuestion)), _react.default.createElement(TwoButtonBox, null, _react.default.createElement(_.Button, {
    variant: "secondary",
    size: "m",
    fullWidth: true,
    onClick: function onClick() {
      return setDismissMode(false);
    }
  }, dismissCancelLabel), _react.default.createElement(StyledButton, {
    variant: "negative",
    size: "m",
    fullWidth: true,
    onClick: onDismiss
  }, dismissConfirmLabel)));
  return _react.default.createElement(_TextButtonCard.default, {
    titleIcon: icon || _react.default.createElement(_.Icon.Lightbulb24, null),
    title: title || 'Default title',
    titleBadgeText: !isCompleted ? "+".concat(getPercentage, "%") : undefined,
    description: description || 'Default description',
    buttonText: !isDrawer && !isMobile && startAction ? startAction.label : '',
    action: !isDrawer || isDrawer && isCompleted ? startAction : undefined,
    statusIcon: isDrawer && isCompleted && _react.default.createElement(_.Icon.CheckCircleFill24, null)
  }, buttons, dialog);
};
var _default = exports.default = CheckListStep;