"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.formatSecond = formatSecond;
var _react = _interopRequireDefault(require("react"));
var _inputNumber = _interopRequireDefault(require("../input-number"));
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 格式化秒
 *
 * @param result
 * @returns {string}
 */
function formatSecond(result) {
  let formatText = '';
  const h = Math.floor(result / 3600);
  const m = Math.floor(result / 60 % 60);
  const s = Math.floor(result % 60);
  formatText = `${s}秒`;
  if (m > 0) {
    formatText = `${m}分钟${formatText}`;
  }
  if (h > 0) {
    formatText = `${h}小时${formatText}`;
  }
  return formatText;
}

/**
 * 格式化秒
 *
 * @param FieldSecond
 */
const Second = ({
  text,
  mode: type,
  render,
  renderFormItem,
  fieldProps,
  ...rest
}, ref) => {
  if (type === 'read') {
    const secondText = formatSecond(Number(text));
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      ref: ref,
      children: secondText
    });
    if (render) {
      return render(text, {
        mode: type,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  if (type === 'edit' || type === 'update') {
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_inputNumber.default, {
      ref: ref,
      min: 0,
      style: {
        width: '100%'
      },
      ...rest,
      ...fieldProps
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode: type,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
var _default = /*#__PURE__*/_react.default.forwardRef(Second);
exports.default = _default;