1import{i as S,bc as n,R as g,u as h,b as E,ad as l,J as M,bd as F,G as c,a as N,e as p,T as C,aM as v,be as T,N as k,H as P,r as I,C as b}from"./storefrontApp.CsApItsi.min.js";import{W as y}from"./chunk-webapi_http_api.C3s8IQv.js";import{B as R}from"./chunk-base_http_api_url.H743YfZ.js";import{T as O,b as U,d as Q,$,e as m}from"./chunk-vendor-lit.NvY0u02.js";import{S as w}from"./chunk-storefront_base_lit_element.lX23Jvc.js";import{S as A}from"./chunk-storefront_settings_constants.DIF02Gz.js";import{M as d}from"./chunk-modal_constants.RvL-5Lb.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-vendor-rxjs.Dp7kflo.js";import"./chunk-vendor-lodash.CWHFt7Z.js";import"./chunk-vendor-phoenix.cdKS79L.js";class H extends S{constructor({productAskQuestionsService:e}){super(),this.moduleName=n.api,this.#s=e}#s;async askForProduct(e){return this.#s.askForProduct(e)}}class _ extends R{constructor(e,s){super(e,s)}getAskForProductUrl(e){return`${this.webapiUrl}/products/${e}/ask-question/`}}class L extends y{static{this.moduleName=n.httpApi}#s;constructor({httpApi:e,settingsApi:s,localeOptions:t}){super(e),this.#s=new _(s,t)}askForProduct(e,s){const r={url:this.#s.getAskForProductUrl(e),method:g.post,data:s};return this.fetch(r,{decorators:[h.status,h.flashMessages]})}}class q extends E{#s;#e;constructor({httpApi:e,settingsApi:s,localeOptions:t,flashMessengerApi:r}){super(),this.#s=new L({httpApi:e,settingsApi:s,localeOptions:t}),this.#e=r}async askForProduct({productId:e,askQuestionDetails:s,flashMessengerContainer:t}){try{const{data:r}=await this.#s.askForProduct(e,s).response,{flashMessages:i,status:o}=r;return o===l.success&&(this._displayFlashMessages(i),this.eventBus.emit(new M(F.askForProductSuccess,s))),o===l.failed&&this._displayFlashMessages(i,t),o}catch(r){const{_flash_messenger:i}=r.response.data;this._displayFlashMessages(i,t);return}}_displayFlashMessages(e,s){if(!e)return;const t=s||c;this.#e.parseAndAddFlashMessages(e,t)}}class x{constructor({host:e,formRef:s}){this.getFormValues=async()=>{const t=this.getFormService(),r=t.getFormControls();await t.validateControls();const i={mail:"",question:"",challenge:""};return r.forEach(o=>{O.isDefined(o.value)&&(i[o.name]=o.value)}),i},this.clearFormValues=()=>{const t=this.getFormService();t.getFormControls().forEach(({id:r})=>{t.updateFormControl(r,{value:""})})},this.#s=e,this.#e=s,this.#s.addController(this)}#s;#e;hostConnected(){}getFormState(){return this.getFormService().getFormState()}getFormService(){if(!this.#e.value)throw"No form found";return this.#e.value?.formService}}var D=Object.defineProperty,f=(a,e,s,t)=>{for(var r=void 0,i=a.length-1,o;i>=0;i--)(o=a[i])&&(r=o(e,s,r)||r);return r&&D(e,s,r),r};class u extends w{constructor(){super(),this.productId="",this.moduleInstanceId="",this._formConnectorRef=U(),this._flashMessengerContainerName=c,this._userApi=null,this._fillEmailFieldWithDefaultValue=()=>{if(!this._userApi)return;const s=this._userApi.getUser()?.email,t=this.querySelector('h-input[type="email"]');!s||!t||(t.value=s)},this._removeAllMessages=()=>{this._flashMessengerApi.removeAllFlashMessages(this._flashMessengerContainerName)},this._onSubmit=s=>{const t=s.detail.submitActionProps.responseObject,{flashMessages:r,status:i}=t.data;r&&(i===l.success&&(this._flashMessengerApi.removeAllFlashMessages(this._flashMessengerContainerName),this._flashMessengerApi.parseAndAddFlashMessages(r,c),this._productAskQuestionsController.clearFormValues(),this._closeModal()),i===l.failed&&this._flashMessengerApi.parseAndAddFlashMessages(r,this._flashMessengerContainerName))},this._onSubmitError=s=>{this._flashMessengerApi.removeAllFlashMessages(this._flashMessengerContainerName);const t=s.detail.submitActionProps.err.response?.data._flash_messenger;t&&this._flashMessengerApi.parseAndAddFlashMessages(t,this._flashMessengerContainerName)},this._onFormInvalid=()=>{this._flashMessengerApi.removeAllFlashMessages(this._flashMessengerContainerName),this._flashMessengerApi.addFlashMessage({content:this._translationApi.translate("Fill in all required fields correctly and try again."),type:N.error,isCloseable:!1,timeout:0},this._flashMessengerContainerName)},this._flashMessengerApi=this.getApiSync(p.api),this._translationApi=this.getApiSync(C.api);const e=this.getApiSync(A.api);this._productAskQuestionsUrls=new _(e),this._productAskQuestionsController=new x({host:this,formRef:this._formConnectorRef}),this.getApi(n.api).then(s=>{this._productAskQuestionsApi=s}),this.getApi(v.api).then(s=>{this._userApi=s})}static{this.moduleName=n.component}connectedCallback(){super.connectedCallback(),this._flashMessengerContainerName=`${T}-${this.moduleInstanceId}`,document.addEventListener(d.close,this._removeAllMessages),this._fillEmailFieldWithDefaultValue()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(d.close,this._removeAllMessages)}_closeModal(){document.querySelector(`#product-ask-questions-modal-${this.moduleInstanceId}`)?.close()}render(){return $` 2 <form-connector 3 ${Q(this._formConnectorRef)} 4 @submit=${this._onSubmit} 5 @submitError=${this._onSubmitError} 6 @formInvalid=${this._onFormInvalid} 7 id="product-ask-questions-connector-${this.moduleInstanceId}" 8 submit-strategy="frontApi" 9 > 10 <form 11 id="product-ask-questions-form-${this.moduleInstanceId}" 12 action="${this._productAskQuestionsUrls.getAskForProductUrl(this.productId)}" 13 method="post" 14 >
15 ${this.getSlot("form")} 16 </form> 17 </form-connector> 18 `}}f([m({type:Number,attribute:"product-id"})],u.prototype,"productId");f([m({type:Number,attribute:"module-instance-id"})],u.prototype,"moduleInstanceId");class ss extends k{static{this.featureName=n.feature}async init(){const e=this.getApiSync(P),s=await this.getApi(A.api),t=await this.getApi(p.api),r=new q({httpApi:e,settingsApi:s,flashMessengerApi:t});return{cores:[{type:I.api,instance:[new H({productAskQuestionsService:r})]},{type:b,instance:[u]}]}}}export{ss as ProductAskQuestionsInitializer};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.