"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _box = _interopRequireDefault(require("@alifd/next/lib/box"));
var _input = _interopRequireDefault(require("@alifd/next/lib/input"));
var _switch = _interopRequireDefault(require("@alifd/next/lib/switch"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var TitleSetter = function TitleSetter(props) {
  var _target$getHotValue;
  var value = props.value,
    defaultValue = props.defaultValue,
    defaultChecked = props.defaultChecked,
    onChange = props.onChange,
    field = props.field,
    prop = props.prop;
  var _useState = (0, _react.useState)(defaultChecked),
    checked = _useState[0],
    setChecked = _useState[1];
  var target = field || prop;
  var theVal = (target === null || target === void 0 ? void 0 : (_target$getHotValue = target.getHotValue) === null || _target$getHotValue === void 0 ? void 0 : _target$getHotValue.call(target)) || defaultValue || value;
  var handleToggle = function handleToggle(vis) {
    onChange === null || onChange === void 0 ? void 0 : onChange(vis ? theVal : '');
    setChecked(vis);
  };
  var handleChangeText = function handleChangeText(text) {
    onChange === null || onChange === void 0 ? void 0 : onChange(text);
  };
  return /*#__PURE__*/_react["default"].createElement(_box["default"], {
    className: "setter-title",
    direction: "row",
    align: "center",
    spacing: 10
  }, /*#__PURE__*/_react["default"].createElement(_switch["default"], {
    size: "small",
    checked: checked,
    onChange: handleToggle
  }), checked && /*#__PURE__*/_react["default"].createElement(_input["default"], {
    size: "small",
    value: theVal,
    onChange: handleChangeText
  }));
};
var _default = exports["default"] = TitleSetter;