"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _componentHeader = _interopRequireDefault(require("./component-header"));

var _componentLabel = _interopRequireDefault(require("./component-label"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

class CustomElement extends _react.Component {
  constructor(props) {
    super(props);
    this.inputField = /*#__PURE__*/_react.default.createRef();
    this.state = {
      hasClicked: false
    };
  }

  render() {
    const props = {};
    props.name = this.props.data.field_name;
    props.defaultValue = this.props.defaultValue; // props.hasClicked = this.state.hasClicked;

    console.log("this.state.hasClicked", this.state.hasClicked);

    if (this.props.mutable && this.props.data.forwardRef) {
      props.ref = this.inputField;
    }

    if (this.props.read_only) {
      props.disabled = "disabled";
    } // Return if component is invalid.


    if (!this.props.data.component) return null;
    const Element = this.props.data.component;
    let baseClasses = "SortableItem rfb-item";

    if (this.props.data.pageBreakBefore) {
      baseClasses += " alwaysbreak";
    }

    return /*#__PURE__*/_react.default.createElement("div", {
      className: baseClasses,
      onClick: () => this.setState({
        hasClicked: !this.state.hasClicked
      })
    }, /*#__PURE__*/_react.default.createElement(_componentHeader.default, _extends({}, this.props, {
      hasClicked: this.state.hasClicked
    })), /*#__PURE__*/_react.default.createElement("div", {
      className: "form-group"
    }, /*#__PURE__*/_react.default.createElement(_componentLabel.default, _extends({
      className: "form-label"
    }, this.props)), /*#__PURE__*/_react.default.createElement(Element, _extends({
      data: this.props.data
    }, this.props.data.props, props))));
  }

}

CustomElement.propTypes = {};
var _default = CustomElement;
exports.default = _default;