Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.156/page_editor/app/components/fragment_configuration_fields/ItemSelectorField",["module","exports","require","@frontend-taglib-clay$clayui/form","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../../common/components/ItemSelector","../../../common/hooks/useId","../../../prop_types/index","../../contexts/CollectionItemContext","../../contexts/StoreContext","../../services/InfoItemService","../../utils/item_selector_value/itemSelectorValueToInfoItem"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.ItemSelectorField=function ItemSelectorField({field:e,onValueSelect:t,value:r={}}){const n=(0,a.useContext)(i.CollectionItemContext),{typeOptions:c={}}=e,u=n.collectionItem,s=null!==u,m=s?u.className:r.className,p=s?u.classPK:r.classPK;return a.default.createElement(a.default.Fragment,null,a.default.createElement(o.default,{helpText:e.description,itemSelectorURL:c.infoItemSelectorURL,label:e.label,modalProps:{height:"60vh",size:c.modalSize},onItemSelect:r=>{t(e.name,r)},selectedItem:s?u||{title:Liferay.Language.get("collection-item")}:r,showEditControls:!s,transformValueCallback:f.default}),c.enableSelectTemplate&&m&&a.default.createElement(l.default.Group,{small:!0},a.default.createElement(TemplateSelector,{className:m,classPK:p,onTemplateSelect:l=>{t(e.name,_objectSpread(_objectSpread({},r),{},{template:l}))},selectedTemplate:r.template})))};var l=_interopRequireDefault(r("@frontend-taglib-clay$clayui/form")),n=r("@liferay/frontend-js-react-web"),a=(_interopRequireDefault(r("liferay!frontend-js-react-web$prop-types")),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={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var a=l?Object.getOwnPropertyDescriptor(e,n):null;a&&(a.get||a.set)?Object.defineProperty(r,n,a):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),o=_interopRequireDefault(r("../../../common/components/ItemSelector")),c=r("../../../common/hooks/useId"),i=(r("../../../prop_types/index"),r("../../contexts/CollectionItemContext")),u=r("../../contexts/StoreContext"),s=_interopRequireDefault(r("../../services/InfoItemService")),f=_interopRequireDefault(r("../../utils/item_selector_value/itemSelectorValueToInfoItem"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);t&&(l=l.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,l)}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 TemplateSelector=({className:e,classPK:t,onTemplateSelect:r,selectedTemplate:o})=>{const i=(0,u.useDispatch)(),[f,m]=(0,a.useState)([]),p=(0,n.useIsMounted)(),d=(0,c.useId)();return(0,a.useEffect)((()=>{p()&&s.default.getAvailableTemplates({className:e,classPK:t,onNetworkStatus:i}).then((e=>{m(e)}))}),[e,t,i,p]),a.default.createElement(a.default.Fragment,null,a.default.createElement(l.default.Group,{small:!0},a.default.createElement("label",{htmlFor:d},Liferay.Language.get("template")),a.default.createElement("select",{className:"form-control",id:d,onChange:e=>{r(e.target.options[e.target.selectedIndex].dataset)}},f.map((e=>e.templates?a.default.createElement("optgroup",{key:e.label,label:e.label},e.templates.map((e=>a.default.createElement("option",{"data-info-item-renderer-key":e.infoItemRendererKey,"data-template-key":e.templateKey,key:e.label,selected:o&&o.infoItemRendererKey===e.infoItemRendererKey&&(!o.templateKey||o.templateKey&&o.templateKey===e.templateKey)},e.label)))):a.default.createElement("option",{"data-info-item-renderer-key":e.infoItemRendererKey,key:e.label,selected:o&&o.infoItemRendererKey===e.infoItemRendererKey},e.label))))))}}}));
//# sourceMappingURL=ItemSelectorField.js.map