1import{u as I,j as s,D as E,r,aW as L}from"./vendor-799a4a96.js";import{g as D,h as R,i as F,C as G,f as V}from"./catalog-event-params-9bc5ad87.js";import{u as q,r as w,i as B}from"./resolve-catalog-context-ca2161a8.js";import{at as K,r as j,b as O,j as H}from"./index-e8881ec2.js";import{u as W}from"./useSignupStepGuard-d6debf09.js";import{f as X}from"./finish-onboarding-8dc823eb.js";import"./signup-variant.adapter-e5ee2c99.js";const z=e=>{/^\d$/.test(e.key)||e.preventDefault()},J=e=>{const t=e.currentTarget,n=t.value.length;t.setSelectionRange(n,n)};function Q({item:e,value:t,placeholder:n,maxLength:a,formatValue:c,onChange:o}){const{t:u}=I("signup");return s.jsxs("div",{className:"new-signup__price-row",children:[s.jsx("span",{className:"new-signup__price-row-name",children:e.description}),s.jsx("span",{className:"new-signup__price-row-spacer"}),s.jsx("label",{className:"new-signup__price-row-label",htmlFor:`price-${e.uid}`,children:u("price_label")}),s.jsx("input",{id:`price-${e.uid}`,className:"new-signup__price-input",inputMode:"numeric",placeholder:n,value:t,maxLength:a,"data-cy":`price-input-${e.uid}`,onClick:J,onKeyPress:z,onChange:l=>o(e.uid,c(l.target.value))})]})}const U=9;function k(e){return U+e.decimalPlaces}function N(e,t){return String(e??"").replace(/\D/g,"").slice(0,k(t))}function Y(e){const t={...K,...e??{}};return{symbol:t.currency_code,decimalSeparator:t.currency_decimal_separator,thousandsSeparator:t.currency_thousands_separator,decimalPlaces:t.currency_decimal_places}}function C(e,t){const n=N(e,t);if(!n)return"";const a=10**t.decimalPlaces,c=parseInt(n,10),o=Math.floor(c/a).toString().replace(/\B(?=(\d{3})+(?!\d))/g,t.thousandsSeparator),u=String(c%a).padStart(t.decimalPlaces,"0");return t.decimalPlaces>0?`${t.symbol} ${o}${t.decimalSeparator}${u}`:`${t.symbol} ${o}`}function Z(e,t){const n=N(e,t);return n?Number.parseInt(n,10)/10**t.decimalPlaces:0}function ee(e){return C("0",e)}function te(e){return C("9".repeat(k(e)),e).length}const y=`${j.newSignup.home}/${j.newSignup.install}`,se=()=>{const e=E(),{isAllowed:t}=W("prices"),n=O(i=>{var _;return(_=i.formSignupData)==null?void 0:_.locale_config}),{status:a,bucketId:c,items:o,selectedIds:u,prices:l,loadInitialCatalogAct:f,setPriceAct:b,resetCatalogAct:h}=q(),[m,d]=r.useState(!1),x=r.useRef(!1);r.useEffect(()=>{t&&a==="available"&&!x.current&&(x.current=!0,D())},[t,a]),r.useEffect(()=>{if(t&&a==="idle"){const i=w();f(i.shopCode,i.bucketId)}},[t,a,f]);const S=r.useCallback(()=>{H.setCurrentStep("install"),e(y,{replace:!0})},[e]);r.useEffect(()=>{t&&(a==="unavailable"||a==="error")&&S()},[t,a,S]);const p=r.useMemo(()=>Y(n),[n]),M=r.useMemo(()=>ee(p),[p]),T=r.useMemo(()=>te(p),[p]),$=r.useCallback(i=>C(i,p),[p]),g=r.useMemo(()=>o.filter(i=>u.includes(i.uid)),[o,u]),v=g.filter(i=>!!l[i.uid]).length,A=r.useCallback(async()=>{const{shopCode:i}=w();if(m||!i||!c||!g.length)return;const _={bucket_id:c,items:g.map(P=>({...P,price:Z(l[P.uid]??"",p)}))};d(!0);try{const{success:P}=await B.createInitialCatalog(i,_);P&&(R(F(g,l)),await X(),h(),e(y,{replace:!0}))}finally{d(!1)}},[m,c,g,l,p,h,e]);return{isAllowed:t,isLoading:a==="idle"||a==="loading",isSubmitting:m,selectedItems:g,pricedCount:v,prices:l,pricePlaceholder:M,priceMaxLength:T,formatValue:$,setPrice:b,handleConclude:A}};function ue(){const{t:e}=I("signup"),{isAllowed:t,isLoading:n,isSubmitting:a,selectedItems:c,pricedCount:o,prices:u,pricePlaceholder:l,priceMaxLength:f,formatValue:b,setPrice:h,handleConclude:m}=se();return t?s.jsx(G,{dataCy:"prices-step",header:s.jsxs(s.Fragment,{children:[s.jsx("h1",{children:e("prices_title")}),s.jsxs("p",{children:[s.jsx("span",{className:"new-signup__tag",children:e("prices_optional_tag")}),s.jsx("span",{children:e("prices_subtitle")})]})]}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"new-signup__fluid-counter",children:s.jsx(L,{i18nKey:"signup:prices_counter",values:{priced:o,total:c.length},components:{b:s.jsx("b",{})}})}),s.jsx("button",{type:"button",className:"new-signup__button new-signup__button--compact","data-cy":"prices-conclude",disabled:n||a,onClick:m,children:e("translations:conclude")})]}),children:n?s.jsx(V,{withPrice:!0,groups:1,rowsPerGroup:6,dataCy:"prices-skeleton"}):c.map(d=>s.jsx(Q,{item:d,value:u[d.uid]??"",placeholder:l,maxLength:f,formatValue:b,onChange:h},d.uid))}):null}export{ue as default};
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.