1import{r as g,aj as s,C as R,ac as N,bl as y,p as e,a0 as n,B as I,T as w,a1 as a,ag as u,w as U,S as c,v,b2 as b,y as E,bj as P}from"./index-C9IH3k-2.js";import{R as C}from"./ArrowLeftOutlined-Bixtqyn1.js";import{I as D}from"./TemplateUtil-D1DzmWLm.js";import{R as q}from"./InfoCircleOutlined-B7sKwm1k.js";import{D as A}from"./index-CmSVNJzc.js";import"./Wrapper-ChjuDa3w.js";import"./HelperMethods-C-ewwU_x.js";import"./index-Bv3SRNsl.js";import"./CalendarOutlined-DyzsKNdO.js";import"./ClockCircleOutlined-Cym7vptW.js";const{Title:F}=w,{Option:l}=c,f=[{value:"INR",label:"INR",symbol:"â¹"},{value:"USD",label:"USD",symbol:"$"}],S=m=>{if(!m)return{amount:void 0,currency:"INR"};const d=m.trim(),o={"â¹":"INR",$:"USD"},h=d.charAt(0),p=o[h]||"INR",r=Number(d.replace(/[â¹$,]/g,"").trim());return{amount:isNaN(r)?void 0:r,currency:p}},H=()=>{const[m,d]=g.useState(!1),[o]=s.useForm(),h=R(),r=N().state?.itemdata;g.useEffect(()=>{if(r){const t=S(r.price),i=S(r.sale_price),x={...r,price:{currency:t.currency,amount:t.amount},salePrice:{currency:i.currency,amount:i.amount},sale_dates:r.sale_price_start_date&&r.sale_price_end_date?[y(r.sale_price_start_date),y(r.sale_price_end_date)]:void 0};o.setFieldsValue(x)}},[r,o]);const _=async t=>{d(!0);try{const{sale_dates:i,...x}=t,j={...x,price:`${t.price.amount} ${t.price.currency}`,sale_price:`${t.salePrice.amount} ${t.salePrice.currency}`,sale_price_start_date:i?.[0]?.toISOString(),sale_price_end_date:i?.[1]?.toISOString()};r?.id&&(j.id=r.id),await E("/api/v1/catalog/product",j)&&(P.success({title:"Success",description:`Item successfully ${r?"updated":"added"} to catalog`}),h("/Catalog/ItemsList"))}catch(i){P.error({title:"Error",description:`Failed to ${r?"update":"add"} item to catalog`}),console.error(`Failed to ${r?"update":"add"} item:`,i)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(n,{align:"middle",style:{marginBottom:"24px"},children:[e.jsx(I,{icon:e.jsx(C,{}),onClick:()=>h("/Catalog/ItemsList"),style:{marginRight:"16px"}}),e.jsxs(F,{level:4,style:{margin:0},children:[r?"Update":"Add New"," Catalog Item"]})]}),e.jsx(D,{style:{borderRadius:"12px"},children:e.jsxs(s,{form:o,layout:"vertical",onFinish:_,initialValues:{condition:"NEW",availability:"in_stock",regularPrice:{currency:"INR",amount:void 0},salePrice:{currency:"INR",amount:void 0}},children:[e.jsxs(n,{gutter:[16,16],children:[e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"retailer_id",label:e.jsxs("span",{children:["Retailer Product ID / SKU Id"," ",e.jsx(U,{title:"Unique ID of the product",children:e.jsx(q,{})})]}),rules:[{required:!0,message:"Please enter Retailer ID"}],children:e.jsx(u,{placeholder:"Enter Retailer ID"})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"name",label:"Name",rules:[{required:!0,message:"Please enter the name"}],children:e.jsx(u,{placeholder:"Enter Product Name"})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:12,children:e.jsx(s.Item,{name:"description",label:"Description",children:e.jsx(u.TextArea,{rows:1,placeholder:"Enter a brief description"})})})]}),e.jsxs(n,{gutter:[16,16],children:[e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"age_group",label:"Age Group",children:e.jsxs(c,{placeholder:"Select Age Group",children:[e.jsx(l,{value:"newborn",children:"Newborn"}),e.jsx(l,{value:"infant",children:"Infant"}),e.jsx(l,{value:"toddler",children:"Toddler"}),e.jsx(l,{value:"kids",children:"Kids"}),e.jsx(l,{value:"adult",children:"Adult"})]})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"availability",label:"Availability",rules:[{required:!0,message:"Please select availability"}],children:e.jsxs(c,{placeholder:"Select Availability",children:[e.jsx(l,{value:"in_stock",children:"In Stock"}),e.jsx(l,{value:"out_of_stock",children:"Out of Stock"}),e.jsx(l,{value:"available_for_order",children:"Available for Order"}),e.jsx(l,{value:"discontinued",children:"Discontinued"})]})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"condition",label:"Condition",rules:[{required:!0,message:"Please select a condition"}],children:e.jsxs(c,{placeholder:"Select Condition",children:[e.jsx(l,{value:"NEW",children:"New"}),e.jsx(l,{value:"REFURBISHED",children:"Refurbished"}),e.jsx(l,{value:"USED",children:"Used"})]})})})]}),e.jsxs(n,{gutter:[16,16],children:[e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{label:"Price",required:!0,children:e.jsxs(v.Compact,{style:{width:"100%"},children:[e.jsx(s.Item,{name:["price","currency"],rules:[{required:!0,message:"Please select currency"}],noStyle:!0,children:e.jsx(c,{showSearch:!0,style:{width:105},popupMatchSelectWidth:!1,placeholder:"Currency",optionFilterProp:"children",children:f.map(t=>e.jsx(l,{value:t.value,children:t.label},t.value))})}),e.jsx(s.Item,{name:["price","amount"],rules:[{required:!0,message:"Please enter price"}],noStyle:!0,children:e.jsx(b,{style:{width:"100%"},placeholder:"Enter Price",precision:2,min:0})})]})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{label:"Sale Price",required:!0,children:e.jsxs(v.Compact,{style:{width:"100%"},children:[e.jsx(s.Item,{name:["salePrice","currency"],rules:[{required:!0,message:"Please select currency"}],noStyle:!0,children:e.jsx(c,{showSearch:!0,style:{width:105},popupMatchSelectWidth:!1,placeholder:"Currency",optionFilterProp:"children",children:f.map(t=>e.jsx(l,{value:t.value,children:t.label},t.value))})}),e.jsx(s.Item,{name:["salePrice","amount"],rules:[{required:!0,message:"Please enter sale price"}],noStyle:!0,children:e.jsx(b,{style:{width:"100%"},placeholder:"Enter Sale Price",precision:2,min:0})})]})})})]}),e.jsxs(n,{gutter:[16,16],children:[e.jsx(a,{xs:24,sm:12,md:12,lg:6,children:e.jsx(s.Item,{name:"url",label:"Product URL",rules:[{required:!0,type:"url",message:"Please enter a valid URL"}],children:e.jsx(u,{placeholder:"Enter Product URL"})})}),e.jsx(a,{xs:24,sm:12,md:12,lg:6,children:e.jsx(s.Item,{name:"image_url",label:"Image URL",rules:[{required:!0,type:"url",message:"Please enter a valid URL"}],children:e.jsx(u,{placeholder:"Enter Image URL"})})})]}),e.jsxs(n,{gutter:[16,16],children:[e.jsx(a,{xs:24,md:12,lg:12,children:e.jsx(s.Item,{name:"sale_dates",label:"Sale Period",children:e.jsx(A.RangePicker,{showTime:!0,style:{width:"100%"}})})}),e.jsx(a,{xs:24,sm:12,md:8,lg:6,children:e.jsx(s.Item,{name:"gender",label:"Gender",children:e.jsxs(c,{placeholder:"Select gender",children:[e.jsx(l,{value:"male",children:"Male"}),e.jsx(l,{value:"female",children:"Female"}),e.jsx(l,{value:"unisex",children:"Unisex"})]})})})]}),e.jsx(n,{justify:"end",children:e.jsx(a,{children:e.jsxs(I,{type:"primary",htmlType:"submit",loading:m,children:[r?"Update":"Add"," Item"]})})})]})})]})};export{H 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.