import{g as I,i as K,aH as C,a as N,r as U,cV as c,cR as u,_ as a,j as t,h as r,f,bG as j}from"./main-634.js";import{F}from"./bf-767-388.js";import{c as _}from"./bf-717-463.js";import{F as A}from"./bf-457-387.js";import{C as P}from"./bf-297-103.js";import{S as M}from"./bf-26-460.js";import{S as k}from"./bf-497-246.js";import"./bf-534-247.js";import"./bf-25-81.js";import"./bf-299-245.js";function z({className:S=""}){var b;const{fieldKey:e}=I(),[m,x]=K(C),{css:d}=N();if(!e)return null;const s=m[e],y=(s==null?void 0:s.payType)==="subscription",p=(s==null?void 0:s.amountType)==="dynamic",h=(b=s==null?void 0:s.lbl)!=null?b:"",$=()=>Object.entries(m).filter(i=>i[1].typ.match(/^(radio|number|currency)/)).map(i=>t.jsx("option",{value:i[0],children:i[1].adminLbl||i[1].lbl},i[0])),g=(n,o)=>{o?(s[n]=o,n==="planId"&&c(e,"paypalPlanIdMissing")):delete s[n];const i=f(m,l=>{l[e]=s});x(i),j({event:`${n} changed to ${o}: ${h||e}`,type:`${n}_changed`,state:{fields:i,fldKey:e}})},T=n=>{const{checked:o}=n.target,i=f(m,l=>{o?(l[e].payType="subscription",delete l[e].currency,u({fieldKey:e,errorKey:"paypalPlanIdMissing",errorMsg:a("PayPal Plan Id missing"),errorUrl:`field-settings/${e}`}),c(e,"paypalAmountMissing"),c(e,"paypalAmountFldMissing")):(l[e].currency="USD",delete l[e].payType,delete l[e].planId,c(e,"paypalPlanIdMissing"),u({fieldKey:e,errorKey:"paypalAmountMissing",errorMsg:a("PayPal Fixed Amount is not valid"),errorUrl:`field-settings/${e}`})),delete l[e].amountType,delete l[e].amount,delete l[e].amountFld});x(i),j({event:`Subscription "${o?"On":"Off"}": ${h||e}`,type:"toggle_subscription",state:{fields:i,fldKey:e}})},v=n=>{const{value:o}=n.target,i=f(m,l=>{o?l[e].amountType=o:delete l[e].amountType,delete l[e].amount,delete l[e].amountFld});x(i),j({event:`Amount Type Changed to "${o}": ${h||e}`,type:"set_amount",state:{fields:i,fldKey:e}})};return U.useEffect(()=>{c(e,"paypalAmountFldMissing"),c(e,"paypalAmountMissing"),p&&!s.amountFld?u({fieldKey:e,errorKey:"paypalAmountFldMissing",errorMsg:a("PayPal Dynamic Amount Field is not Selected"),errorUrl:`field-settings/${e}`}):!p&&(!s.amount||s.amount<=0)&&!y&&u({fieldKey:e,errorKey:"paypalAmountMissing",errorMsg:a("PayPal Fixed Amount is not valid"),errorUrl:`field-settings/${e}`}),s.isSubscription&&(s.planId?(c(e,"paypalAmountFldMissing"),c(e,"paypalAmountMissing")):u({fieldKey:e,errorKey:"paypalPlanIdMissing",errorMsg:a("PayPal Plan Id missing"),errorUrl:`field-settings/${e}`}))},[s==null?void 0:s.amountType,s==null?void 0:s.amount,s==null?void 0:s.amountFld]),t.jsxs("div",{className:S,children:[t.jsxs("div",{className:d(r.ml2,r.mr2,r.p1),children:[t.jsx(k,{id:"sbscrptn",title:a("Subscription:"),action:T,isChecked:y,className:"mt-1 mb-1"}),y&&t.jsx(M,{id:"pln-id",inpType:"text",title:a("Plan Id"),value:s.planId||"",action:n=>g("planId",n.target.value),cls:d(F.input)})]}),t.jsx(A,{}),!y&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:d(r.ml2,r.mr2,r.p1),children:t.jsxs("label",{htmlFor:"currency",children:[t.jsx("b",{children:a("Currency")}),t.jsx("select",{"data-testid":"crncy-fld-slct",onChange:n=>g("currency",n.target.value),name:"currency",value:s.currency||"USD",className:d(F.input),children:_.map(n=>t.jsx("option",{value:n.code,children:`${n.currency} - ${n.code}`},n.currency))})]})}),t.jsx(A,{}),t.jsxs("div",{className:d(r.ml2,r.mr2,r.p1),children:[t.jsx("b",{children:a("Amount Type")}),t.jsx("br",{}),t.jsx(P,{id:"amnt-typ-fxd",onChange:v,radio:!0,checked:!p,title:a("Fixed")}),t.jsx(P,{id:"amnt-typ-dynmc",onChange:v,radio:!0,checked:p,title:a("Dynamic"),value:"dynamic"})]}),!p&&t.jsx("div",{className:d(r.ml2,r.mr2,r.p1),children:t.jsx(M,{id:"amnt",cls:d(F.input),inpType:"number",title:a("Amount"),value:s.amount||"",action:n=>g("amount",n.target.value),className:d({mt:0})})}),p&&t.jsxs("div",{className:d(r.ml2,r.mr2,r.p1),children:[t.jsx("b",{children:a("Select Amount Field")}),t.jsxs("select",{"data-testid":"slct-amnt-slct",onChange:n=>g("amountFld",n.target.value),name:"amountFld",className:d(F.input),value:s.amountFld||"",children:[t.jsx("option",{value:"",children:a("Select Field")}),$()]})]})]})]})}export{z as default};
