"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkMXOHFF6Ijs = require('./chunk-MXOHFF6I.js');


var _chunkBMDB3QCEjs = require('./chunk-BMDB3QCE.js');


var _chunkPUGD275Hjs = require('./chunk-PUGD275H.js');


var _chunk426N5EH7js = require('./chunk-426N5EH7.js');


var _chunkHNNL5DW4js = require('./chunk-HNNL5DW4.js');


var _chunkUNMRC26Sjs = require('./chunk-UNMRC26S.js');


var _chunkR3HOXLXLjs = require('./chunk-R3HOXLXL.js');

// tmp-babel/profiles/web/ProfileComponent/ReportButtonWithDialog/components/ReportDialogContent.js
var _react = require('react');
var _icons = require('@baseapp-frontend/design-system/components/web/icons');
var _web = require('@baseapp-frontend/design-system/hooks/web');
var _material = require('@mui/material');
var _reactrelay = require('react-relay');
var _jsxruntime = require('react/jsx-runtime');
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
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 = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var ReportDialogContent = function ReportDialogContent2(_ref) {
  var _reportType$subTypes2, _steps$find;
  var targetId = _ref.targetId, handleClose = _ref.handleClose;
  var _useLazyLoadQuery = _reactrelay.useLazyLoadQuery.call(void 0, _chunkR3HOXLXLjs.ReportTypeListQuery, {
    topLevelOnly: true,
    targetObjectId: targetId
  }), allReportTypes = _useLazyLoadQuery.allReportTypes;
  var _useState = _react.useState.call(void 0, _chunkHNNL5DW4js.STEPS.report), _useState2 = _slicedToArray(_useState, 2), currentStep = _useState2[0], setCurrentStep = _useState2[1];
  var _useState3 = _react.useState.call(void 0, ), _useState4 = _slicedToArray(_useState3, 2), reportType = _useState4[0], setReportType = _useState4[1];
  var _useState5 = _react.useState.call(void 0, ), _useState6 = _slicedToArray(_useState5, 2), reportSubType = _useState6[0], setReportSubType = _useState6[1];
  var _useState7 = _react.useState.call(void 0, ""), _useState8 = _slicedToArray(_useState7, 2), reportText = _useState8[0], setReportText = _useState8[1];
  var smDown = _web.useResponsive.call(void 0, "down", "sm");
  var _useReportCreateMutat = _chunkUNMRC26Sjs.useReportCreateMutation.call(void 0, ), _useReportCreateMutat2 = _slicedToArray(_useReportCreateMutat, 2), commitMutation = _useReportCreateMutat2[0], isMutationInFlight = _useReportCreateMutat2[1];
  var reportTypes = _react.useMemo.call(void 0, function() {
    var _allReportTypes$edges;
    return (allReportTypes === null || allReportTypes === void 0 || (_allReportTypes$edges = allReportTypes.edges) === null || _allReportTypes$edges === void 0 ? void 0 : _allReportTypes$edges.filter(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    }).map(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    }).sort(function(a, b) {
      if (!a) return -1;
      if (!b) return 1;
      if (a.key === "other") return 1;
      if (b.key === "other") return -1;
      return a.key > b.key ? 1 : -1;
    })) || [];
  }, [allReportTypes === null || allReportTypes === void 0 ? void 0 : allReportTypes.edges]);
  var subTypes = _react.useMemo.call(void 0, function() {
    var _reportType$subTypes;
    return (reportType === null || reportType === void 0 || (_reportType$subTypes = reportType.subTypes) === null || _reportType$subTypes === void 0 || (_reportType$subTypes = _reportType$subTypes.edges) === null || _reportType$subTypes === void 0 ? void 0 : _reportType$subTypes.filter(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    }).map(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    })) || [];
  }, [reportType === null || reportType === void 0 || (_reportType$subTypes2 = reportType.subTypes) === null || _reportType$subTypes2 === void 0 ? void 0 : _reportType$subTypes2.edges]);
  var onClose = function onClose2() {
    handleClose();
    setCurrentStep(_chunkHNNL5DW4js.STEPS.report);
  };
  var handleReport = function handleReport2() {
    if (isMutationInFlight || !targetId || !reportType) {
      return;
    }
    commitMutation({
      variables: {
        input: {
          reportSubject: reportText,
          reportTypeId: reportType.id,
          targetObjectId: targetId
        }
      },
      onCompleted: function onCompleted(_, errors) {
        if (!errors) {
          setCurrentStep(_chunkHNNL5DW4js.STEPS.confirmation);
          return;
        }
        onClose();
      },
      onError: function onError() {
        onClose();
      }
    });
  };
  var steps = [{
    name: _chunkHNNL5DW4js.STEPS.report,
    content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkMXOHFF6Ijs.SelectReportTypeStep_default, {
      reportTypes,
      reportType,
      setReportType,
      setCurrentStep,
      setReportSubType
    })
  }, {
    name: _chunkHNNL5DW4js.STEPS.subTypes,
    content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkMXOHFF6Ijs.SelectReportTypeStep_default, {
      reportTypes: subTypes,
      reportType,
      setReportType,
      setCurrentStep,
      setReportSubType,
      subType: true
    })
  }, {
    name: _chunkHNNL5DW4js.STEPS.text,
    content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkPUGD275Hjs.TextStep_default, {
      reportText,
      setReportText,
      setCurrentStep
    })
  }, {
    name: _chunkHNNL5DW4js.STEPS.summary,
    content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBMDB3QCEjs.SummaryStep_default, {
      reportType,
      reportSubType,
      reportText,
      isMutationInFlight,
      handleReport
    })
  }, {
    name: _chunkHNNL5DW4js.STEPS.confirmation,
    content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk426N5EH7js.ConfirmationStep_default, {
      reportType,
      onClose
    })
  }];
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
    display: "flex",
    flexDirection: "column",
    padding: smDown ? 2 : 4,
    gap: 2,
    children: [currentStep === _chunkHNNL5DW4js.STEPS.confirmation ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      display: "flex",
      alignItems: "center",
      gap: 2,
      justifyContent: smDown ? "center" : "flex-start",
      children: smDown ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.OutlinedCheckMarkIcon, {
        sx: {
          color: "success.main",
          width: 55,
          height: 55
        }
      }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.NegativeCheckMarkIcon, {
          sx: {
            color: "success.main",
            width: 35,
            height: 35
          }
        }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
          variant: "subtitle1",
          children: "Report"
        })]
      })
    }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      display: "flex",
      justifyContent: smDown ? "center" : "flex-start",
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
        variant: smDown ? "caption" : "subtitle1",
        children: "Report"
      })
    }), steps === null || steps === void 0 || (_steps$find = steps.find(function(step) {
      return step.name === currentStep;
    })) === null || _steps$find === void 0 ? void 0 : _steps$find.content]
  });
};
var ReportDialogContentSuspended = function ReportDialogContentSuspended2(_ref2) {
  var targetId = _ref2.targetId, handleClose = _ref2.handleClose;
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, {
    fallback: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      height: "100%",
      padding: 4,
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.CircularProgress, {})
    }),
    children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ReportDialogContent, {
      targetId,
      handleClose
    })
  });
};
var ReportDialogContent_default = ReportDialogContentSuspended;



exports.ReportDialogContent_default = ReportDialogContent_default;
//# sourceMappingURL=chunk-EVRD5IK7.js.map