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; }
import React, { useState } from 'react';
import styled from 'styled-components';
import { Button, Flexbox, Icon, Typography, useMedia } from '../..';
import TextButtonCard from './TextButtonCard';
var AbsoluteFlexbox = styled(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 = styled(Button).withConfig({
  displayName: "CheckListStep__StyledButton",
  componentId: "sc-12u0g75-1"
})(["background-color:", ";"], function (t) {
  return t.theme.colorTokens.error.background_default;
});
var TwoButtonBox = styled.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 = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    dismissMode = _useState2[0],
    setDismissMode = _useState2[1];
  var isDrawer = displayMode === 'DRAWER';
  var isMobile = 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.createElement(TwoButtonBox, null, React.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.createElement(Button.Pill, _extends({
    variant: "secondary",
    size: "m",
    fullWidth: true
  }, startAction), startAction.label));
  var dialog = isDrawer && dismissMode && React.createElement(AbsoluteFlexbox, {
    container: true,
    wrap: "wrap",
    gap: 3,
    alignContent: "center",
    alignItems: "center"
  }, React.createElement(Flexbox, {
    item: true,
    container: true,
    justifyContent: "center",
    alignItems: "center",
    shrink: 0,
    grow: 1,
    basis: "320px"
  }, React.createElement(Typography, {
    type: "primary",
    weight: "bold"
  }, dismissQuestion)), React.createElement(TwoButtonBox, null, React.createElement(Button, {
    variant: "secondary",
    size: "m",
    fullWidth: true,
    onClick: function onClick() {
      return setDismissMode(false);
    }
  }, dismissCancelLabel), React.createElement(StyledButton, {
    variant: "negative",
    size: "m",
    fullWidth: true,
    onClick: onDismiss
  }, dismissConfirmLabel)));
  return React.createElement(TextButtonCard, {
    titleIcon: icon || React.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.createElement(Icon.CheckCircleFill24, null)
  }, buttons, dialog);
};
export default CheckListStep;