"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),n=require("primereact/componentbase"),o=require("primereact/hooks"),r=require("primereact/utils"),a=require("primereact/button"),l=require("primereact/icons/angledoubledown"),i=require("primereact/icons/angledoubleup"),c=require("primereact/icons/angledown"),s=require("primereact/icons/angleup"),u=require("primereact/icons/search"),p=require("primereact/ripple"),d=require("primereact/icons/angledoubleleft"),m=require("primereact/icons/angledoubleright"),f=require("primereact/icons/angleleft"),v=require("primereact/icons/angleright");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var y=h(e),b=g(t);function T(e){throw new TypeError('"'+e+'" is read-only')}function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function I(e,t){if("object"!=S(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=S(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function E(e){var t=I(e,"string");return"symbol"==S(t)?t:t+""}function w(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n=0;a--){var l=r.ObjectUtils.findIndexInList(n[a],o,e.dataKey);if(l===o.length-1)break;var i=o[l+1];o[l+1]=o[l],o[l]=i}e.onReorder&&e.onReorder({originalEvent:t,value:o,direction:"down"})}},pt:u("moveDownButton"),unstyled:d,"aria-label":t.ariaLabel("moveDown"),__parentMetadata:{parent:e.metaData}}),y.createElement(a.Button,{disabled:h,type:"button",icon:g,onClick:function(t){var n=e.selection;if(n&&n.length){for(var o=L(e.list),a=n.length-1;a>=0;a--){var l=r.ObjectUtils.findIndexInList(n[a],o,e.dataKey);if(l===o.length-1)break;var i=o.splice(l,1)[0];o.push(i)}e.onReorder&&e.onReorder({originalEvent:t,value:o,direction:"bottom"})}},pt:u("moveBottomButton"),unstyled:d,"aria-label":t.ariaLabel("moveBottom"),__parentMetadata:{parent:e.metaData}}))}));_.displayName="PickListControls";var j=y.memo((function(e){var t=o.useMergeProps(),n=e.ptm,a=e.cx,l=e.template?e.template(e.value):e.value,i=t({className:r.classNames(e.className,a("item",{selected:e.selected,focused:e.focused})),id:e.id,onClick:function(t){e.onClick&&e.onClick({originalEvent:t,value:e.value,id:e.id})},onKeyDown:function(t){e.onKeyDown&&e.onKeyDown({originalEvent:t,value:e.value})},onFocus:function(t){e.onFocus&&e.onFocus(t)},onMouseDown:function(t){e.onMouseDown&&e.onMouseDown(t)},onMouseMove:e.onMouseMove,role:"option","aria-selected":e.selected,"data-p-highlight":e.selected,"data-p-focused":e.focused},n("item",{hostName:e.hostName,context:{selected:e.selected}}));return y.createElement("li",i,l,y.createElement(p.Ripple,null))}));function U(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function R(e){for(var t=1;t0?e.tabIndex:-1,onKeyDown:e.onListKeyDown,onFocus:function(t){e.onListFocus(t,e.type)},onBlur:e.onListBlur,style:e.style},c("list")),y.createElement("ul",v,f)),S=n({className:r.classNames(e.className,i("listWrapper"))},c("listWrapper"));return y.createElement("div",S,h,b,T)})));function B(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:1,n=e.getElementsByClassName("p-highlight");r.ObjectUtils.isNotEmpty(n)&&r.DomHandler.scrollInView(e,-1===t?n[0]:n[n.length-1])},ue=function(e,t,n){"sourceSelection"===t?p(e.value):f(e.value),n&&n(e)},pe=function(e){var t=e.originalEvent,n=e.value,o=P("source"===e.type?[h,c.onSourceFilterChange]:[E,c.onTargetFilterChange],2),r=o[0],a=o[1];a?a({originalEvent:t,value:n}):r(n)},de=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().toLocaleLowerCase(c.filterLocale);return fe(c.source,e)},me=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().toLocaleLowerCase(c.filterLocale);return fe(c.target,e)},fe=function(e,n){var o=re?c.filterBy.split(","):[];return t.FilterService.filter(e,o,n,c.filterMatchMode,c.filterLocale)},ve=function(e,t){var n=P("source"===t?[ne,de]:[oe,me],2),o=n[0],a=n[1];return re&&r.ObjectUtils.isNotEmpty(o)?a(o):e},ge=ve(c.source,"source"),he=ve(c.target,"target"),ye=function(e){if(-1===k){var t=e&&e.children?L(e.children):[],n=be(e,t);return c.autoOptionFocus&&-1===n&&(n=Te(e,t)),n}return-1},be=function(e,t){if(u.length||m.length){var n=r.DomHandler.findSingle(e,'[data-p-highlight="true"]');return r.ObjectUtils.findIndexInList(n,t)}return-1},Te=function(e,t){var n=r.DomHandler.findSingle(e,'[data-pc-section="item"]');return r.ObjectUtils.findIndexInList(n,t)},Se=function(e,t){B(X(X({},R),{},w({},t,!0)));var n=_e(t),o=ye(n);Pe(o,t),c.onFocus&&c.onFocus(e)},Ie=function(e,t){B(X(X({},R),{},w({},t,!1))),C(-1),c.onBlur&&c.onBlur(e)},Ee=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=e.originalEvent,a=e.value,l=e.id,i="source"===t,s=L(i?ee:te),u=r.ObjectUtils.findIndexInList(a,s,c.dataKey),p=-1!==u,d=c.metaKeySelection;if(n||C(l),d){var m=o.metaKey||o.ctrlKey||o.shiftKey;p&&m?s.splice(u,1):(m||(s.length=0),s.push(a))}else p?s.splice(u,1):s.push(a);i?ue({originalEvent:o,value:s},"sourceSelection",c.onSourceSelectionChange):ue({originalEvent:o,value:s},"targetSelection",c.onTargetSelectionChange)},we=function(e){var t=e.index,n=e.type;B(X(X({},R),{},w({},n,!0))),C(t)},Oe=function(e,t){switch(e.code){case"ArrowDown":Ne(e,t);break;case"ArrowUp":Ae(e,t);break;case"Home":Le(e,t);break;case"End":Ce(e,t);break;case"Enter":case"NumpadEnter":De(e,t);break;case"Space":ke(e,t);break;case"KeyA":if(e.ctrlKey){var n="source"===t;n?p(L(ge)):f(L(he)),ue({originalEvent:e,value:L(n?ge:he)},n?"sourceSelection":"targetSelection",n?c.onSourceSelectionChange:c.onTargetSelectionChange),e.preventDefault()}break;case"KeyD":if(e.ctrlKey){var o="source"===t;o?p([]):f([]),ue({originalEvent:e,value:[]},o?"sourceSelection":"targetSelection",o?c.onSourceSelectionChange:c.onTargetSelectionChange),e.preventDefault()}}},Ne=function(e,t){var n=Me(k,t),o=ve("source"===t?c.source:c.target,t);Pe(n,t),o&&o.length>0&&e.shiftKey&&Ee({originalEvent:e,value:o[n]},t,!0),e.preventDefault()},Ae=function(e,t){var n=xe(k,t),o=ve("source"===t?c.source:c.target,t);Pe(n,t),o&&o.length>0&&e.shiftKey&&Ee({originalEvent:e,value:o[n]},t,!0),e.preventDefault()},De=function(e,t){var n=_e(t),o=ve("source"===t?c.source:c.target,t),a=r.DomHandler.find(n,'[data-pc-section="item"]'),l=r.DomHandler.findSingle(n,'[data-pc-section="item"][id='.concat(k,"]")),i=l&&l.getAttribute("id"),s=L(a).findIndex((function(e){return e===l}));o&&o.length>0&&Ee({originalEvent:e,value:o[s],id:i},t),e.preventDefault()},ke=function(e,t){e.preventDefault();var n="source"===t,o=n?u:m;if(e.shiftKey&&o&&o.length>0){var a=n?ge:he,l=_e(t),i=r.DomHandler.find(l,'[data-pc-section="item"]'),s=r.ObjectUtils.findIndexInList(o[0],L(a)),p=r.DomHandler.findSingle(l,'[data-pc-section="item"][id='.concat(k,"]")),d=L(i).findIndex((function(e){return e===p}));L(a).slice(Math.min(s,d),Math.max(s,d)+1),T("selection"),n?ue({originalEvent:e,value:o},"sourceSelection",c.onSourceSelectionChange):ue({originalEvent:e,value:o},"targetSelection",c.onTargetSelectionChange)}else De(e,t)},Le=function(e,t){if(e.ctrlKey&&e.shiftKey){var n="source"===t,o=n?ge:he,a=_e(t),l=r.DomHandler.find(a,'[data-pc-section="item"]'),i=r.DomHandler.findSingle(a,'[data-pc-section="item"][id='.concat(k,"]")),s=L(l).findIndex((function(e){return e===i})),u=L(o).slice(0,s+1);n?ue({originalEvent:e,value:u},"sourceSelection",c.onSourceSelectionChange):ue({originalEvent:e,value:u},"targetSelection",c.onTargetSelectionChange)}else Pe(0,t);e.preventDefault()},Ce=function(e,t){var n=_e(t),o=r.DomHandler.find(n,'[data-pc-section="item"]');if(e.ctrlKey&&e.shiftKey){var a="source"===t,l=a?ge:he,i=r.DomHandler.findSingle(n,'[data-pc-section="item"][id='.concat(k,"]")),s=L(o).findIndex((function(e){return e===i})),u=L(l).slice(s,o.length);a?ue({originalEvent:e,value:u},"sourceSelection",c.onSourceSelectionChange):ue({originalEvent:e,value:u},"targetSelection",c.onTargetSelectionChange)}else Pe(o.length-1,t);e.preventDefault()},Me=function(e,t){var n=_e(t),o=L(r.DomHandler.find(n,'[data-pc-section="item"]')).findIndex((function(t){return t.id===e}));return o>-1?o+1:0},xe=function(e,t){var n=_e(t),o=L(r.DomHandler.find(n,'[data-pc-section="item"]')).findIndex((function(t){return t.id===e}));return o>-1?o-1:0},Pe=function(e,t){var n,o=_e(t),a=r.DomHandler.find(o,'[data-pc-section="item"]');if(e>=a.length)n=a.length-1;else{if(e<0)return;n=e}C(a[n].getAttribute("id")),Fe(a[n].getAttribute("id"),t)},Fe=function(e,t){var n=_e(t),o=r.DomHandler.findSingle(n,'[data-pc-section="item"][id="'.concat(e,'"]'));o&&o.scrollIntoView&&o.scrollIntoView({block:"nearest",inline:"start"})},_e=function(e){return"source"===e?Q.current.getElement():Y.current.getElement()},je=function(){if(!$.current){$.current=r.DomHandler.createInlineStyle(i&&i.nonce||b.default.nonce,i&&i.styleContainer);var e="\n@media screen and (max-width: ".concat(c.breakpoint,") {\n .p-picklist[").concat(N,"] {\n flex-direction: column;\n }\n\n .p-picklist[").concat(N,"] .p-picklist-buttons {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-picklist[").concat(N,"] .p-picklist-buttons .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-picklist[").concat(N,"] .p-picklist-buttons .p-button:last-child {\n margin-right: 0;\n }\n}\n");$.current.innerHTML=e}};y.useImperativeHandle(a,(function(){return{props:c,getElement:function(){return J.current}}})),o.useUpdateEffect((function(){return N&&(J.current.setAttribute(N,""),je()),function(){$.current=r.DomHandler.removeInlineStyle($.current)}}),[N,c.breakpoint]),o.useUpdateEffect((function(){c.id||N||A(r.UniqueComponentId()),z.current&&(ie(z.current,Z.current),z.current=null,Z.current=null)})),o.useUpdateEffect((function(){j(-1!==k?k:null)}),[k]);var Ue=c.sourceItemTemplate?c.sourceItemTemplate:c.itemTemplate,Re=c.targetItemTemplate?c.targetItemTemplate:c.itemTemplate,Ke=l({id:N,ref:J,className:r.classNames(c.className,V("root")),style:c.style},F.getOtherProps(c),W("root"));return y.createElement("div",Ke,c.showSourceControls&&y.createElement(_,{hostName:"PickList",list:c.source,selection:ee,onReorder:function(e){ce(e,e.value,c.target),z.current=_e("source"),Z.current=e.direction},className:V("sourceControls"),dataKey:c.dataKey,moveUpIcon:c.moveUpIcon,moveTopIcon:c.moveTopIcon,moveDownIcon:c.moveDownIcon,moveBottomIcon:c.moveBottomIcon,ptm:W,cx:V,unstyled:c.unstyled,metaData:H}),y.createElement(K,{hostName:"PickList",ref:Q,type:"source",list:ge,parentId:N,selection:ee,onSelectionChange:function(e){return ue(e,"sourceSelection",c.onSourceSelectionChange)},onListKeyDown:function(e){return Oe(e,"source")},onListFocus:function(e){return Se(e,"source")},onListBlur:function(e){return Ie(e,"source")},onOptionMouseDown:function(e){return we(e)},onItemClick:function(e){return Ee(e,"source")},focusedOptionId:R.source?x:null,ariaActivedescendant:R.source?x:null,itemTemplate:Ue,header:c.sourceHeader,style:c.sourceStyle,className:V("listSourceWrapper"),listClassName:V("listSource"),metaKeySelection:c.metaKeySelection,tabIndex:c.tabIndex,dataKey:c.dataKey,filterValue:ne,onFilter:pe,showFilter:ae,placeholder:c.sourceFilterPlaceholder,filterTemplate:c.sourceFilterTemplate,sourceFilterIcon:c.sourceFilterIcon,ptm:W,cx:V,focusedList:R,changeFocusedOptionIndex:Pe,focusOnHover:c.focusOnHover}),y.createElement(G,{hostName:"PickList",onTransfer:function(e){var t=e.originalEvent,n=e.source,o=e.target,r=[];switch(e.direction){case"toTarget":r=ee,c.onMoveToTarget&&c.onMoveToTarget({originalEvent:t,value:r});break;case"allToTarget":r=c.source,c.onMoveAllToTarget&&c.onMoveAllToTarget({originalEvent:t,value:r}),r=[];break;case"toSource":r=te,c.onMoveToSource&&c.onMoveToSource({originalEvent:t,value:r});break;case"allToSource":r=c.target,c.onMoveAllToSource&&c.onMoveAllToSource({originalEvent:t,value:r}),r=[]}ue({originalEvent:t,value:r},"sourceSelection",c.onSourceSelectionChange),ue({originalEvent:t,value:r},"targetSelection",c.onTargetSelectionChange),f([]),p([]),ce(e,n,o)},source:c.source,visibleSourceList:ge,target:c.target,breakpoint:c.breakpoint,visibleTargetList:he,sourceSelection:ee,targetSelection:te,dataKey:c.dataKey,moveToTargetIcon:c.moveToTargetIcon,moveAllToTargetIcon:c.moveAllToTargetIcon,moveToSourceIcon:c.moveToSourceIcon,moveAllToSourceIcon:c.moveAllToSourceIcon,ptm:W,cx:V,unstyled:c.unstyled,metaData:H}),y.createElement(K,{hostName:"PickList",ref:Y,type:"target",list:he,selection:te,parentId:N,onSelectionChange:function(e){return ue(e,"targetSelection",c.onTargetSelectionChange)},onListKeyDown:function(e){return Oe(e,"target")},onListFocus:function(e){return Se(e,"target")},onListBlur:function(e){return Ie(e,"target")},onOptionMouseDown:function(e){return we(e)},onItemClick:function(e){return Ee(e,"target")},focusedOptionId:R.target?x:null,ariaActivedescendant:R.target?x:null,itemTemplate:Re,header:c.targetHeader,style:c.targetStyle,className:V("listTargetWrapper"),listClassName:V("listWrapper"),metaKeySelection:c.metaKeySelection,tabIndex:c.tabIndex,dataKey:c.dataKey,filterValue:oe,onFilter:pe,showFilter:le,placeholder:c.targetFilterPlaceholder,filterTemplate:c.targetFilterTemplate,targetFilterIcon:c.targetFilterIcon,ptm:W,cx:V,focusedList:R,changeFocusedOptionIndex:Pe,focusOnHover:c.focusOnHover}),c.showTargetControls&&y.createElement(_,{hostName:"PickList",list:c.target,selection:te,onReorder:function(e){ce(e,c.source,e.value),z.current=_e("target"),Z.current=e.direction},className:V("targetControls"),dataKey:c.dataKey,moveUpIcon:c.moveUpIcon,moveTopIcon:c.moveTopIcon,moveDownIcon:c.moveDownIcon,moveBottomIcon:c.moveBottomIcon,ptm:W,cx:V,unstyled:c.unstyled,metaData:H}))})));Z.displayName="PickList",exports.PickList=Z;