import{r as e}from"./chunk-DECur_0Z.js";import{t}from"./react-CO2uhaBc.js";import{C as n,S as r,_ as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,o as h,p as g,s as _,tm as v,u as y,v as b,w as x,x as S,y as C}from"./messages-CL4J6BaJ.js";import{t as w}from"./button-NLSeBFht.js";import{t as T}from"./switch-BST3z-JX.js";import{a as E,c as D,s as O}from"./zod-rwFXxHlg.js";import{a as k,c as A,i as j,l as M,n as N,o as P,r as F,s as I,t as L}from"./form-C_YekIvK.js";import{t as R}from"./input-DAqep8ZY.js";import{t as z}from"./password-input-D9YsRteD.js";import{t as B}from"./page-header-B7O10aw9.js";import{a as V,i as H,n as U,r as W,t as G}from"./lib-Ku8Lh36m.js";var K=e(t(),1),q=v(),J=O({allowTokens:D(),apiUrl:D(),callbackUrl:D().url(m()),enabled:E(),returnUrl:D(),shopId:D().min(1,C()),shopToken:D().min(1,i()),timeoutSeconds:D().min(1,c()).refine(e=>Number.isInteger(Number(e))&&Number(e)>0,{message:y()})});function Y(){let e=H(`okpay`),t=V(),n=M({resolver:A(J),defaultValues:{allowTokens:`USDT`,apiUrl:``,callbackUrl:``,enabled:!1,returnUrl:``,shopId:``,shopToken:``,timeoutSeconds:`600`}});(0,K.useEffect)(()=>{let t=e.data?.data;t&&n.reset({allowTokens:X(G(t,`okpay.allow_tokens`,`USDT`)).join(`,`),apiUrl:G(t,`okpay.api_url`),callbackUrl:G(t,`okpay.callback_url`),enabled:[`1`,`true`,`yes`].includes(G(t,`okpay.enabled`).toLowerCase()),returnUrl:G(t,`okpay.return_url`),shopId:G(t,`okpay.shop_id`),shopToken:G(t,`okpay.shop_token`),timeoutSeconds:G(t,`okpay.timeout_seconds`,`600`)})},[e.data,n]);async function i(n){await W(t.mutateAsync,[{group:`okpay`,key:`okpay.enabled`,type:`bool`,value:n.enabled?`true`:`false`},{group:`okpay`,key:`okpay.shop_id`,type:`string`,value:n.shopId},{group:`okpay`,key:`okpay.shop_token`,type:`string`,value:n.shopToken},{group:`okpay`,key:`okpay.timeout_seconds`,type:`int`,value:n.timeoutSeconds},{group:`okpay`,key:`okpay.callback_url`,type:`string`,value:n.callbackUrl}],h()),await e.refetch()}async function c(){await U(t.mutateAsync,[{group:`okpay`,key:`okpay.enabled`,type:`bool`,value:!1},{group:`okpay`,key:`okpay.shop_id`,type:`string`,value:``},{group:`okpay`,key:`okpay.shop_token`,type:`string`,value:``},{group:`okpay`,key:`okpay.api_url`,type:`string`,value:``},{group:`okpay`,key:`okpay.callback_url`,type:`string`,value:``},{group:`okpay`,key:`okpay.return_url`,type:`string`,value:``},{group:`okpay`,key:`okpay.timeout_seconds`,type:`int`,value:600},{group:`okpay`,key:`okpay.allow_tokens`,type:`string`,value:``}],f()),await e.refetch()}return(0,q.jsx)(L,{...n,children:(0,q.jsxs)(`form`,{className:`space-y-6`,onSubmit:n.handleSubmit(i),children:[(0,q.jsx)(j,{control:n.control,name:`enabled`,render:({field:e})=>(0,q.jsxs)(k,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,q.jsx)(P,{children:r()}),(0,q.jsx)(F,{children:S()})]}),(0,q.jsx)(N,{children:(0,q.jsx)(T,{checked:e.value,onCheckedChange:e.onChange})})]})}),(0,q.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,q.jsx)(j,{control:n.control,name:`shopId`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:o()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{autoComplete:`off`,...e})}),(0,q.jsx)(I,{})]})}),(0,q.jsx)(j,{control:n.control,name:`shopToken`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:b()}),(0,q.jsx)(N,{children:(0,q.jsx)(z,{autoComplete:`off`,...e})}),(0,q.jsx)(I,{})]})}),(0,q.jsx)(j,{control:n.control,name:`timeoutSeconds`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:l()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{inputMode:`numeric`,placeholder:`600`,...e})}),(0,q.jsx)(I,{})]})})]}),(0,q.jsx)(j,{control:n.control,name:`apiUrl`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:u()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{disabled:!0,placeholder:`https://api.okpay.example`,...e})}),(0,q.jsx)(I,{})]})}),(0,q.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,q.jsx)(j,{control:n.control,name:`callbackUrl`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:d()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{placeholder:`https://example.com/notify`,...e})}),(0,q.jsx)(I,{})]})}),(0,q.jsx)(j,{control:n.control,name:`returnUrl`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:g()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{disabled:!0,placeholder:`https://example.com/success`,...e})}),(0,q.jsx)(I,{})]})})]}),(0,q.jsx)(j,{control:n.control,name:`allowTokens`,render:({field:e})=>(0,q.jsxs)(k,{children:[(0,q.jsx)(P,{children:p()}),(0,q.jsx)(N,{children:(0,q.jsx)(R,{disabled:!0,placeholder:`USDT,USDC`,...e})}),(0,q.jsx)(F,{children:s()}),(0,q.jsx)(I,{})]})}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(w,{disabled:t.isPending||e.isLoading,type:`submit`,children:_()}),(0,q.jsx)(w,{disabled:t.isPending,onClick:c,type:`button`,variant:`outline`,children:a()})]})]})})}function X(e){return e.split(/[\s,]+/).map(e=>e.trim().toUpperCase()).filter(Boolean)}function Z(){return(0,q.jsx)(B,{description:n(),title:x(),variant:`section`,children:(0,q.jsx)(Y,{})})}var Q=Z;export{Q as component};