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 { useRequest } from "ahooks";
import { Button, Form, Skeleton, message } from "antd";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { locales } from "@pisell/utils";
import MaxParticipantsModule from "../../products/ProductDetailDrawer/ProductDetail/MaxParticipantsModule";
import SchedulesModule from "../../products/ProductDetailDrawer/ProductDetail/SchedulesModule";
import RelationProduct from "../relationProduct";
import { setResourceRelation } from "../serve";
import "./index.less";
var ResourcesDetailContent = function ResourcesDetailContent(props, refs) {
  var _Form$useForm = Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var useSchedule = Form.useWatch("schedule", form);
  var loading = props.loading,
    onClose = props.onClose,
    drawerContainer = props.drawerContainer,
    isAutoSetCalendarData = props.isAutoSetCalendarData,
    tabKey = props.tabKey;
  var _useState = useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    detail = _useState2[0],
    setDetail = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isChangeData = _useState4[0],
    setIsChangeData = _useState4[1];
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    canChange = _useState6[0],
    setCanChange = _useState6[1];
  useImperativeHandle(refs, function () {
    return {
      setFieldsValue: function setFieldsValue(data) {
        setDetail(data);
        form.setFieldsValue(data);
      },
      getIsEdit: function getIsEdit() {
        return isChangeData;
      }
    };
  });
  var _setResourceRelation = useRequest(setResourceRelation, {
    manual: true,
    onSuccess: function onSuccess(res) {
      if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
        onClose === null || onClose === void 0 || onClose(true);
        message.success(locales.getText("pisell2.text.schedules.save-success"));
        setIsChangeData(false);
      }
    }
  });
  var onFinish = function onFinish(params) {
    _setResourceRelation.run({
      item_id: detail.form_record_id,
      item_type: "form",
      schedules: params
    });
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "resources-detail-card product-detail-card"
  }, /*#__PURE__*/React.createElement(Skeleton, {
    round: true,
    active: true,
    loading: loading
  }, /*#__PURE__*/React.createElement(Form, {
    form: form,
    onFinish: onFinish,
    onValuesChange: function onValuesChange() {
      if (canChange) {
        setIsChangeData(true);
      }
    }
  }, /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "schedule"
  }, /*#__PURE__*/React.createElement(SchedulesModule, {
    drawerContainer: drawerContainer,
    ruleFn: function ruleFn() {
      return isAutoSetCalendarData;
    },
    tabKey: tabKey
  })), /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "max_participants"
  }, /*#__PURE__*/React.createElement(MaxParticipantsModule, {
    form: form,
    useSchedule: useSchedule,
    onData: function onData() {
      setTimeout(function () {
        setCanChange(true);
      }, 500);
    }
  })), /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "products"
  }, /*#__PURE__*/React.createElement(RelationProduct, null))))), /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__schedules-component-resources-detail-footer"
  }, /*#__PURE__*/React.createElement(Button, {
    className: "footer-btn",
    type: "primary",
    onClick: form.submit,
    loading: _setResourceRelation.loading,
    disabled: !isChangeData
  }, locales.getText("pisell2.text.schedules.save"))));
};
export default /*#__PURE__*/forwardRef(ResourcesDetailContent);