Liferay.Loader.define("@liferay/commerce-product-definitions-web@7.0.115/js/ProductOptionText",["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"),i=_interopRequireDefault(r("liferay!frontend-js-react-web$classnames")),o=_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 i=n?Object.getOwnPropertyDescriptor(e,a):null;i&&(i.get||i.set)?Object.defineProperty(r,a,i):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:s})=>{const[d,f]=(0,u.useState)(!1),[p,y]=(0,u.useState)(""),[b,O]=(0,a.useLiferayState)(o.default);return(0,u.useEffect)((()=>O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(d,s,b)}))),[d]),(0,u.useEffect)((()=>(s.required&&f(!0),O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(s.required,s,b),namespace:r,skuOptions:[...b.skuOptions,{key:s.key,skuOptionKey:s.key,value:[]}]})),()=>O(l.initialSkuOptionsAtomState))),[]),u.default.createElement(n.default.Group,{className:(0,i.default)({"has-error":d})},u.default.createElement("label",{htmlFor:e},(0,l.getProductOptionName)(s.name),u.default.createElement(c.default,{required:(0,l.isRequired)(t,b.isAdmin,s)})),u.default.createElement(n.ClayInput,{disabled:b.updating,id:e,name:s.key,onChange:({target:{value:e}})=>{if(b.updating)return;O(_objectSpread(_objectSpread({},b),{},{updating:!0})),y(e);let r=b.skuOptions;if(r.filter((e=>e.skuOptionKey===s.key))[0]){const t=r.findIndex((e=>e.skuOptionKey===s.key));r[t]={key:s.key,skuOptionKey:s.key,value:[e]}}else r=[...r,{key:s.key,skuOptionKey:s.key,value:[e]}];const n=(t||s.required)&&!e;f(n),O(_objectSpread(_objectSpread({},b),{},{errors:(0,l.getSkuOptionsErrors)(n,s,b),skuOptions:r,updating:!1}))},type:"text",value:p}),d&&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=ProductOptionText.js.map