1import{r as i,aj as s,p as e,L as U,T as W,B as h,af as q,S as o,ag as x,v as n,b2 as y,bF as M,bj as b}from"./index-C9IH3k-2.js";import{S as V,V as _,P as D,C as Y,l as $,g as B,s as H,d as K}from"./planFeatureItemPriceApi-CNS5-Qqw.js";import{I as G,N as J,T as d,J as Q}from"./TemplateUtil-D1DzmWLm.js";import{F as X}from"./Table-isZ0WXp4.js";import{S as g}from"./index-8jSYgZzf.js";import{P as Z}from"./index-C0dhduHx.js";import"./Wrapper-ChjuDa3w.js";import"./HelperMethods-C-ewwU_x.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";const{Title:ee,Text:te}=W,ue=()=>{const[I,S]=i.useState([]),[c,T]=i.useState([]),[w,j]=i.useState(!1),[P,m]=i.useState(!1),[r,p]=i.useState(null),[C,f]=i.useState(!1),[l]=s.useForm(),v=s.useWatch("valueType",l),u=async()=>{j(!0);try{const t=await $();t?.status===200&&S(t.data||[])}finally{j(!1)}},F=async()=>{try{const t=await B();t?.status===200&&T((t.data||[]).filter(a=>a.name))}catch{}};i.useEffect(()=>{u(),F()},[]);const E=i.useMemo(()=>c.map(t=>({value:t.name,label:t.displayName||t.name})),[c]),k=i.useMemo(()=>Object.fromEntries(c.map(t=>[t.name,t.displayName||t.name])),[c]),A=()=>{p(null),l.resetFields(),l.setFieldsValue({active:!0,display:!0,currency:"INR",valueType:"COUNT",priceType:"MONTHLY"}),m(!0)},O=t=>{p(t),l.setFieldsValue({...t}),m(!0)},N=t=>{t&&!l.getFieldValue("section")&&l.setFieldsValue({section:t.split(".")[0]})},L=async t=>{f(!0);try{(await H({...r||{},...t}))?.status===200&&(b.success({title:r?"Add-on updated":"Add-on created"}),m(!1),p(null),l.resetFields(),u())}catch{}finally{f(!1)}},z=async t=>{(await K(t))?.status===200&&(b.success({title:"Add-on deleted"}),u())},R=[{title:"Key",dataIndex:"key",fixed:"left",width:220},{title:"Label",dataIndex:"label"},{title:"Section",dataIndex:"section",width:130},{title:"Type",dataIndex:"valueType",width:90,render:t=>e.jsx(d,{children:t})},{title:"Billing",dataIndex:"priceType",width:100,render:t=>e.jsx(d,{color:t==="MONTHLY"?"blue":"purple",children:t})},{title:"Price",key:"price",width:130,render:(t,a)=>`${a.currency||""} ${a.price??"-"}${a.valueType==="COUNT"&&a.unit?` / ${a.unit}`:""}`},{title:"Order",dataIndex:"displayOrder",width:80},{title:"Applicable plans",dataIndex:"applicablePlanSlugs",render:t=>t&&t.length?e.jsx(n,{wrap:!0,size:[4,4],children:t.map(a=>e.jsx(d,{color:"geekblue",children:k[a]||a},a))}):e.jsx(d,{children:"All plans"})},{title:"Status",key:"status",width:150,render:(t,a)=>e.jsxs(n,{children:[e.jsx(d,{color:a.active?"green":"default",children:a.active?"Active":"Inactive"}),e.jsx(d,{color:a.display?"green":"default",children:a.display?"Shown":"Hidden"})]})},{title:"Actions",key:"actions",fixed:"right",width:130,render:(t,a)=>e.jsxs(n,{children:[e.jsx(h,{type:"text",icon:e.jsx(M,{}),size:"small",onClick:()=>O(a),children:"Edit"}),e.jsx(Z,{title:"Delete this add-on?",okText:"Yes",cancelText:"No",onConfirm:()=>z(a.id),children:e.jsx(h,{type:"text",danger:!0,icon:e.jsx(Q,{}),size:"small",children:"Delete"})})]})}];return e.jsxs(G,{children:[e.jsxs(U,{justify:"space-between",align:"center",style:{marginBottom:16},children:[e.jsx(ee,{level:4,style:{margin:0},children:"Add-on Catalog"}),e.jsx(h,{type:"primary",icon:e.jsx(q,{}),onClick:A,children:"Create add-on"})]}),e.jsx(X,{rowKey:"key",columns:R,dataSource:I,loading:w,scroll:{x:1200},pagination:{pageSize:20,showSizeChanger:!0}}),e.jsx(J,{open:P,title:r?"Edit add-on":"Create add-on",okText:r?"Update":"Create",confirmLoading:C,onCancel:()=>m(!1),onOk:()=>l.submit(),destroyOnHidden:!0,width:640,children:e.jsxs(s,{form:l,layout:"vertical",onFinish:L,children:[e.jsx(s.Item,{name:"key",label:"Feature key",rules:[{required:!0,message:"Select a feature key"}],children:e.jsx(o,{placeholder:"Select feature key",disabled:!!r,showSearch:!0,onChange:N,options:V.map(t=>({value:t,label:t}))})}),e.jsx(s.Item,{name:"label",label:"Label",rules:[{required:!0,message:"Label is required"}],children:e.jsx(x,{placeholder:"e.g. Extra agent"})}),e.jsx(s.Item,{name:"description",label:"Description",children:e.jsx(x.TextArea,{rows:2,placeholder:"Shown to the customer"})}),e.jsxs(n,{style:{width:"100%"},size:"middle",children:[e.jsx(s.Item,{name:"section",label:"Section",style:{flex:1,minWidth:180},children:e.jsx(x,{placeholder:"auto from key"})}),e.jsx(s.Item,{name:"displayOrder",label:"Display order",style:{minWidth:140},children:e.jsx(y,{min:0,style:{width:"100%"}})})]}),e.jsxs(n,{style:{width:"100%"},size:"middle",children:[e.jsx(s.Item,{name:"valueType",label:"Value type",rules:[{required:!0}],style:{minWidth:160},children:e.jsx(o,{options:_.map(t=>({value:t,label:t}))})}),e.jsx(s.Item,{name:"priceType",label:"Billing",rules:[{required:!0}],style:{minWidth:160},children:e.jsx(o,{options:D.map(t=>({value:t,label:t}))})}),v==="COUNT"&&e.jsx(s.Item,{name:"unit",label:"Unit (per N)",style:{minWidth:140},tooltip:"Increment size, e.g. 1 agent or 1000 contacts",children:e.jsx(y,{min:1,style:{width:"100%"}})})]}),e.jsxs(n,{style:{width:"100%"},size:"middle",children:[e.jsx(s.Item,{name:"price",label:"Price (pre-GST)",rules:[{required:!0,message:"Price is required"}],style:{minWidth:180},children:e.jsx(y,{min:0,style:{width:"100%"}})}),e.jsx(s.Item,{name:"currency",label:"Currency",style:{minWidth:140},children:e.jsx(o,{showSearch:!0,options:Y.map(t=>({value:t,label:t}))})})]}),e.jsx(s.Item,{name:"applicablePlanSlugs",label:"Applicable plans",extra:"Leave empty to offer this add-on on all plans.",children:e.jsx(o,{mode:"multiple",allowClear:!0,showSearch:!0,optionFilterProp:"label",placeholder:"All plans",options:E})}),e.jsxs(n,{size:"large",children:[e.jsx(s.Item,{name:"active",label:"Active",valuePropName:"checked",children:e.jsx(g,{})}),e.jsx(s.Item,{name:"display",label:"Shown in catalog",valuePropName:"checked",children:e.jsx(g,{})})]}),!r&&e.jsx(te,{type:"secondary",children:"The feature key is fixed once created (it is the catalog identity)."})]})})]})};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.