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 { VtxImage } from '@vtx/components';
import { getVtxToken, request } from '@vtx/utils';
import { Button, Space, Tooltip } from 'antd';
import Base64 from 'base-64';
import { useEffect, useState } from 'react';
import { VmEmpty } from "../../../_components";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var preview = function preview() {
  var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
    id: '',
    name: ''
  };
  window.open("/cloud/kkPreview/onlinePreview?url=".concat(Base64.encode("".concat(location.origin, "/cloudFile/common/downloadFile?token=").concat(getVtxToken('token'), "&id=").concat(item.id, "&fullfilename=").concat(encodeURIComponent(item.name))), "&token=").concat(getVtxToken('token')));
};
export var renderFile = function renderFile(list) {
  return list.map(function (item) {
    return /*#__PURE__*/_jsx("div", {
      children: /*#__PURE__*/_jsx(Tooltip, {
        color: "#fff",
        title: /*#__PURE__*/_jsxs(Space, {
          children: [/*#__PURE__*/_jsx(Button, {
            type: "primary",
            onClick: function onClick() {
              return preview(item);
            },
            children: "\u9884\u89C8"
          }), /*#__PURE__*/_jsx(Button, {
            onClick: function onClick() {
              return window.open("/cloudFile/common/downloadFile?token=".concat(getVtxToken('token'), "&id=").concat(item.id));
            },
            children: "\u4E0B\u8F7D"
          })]
        }),
        children: /*#__PURE__*/_jsx("a", {
          className: "fileName",
          title: item.name,
          children: item.name
        })
      })
    }, item.id);
  });
};

//list
var getFields = function getFields(params) {
  return request.get('/cloud/jcss-reborn/facility/type/view/list', {
    data: params
  });
};
var getList = function getList(params) {
  return request.get('/cloud/jcss-reborn/status/approval/facility/changeList', {
    data: params
  });
};
export default (function (props) {
  var id = props.id;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    fields = _useState2[0],
    setFields = _useState2[1];
  var _useState3 = useState([]),
    _useState4 = _slicedToArray(_useState3, 2),
    list = _useState4[0],
    setList = _useState4[1];
  useEffect(function () {
    getFields({
      code: 'wr'
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setFields(res.data.showFields || []);
      }
    });
  }, []);
  useEffect(function () {
    id && getList({
      jcssId: id
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setList(res.data || []);
      }
    });
  }, [id]);
  var getFileComponents = function getFileComponents(fileJson) {
    if (!JSON.stringify(fileJson)) {
      return;
    }
    var components;
    for (var key in fileJson) {
      var _fileJson$key;
      components = /*#__PURE__*/_jsxs(_Fragment, {
        children: [components, /*#__PURE__*/_jsxs("div", {
          className: "wr-step-line",
          style: {
            width: '100%'
          },
          children: [/*#__PURE__*/_jsxs("span", {
            className: "wr-step-label",
            children: [key, "\uFF1A"]
          }), (_fileJson$key = fileJson[key]) !== null && _fileJson$key !== void 0 && _fileJson$key.length ? renderFile(fileJson[key]) : '--']
        })]
      });
    }
    return components;
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "wr-build-content",
    children: [/*#__PURE__*/_jsx("div", {
      className: "wr-build-title",
      children: "\u5EFA\u8BBE\u4FE1\u606F"
    }), /*#__PURE__*/_jsx("div", {
      className: "wr-build-inner",
      children: list.length ? list.map(function (item) {
        return /*#__PURE__*/_jsxs("div", {
          className: "wr-build-panel",
          children: [/*#__PURE__*/_jsxs("div", {
            className: "wr-step-title",
            children: [/*#__PURE__*/_jsx("div", {
              className: "wr-step-time",
              children: item.currApprovedDate
            }), /*#__PURE__*/_jsx("div", {
              className: "wr-step-circle",
              children: /*#__PURE__*/_jsx("div", {
                className: "wr-circle-inner"
              })
            }), /*#__PURE__*/_jsx("div", {
              className: "wr-step-text",
              children: item.facilityStatus
            })]
          }), /*#__PURE__*/_jsxs("div", {
            className: "wr-step-content",
            children: [fields.map(function (each) {
              var _each$component, _each$component2, _item$dataJson, _item$dataJson2, _item$dataJson3, _item$dataJson4;
              return /*#__PURE__*/_jsxs("div", {
                className: "wr-step-line",
                style: {
                  width: ((_each$component = each.component) === null || _each$component === void 0 ? void 0 : _each$component.type) === 'IMAGE' ? '100%' : '50%'
                },
                children: [/*#__PURE__*/_jsxs("span", {
                  className: "wr-step-label",
                  children: [each.showName, "\uFF1A"]
                }), ((_each$component2 = each.component) === null || _each$component2 === void 0 ? void 0 : _each$component2.type) === 'IMAGE' ? (_item$dataJson = item.dataJson) !== null && _item$dataJson !== void 0 && _item$dataJson[each.showKey] ? /*#__PURE__*/_jsx(VtxImage.PreviewGroup, {
                  children: JSON.parse((_item$dataJson2 = item.dataJson) === null || _item$dataJson2 === void 0 ? void 0 : _item$dataJson2[each.showKey]).map(function (a) {
                    return /*#__PURE__*/_jsx(VtxImage, {
                      src: "/cloudFile/common/downloadFile?id=".concat(a.id, "&token=").concat(getVtxToken('token')),
                      alt: a.name,
                      style: {
                        width: '56px',
                        height: '56px',
                        margin: '10px 10px 0 0'
                      }
                    }, a.id);
                  })
                }) : '--' : /*#__PURE__*/_jsx("span", {
                  title: (_item$dataJson3 = item.dataJson) === null || _item$dataJson3 === void 0 ? void 0 : _item$dataJson3[each.showKey],
                  children: ((_item$dataJson4 = item.dataJson) === null || _item$dataJson4 === void 0 ? void 0 : _item$dataJson4[each.showKey]) || '--'
                })]
              }, each.showKey);
            }), getFileComponents(item.fileJson)]
          })]
        }, item.id);
      }) : /*#__PURE__*/_jsx(VmEmpty, {})
    })]
  });
});