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