"use strict";

exports.__esModule = true;
exports.useTagsWidgetInternal = exports.useTagsWidget = void 0;
var _react = require("react");
var _react2 = require("@wix/bex-core/react");
var _bexCore = require("@wix/bex-core");
var _useWidgetForm = require("./useWidgetForm");
const useTagsWidget = ({
  fqdn,
  origin = 'tags_widget'
}) => {
  const container = (0, _react2.useWixPatternsContainer)();
  const [state] = (0, _react.useState)(() => new _bexCore.TagsWidgetState({
    container,
    fqdn: (0, _bexCore.parseFqdn)(fqdn),
    origin
  }));
  (0, _react.useEffect)(() => state.init(), []);
  return state;
};
exports.useTagsWidget = useTagsWidget;
const useTagsWidgetInternal = ({
  fqdn,
  origin = 'tags_widget',
  fieldName = 'tags',
  externalState
}) => {
  const container = (0, _react2.useWixPatternsContainer)();
  const widgetForm = (0, _useWidgetForm.useWidgetForm)();
  const [{
    state
  }] = (0, _react.useState)(() => {
    const finalState = externalState ?? new _bexCore.TagsWidgetState({
      container,
      fqdn: (0, _bexCore.parseFqdn)(fqdn ?? ''),
      origin
    });
    widgetForm == null || widgetForm.registerWidget(fieldName, finalState);
    return {
      state: finalState
    };
  });
  (0, _react.useEffect)(() => state.init(), []);
  return state;
};
exports.useTagsWidgetInternal = useTagsWidgetInternal;
//# sourceMappingURL=useTagsWidget.js.map