1import{aZ as f,au as D,T as w,u as H,a3 as q,a as K,r as o,b6 as x,s as z,b7 as B,j as s,b as Z,g as h,F as G,R as u,C as r,L as d,I as j,az as R,z as J,b8 as Q,E as W,ag as X,e as P}from"./index-CvXYjFvv.js";import{D as Y}from"./Divider-KYSi5gra.js";import{c as E}from"./Translated-8PB2D1ma.js";import{f as _}from"./Partner-BPk4FTGv.js";import{S as ee}from"./SelectField-gTpXyXxZ.js";import{I as se}from"./InputPrice-BXeASI-k.js";import{U as te}from"./UploadImage-CPjt1-l0.js";import"./Loading-BY5f2I3F.js";function ne(e){const n={};return n.info=E(i=>({name:e.info[i]?.name||e.info[i]?.description||"",description:e.info[i]?.description||e.info[i]?.name||""})),n.idOnPos=e.idOnPos,n.nameOnPos=e.nameOnPos,n.price=e.price,n.type=e.type,n.image=e.image?.id?{id:e.image.id||0,path:e.image.path||"",url:e.image.url||""}:null,n}function ae(e){const n=f(),i=n.map(c=>`info.${c.code}.description`);return i.push("type"),D(i,e)?null:(n.map(c=>{e.info[c.code].name=e.info[c.code].description}),e.image=e.image?.id?{id:+e.image.id}:null,e)}const ue=()=>{const e=w(),n=H(),c=q.getState().bootstrap.partnerMeta?.pos?.name?.toLowerCase()||"",S=!["ipratico"].includes(c),b=!["xenia"].includes(c),{variantId:l,partnerId:a}=K(),m=l==="0",y=e(m?"common.actions.createVariant":"common.actions.modifyVariant"),M={isActive:!0,partnerId:a,isPublished:!1,info:E(()=>({name:"",description:""})),nameOnPos:"",idOnPos:"",price:0,type:"single",image:{id:0,path:"",url:""}},[T,F]=o.useState(f()),[V,I]=o.useState(x()),[$,g]=o.useState(!0),O=o.useRef(null),[v,L]=o.useState(M),[N,C]=o.useState(!1);o.useEffect(()=>{n(z(`${y}`))}),o.useEffect(()=>{m?_(a).then(()=>{g(!1),F(f()),I(x())}).catch(t=>{console.error(t)}):B(a,l).then(t=>{if(t!==void 0){const p=ne(t);g(!1),F(f()),I(x()),L({...p})}else C(!0),g(!1)}).catch(t=>{console.error(t)})},[a]);const U=[{id:"single",name:e("common.fields.singleSelection")},{id:"multiple",name:e("common.fields.multipleSelection")}],k=t=>{W(t.message);for(const p in t.fields){const A=t.fields[p];X(p,A.message)}};return s.jsx(s.Fragment,{children:N?s.jsx(Q,{}):s.jsxs(s.Fragment,{children:[s.jsx(Z,{pageName:e(y),back:{label:e("common.actions.goBack"),url:h(P.myMenusSubpage,{partnerId:a,tabId:"variants"})},mainAction:{},formikRef:O}),s.jsx(G,{isNewItem:m,action:m?`/menu/variant/${a}`:`/menu/variant/${a}/${l}`,redirectTo:m?h(P.myMenusSubpage,{partnerId:a,tabId:"variants"}):h(P.myMenusSubpage,{partnerId:a,tabId:"variants"})+`#${l}`,beforeSend:ae,initialValues:v,debugMode:!1,successMessage:e("common.actions.changesSaved"),loadingState:$,formikRef:O,errorHandler:k,children:()=>s.jsxs(s.Fragment,{children:[s.jsxs(u,{cells:2,cellAlignment:"start",children:[s.jsx(r,{children:s.jsx(u,{children:T.map(t=>s.jsx(r,{children:s.jsx(d,{text:`${e("common.fields.description")} (${t.code.toUpperCase()})`,isRequired:!0,children:s.jsx(j,{type:"text",name:`info.${t.code}.description`,flag:t.code.toUpperCase(),placeholder:e("common.fields.description")+` (${t.code.toUpperCase()})`})})},t.code))})}),s.jsx(r,{children:s.jsxs(u,{children:[s.jsx(r,{children:s.jsx(d,{text:e("page.interface.posName"),children:s.jsx(j,{type:"text",name:"nameOnPos",isReadOnly:!0,placeholder:e("page.interface.posName")})})}),s.jsx(r,{children:s.jsx(d,{text:e("page.interface.posId"),children:s.jsx(j,{type:"text",name:"idOnPos",flag:"ID",isReadOnly:!0,placeholder:e("page.interface.posId")})})}),s.jsx(r,{children:s.jsxs(d,{text:e("common.fields.price"),children:[s.jsx(se,{name:"price",isReadOnly:!S}),!S&&s.jsx(R,{text:e("common.messages.cannotEditForPos")})]})})]})})]}),s.jsx(Y,{}),s.jsxs(u,{children:[s.jsx(r,{children:s.jsxs(d,{text:e("common.fields.type"),children:[s.jsx(ee,{name:"type",incomingObject:U,optionValue:"id",optionText:"name",isReadOnly:!b}),!b&&s.jsx(R,{text:e("common.messages.cannotEditForPos")})]})}),V&&s.jsx(r,{children:s.jsx(te,{name:"image",label:e("common.fields.image"),scope:["partners",a]})})]}),s.jsx(J,{children:e("common.actions.saveChanges")})]})})]})})};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.