Liferay.Loader.define("portal-search-web@6.0.73/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=m,t.default=t.ITEM_TYPES=void 0;var n=f(r("@frontend-taglib-clay$clayui/button")),a=u(r("@frontend-taglib-clay$clayui/form")),l=f(r("@frontend-taglib-clay$clayui/icon")),o=u(r("liferay!frontend-js-react-web$react")),c=r("liferay!frontend-js-react-web$react-dnd"),i=r("liferay!frontend-js-react-web$react-dnd-html5-backend");function d(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return d=function(){return e},e}function u(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=d();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 f(e){return e&&e.__esModule?e:{default:e}}function s(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 p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(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 m(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 b({index:t,move:r}){const[{isOver:n},a]=(0,c.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 g({children:t,index:r,onDelete:i,showDeleteButton:d,showDragButton:u}){const[{isDragging:f},s]=(0,c.useDrag)({collect:e=>({isDragging:!!e.isDragging()}),item:{index:r,type:e.FIELD}});return o.default.createElement("div",{ref:s,style:{cursor:"move",opacity:f?.5:1}},o.default.createElement(a.default.Group,{className:"field-item"},o.default.createElement(a.ClayInput.Group,null,o.default.createElement(a.ClayInput.GroupItem,{shrink:!0},u&&o.default.createElement(n.default,{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,{borderless:!0,displayType:"secondary",monospaced:!0,onClick:i,small:!0},o.default.createElement(l.default,{symbol:"trash"}))))))}t.ITEM_TYPES=e;var v=function({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 y=(0,o.useRef)(1e4),v=e=>t=>{r(s.map(((r,n)=>n===e?p(p({},r),t):r)))},O=(e,t)=>{r(m(s,e,t))},E=e=>t=>{r(s.map(((r,n)=>n===e?t:r)))};return o.default.createElement("div",{className:"field-list"},o.default.createElement(c.DndProvider,{backend:i.HTML5Backend},s.map(((e,t)=>o.default.createElement("div",{key:e.id},o.default.createElement(b,{index:t,move:O}),o.default.createElement(g,{index:t,onDelete:()=>(e=>{r(s.filter(((t,r)=>r!==e)))})(t),showDeleteButton:u,showDragButton:f},a({index:t,onChange:v(t),onReplace:E(t),value:e}))))),o.default.createElement(b,{index:s.length,move:O}),d&&o.default.createElement(n.default,{displayType:"secondary",onClick:()=>{r([...s,p(p({},t),{},{id:y.current++})])}},o.default.createElement("span",{className:"inline-item inline-item-before"},o.default.createElement(l.default,{symbol:"plus"})),e)))};t.default=v}}));
//# sourceMappingURL=FieldList.js.map