import{j as e,u as D,a as T,b as W,c as q,d as H,A as O,P as Y,t,e as G,E as Q,f as U}from"./index-CzTQZzQy.js";import{r as a}from"./vendor-L5FivjNr.js";import{C as J,a as K,b as V,F as S,c as p,I}from"./index-BrpHLgnY.js";import{H as j,S as X}from"./index-CTAc7x3r.js";import{N as g,T as d}from"./index-Dm0I4kYC.js";/**
 * 2026 Paysera
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 *
 * @author Paysera <plugins@paysera.com>
 * @copyright 2026 Paysera
 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
 */const Z=()=>e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),$=()=>e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"}),e.jsx("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"}),e.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}),ee="_noticeContent_trh3h_1",se="_formBody_trh3h_16",te="_fieldRow_trh3h_20",ne="_fieldLabel_trh3h_32",ae="_fieldContent_trh3h_48",re="_requiredMark_trh3h_53",oe="_inputField_trh3h_58",ie="_passwordWrapper_trh3h_81",ce="_toggleButton_trh3h_105",le="_helpText_trh3h_126",de="_connectButton_trh3h_134",ue="_noticeSpacing_trh3h_163",s={noticeContent:ee,formBody:se,fieldRow:te,fieldLabel:ne,fieldContent:ae,requiredMark:re,inputField:oe,passwordWrapper:ie,toggleButton:ce,helpText:le,connectButton:de,noticeSpacing:ue},he=()=>{const[B,z]=a.useState(!0),[x,w]=a.useState(""),[m,_]=a.useState(""),[f,E]=a.useState(!1),[c,N]=a.useState(!1),[k,u]=a.useState(!1),[l,y]=a.useState(!1),v=D(),{setUser:C}=T(),[F]=W(),[M]=q(),{data:o,isLoading:P}=H(void 0,{refetchOnMountOrArgChange:!1});a.useEffect(()=>{!P&&o&&o.credentials!==void 0&&o.credentials!==null&&(w(o.credentials.clientId),_(o.credentials.clientSecret))},[o,P]);const[i,h]=a.useState({projectId:null,projectPassword:null}),L=()=>{const n={projectId:null,projectPassword:null};let r=!0;return x||(n.projectId=t("Client ID cannot be empty"),r=!1),m||(n.projectPassword=t("Client secret cannot be empty"),r=!1),h(n),r},R=async()=>{if(L()){N(!0),u(!1),y(!1),h({projectId:null,projectPassword:null});try{(await F({clientId:x,clientSecret:m}).unwrap()).success?(y(!0),C(r=>({...r,authorized:!0}))):u(!0)}catch{u(!0),C(r=>({...r,authorized:!1}))}finally{const n=await M().unwrap();C(r=>({...r,connectionStatus:n.connection_status})),N(!1)}}};return e.jsxs(O,{className:"paysera-authorization-page",children:[e.jsx(Y,{title:t("Authorisation"),subtitle:t("Connect your Paysera account to start accepting payments.")}),B&&e.jsx(g,{status:"warning",className:"paysera-custom-notice",onDismiss:()=>{z(!1)},children:e.jsxs("div",{className:s.noticeContent,children:[e.jsx(j,{level:"3",children:t("Security information")}),e.jsx("div",{className:s.noticeSpacing,children:e.jsx(d,{as:"p",children:t("Your connection credentials are securely stored and encrypted. Paysera uses industry-standard security protocols to ensure all transactions are protected.")})})]})}),k&&e.jsx(g,{className:"paysera-custom-notice",status:"error",onDismiss:()=>u(!1),children:e.jsxs("div",{className:s.noticeContent,children:[e.jsx(j,{level:"3",children:t("Connection failed")}),e.jsx("div",{className:s.noticeSpacing,children:e.jsx(d,{as:"p",children:t("Invalid Client ID or Secret. Please check your credentials and try again.")})})]})}),l&&e.jsx(g,{className:"paysera-custom-notice",status:"success",onDismiss:()=>{y(!1)},children:e.jsxs("div",{className:s.noticeContent,children:[e.jsx(j,{level:"3",children:t("Connection successful")}),e.jsx("div",{className:s.noticeSpacing,children:e.jsx(d,{as:"p",children:t("Your Paysera account is connected. You can now configure payment settings.")})})]})}),e.jsxs(J,{className:"paysera-authorization-form",children:[e.jsx(K,{className:"paysera-authorization-form-header",children:e.jsx(j,{level:"3",children:t("Credentials connection")})}),e.jsx(V,{className:s.formBody,children:e.jsxs(S,{gap:v.spacing.xl,direction:"column",children:[e.jsx(p,{children:e.jsxs(S,{gap:v.spacing.lg,direction:"column",children:[e.jsx(p,{children:e.jsxs("div",{className:s.fieldRow,children:[e.jsxs("label",{htmlFor:"paysera-client-id",className:s.fieldLabel,children:[t("Client ID"),e.jsx("span",{className:s.requiredMark,"aria-hidden":"true",children:"*"})]}),e.jsxs("div",{className:s.fieldContent,children:[e.jsx(I,{id:"paysera-client-id",className:s.inputField,value:x,placeholder:t("Client ID"),onChange:n=>{w(n??""),i.projectId&&n&&h({...i,projectId:null})},disabled:c||l,error:i.projectId??void 0}),e.jsx(d,{as:"p",className:s.helpText,children:t("Enter your Client ID found in Paysera Project > Integrations > Authentication Credentials")})]})]})}),e.jsx(p,{children:e.jsxs("div",{className:s.fieldRow,children:[e.jsxs("label",{htmlFor:"paysera-client-secret",className:s.fieldLabel,children:[t("Client secret"),e.jsx("span",{className:s.requiredMark,"aria-hidden":"true",children:"*"})]}),e.jsxs("div",{className:s.fieldContent,children:[e.jsxs("div",{className:s.passwordWrapper,children:[e.jsx(I,{id:"paysera-client-secret",type:f?"text":"password",value:m,onChange:n=>{_(n??""),i.projectPassword&&n&&h({...i,projectPassword:null})},placeholder:t("Client secret"),disabled:c||l,error:i.projectPassword??void 0}),e.jsx("button",{type:"button",className:s.toggleButton,onClick:()=>E(n=>!n),disabled:c||l,"aria-label":f?t("Hide password"):t("Show password"),children:f?e.jsx(Z,{}):e.jsx($,{})})]}),e.jsx(d,{as:"p",className:s.helpText,children:t("Enter your Client secret found in Paysera Project > Integrations > Authentication Credentials")})]})]})})]})}),e.jsx(p,{children:e.jsxs("div",{className:s.fieldRow,children:[e.jsx("div",{className:s.fieldLabel,"aria-hidden":"true"}),e.jsx("div",{className:s.fieldContent,children:e.jsx("button",{type:"button",className:s.connectButton,onClick:R,disabled:c||l,children:c?e.jsx(X,{}):t("Connect to Paysera")})})]})})]})})]})]})},A=a.memo(he);A.displayName="AuthorizationPage";const b=document.getElementById("paysera-react-root");b&&G(b).render(e.jsx(Q,{children:e.jsx(U,{children:e.jsx(A,{})})}));
