Liferay.Loader.define("@liferay/commerce-product-definitions-web@7.0.115/js/ProductOptionCheckbox",["module","exports","require","@frontend-taglib-clay$clayui/form","@liferay/frontend-js-state-web","liferay!frontend-js-react-web$classnames","commerce-frontend-js/utilities/atoms/skuOptionsAtom","liferay!frontend-js-react-web$react","./Asterisk","./utils"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=_interopRequireWildcard(r("@frontend-taglib-clay$clayui/form")),a=r("@liferay/frontend-js-state-web"),o=_interopRequireDefault(r("liferay!frontend-js-react-web$classnames")),i=_interopRequireDefault(r("commerce-frontend-js/utilities/atoms/skuOptionsAtom")),u=_interopRequireWildcard(r("liferay!frontend-js-react-web$react")),c=_interopRequireDefault(r("./Asterisk")),l=r("./utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}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={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var o=n?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(r,a,o):r[a]=e[a]}return r.default=e,t&&t.set(e,r),r}function ownKeys(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 _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}var _default=({componentId:e,forceRequired:t,namespace:r,productOption:d})=>{const[s,f]=(0,u.useState)(!1),[p,y]=(0,u.useState)(!1),[b,O]=(0,a.useLiferayState)(i.default);return(0,u.useEffect)((()=>O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(s,d,b)}))),[s]),(0,u.useEffect)((()=>(O(_objectSpread(_objectSpread({},b),{},{namespace:r})),d.required&&f(!0),O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(d.required,d,b),namespace:r})),()=>O(l.initialSkuOptionsAtomState))),[]),u.default.createElement(n.default.Group,{className:(0,o.default)({"has-error":s})},u.default.createElement("label",{htmlFor:e},(0,l.getProductOptionName)(d.name),u.default.createElement(c.default,{required:(0,l.isRequired)(t,b.isAdmin,d)})),u.default.createElement(n.ClayCheckbox,{checked:p,disabled:b.updating,id:e,name:d.key,onChange:({target:{checked:e,value:r}})=>{if(b.updating)return;O(_objectSpread(_objectSpread({},b),{},{updating:!0})),y(e);let n=b.skuOptions;if(n.filter((e=>e.skuOptionKey===d.key))[0]){const t=n.findIndex((e=>e.skuOptionKey===d.key));n[t]={key:d.key,skuOptionKey:d.key,value:e?[r]:[]}}else n=[...n,{key:d.key,skuOptionKey:d.key,value:[r]}];const a=(t||d.required)&&!e;f(a),O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(a,d,b),skuOptions:n,updating:!1}))},value:d.key}),s&&u.default.createElement(n.default.FeedbackItem,null,u.default.createElement(n.default.FeedbackIndicator,{symbol:"exclamation-full"}),Liferay.Language.get("this-field-is-required")))};t.default=_default}}));
//# sourceMappingURL=ProductOptionCheckbox.js.map