import{a as e,n as t,r as n}from"./react-dom-stZKkA6x.js";import{a as r,d as i,r as a,u as o}from"./theme-DNlqAiGO.js";import{G as s,i as c,jt as l,kt as u,n as d,st as f,t as p}from"./jsx-runtime-dm82oUI8.js";import{o as m}from"./grid-DcIFgt5N.js";import{n as h,r as g,t as _}from"./table-CHt5qwx3.js";import{n as v,r as y,t as b}from"./StatusPill-Bcw_ne6L.js";import{t as x}from"./descriptions-vs1os_w7.js";import{t as S}from"./form-BRrMNJiX.js";import{t as ee}from"./input-0_Xo22Fl.js";import{t as te}from"./modal-BNBPl4Qp.js";import{t as ne}from"./popconfirm-DHzKhZl9.js";import{t as re}from"./CopyOutlined-CjLq_nuP.js";import{n as ie,t as ae}from"./EditOutlined-BjvG9r8B.js";import{t as oe}from"./PlusOutlined-CILz_LKx.js";import{t as se}from"./ReloadOutlined-Cq8HKCaL.js";import{_ as C,b as w,f as ce,h as le,n as ue,o as de,p as fe}from"./index-CBPGvhVC.js";import{t as pe}from"./EmptyState-rI31ioMm.js";import{t as T}from"./CodeBlock-B-NIgQUI.js";import{n as E,t as D}from"./navigation-state-ixI_efPF.js";var O=n((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={icon:{tag:`svg`,attrs:{viewBox:`64 64 896 896`,focusable:`false`},children:[{tag:`path`,attrs:{d:`M928 161H699.2c-49.1 0-97.1 14.1-138.4 40.7L512 233l-48.8-31.3A255.2 255.2 0 00324.8 161H96c-17.7 0-32 14.3-32 32v568c0 17.7 14.3 32 32 32h228.8c49.1 0 97.1 14.1 138.4 40.7l44.4 28.6c1.3.8 2.8 1.3 4.3 1.3s3-.4 4.3-1.3l44.4-28.6C602 807.1 650.1 793 699.2 793H928c17.7 0 32-14.3 32-32V193c0-17.7-14.3-32-32-32zM324.8 721H136V233h188.8c35.4 0 69.8 10.1 99.5 29.2l48.8 31.3 6.9 4.5v462c-47.6-25.6-100.8-39-155.2-39zm563.2 0H699.2c-54.4 0-107.6 13.4-155.2 39V298l6.9-4.5 48.8-31.3c29.7-19.1 64.1-29.2 99.5-29.2H888v488zM396.9 361H211.1c-3.9 0-7.1 3.4-7.1 7.5v45c0 4.1 3.2 7.5 7.1 7.5h185.7c3.9 0 7.1-3.4 7.1-7.5v-45c.1-4.1-3.1-7.5-7-7.5zm223.1 7.5v45c0 4.1 3.2 7.5 7.1 7.5h185.7c3.9 0 7.1-3.4 7.1-7.5v-45c0-4.1-3.2-7.5-7.1-7.5H627.1c-3.9 0-7.1 3.4-7.1 7.5zM396.9 501H211.1c-3.9 0-7.1 3.4-7.1 7.5v45c0 4.1 3.2 7.5 7.1 7.5h185.7c3.9 0 7.1-3.4 7.1-7.5v-45c.1-4.1-3.1-7.5-7-7.5zm416 0H627.1c-3.9 0-7.1 3.4-7.1 7.5v45c0 4.1 3.2 7.5 7.1 7.5h185.7c3.9 0 7.1-3.4 7.1-7.5v-45c.1-4.1-3.1-7.5-7-7.5z`}}]},name:`read`,theme:`outlined`}})),k=e(t()),A=e(O());function j(){return j=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},j.apply(this,arguments)}var me=k.forwardRef((e,t)=>k.createElement(o,j({},e,{ref:t,icon:A.default})));function M(e={}){return!!(e.token&&e.tokenRecoverable!==!1)}function he(e={}){return M(e)?String(e.token):``}function ge(e={}){return e.tokenPrefix?`${e.tokenPrefix}...`:`-`}function N({endpoint:e=`/api/send`,token:t=`<USER_API_TOKEN>`,from:n=`noreply@example.com`,to:r=`user@example.com`}={}){let i=JSON.stringify({from:n,to:r,subject:`Hello from MailHub`,text:`Signed with DKIM and queued by MailHub.`},null,2);return{requestBody:i,successResponse:JSON.stringify({queued:!0,domain:L(n)||`example.com`,recipients:[r],smtp:`Message queued`},null,2),curl:`curl -X POST ${e} \\
  -H 'Authorization: Bearer ${t}' \\
  -H 'Content-Type: application/json' \\
  -d '${i}'`,nodeFetch:`const response = await fetch('${e}', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer ${t}',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    from: '${n}',
    to: '${r}',
    subject: 'Hello from MailHub',
    text: 'Signed with DKIM and queued by MailHub.'
  })
});

const result = await response.json();`}}function _e({endpoint:e=`/api/mailboxes`,token:t=`<USER_API_TOKEN>`,domain:n=`example.com`}={}){let r={mode:`permanent`,address:`support@${n}`,password:`<MAILBOX_PASSWORD>`,displayName:`Support`},i={mode:`temporary`,domain:n,expiresInMinutes:60};return{permanent:JSON.stringify(r,null,2),temporary:JSON.stringify(i,null,2),permanentCurl:F(e,t,r),temporaryCurl:F(e,t,i),successResponse:JSON.stringify({mailbox:{address:`tmp-abc123@${n}`,temporary:!0,expiresAt:`2026-07-14T12:00:00.000Z`},password:`<GENERATED_MAILBOX_PASSWORD>`,clientConfig:{incoming:{protocol:`IMAP`,port:993,security:`SSL/TLS`},outgoing:{protocol:`SMTP`,port:465,security:`SSL/TLS`}}},null,2)}}function P({endpoint:e=`/api/inbound-messages`,mailboxEndpoint:t=`/api/inbound-mailboxes`,token:n=`<USER_API_TOKEN>`,mailboxId:r=42,messageId:i=108}={}){let a=`${e}?${new URLSearchParams({page:`1`,pageSize:`20`,mailboxId:String(r),folder:`INBOX`,read:`false`,q:`invoice`})}`,o=`${e}/${i}`,s=`${t}/${r}/folders`,c={id:i,mailboxId:r,folder:`INBOX`,sender:`billing@example.net`,recipients:[`accounts@example.com`],subject:`Invoice 2026-07`,messageId:`<invoice-2026-07@example.net>`,read:!1,receivedAt:`2026-07-14T12:00:00.000Z`};return{listCurl:I(a,n),detailCurl:I(o,n),foldersCurl:I(s,n),listResponse:JSON.stringify({messages:[c],total:1,page:1,pageSize:20},null,2),detailResponse:JSON.stringify({message:{...c,textBody:`Invoice details`,htmlBody:`<p>Invoice details</p>`,rawMessage:`From: billing@example.net\\r\\nSubject: Invoice 2026-07`}},null,2),foldersResponse:JSON.stringify({folders:[{name:`INBOX`,specialUse:null,messageCount:12,unreadCount:3},{name:`Sent`,specialUse:`\\Sent`,messageCount:8,unreadCount:0}]},null,2)}}function F(e,t,n){return`curl -X POST ${e} \\
  -H 'Authorization: Bearer ${t}' \\
  -H 'Content-Type: application/json' \\
  -d '${JSON.stringify(n,null,2)}'`}function I(e,t){return`curl '${e}' \\
  -H 'Authorization: Bearer ${t}'`}function L(e){return String(e||``).split(`@`)[1]||``}var R=p(),ve=[{label:`send`,value:`send`},{label:`mailboxes:read`,value:`mailboxes:read`},{label:`mailboxes:write`,value:`mailboxes:write`},{label:`messages:read`,value:`messages:read`}];function z(){let{message:e}=i.useApp(),{t}=r(),{config:n,user:o}=ue(),l=ce(),p=fe(),[O,A]=le(),[j]=S.useForm(),[N,_e]=(0,k.useState)([]),[P,F]=(0,k.useState)([]),[I,L]=(0,k.useState)(!0),[z,V]=(0,k.useState)(``),[H,U]=(0,k.useState)(``),[W,G]=(0,k.useState)(``),[ke,K]=(0,k.useState)(!1),[q,Ae]=(0,k.useState)(null),[J,je]=(0,k.useState)(null),[Me,Ne]=(0,k.useState)(`created`),Pe=(0,k.useRef)(null),Fe=S.useWatch(`scopes`,j)||[],Ie=S.useWatch(`mailboxAccess`,j)||`owner`,Le=Fe.includes(`messages:read`),Y=o?.role===`admin`,X=De(O.get(`tokenId`)),Re=O.get(`guide`),ze=Oe(Re),Be=Re!=null,Z=(0,k.useMemo)(()=>X&&N.find(e=>e.id===X)||null,[X,N]),Q=(0,k.useCallback)(async()=>{L(!0),V(``),U(``);let[e,n]=await Promise.allSettled([a.apiTokens(),a.inboundMailboxes(Y)]);if(e.status===`fulfilled`){let t=e.value.tokens||[];_e(t)}else V(e.reason instanceof Error?e.reason.message:t(`common.error`));n.status===`fulfilled`?F(n.value.mailboxes||[]):U(n.reason instanceof Error?n.reason.message:t(`common.error`)),L(!1)},[Y,t]);(0,k.useEffect)(()=>{Q()},[Q]),(0,k.useEffect)(()=>{let e=Pe.current;!e||E(l.state)?.origin===`direct`||(Pe.current=null,p(e,{replace:!0}))},[l.key,l.state,p]);async function $(n){n&&(await navigator.clipboard.writeText(n),e.success(t(`common.copied`)))}function Ve(){Ae(null),j.resetFields(),j.setFieldsValue({name:``,scopes:[`send`],expiresAt:``,mailboxAccess:`owner`,mailboxIds:[]}),K(!0)}function He(e){let t=e.mailboxAccess===`all`&&!Y?`owner`:e.mailboxAccess||`owner`;Ae(e),j.resetFields(),j.setFieldsValue({name:e.name,scopes:e.scopes||[`send`],expiresAt:we(e.expiresAt),mailboxAccess:t,mailboxIds:e.mailboxIds||[]}),K(!0)}async function Ue(){let n=await j.validateFields(),r=Se(n),i=q?`save:${q.id}`:`create`;G(i);try{if(q)await a.updateApiToken(q.id,r),e.success(t(`tokens.updatedSuccess`));else{let i=await a.createApiToken({...r,name:n.name.trim()});e.success(t(`tokens.createdSuccess`)),i.token&&M(i.token)&&(Ne(`created`),je(i.token))}K(!1),Ae(null),j.resetFields(),await Q()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{G(``)}}async function We(n){G(`rotate:${n.id}`);try{let r=await a.rotateApiToken(n.id);e.success(t(`tokens.rotatedSuccess`)),Ne(`rotated`),je(r.token),await Q()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{G(``)}}async function Ge(n){G(`revoke:${n.id}`);try{await a.deleteApiToken(n.id),e.success(t(`tokens.revokedSuccess`)),X===n.id&&qe(),await Q()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{G(``)}}function Ke(e){let t=new URLSearchParams(O);t.set(`tokenId`,String(e.id)),A(t,{state:D(`${l.pathname}${l.search}`,1)})}function qe(){let e=E(l.state);if(e){p(-e.depth);return}let t=new URLSearchParams(O);t.delete(`tokenId`),A(t,{replace:!0,state:null})}function Je(e=`send`){if(Be&&e===ze)return;let t=new URLSearchParams(O);if(t.set(`guide`,e),!Be){A(t,{state:D(`${l.pathname}${l.search}`,1)});return}let n=E(l.state),r=t.toString();if(n){p({pathname:l.pathname,search:r?`?${r}`:``},{state:D(n.listPath,n.depth+1,n.origin)});return}let i=new URLSearchParams(O);i.delete(`guide`);let a=i.toString();p({pathname:l.pathname,search:r?`?${r}`:``},{state:D(`${l.pathname}${a?`?${a}`:``}`,1,`direct`)})}function Ye(){let e=E(l.state);if(e?.origin===`list`){p(-e.depth);return}if(e?.origin===`direct`){Pe.current=e.listPath,p(-e.depth);return}let t=new URLSearchParams(O);t.delete(`guide`),A(t,{replace:!0,state:null})}let Xe=[{title:t(`tokens.name`),dataIndex:`name`,width:180,render:e=>(0,R.jsx)(d.Text,{strong:!0,children:e})},{title:t(`tokens.fullToken`),dataIndex:`token`,width:320,render:(e,n)=>(0,R.jsx)(ye,{token:n,onCopy:$,t})},{title:t(`tokens.scopes`),dataIndex:`scopes`,width:250,responsive:[`xl`],render:e=>(0,R.jsx)(c,{size:[4,4],wrap:!0,children:(e||[]).map(e=>(0,R.jsx)(C,{children:e},e))})},{title:t(`tokens.mailboxAccess`),dataIndex:`mailboxAccess`,width:210,responsive:[`xl`],render:(e,n)=>Ce(n,t)},{title:t(`tokens.status`),dataIndex:`status`,width:120,render:(e,n)=>(0,R.jsx)(b,{tone:Te(n.status),children:Ee(n.status,t)})},{title:t(`tokens.lastUsed`),dataIndex:`lastUsedAt`,width:190,render:e=>e?B(e):t(`tokens.neverUsed`)},{title:t(`tokens.actions`),width:180,fixed:`right`,render:(e,n)=>(0,R.jsxs)(c,{onClick:e=>e.stopPropagation(),children:[M(n)?null:(0,R.jsx)(be,{token:n,loading:W===`rotate:${n.id}`,onRotate:We,t}),(0,R.jsx)(u,{"aria-label":`${t(`tokens.edit`)} ${n.name}`,disabled:n.status===`revoked`,icon:(0,R.jsx)(ae,{}),onClick:()=>He(n)}),(0,R.jsx)(ne,{title:t(`tokens.revokeConfirm`),onConfirm:()=>void Ge(n),disabled:n.status===`revoked`,children:(0,R.jsx)(u,{"aria-label":`${t(`tokens.revoke`)} ${n.name}`,danger:!0,disabled:n.status===`revoked`,icon:(0,R.jsx)(ie,{}),loading:W===`revoke:${n.id}`})})]})}],Ze=P.map(e=>({value:e.id,label:`${e.address}${Y&&e.userId!==o?.id?` · UID ${e.userId}`:``}`})),Qe=[{label:t(`tokens.mailboxAccessOwner`),value:`owner`},{label:t(`tokens.mailboxAccessSelected`),value:`selected`},...Y?[{label:t(`tokens.mailboxAccessAll`),value:`all`}]:[]];return(0,R.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,R.jsx)(y,{title:t(`nav.tokens`),subtitle:t(`tokens.subtitle`),extra:(0,R.jsxs)(c,{wrap:!0,children:[(0,R.jsx)(u,{icon:(0,R.jsx)(me,{}),onClick:()=>Je(),style:{minHeight:44},children:t(`tokens.docsTitle`)}),(0,R.jsx)(u,{type:`primary`,icon:(0,R.jsx)(oe,{}),onClick:Ve,style:{minHeight:44},children:t(`tokens.create`)})]})}),z?(0,R.jsx)(m,{type:`error`,showIcon:!0,message:z,action:(0,R.jsx)(u,{icon:(0,R.jsx)(se,{}),onClick:()=>void Q(),children:t(`common.refresh`)})}):null,z&&!N.length?null:(0,R.jsxs)(v,{title:t(`tokens.listTitle`),extra:(0,R.jsx)(b,{tone:`neutral`,children:N.length}),children:[(0,R.jsx)(m,{type:`info`,showIcon:!0,message:t(`tokens.prefixOnlyHelp`),style:{marginBottom:16}}),I?(0,R.jsx)(f,{active:!0,paragraph:{rows:6}}):N.length?(0,R.jsx)(_,{rowKey:`id`,columns:Xe,dataSource:N,scroll:{x:1030},onRow:e=>({onClick:()=>Ke(e),style:{cursor:`pointer`},tabIndex:0,onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Ke(e))}})}):(0,R.jsx)(pe,{description:t(`tokens.noTokenHint`),action:(0,R.jsx)(u,{icon:(0,R.jsx)(oe,{}),onClick:Ve,children:t(`tokens.create`)})})]}),(0,R.jsxs)(w,{title:t(q?`tokens.editTitle`:`tokens.createTitle`),width:560,open:ke,onClose:()=>K(!1),destroyOnHidden:!0,footer:(0,R.jsxs)(c,{style:{display:`flex`,justifyContent:`flex-end`},children:[(0,R.jsx)(u,{onClick:()=>K(!1),children:t(`common.cancel`)}),(0,R.jsx)(u,{type:`primary`,icon:(0,R.jsx)(de,{}),loading:W===`create`||W.startsWith(`save:`),onClick:()=>void Ue(),children:t(q?`common.save`:`tokens.create`)})]}),children:[q?null:(0,R.jsx)(m,{type:`info`,showIcon:!0,message:t(`tokens.createdWarning`),style:{marginBottom:20}}),(0,R.jsxs)(S,{form:j,layout:`vertical`,initialValues:{scopes:[`send`],mailboxAccess:`owner`,mailboxIds:[]},children:[(0,R.jsx)(S.Item,{name:`name`,label:t(`tokens.name`),rules:[{required:!0,message:t(`tokens.nameRequired`)}],children:(0,R.jsx)(ee,{placeholder:t(`tokens.namePlaceholder`),autoComplete:`off`})}),(0,R.jsx)(S.Item,{name:`expiresAt`,label:t(`tokens.expiresAt`),extra:t(`tokens.expiresAtExtra`),children:(0,R.jsx)(ee,{type:`datetime-local`})}),(0,R.jsx)(S.Item,{name:`scopes`,label:t(`tokens.scopes`),rules:[{required:!0,type:`array`,min:1,message:t(`tokens.scopesRequired`)}],extra:t(`tokens.scopesExtra`),children:(0,R.jsx)(h.Group,{options:ve})}),Le?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(S.Item,{name:`mailboxAccess`,label:t(`tokens.mailboxAccess`),extra:t(`tokens.mailboxAccessExtra`),rules:[{required:!0}],children:(0,R.jsx)(g.Group,{className:`full-width`,style:{display:`grid`,gap:4},children:Qe.map(e=>(0,R.jsx)(g,{value:e.value,style:{alignItems:`center`,minHeight:44},children:e.label},e.value))})}),Ie===`selected`?(0,R.jsx)(S.Item,{name:`mailboxIds`,label:t(`tokens.mailboxIds`),rules:[{type:`array`,min:1,required:!0,message:t(`tokens.mailboxIdsRequired`)}],children:(0,R.jsx)(s,{mode:`multiple`,allowClear:!0,showSearch:!0,optionFilterProp:`label`,options:Ze,placeholder:t(`tokens.mailboxIdsPlaceholder`),status:H?`error`:void 0})}):null,H?(0,R.jsx)(m,{type:`error`,showIcon:!0,message:H,action:(0,R.jsx)(u,{size:`small`,onClick:()=>void Q(),children:t(`common.refresh`)})}):null]}):null]})]}),(0,R.jsx)(w,{title:Z?.name||t(`nav.tokens`),width:600,open:!!X,onClose:qe,children:I&&!Z?(0,R.jsx)(f,{active:!0,paragraph:{rows:6}}):Z?(0,R.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,R.jsxs)(x,{bordered:!0,column:1,size:`small`,children:[(0,R.jsx)(x.Item,{label:t(`tokens.fullToken`),children:(0,R.jsx)(ye,{token:Z,onCopy:$,t})}),(0,R.jsx)(x.Item,{label:t(`tokens.prefix`),children:(0,R.jsx)(d.Text,{code:!0,children:ge(Z)})}),(0,R.jsx)(x.Item,{label:t(`tokens.status`),children:(0,R.jsx)(b,{tone:Te(Z.status),children:Ee(Z.status,t)})}),(0,R.jsx)(x.Item,{label:t(`tokens.scopes`),children:(0,R.jsx)(c,{wrap:!0,children:Z.scopes.map(e=>(0,R.jsx)(C,{children:e},e))})}),(0,R.jsx)(x.Item,{label:t(`tokens.mailboxAccess`),children:Ce(Z,t)}),Z.scopes.includes(`messages:read`)&&Z.mailboxAccess===`selected`?(0,R.jsx)(x.Item,{label:t(`tokens.mailboxIds`),children:(0,R.jsx)(c,{size:[4,4],wrap:!0,children:Z.mailboxIds.map(e=>(0,R.jsx)(C,{children:P.find(t=>t.id===e)?.address||`#${e}`},e))})}):null,(0,R.jsx)(x.Item,{label:t(`tokens.expiresAt`),children:B(Z.expiresAt)}),(0,R.jsx)(x.Item,{label:t(`tokens.lastUsed`),children:Z.lastUsedAt?B(Z.lastUsedAt):t(`tokens.neverUsed`)}),(0,R.jsx)(x.Item,{label:t(`tokens.createdAt`),children:B(Z.createdAt)})]}),(0,R.jsx)(m,{type:M(Z)?`success`:`warning`,showIcon:!0,message:M(Z)?t(`tokens.secretAvailable`):t(`tokens.secretUnavailable`),action:!M(Z)&&Z.status!==`revoked`?(0,R.jsx)(be,{token:Z,loading:W===`rotate:${Z.id}`,onRotate:We,t,text:!0}):void 0}),(0,R.jsx)(u,{icon:(0,R.jsx)(me,{}),onClick:()=>Je(),children:t(`tokens.docsTitle`)})]}):z&&X?(0,R.jsx)(m,{type:`error`,showIcon:!0,message:z,action:(0,R.jsx)(u,{icon:(0,R.jsx)(se,{}),onClick:()=>void Q(),children:t(`common.refresh`)})}):X?(0,R.jsx)(pe,{description:t(`common.notFound`)}):null}),(0,R.jsx)(xe,{open:Be,section:ze,config:n,onClose:Ye,onSectionChange:Je,onCopy:$}),(0,R.jsx)(te,{title:t(Me===`rotated`?`tokens.rotatedTitle`:`tokens.createdTitle`),open:!!J,closable:!1,maskClosable:!1,keyboard:!1,destroyOnHidden:!0,footer:[(0,R.jsx)(u,{icon:(0,R.jsx)(re,{}),onClick:()=>void $(he(J||{})||``),children:t(`tokens.copyCreated`)},`copy`),(0,R.jsx)(u,{type:`primary`,onClick:()=>je(null),children:t(`common.confirm`)},`done`)],children:J?(0,R.jsxs)(c,{direction:`vertical`,size:16,className:`full-width`,children:[(0,R.jsx)(m,{type:Me===`rotated`?`warning`:`info`,showIcon:!0,message:t(Me===`rotated`?`tokens.rotatedWarning`:`tokens.createdWarning`)}),(0,R.jsx)(T,{value:he(J)||``,onCopy:$})]}):null})]})}function ye({token:e,onCopy:t,t:n}){return M(e)?(0,R.jsxs)(c,{size:8,align:`start`,style:{maxWidth:`100%`},children:[(0,R.jsx)(d.Text,{code:!0,style:{overflowWrap:`anywhere`,wordBreak:`break-all`},children:e.token}),(0,R.jsx)(u,{"aria-label":`${n(`tokens.copyFull`)} ${e.name}`,icon:(0,R.jsx)(re,{}),onClick:n=>{n.stopPropagation(),t(e.token||``)},style:{minHeight:44,minWidth:44}})]}):(0,R.jsx)(b,{tone:`warning`,children:n(`tokens.unrecoverable`)})}function be({token:e,loading:t,onRotate:n,t:r,text:i=!1}){return(0,R.jsx)(ne,{title:r(`tokens.rotateConfirm`),description:r(`tokens.rotateConfirmDescription`),okText:r(`tokens.rotate`),okButtonProps:{danger:!0},onConfirm:()=>void n(e),disabled:e.status===`revoked`,children:(0,R.jsx)(u,{"aria-label":`${r(`tokens.rotate`)} ${e.name}`,icon:(0,R.jsx)(se,{}),danger:!0,disabled:e.status===`revoked`,loading:t,style:{minHeight:44,minWidth:i?void 0:44},children:i?r(`tokens.rotate`):null})})}function xe({open:e,section:t,config:n,onClose:i,onSectionChange:a,onCopy:o}){let{t:s}=r(),u=V(n?.appBaseUrl,window.location.origin),f=`${u}/api/send`,p=`${u}/api/mailboxes`,h=`${u}/api/inbound-messages`,g=`${u}/api/inbound-mailboxes`,_=(0,k.useMemo)(()=>N({endpoint:f,token:`<USER_API_TOKEN>`,from:`noreply@example.com`,to:`user@example.com`}),[f]),v=(0,k.useMemo)(()=>_e({endpoint:p,token:`<MAILBOX_API_TOKEN>`}),[p]),y=(0,k.useMemo)(()=>P({endpoint:h,mailboxEndpoint:g,token:`<MESSAGES_API_TOKEN>`}),[g,h]);return(0,R.jsx)(w,{title:s(`tokens.docsTitle`),width:760,open:e,onClose:i,children:(0,R.jsxs)(c,{direction:`vertical`,size:16,className:`full-width`,children:[(0,R.jsxs)(x,{column:1,bordered:!0,size:`small`,children:[(0,R.jsx)(x.Item,{label:s(`tokens.endpoint`),children:(0,R.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(f)},children:f})}),(0,R.jsx)(x.Item,{label:s(`tokens.mailboxEndpoint`),children:(0,R.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(p)},children:p})}),(0,R.jsx)(x.Item,{label:s(`tokens.messagesApi`),children:(0,R.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(h)},children:h})}),(0,R.jsx)(x.Item,{label:s(`tokens.authHeader`),children:(0,R.jsx)(d.Text,{code:!0,children:s(`tokens.authHeaderValue`)})})]}),(0,R.jsx)(l,{accordion:!0,activeKey:t,onChange:e=>a(Oe(Array.isArray(e)?e[0]:e)),items:[{key:`send`,label:s(`tokens.sendApi`),children:(0,R.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.curlExample`)}),(0,R.jsx)(T,{value:_.curl,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.requestExample`)}),(0,R.jsx)(T,{value:_.requestBody,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.responseExample`)}),(0,R.jsx)(T,{value:_.successResponse,onCopy:o})]})},{key:`mailboxes`,label:s(`tokens.mailboxApi`),children:(0,R.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,R.jsx)(m,{type:`info`,showIcon:!0,message:s(`tokens.mailboxApiHint`)}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.permanentMailbox`)}),(0,R.jsx)(T,{value:v.permanentCurl,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.temporaryMailbox`)}),(0,R.jsx)(T,{value:v.temporaryCurl,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.mailboxResponse`)}),(0,R.jsx)(T,{value:v.successResponse,onCopy:o})]})},{key:`messages`,label:s(`tokens.messagesApi`),children:(0,R.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,R.jsx)(m,{type:`info`,showIcon:!0,message:s(`tokens.messagesApiHint`),description:s(`tokens.messagesAccess`)}),(0,R.jsx)(d.Text,{children:s(`tokens.messagesFilters`)}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.messagesList`)}),(0,R.jsx)(T,{value:y.listCurl,onCopy:o}),(0,R.jsx)(T,{value:y.listResponse,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.messageDetail`)}),(0,R.jsx)(T,{value:y.detailCurl,onCopy:o}),(0,R.jsx)(T,{value:y.detailResponse,onCopy:o}),(0,R.jsx)(d.Text,{strong:!0,children:s(`tokens.mailboxFolders`)}),(0,R.jsx)(T,{value:y.foldersCurl,onCopy:o}),(0,R.jsx)(T,{value:y.foldersResponse,onCopy:o})]})}]}),(0,R.jsx)(m,{type:`warning`,showIcon:!0,message:s(`tokens.securityTipStore`),description:s(`tokens.securityTipScopes`)})]})})}function Se(e){let t=e.scopes.includes(`messages:read`),n=t&&e.mailboxAccess||`owner`;return{name:e.name.trim(),scopes:e.scopes,expiresAt:e.expiresAt?new Date(e.expiresAt).toISOString():null,mailboxAccess:n,mailboxIds:t&&n===`selected`&&e.mailboxIds||[]}}function Ce(e,t){return e.scopes.includes(`messages:read`)?e.mailboxAccess===`all`?(0,R.jsx)(b,{tone:`warning`,children:t(`tokens.mailboxAccessAll`)}):e.mailboxAccess===`selected`?(0,R.jsxs)(b,{tone:`info`,children:[t(`tokens.mailboxAccessSelected`),` · `,e.mailboxIds.length]}):(0,R.jsx)(b,{tone:`neutral`,children:t(`tokens.mailboxAccessOwner`)}):`—`}function we(e){if(!e)return``;let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=t.getTimezoneOffset()*6e4;return new Date(t.getTime()-n).toISOString().slice(0,16)}function Te(e){return e===`active`?`success`:e===`expired`?`warning`:e===`revoked`?`error`:`neutral`}function Ee(e,t){return e===`active`?t(`tokens.statusActive`):e===`expired`?t(`tokens.statusExpired`):e===`revoked`?t(`tokens.statusRevoked`):`—`}function B(e){return e?new Date(e).toLocaleString():`—`}function De(e){let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Oe(e){return e===`mailboxes`||e===`messages`?e:`send`}function V(e,t){let n=H(t);if(n?.protocol===`https:`)return n.origin;let r=H(e);return r?.protocol===`https:`?r.origin:r&&!U(r.hostname)?(r.protocol=`https:`,r.origin):r?.origin||n?.origin||``}function H(e){if(!e)return null;try{return new URL(e)}catch{return null}}function U(e){return e===`localhost`||e===`127.0.0.1`||e===`::1`}export{z as default};