Liferay.Loader.define("portal-search-web@6.0.90/js/components/FieldList",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","liferay!frontend-js-react-web$react","liferay!frontend-js-react-web$react-dnd","liferay!frontend-js-react-web$react-dnd-html5-backend"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.move=move,t.default=t.ITEM_TYPES=void 0;var n=_interopRequireDefault(r("@frontend-taglib-clay$clayui/button")),a=_interopRequireWildcard(r("@frontend-taglib-clay$clayui/form")),l=_interopRequireDefault(r("@frontend-taglib-clay$clayui/icon")),o=_interopRequireWildcard(r("liferay!frontend-js-react-web$react")),i=r("liferay!frontend-js-react-web$react-dnd"),c=r("liferay!frontend-js-react-web$react-dnd-html5-backend");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var l=n?Object.getOwnPropertyDescriptor(e,a):null;l&&(l.get||l.set)?Object.defineProperty(r,a,l):r[a]=e[a]}return r.default=e,t&&t.set(e,r),r}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e={FIELD:"field"};function move(e,t,r){const n=[...e.slice(0,r),e[t],...e.slice(r,e.length)],a=t>r?t+1:t;return n.filter(((e,t)=>t!==a))}function DropZone({index:t,move:r}){const[{isOver:n},a]=(0,i.useDrop)({accept:e.FIELD,collect:e=>({isOver:!!e.isOver()}),drop:e=>{r(e.index,t)}},[r]);return o.default.createElement("div",{className:"field-drop-zone",ref:a},n&&o.default.createElement("div",{className:"field-drop-zone-over"}))}function Field({children:t,index:r,onDelete:c,showDeleteButton:d,showDragButton:u}){const[{isDragging:f},s,p]=(0,i.useDrag)({collect:e=>({isDragging:!!e.isDragging()}),item:{index:r,type:e.FIELD}});return o.default.createElement(a.default.Group,{className:"field-item",ref:p},o.default.createElement(a.ClayInput.Group,null,o.default.createElement(a.ClayInput.GroupItem,{ref:s,shrink:!0,style:{cursor:"move",opacity:f?.5:1}},u&&o.default.createElement(n.default,{"aria-label":Liferay.Language.get("move"),borderless:!0,className:"drag-handle",displayType:"secondary",monospaced:!0,small:!0},o.default.createElement(l.default,{symbol:"drag"}))),t,d&&o.default.createElement(a.ClayInput.GroupItem,{shrink:!0},o.default.createElement(n.default,{"aria-label":Liferay.Language.get("delete"),borderless:!0,displayType:"secondary",monospaced:!0,onClick:c,small:!0},o.default.createElement(l.default,{symbol:"trash"})))))}t.ITEM_TYPES=e;var d=function FieldList({addButtonLabel:e=Liferay.Language.get("add-option"),defaultValue:t={},onChange:r,renderInputs:a,showAddButton:d=!0,showDeleteButton:u=!0,showDragButton:f=!0,value:s}){const p=(0,o.useRef)(1e4),_handleChangeField=e=>t=>{r(s.map(((r,n)=>n===e?_objectSpread(_objectSpread({},r),t):r)))},_handleMoveField=(e,t)=>{r(move(s,e,t))},_handleReplaceField=e=>t=>{r(s.map(((r,n)=>n===e?_objectSpread({id:r.id},t):r)))};return o.default.createElement("div",{className:"field-list"},o.default.createElement(i.DndProvider,{backend:c.HTML5Backend},s.map(((e,t)=>o.default.createElement("div",{key:e.id},o.default.createElement(DropZone,{index:t,move:_handleMoveField}),o.default.createElement(Field,{index:t,onDelete:()=>(e=>{r(s.filter(((t,r)=>r!==e)))})(t),showDeleteButton:u,showDragButton:f},a({index:t,onChange:_handleChangeField(t),onReplace:_handleReplaceField(t),value:e}))))),o.default.createElement(DropZone,{index:s.length,move:_handleMoveField}),d&&o.default.createElement(n.default,{"aria-label":e,displayType:"secondary",onClick:()=>{r([...s,_objectSpread(_objectSpread({},t),{},{id:p.current++})])}},o.default.createElement("span",{className:"inline-item inline-item-before"},o.default.createElement(l.default,{symbol:"plus"})),e)))};t.default=d}}));
//# sourceMappingURL=FieldList.js.map