import{a as e,n as t,r as n}from"./react-dom-stZKkA6x.js";import{d as r,f as i,o as a,r as o}from"./theme-Dpxy803y.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-DzYWI3CD.js";import{n as h,r as g,t as _}from"./table-DJa-z-YA.js";import{n as v,t as y}from"./SectionCard--w8cgqOe.js";import{t as b}from"./descriptions-vs1os_w7.js";import{t as x}from"./form-Dp5ppmPu.js";import{t as ee}from"./input-0_Xo22Fl.js";import{t as te}from"./modal-BGjs3E6e.js";import{t as ne}from"./popconfirm-cq-yGQ-9.js";import{t as re}from"./CopyOutlined-UbpGsh_G.js";import{n as ie,t as ae}from"./EditOutlined-Xr2lIYb3.js";import{t as oe}from"./PlusOutlined-DoGMjNQS.js";import{t as se}from"./ReloadOutlined-9AZGcoed.js";import{_ as ce,b as le,f as ue,h as de,n as fe,o as pe,p as me}from"./index-DG1WRIOp.js";import{t as he}from"./EmptyState-rI31ioMm.js";import{t as S}from"./StatusPill-BM21x0ED.js";import{t as C}from"./CodeBlock-z4Jy8-Be.js";import{n as w,t as T}from"./navigation-state-ixI_efPF.js";var E=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`}})),D=e(t()),O=e(E());function k(){return k=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},k.apply(this,arguments)}var ge=D.forwardRef((e,t)=>D.createElement(r,k({},e,{ref:t,icon:O.default})));function A(e={}){return!!(e.token&&e.tokenRecoverable!==!1)}function _e(e={}){return A(e)?String(e.token):``}function ve(e={}){return e.tokenPrefix?`${e.tokenPrefix}...`:`-`}function j({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:F(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 ye({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:N(e,t,r),temporaryCurl:N(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 M({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:P(a,n),detailCurl:P(o,n),foldersCurl:P(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 N(e,t,n){return`curl -X POST ${e} \\
  -H 'Authorization: Bearer ${t}' \\
  -H 'Content-Type: application/json' \\
  -d '${JSON.stringify(n,null,2)}'`}function P(e,t){return`curl '${e}' \\
  -H 'Authorization: Bearer ${t}'`}function F(e){return String(e||``).split(`@`)[1]||``}var I=p(),be=[{label:`send`,value:`send`},{label:`mailboxes:read`,value:`mailboxes:read`},{label:`mailboxes:write`,value:`mailboxes:write`},{label:`messages:read`,value:`messages:read`}];function L(){let{message:e}=i.useApp(),{t}=a(),{config:n,user:r}=fe(),l=ue(),p=me(),[E,O]=de(),[k]=x.useForm(),[j,ye]=(0,D.useState)([]),[M,N]=(0,D.useState)([]),[P,F]=(0,D.useState)(!0),[L,B]=(0,D.useState)(``),[V,H]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[je,G]=(0,D.useState)(!1),[K,Me]=(0,D.useState)(null),[q,Ne]=(0,D.useState)(null),[Pe,Fe]=(0,D.useState)(`created`),Ie=(0,D.useRef)(null),Le=x.useWatch(`scopes`,k)||[],Re=x.useWatch(`mailboxAccess`,k)||`owner`,ze=R(Le),J=r?.role===`admin`,Y=ke(E.get(`tokenId`)),Be=E.get(`guide`),Ve=Ae(Be),He=Be!=null,X=(0,D.useMemo)(()=>Y&&j.find(e=>e.id===Y)||null,[Y,j]),Z=(0,D.useCallback)(async()=>{F(!0),B(``),H(``);let[e,n]=await Promise.allSettled([o.apiTokens(),o.inboundMailboxes(J?`all`:`effective`)]);if(e.status===`fulfilled`){let t=e.value.tokens||[];ye(t)}else B(e.reason instanceof Error?e.reason.message:t(`common.error`));n.status===`fulfilled`?N(n.value.mailboxes||[]):H(n.reason instanceof Error?n.reason.message:t(`common.error`)),F(!1)},[J,t]);(0,D.useEffect)(()=>{Z()},[Z]),(0,D.useEffect)(()=>{let e=Ie.current;!e||w(l.state)?.origin===`direct`||(Ie.current=null,p(e,{replace:!0}))},[l.key,l.state,p]);async function Q(n){n&&(await navigator.clipboard.writeText(n),e.success(t(`common.copied`)))}function Ue(){Me(null),k.resetFields(),k.setFieldsValue({name:``,scopes:[`send`],expiresAt:``,mailboxAccess:`owner`,mailboxIds:[]}),G(!0)}function We(e){let t=e.mailboxAccess===`all`&&!J?`owner`:e.mailboxAccess||`owner`;Me(e),k.resetFields(),k.setFieldsValue({name:e.name,scopes:e.scopes||[`send`],expiresAt:Ee(e.expiresAt),mailboxAccess:t,mailboxIds:e.mailboxIds||[]}),G(!0)}async function Ge(){let n=await k.validateFields(),r=we(n),i=K?`save:${K.id}`:`create`;W(i);try{if(K)await o.updateApiToken(K.id,r),e.success(t(`tokens.updatedSuccess`));else{let i=await o.createApiToken({...r,name:n.name.trim()});e.success(t(`tokens.createdSuccess`)),i.token&&A(i.token)&&(Fe(`created`),Ne(i.token))}G(!1),Me(null),k.resetFields(),await Z()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{W(``)}}async function Ke(n){W(`rotate:${n.id}`);try{let r=await o.rotateApiToken(n.id);e.success(t(`tokens.rotatedSuccess`)),Fe(`rotated`),Ne(r.token),await Z()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{W(``)}}async function qe(n){W(`revoke:${n.id}`);try{await o.deleteApiToken(n.id),e.success(t(`tokens.revokedSuccess`)),Y===n.id&&Ye(),await Z()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{W(``)}}function Je(e){let t=new URLSearchParams(E);t.set(`tokenId`,String(e.id)),O(t,{state:T(`${l.pathname}${l.search}`,1)})}function Ye(){let e=w(l.state);if(e){p(-e.depth);return}let t=new URLSearchParams(E);t.delete(`tokenId`),O(t,{replace:!0,state:null})}function $(e=`send`){if(He&&e===Ve)return;let t=new URLSearchParams(E);if(t.set(`guide`,e),!He){O(t,{state:T(`${l.pathname}${l.search}`,1)});return}let n=w(l.state),r=t.toString();if(n){p({pathname:l.pathname,search:r?`?${r}`:``},{state:T(n.listPath,n.depth+1,n.origin)});return}let i=new URLSearchParams(E);i.delete(`guide`);let a=i.toString();p({pathname:l.pathname,search:r?`?${r}`:``},{state:T(`${l.pathname}${a?`?${a}`:``}`,1,`direct`)})}function Xe(){let e=w(l.state);if(e?.origin===`list`){p(-e.depth);return}if(e?.origin===`direct`){Ie.current=e.listPath,p(-e.depth);return}let t=new URLSearchParams(E);t.delete(`guide`),O(t,{replace:!0,state:null})}let Ze=[{title:t(`tokens.name`),dataIndex:`name`,width:180,render:e=>(0,I.jsx)(d.Text,{strong:!0,children:e})},{title:t(`tokens.fullToken`),dataIndex:`token`,width:320,render:(e,n)=>(0,I.jsx)(xe,{token:n,onCopy:Q,t})},{title:t(`tokens.scopes`),dataIndex:`scopes`,width:250,responsive:[`xl`],render:e=>(0,I.jsx)(c,{size:[4,4],wrap:!0,children:(e||[]).map(e=>(0,I.jsx)(ce,{children:e},e))})},{title:t(`tokens.mailboxAccess`),dataIndex:`mailboxAccess`,width:210,responsive:[`xl`],render:(e,n)=>Te(n,t)},{title:t(`tokens.status`),dataIndex:`status`,width:120,render:(e,n)=>(0,I.jsx)(S,{tone:De(n.status),children:Oe(n.status,t)})},{title:t(`tokens.lastUsed`),dataIndex:`lastUsedAt`,width:190,render:e=>e?z(e):t(`tokens.neverUsed`)},{title:t(`tokens.actions`),width:180,fixed:`right`,render:(e,n)=>(0,I.jsxs)(c,{onClick:e=>e.stopPropagation(),children:[A(n)?null:(0,I.jsx)(Se,{token:n,loading:U===`rotate:${n.id}`,onRotate:Ke,t}),(0,I.jsx)(u,{"aria-label":`${t(`tokens.edit`)} ${n.name}`,disabled:n.status===`revoked`,icon:(0,I.jsx)(ae,{}),onClick:()=>We(n)}),(0,I.jsx)(ne,{title:t(`tokens.revokeConfirm`),onConfirm:()=>void qe(n),disabled:n.status===`revoked`,children:(0,I.jsx)(u,{"aria-label":`${t(`tokens.revoke`)} ${n.name}`,danger:!0,disabled:n.status===`revoked`,icon:(0,I.jsx)(ie,{}),loading:U===`revoke:${n.id}`})})]})}],Qe=M.filter(e=>J||e.access?.permissions.view!==!1).map(e=>({value:e.id,label:`${e.address}${J&&e.userId!==r?.id?` · UID ${e.userId}`:``}${!J&&e.access?.type===`assigned`?` · ${t(`account.adminAssigned`)}`:``}`})),$e=[{label:t(`tokens.mailboxAccessOwner`),value:`owner`},{label:t(`tokens.mailboxAccessSelected`),value:`selected`},...J?[{label:t(`tokens.mailboxAccessAll`),value:`all`}]:[]];return(0,I.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,I.jsx)(v,{title:t(`nav.tokens`),subtitle:t(`tokens.subtitle`),extra:(0,I.jsxs)(c,{wrap:!0,children:[(0,I.jsx)(u,{icon:(0,I.jsx)(ge,{}),onClick:()=>$(),style:{minHeight:44},children:t(`tokens.docsTitle`)}),(0,I.jsx)(u,{type:`primary`,icon:(0,I.jsx)(oe,{}),onClick:Ue,style:{minHeight:44},children:t(`tokens.create`)})]})}),L?(0,I.jsx)(m,{type:`error`,showIcon:!0,message:L,action:(0,I.jsx)(u,{icon:(0,I.jsx)(se,{}),onClick:()=>void Z(),children:t(`common.refresh`)})}):null,L&&!j.length?null:(0,I.jsxs)(y,{title:t(`tokens.listTitle`),extra:(0,I.jsx)(S,{tone:`neutral`,children:j.length}),children:[(0,I.jsx)(m,{type:`info`,showIcon:!0,message:t(`tokens.prefixOnlyHelp`),style:{marginBottom:16}}),P?(0,I.jsx)(f,{active:!0,paragraph:{rows:6}}):j.length?(0,I.jsx)(_,{rowKey:`id`,columns:Ze,dataSource:j,scroll:{x:1030},onRow:e=>({onClick:()=>Je(e),style:{cursor:`pointer`},tabIndex:0,onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Je(e))}})}):(0,I.jsx)(he,{description:t(`tokens.noTokenHint`),action:(0,I.jsx)(u,{icon:(0,I.jsx)(oe,{}),onClick:Ue,children:t(`tokens.create`)})})]}),(0,I.jsxs)(le,{title:t(K?`tokens.editTitle`:`tokens.createTitle`),width:560,open:je,onClose:()=>G(!1),destroyOnHidden:!0,footer:(0,I.jsxs)(c,{style:{display:`flex`,justifyContent:`flex-end`},children:[(0,I.jsx)(u,{onClick:()=>G(!1),children:t(`common.cancel`)}),(0,I.jsx)(u,{type:`primary`,icon:(0,I.jsx)(pe,{}),loading:U===`create`||U.startsWith(`save:`),onClick:()=>void Ge(),children:t(K?`common.save`:`tokens.create`)})]}),children:[K?null:(0,I.jsx)(m,{type:`info`,showIcon:!0,message:t(`tokens.createdWarning`),style:{marginBottom:20}}),(0,I.jsxs)(x,{form:k,layout:`vertical`,initialValues:{scopes:[`send`],mailboxAccess:`owner`,mailboxIds:[]},children:[(0,I.jsx)(x.Item,{name:`name`,label:t(`tokens.name`),rules:[{required:!0,message:t(`tokens.nameRequired`)}],children:(0,I.jsx)(ee,{placeholder:t(`tokens.namePlaceholder`),autoComplete:`off`})}),(0,I.jsx)(x.Item,{name:`expiresAt`,label:t(`tokens.expiresAt`),extra:t(`tokens.expiresAtExtra`),children:(0,I.jsx)(ee,{type:`datetime-local`})}),(0,I.jsx)(x.Item,{name:`scopes`,label:t(`tokens.scopes`),rules:[{required:!0,type:`array`,min:1,message:t(`tokens.scopesRequired`)}],extra:t(`tokens.scopesExtra`),children:(0,I.jsx)(h.Group,{options:be})}),ze?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(x.Item,{name:`mailboxAccess`,label:t(`tokens.mailboxAccess`),extra:t(`tokens.mailboxAccessExtra`),rules:[{required:!0}],children:(0,I.jsx)(g.Group,{className:`full-width`,style:{display:`grid`,gap:4},children:$e.map(e=>(0,I.jsx)(g,{value:e.value,style:{alignItems:`center`,minHeight:44},children:e.label},e.value))})}),Re===`selected`?(0,I.jsx)(x.Item,{name:`mailboxIds`,label:t(`tokens.mailboxIds`),rules:[{type:`array`,min:1,required:!0,message:t(`tokens.mailboxIdsRequired`)}],children:(0,I.jsx)(s,{mode:`multiple`,allowClear:!0,showSearch:!0,optionFilterProp:`label`,options:Qe,placeholder:t(`tokens.mailboxIdsPlaceholder`),status:V?`error`:void 0})}):null,V?(0,I.jsx)(m,{type:`error`,showIcon:!0,message:V,action:(0,I.jsx)(u,{size:`small`,onClick:()=>void Z(),children:t(`common.refresh`)})}):null]}):null]})]}),(0,I.jsx)(le,{title:X?.name||t(`nav.tokens`),width:600,open:!!Y,onClose:Ye,children:P&&!X?(0,I.jsx)(f,{active:!0,paragraph:{rows:6}}):X?(0,I.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,I.jsxs)(b,{bordered:!0,column:1,size:`small`,children:[(0,I.jsx)(b.Item,{label:t(`tokens.fullToken`),children:(0,I.jsx)(xe,{token:X,onCopy:Q,t})}),(0,I.jsx)(b.Item,{label:t(`tokens.prefix`),children:(0,I.jsx)(d.Text,{code:!0,children:ve(X)})}),(0,I.jsx)(b.Item,{label:t(`tokens.status`),children:(0,I.jsx)(S,{tone:De(X.status),children:Oe(X.status,t)})}),(0,I.jsx)(b.Item,{label:t(`tokens.scopes`),children:(0,I.jsx)(c,{wrap:!0,children:X.scopes.map(e=>(0,I.jsx)(ce,{children:e},e))})}),(0,I.jsx)(b.Item,{label:t(`tokens.mailboxAccess`),children:Te(X,t)}),R(X.scopes)&&X.mailboxAccess===`selected`?(0,I.jsx)(b.Item,{label:t(`tokens.mailboxIds`),children:(0,I.jsx)(c,{size:[4,4],wrap:!0,children:X.mailboxIds.map(e=>(0,I.jsx)(ce,{children:M.find(t=>t.id===e)?.address||`#${e}`},e))})}):null,(0,I.jsx)(b.Item,{label:t(`tokens.expiresAt`),children:z(X.expiresAt)}),(0,I.jsx)(b.Item,{label:t(`tokens.lastUsed`),children:X.lastUsedAt?z(X.lastUsedAt):t(`tokens.neverUsed`)}),(0,I.jsx)(b.Item,{label:t(`tokens.createdAt`),children:z(X.createdAt)})]}),(0,I.jsx)(m,{type:A(X)?`success`:`warning`,showIcon:!0,message:A(X)?t(`tokens.secretAvailable`):t(`tokens.secretUnavailable`),action:!A(X)&&X.status!==`revoked`?(0,I.jsx)(Se,{token:X,loading:U===`rotate:${X.id}`,onRotate:Ke,t,text:!0}):void 0}),(0,I.jsx)(u,{icon:(0,I.jsx)(ge,{}),onClick:()=>$(),children:t(`tokens.docsTitle`)})]}):L&&Y?(0,I.jsx)(m,{type:`error`,showIcon:!0,message:L,action:(0,I.jsx)(u,{icon:(0,I.jsx)(se,{}),onClick:()=>void Z(),children:t(`common.refresh`)})}):Y?(0,I.jsx)(he,{description:t(`common.notFound`)}):null}),(0,I.jsx)(Ce,{open:He,section:Ve,config:n,onClose:Xe,onSectionChange:$,onCopy:Q}),(0,I.jsx)(te,{title:t(Pe===`rotated`?`tokens.rotatedTitle`:`tokens.createdTitle`),open:!!q,closable:!1,maskClosable:!1,keyboard:!1,destroyOnHidden:!0,footer:[(0,I.jsx)(u,{icon:(0,I.jsx)(re,{}),onClick:()=>void Q(_e(q||{})||``),children:t(`tokens.copyCreated`)},`copy`),(0,I.jsx)(u,{type:`primary`,onClick:()=>Ne(null),children:t(`common.confirm`)},`done`)],children:q?(0,I.jsxs)(c,{direction:`vertical`,size:16,className:`full-width`,children:[(0,I.jsx)(m,{type:Pe===`rotated`?`warning`:`info`,showIcon:!0,message:t(Pe===`rotated`?`tokens.rotatedWarning`:`tokens.createdWarning`)}),(0,I.jsx)(C,{value:_e(q)||``,onCopy:Q})]}):null})]})}function xe({token:e,onCopy:t,t:n}){return A(e)?(0,I.jsxs)(c,{size:8,align:`start`,style:{maxWidth:`100%`},children:[(0,I.jsx)(d.Text,{code:!0,style:{overflowWrap:`anywhere`,wordBreak:`break-all`},children:e.token}),(0,I.jsx)(u,{"aria-label":`${n(`tokens.copyFull`)} ${e.name}`,icon:(0,I.jsx)(re,{}),onClick:n=>{n.stopPropagation(),t(e.token||``)},style:{minHeight:44,minWidth:44}})]}):(0,I.jsx)(S,{tone:`warning`,children:n(`tokens.unrecoverable`)})}function Se({token:e,loading:t,onRotate:n,t:r,text:i=!1}){return(0,I.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,I.jsx)(u,{"aria-label":`${r(`tokens.rotate`)} ${e.name}`,icon:(0,I.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 Ce({open:e,section:t,config:n,onClose:r,onSectionChange:i,onCopy:o}){let{t:s}=a(),u=B(n?.appBaseUrl,window.location.origin),f=`${u}/api/send`,p=`${u}/api/mailboxes`,h=`${u}/api/inbound-messages`,g=`${u}/api/inbound-mailboxes`,_=(0,D.useMemo)(()=>j({endpoint:f,token:`<USER_API_TOKEN>`,from:`noreply@example.com`,to:`user@example.com`}),[f]),v=(0,D.useMemo)(()=>ye({endpoint:p,token:`<MAILBOX_API_TOKEN>`}),[p]),y=(0,D.useMemo)(()=>M({endpoint:h,mailboxEndpoint:g,token:`<MESSAGES_API_TOKEN>`}),[g,h]);return(0,I.jsx)(le,{title:s(`tokens.docsTitle`),width:760,open:e,onClose:r,children:(0,I.jsxs)(c,{direction:`vertical`,size:16,className:`full-width`,children:[(0,I.jsxs)(b,{column:1,bordered:!0,size:`small`,children:[(0,I.jsx)(b.Item,{label:s(`tokens.endpoint`),children:(0,I.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(f)},children:f})}),(0,I.jsx)(b.Item,{label:s(`tokens.mailboxEndpoint`),children:(0,I.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(p)},children:p})}),(0,I.jsx)(b.Item,{label:s(`tokens.messagesApi`),children:(0,I.jsx)(d.Text,{code:!0,copyable:{onCopy:()=>o(h)},children:h})}),(0,I.jsx)(b.Item,{label:s(`tokens.authHeader`),children:(0,I.jsx)(d.Text,{code:!0,children:s(`tokens.authHeaderValue`)})})]}),(0,I.jsx)(l,{accordion:!0,activeKey:t,onChange:e=>i(Ae(Array.isArray(e)?e[0]:e)),items:[{key:`send`,label:s(`tokens.sendApi`),children:(0,I.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.curlExample`)}),(0,I.jsx)(C,{value:_.curl,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.requestExample`)}),(0,I.jsx)(C,{value:_.requestBody,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.responseExample`)}),(0,I.jsx)(C,{value:_.successResponse,onCopy:o})]})},{key:`mailboxes`,label:s(`tokens.mailboxApi`),children:(0,I.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,I.jsx)(m,{type:`info`,showIcon:!0,message:s(`tokens.mailboxApiHint`)}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.permanentMailbox`)}),(0,I.jsx)(C,{value:v.permanentCurl,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.temporaryMailbox`)}),(0,I.jsx)(C,{value:v.temporaryCurl,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.mailboxResponse`)}),(0,I.jsx)(C,{value:v.successResponse,onCopy:o})]})},{key:`messages`,label:s(`tokens.messagesApi`),children:(0,I.jsxs)(c,{direction:`vertical`,size:12,className:`full-width`,children:[(0,I.jsx)(m,{type:`info`,showIcon:!0,message:s(`tokens.messagesApiHint`),description:s(`tokens.messagesAccess`)}),(0,I.jsx)(d.Text,{children:s(`tokens.messagesFilters`)}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.messagesList`)}),(0,I.jsx)(C,{value:y.listCurl,onCopy:o}),(0,I.jsx)(C,{value:y.listResponse,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.messageDetail`)}),(0,I.jsx)(C,{value:y.detailCurl,onCopy:o}),(0,I.jsx)(C,{value:y.detailResponse,onCopy:o}),(0,I.jsx)(d.Text,{strong:!0,children:s(`tokens.mailboxFolders`)}),(0,I.jsx)(C,{value:y.foldersCurl,onCopy:o}),(0,I.jsx)(C,{value:y.foldersResponse,onCopy:o})]})}]}),(0,I.jsx)(m,{type:`warning`,showIcon:!0,message:s(`tokens.securityTipStore`),description:s(`tokens.securityTipScopes`)})]})})}function we(e){let t=R(e.scopes),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 Te(e,t){return R(e.scopes)?e.mailboxAccess===`all`?(0,I.jsx)(S,{tone:`warning`,children:t(`tokens.mailboxAccessAll`)}):e.mailboxAccess===`selected`?(0,I.jsxs)(S,{tone:`info`,children:[t(`tokens.mailboxAccessSelected`),` · `,e.mailboxIds.length]}):(0,I.jsx)(S,{tone:`neutral`,children:t(`tokens.mailboxAccessOwner`)}):`—`}function R(e){return e.includes(`send`)||e.includes(`mailboxes:read`)||e.includes(`messages:read`)}function Ee(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 De(e){return e===`active`?`success`:e===`expired`?`warning`:e===`revoked`?`error`:`neutral`}function Oe(e,t){return e===`active`?t(`tokens.statusActive`):e===`expired`?t(`tokens.statusExpired`):e===`revoked`?t(`tokens.statusRevoked`):`—`}function z(e){return e?new Date(e).toLocaleString():`—`}function ke(e){let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Ae(e){return e===`mailboxes`||e===`messages`?e:`send`}function B(e,t){let n=V(t);if(n?.protocol===`https:`)return n.origin;let r=V(e);return r?.protocol===`https:`?r.origin:r&&!H(r.hostname)?(r.protocol=`https:`,r.origin):r?.origin||n?.origin||``}function V(e){if(!e)return null;try{return new URL(e)}catch{return null}}function H(e){return e===`localhost`||e===`127.0.0.1`||e===`::1`}export{L as default};