Liferay.Loader.define("commerce-frontend-js@4.0.75/components/compare_checkbox/CompareCheckbox",["module","exports","require","@frontend-taglib-clay$clayui/form","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/eventsDefinitions"],(function(e,r,t){window;{Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var a=t("@frontend-taglib-clay$clayui/form"),i=(function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(t("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 r=_getRequireWildcardCache();if(r&&r.has(e))return r.get(e);var t={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=a?Object.getOwnPropertyDescriptor(e,i):null;n&&(n.get||n.set)?Object.defineProperty(t,i,n):t[i]=e[i]}t.default=e,r&&r.set(e,t);return t}(t("liferay!frontend-js-react-web$react"))),n=t("../../utilities/eventsDefinitions");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function CompareCheckbox({disabled:e,inCompare:r,itemId:t,label:o,onUpdate:c,pictureUrl:l}){const[d,f]=(0,i.useState)(r),[u,p]=(0,i.useState)(e),s=(0,i.useCallback)((({disabled:e=!0})=>{p(e),c({disabled:e,inCompare:d})}),[d,c]),b=(0,i.useCallback)((({id:e})=>{e===t&&f((()=>(c({disabled:u,inCompare:false}),false)))}),[u,t,c]);return(0,i.useEffect)((()=>(Liferay.on(n.ITEM_REMOVED_FROM_COMPARE,b),Liferay.on(n.PRODUCT_COMPARISON_TOGGLED,s),()=>{Liferay.detach(n.ITEM_REMOVED_FROM_COMPARE,b),Liferay.detach(n.PRODUCT_COMPARISON_TOGGLED,s)})),[b,s]),i.default.createElement(a.ClayCheckbox,{"aria-label":o,checked:d,className:"compare-checkbox-component",disabled:u&&!d,label:o,onChange:()=>f((e=>(Liferay.fire(n.TOGGLE_ITEM_IN_PRODUCT_COMPARISON,{id:t,thumbnail:l}),!e)))})}CompareCheckbox.defaultProps={disabled:!1,inCompare:!1,label:"",onUpdate:()=>{},pictureUrl:""};var o=CompareCheckbox;r.default=o}}));
//# sourceMappingURL=CompareCheckbox.js.map