erdbpro 3.5.3 → 3.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AdminRoute-BUI-EDRz.js → AdminRoute-Di7g34Fy.js} +2 -2
- package/dist/assets/{Combination-Duv0rEfN.js → Combination-DbuVOQYD.js} +1 -1
- package/dist/assets/{DataViewerModeToolbar-Cew4jVJK.js → DataViewerModeToolbar-DGt3QHeI.js} +1 -1
- package/dist/assets/{DbClientEditorRoute-BjEkIYEP.js → DbClientEditorRoute-Dh00hTFE.js} +1 -1
- package/dist/assets/{DiagramEditorRoute-pw5JFieq.js → DiagramEditorRoute-D5Hde5-D.js} +1 -1
- package/dist/assets/{DrawingEditorRoute-D0jtN-sA.js → DrawingEditorRoute-D-2RJREu.js} +2 -2
- package/dist/assets/{DrawingsView-DYU6x0di.js → DrawingsView-DyHATZs0.js} +8 -8
- package/dist/assets/{ERDComments-Bz3nvfof.js → ERDComments-CCD4R_nR.js} +1 -1
- package/dist/assets/{FlowchartEditorRoute-DdgCEBK6.js → FlowchartEditorRoute-DFGhMS9_.js} +1 -1
- package/dist/assets/{LibraryRoute-BGKi1fBG.js → LibraryRoute-BPXgAtDw.js} +1 -1
- package/dist/assets/{NoteEditorRoute-CFk0YU66.js → NoteEditorRoute-OhCVPcxP.js} +2 -2
- package/dist/assets/{NotesView-cyMJpNK8.js → NotesView-BYdBTHX6.js} +1 -1
- package/dist/assets/{TeamInventoryRoute-a3M5BBKT.js → TeamInventoryRoute-Df11PTDL.js} +1 -1
- package/dist/assets/{TeamManagementRoute-DD0y4lvh.js → TeamManagementRoute-Dk1qx63g.js} +1 -1
- package/dist/assets/{TrashView-YKaJU0w7.js → TrashView-dhsn-_QX.js} +1 -1
- package/dist/assets/{UserManagementRoute-4b4y-hfW.js → UserManagementRoute-Bb-Hh32e.js} +1 -1
- package/dist/assets/{WorkspaceProvider-BM4_UNbD.js → WorkspaceProvider-BoxMDrjG.js} +3 -3
- package/dist/assets/{abnfDiagram-VCTEODGH-D4hzq6gY.js → abnfDiagram-VCTEODGH-BO3amG9i.js} +1 -1
- package/dist/assets/{ar-SA-G6X2FPQ2-BXC8NlU7.js → ar-SA-G6X2FPQ2-CJOQOPpt.js} +1 -1
- package/dist/assets/{architectureDiagram-5GKGNRK7-ruC4v0n2.js → architectureDiagram-5GKGNRK7-BtyzNqzc.js} +1 -1
- package/dist/assets/{az-AZ-76LH7QW2-CcAEYRMD.js → az-AZ-76LH7QW2-lzzI76ki.js} +1 -1
- package/dist/assets/{bg-BG-XCXSNQG7-DhjK4zbs.js → bg-BG-XCXSNQG7-BEdk2HPO.js} +1 -1
- package/dist/assets/{blockDiagram-I7D4REHJ-DlIrIyuh.js → blockDiagram-I7D4REHJ-BE36Ylwb.js} +1 -1
- package/dist/assets/{bn-BD-2XOGV67Q-B9dRE1IL.js → bn-BD-2XOGV67Q-DlcRzRAY.js} +1 -1
- package/dist/assets/{c4Diagram-7LVT6UL2-C6l1QJbn.js → c4Diagram-7LVT6UL2-DFndiNum.js} +1 -1
- package/dist/assets/{ca-ES-6MX7JW3Y-ChR1TbOq.js → ca-ES-6MX7JW3Y-ObkT46dg.js} +1 -1
- package/dist/assets/channel-CiNp_8Lf.js +1 -0
- package/dist/assets/{chunk-4HAMMTFA-CF0X3EKf.js → chunk-4HAMMTFA-Cu5Jo4Fp.js} +1 -1
- package/dist/assets/{chunk-75Z2AOVW-CubRuKo4.js → chunk-75Z2AOVW-Bna2GCOH.js} +1 -1
- package/dist/assets/{chunk-DU6HZSFF-C9Qywgxj.js → chunk-DU6HZSFF-CuYCVoRD.js} +1 -1
- package/dist/assets/{chunk-EIO257PC-BL1GsgJ2.js → chunk-EIO257PC-BWGgZw5R.js} +1 -1
- package/dist/assets/{chunk-F27PBJKO-DnacurK_.js → chunk-F27PBJKO-B10Ng-bK.js} +1 -1
- package/dist/assets/{chunk-GMAD6QVW-CxoiwY-Y.js → chunk-GMAD6QVW-DXPK15Ip.js} +1 -1
- package/dist/assets/{chunk-GVQU2GXP-DgaLiECz.js → chunk-GVQU2GXP-DI-3rc0r.js} +1 -1
- package/dist/assets/{chunk-IMKFNOWR-D3i_Gndx.js → chunk-IMKFNOWR-y_oi8Otd.js} +1 -1
- package/dist/assets/{chunk-L3NEJ4N5-8X-xbmD6.js → chunk-L3NEJ4N5-DbZ5g5nb.js} +1 -1
- package/dist/assets/{chunk-OSK3NFVY-9wRidd4V.js → chunk-OSK3NFVY-DYtE3e_L.js} +1 -1
- package/dist/assets/{chunk-P2QGCYS3-DSKo9A8c.js → chunk-P2QGCYS3-C6mucVOJ.js} +1 -1
- package/dist/assets/{chunk-POPQ4Y6H-BvCLKnzC.js → chunk-POPQ4Y6H-x1MxHddc.js} +1 -1
- package/dist/assets/{chunk-PWAF6VOD-99YNMWjU.js → chunk-PWAF6VOD-pglaRXnJ.js} +1 -1
- package/dist/assets/{chunk-SHT3W25Y-ByYZBuM9.js → chunk-SHT3W25Y-Lgeh4VwE.js} +1 -1
- package/dist/assets/{chunk-SVP7TREG-DHwdhdgW.js → chunk-SVP7TREG-BkZdJ2St.js} +1 -1
- package/dist/assets/{chunk-TICWLB2K-Cz0hiPV-.js → chunk-TICWLB2K-Cz2zZo7-.js} +1 -1
- package/dist/assets/classDiagram-ZZMXUADV-CxWakJM6.js +1 -0
- package/dist/assets/classDiagram-v2-VYDZK3BY-CxWakJM6.js +1 -0
- package/dist/assets/{cs-CZ-2BRQDIVT-Duo-zhhu.js → cs-CZ-2BRQDIVT-629VNm4z.js} +1 -1
- package/dist/assets/{cynefinDiagram-5FMLGOSQ-Bf8-RmUI.js → cynefinDiagram-5FMLGOSQ-BPwlf4OS.js} +1 -1
- package/dist/assets/{da-DK-5WZEPLOC-CxQfyOLo.js → da-DK-5WZEPLOC-CP-cfEFq.js} +1 -1
- package/dist/assets/{dagre-GXQ25YYZ-DcK2KIV7.js → dagre-GXQ25YYZ-qJpR0dI2.js} +1 -1
- package/dist/assets/{de-DE-XR44H4JA-Mg3BRJGd.js → de-DE-XR44H4JA-Bm8xaDix.js} +1 -1
- package/dist/assets/{diagram-S7CK7UJ4-DSs6443T.js → diagram-S7CK7UJ4-B_EGteAS.js} +1 -1
- package/dist/assets/{diagram-UQ7AKVKN-KjC9KEQ6.js → diagram-UQ7AKVKN-C6x0_HHB.js} +1 -1
- package/dist/assets/{diagram-VSXAHHWV-7FpkYiXO.js → diagram-VSXAHHWV-COflVHcK.js} +1 -1
- package/dist/assets/{diagram-VX7I27RA-Ba7lioAq.js → diagram-VX7I27RA-BN5q662e.js} +1 -1
- package/dist/assets/{diagram-Z3DM3KII-Bdh1pnpt.js → diagram-Z3DM3KII-DETr0ybJ.js} +1 -1
- package/dist/assets/{dist-C5GMsJtu.js → dist-Biv91BO4.js} +4 -4
- package/dist/assets/{ebnfDiagram-PWID7BFC-CjqJUAx7.js → ebnfDiagram-PWID7BFC-8iKk8xrX.js} +1 -1
- package/dist/assets/{el-GR-BZB4AONW-DTLPPbZL.js → el-GR-BZB4AONW-BFiOHsT1.js} +1 -1
- package/dist/assets/{en-B4ZKOASM-D2it7zPg.js → en-B4ZKOASM-wDEX2DoJ.js} +1 -1
- package/dist/assets/{erDiagram-RLTQ6QDP-BiXLCOUQ.js → erDiagram-RLTQ6QDP-DvAV0Jfg.js} +1 -1
- package/dist/assets/{erdActions-CS8wIQyx.js → erdActions-DrayLKdF.js} +1 -1
- package/dist/assets/{es-ES-U4NZUMDT-UAUuSE2i.js → es-ES-U4NZUMDT-Bu9IdytT.js} +1 -1
- package/dist/assets/{eu-ES-A7QVB2H4-DKb0F5vv.js → eu-ES-A7QVB2H4-DGQ0d179.js} +1 -1
- package/dist/assets/{fa-IR-HGAKTJCU-p9m000Kp.js → fa-IR-HGAKTJCU-BWFqq7Ui.js} +1 -1
- package/dist/assets/{fi-FI-Z5N7JZ37-WkJ2DZDv.js → fi-FI-Z5N7JZ37-BtCpxbUX.js} +1 -1
- package/dist/assets/flowDiagram-HODETNUW-BKP8UOHT.js +1 -0
- package/dist/assets/{fr-FR-RHASNOE6-BS5cQzeR.js → fr-FR-RHASNOE6-B03jjfXs.js} +1 -1
- package/dist/assets/{ganttDiagram-EL5Y4UJY-Ylu7J_J6.js → ganttDiagram-EL5Y4UJY-8XsRQJbL.js} +1 -1
- package/dist/assets/{gitGraphDiagram-WWUBYQGX-DQCz3oii.js → gitGraphDiagram-WWUBYQGX-D9Ug1hhy.js} +1 -1
- package/dist/assets/{gl-ES-HMX3MZ6V-NuiJWYPI.js → gl-ES-HMX3MZ6V-Bo3d1jBh.js} +1 -1
- package/dist/assets/{he-IL-6SHJWFNN-BquHOajf.js → he-IL-6SHJWFNN-DhG_PGw0.js} +1 -1
- package/dist/assets/{hi-IN-IWLTKZ5I-CbKLYNzJ.js → hi-IN-IWLTKZ5I-BAipFZOt.js} +1 -1
- package/dist/assets/{hu-HU-A5ZG7DT2-DmY_rnkZ.js → hu-HU-A5ZG7DT2-BCQm6nPY.js} +1 -1
- package/dist/assets/{id-ID-SAP4L64H-BL0c4E_b.js → id-ID-SAP4L64H-DC-QKTHt.js} +1 -1
- package/dist/assets/{image-GAAHSSAO-BZ2G9LyZ.js → image-GAAHSSAO-CDQGOZci.js} +1 -1
- package/dist/assets/{index-DUgCcn4y.js → index--GCPrghE.js} +4 -4
- package/dist/assets/{infoDiagram-27XIBGKW-DsH_RW1j.js → infoDiagram-27XIBGKW-C6oZBKmx.js} +1 -1
- package/dist/assets/{ishikawaDiagram-5VMMS53U-DTe7_N3Z.js → ishikawaDiagram-5VMMS53U-DJ6BBd4c.js} +1 -1
- package/dist/assets/{it-IT-JPQ66NNP-D_4pv85I.js → it-IT-JPQ66NNP-DgKOPq99.js} +1 -1
- package/dist/assets/{ja-JP-DBVTYXUO-CRcE3B9I.js → ja-JP-DBVTYXUO-BibTvOQE.js} +1 -1
- package/dist/assets/{journeyDiagram-3NMN7TZE-B1sUVEb3.js → journeyDiagram-3NMN7TZE-B8PdIkNt.js} +1 -1
- package/dist/assets/{kaa-6HZHGXH3-CnUol5mr.js → kaa-6HZHGXH3-BanutWho.js} +1 -1
- package/dist/assets/{kab-KAB-ZGHBKWFO-BMMckAYL.js → kab-KAB-ZGHBKWFO-CddRVIqb.js} +1 -1
- package/dist/assets/{kanban-definition-UXKFOSKX-CNBeYGgX.js → kanban-definition-UXKFOSKX-Fj1nS_37.js} +1 -1
- package/dist/assets/{kk-KZ-P5N5QNE5-DppOKhwy.js → kk-KZ-P5N5QNE5-CKf5pahD.js} +1 -1
- package/dist/assets/{km-KH-HSX4SM5Z-BYdZZ8pB.js → km-KH-HSX4SM5Z-BaSP74FW.js} +1 -1
- package/dist/assets/{ko-KR-MTYHY66A-7tgGSYBg.js → ko-KR-MTYHY66A-AdkoZXAw.js} +1 -1
- package/dist/assets/{ku-TR-6OUDTVRD-DXdXzHfd.js → ku-TR-6OUDTVRD-CN7Q52QV.js} +1 -1
- package/dist/assets/{line-UZzqgA7R.js → line-COo4xSrR.js} +1 -1
- package/dist/assets/{lt-LT-XHIRWOB4-CicNjEux.js → lt-LT-XHIRWOB4-DTleDLXy.js} +1 -1
- package/dist/assets/{lv-LV-5QDEKY6T-CSraRmSY.js → lv-LV-5QDEKY6T-la7BpMk8.js} +1 -1
- package/dist/assets/{mindmap-definition-YA3MSWOX-Fq40KZqx.js → mindmap-definition-YA3MSWOX-DfbUEptS.js} +1 -1
- package/dist/assets/{mr-IN-CRQNXWMA-EprMoORK.js → mr-IN-CRQNXWMA-Dbf2eEzk.js} +1 -1
- package/dist/assets/{my-MM-5M5IBNSE-UTyvoesw.js → my-MM-5M5IBNSE-BYvx-ljP.js} +1 -1
- package/dist/assets/{nb-NO-T6EIAALU-EQIvQkJo.js → nb-NO-T6EIAALU-BQFYVrz3.js} +1 -1
- package/dist/assets/{nl-NL-IS3SIHDZ-mu-9qxH2.js → nl-NL-IS3SIHDZ-BLeqB6xv.js} +1 -1
- package/dist/assets/{nn-NO-6E72VCQL-DNuq_NUP.js → nn-NO-6E72VCQL-C24l8_36.js} +1 -1
- package/dist/assets/{note-importer-Cq9PtnCB.js → note-importer-CUx3GQeV.js} +3 -3
- package/dist/assets/{oc-FR-POXYY2M6-D6etRf6Q.js → oc-FR-POXYY2M6-C3YIynoS.js} +1 -1
- package/dist/assets/{pa-IN-N4M65BXN-dDm85aTx.js → pa-IN-N4M65BXN-CoO1prGF.js} +1 -1
- package/dist/assets/{pegDiagram-XKGWAZYB-DeeVjn9X.js → pegDiagram-XKGWAZYB-COWMvd6C.js} +1 -1
- package/dist/assets/percentages-BXMCSKIN-DgJGsHCf.js +1 -0
- package/dist/assets/{pieDiagram-E7YTZNPT-CO072dyI.js → pieDiagram-E7YTZNPT-D9X4d4d1.js} +1 -1
- package/dist/assets/{pl-PL-T2D74RX3-BhYD1ZQc.js → pl-PL-T2D74RX3-B1X-poL2.js} +1 -1
- package/dist/assets/{popover-Kuvm0AEy.js → popover-Bn5au7Co.js} +1 -1
- package/dist/assets/{pt-BR-5N22H2LF-u8dy4fbT.js → pt-BR-5N22H2LF-C9yFhV1R.js} +1 -1
- package/dist/assets/{pt-PT-UZXXM6DQ-DD0agJ8B.js → pt-PT-UZXXM6DQ-stVJkvYT.js} +1 -1
- package/dist/assets/{quadrantDiagram-AXDQQJYC-Cqikl5uX.js → quadrantDiagram-AXDQQJYC-CcfiW8aO.js} +1 -1
- package/dist/assets/{railroadDiagram-O6MQD6OU-DGOjPGFX.js → railroadDiagram-O6MQD6OU-BNTkbyaz.js} +1 -1
- package/dist/assets/{requirementDiagram-BXWQKSXE-BGhuXnzY.js → requirementDiagram-BXWQKSXE-BtBjJEUQ.js} +1 -1
- package/dist/assets/{ro-RO-JPDTUUEW-D8zCjfOU.js → ro-RO-JPDTUUEW-C4NhXozA.js} +1 -1
- package/dist/assets/{ru-RU-B4JR7IUQ-B26zFlSM.js → ru-RU-B4JR7IUQ-DDX1zI-T.js} +1 -1
- package/dist/assets/{sankeyDiagram-P5KCCOFB-Bl-vt77m.js → sankeyDiagram-P5KCCOFB-CatK69vc.js} +1 -1
- package/dist/assets/{sequenceDiagram-WJ2MYXX4-0vL7ATHy.js → sequenceDiagram-WJ2MYXX4-DWGxcwdC.js} +1 -1
- package/dist/assets/{si-LK-N5RQ5JYF-CCcNdNiq.js → si-LK-N5RQ5JYF-BE6U9mIW.js} +1 -1
- package/dist/assets/{sk-SK-C5VTKIMK-CBhpwCYd.js → sk-SK-C5VTKIMK-iUMgcold.js} +1 -1
- package/dist/assets/{sl-SI-NN7IZMDC-Bx9ftGXS.js → sl-SI-NN7IZMDC-D1G5lUtc.js} +1 -1
- package/dist/assets/{stateDiagram-D77RDMKH-Co1h8Nkh.js → stateDiagram-D77RDMKH-lelYMOOe.js} +1 -1
- package/dist/assets/stateDiagram-v2-MP3YSRHH-Bk0iaTxm.js +1 -0
- package/dist/assets/subset-shared.chunk-DuJEfnS7.js +1 -0
- package/dist/assets/{subset-worker.chunk-CTLEiBfD.js → subset-worker.chunk-BDic2OPN.js} +1 -1
- package/dist/assets/{sv-SE-XGPEYMSR-3mz3ZYHE.js → sv-SE-XGPEYMSR-BHeXKZ5c.js} +1 -1
- package/dist/assets/{swimlanes-42K2YHIH-tDXjK8ux.js → swimlanes-42K2YHIH-CrSqZRXr.js} +1 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-DYXS_3qZ.js +8 -0
- package/dist/assets/{ta-IN-2NMHFXQM-CIyl9TQb.js → ta-IN-2NMHFXQM-CdOIjRm5.js} +1 -1
- package/dist/assets/{th-TH-HPSO5L25-rJIwNWQv.js → th-TH-HPSO5L25-Dac61kgA.js} +1 -1
- package/dist/assets/{timeline-definition-24CTP7MA-DK_Bvcsf.js → timeline-definition-24CTP7MA-fcS_OS5R.js} +1 -1
- package/dist/assets/{tr-TR-DEFEU3FU-C_4s-Jd3.js → tr-TR-DEFEU3FU-H0QrEvqw.js} +1 -1
- package/dist/assets/{uk-UA-QMV73CPH-SNwO0Nbr.js → uk-UA-QMV73CPH-BjAf83f7.js} +1 -1
- package/dist/assets/{useLeaveGuard-uyPAt3cT.js → useLeaveGuard-zmp_lcMN.js} +1 -1
- package/dist/assets/{vennDiagram-4TSXK5OY-CP_Sxg8c.js → vennDiagram-4TSXK5OY-D2ZjUfxu.js} +1 -1
- package/dist/assets/{vi-VN-M7AON7JQ-CFfC2MPo.js → vi-VN-M7AON7JQ-DMwokTpB.js} +1 -1
- package/dist/assets/{w3c-keyname-C1hBHVSi.js → w3c-keyname-C3urPNnY.js} +1 -1
- package/dist/assets/{wardleyDiagram-VM6X3IG4-BHjWXrZ9.js → wardleyDiagram-VM6X3IG4-BB139Qli.js} +1 -1
- package/dist/assets/{xychartDiagram-S5SC5T6Z-C4y3qKd5.js → xychartDiagram-S5SC5T6Z-C9BLIrNK.js} +1 -1
- package/dist/assets/{zh-CN-LNUGB5OW-BGFP9PWd.js → zh-CN-LNUGB5OW-CPMDvBFj.js} +1 -1
- package/dist/assets/{zh-HK-E62DVLB3-BiAL7ySq.js → zh-HK-E62DVLB3-CUR872yd.js} +1 -1
- package/dist/assets/{zh-TW-RAJ6MFWO-D8PDPSIf.js → zh-TW-RAJ6MFWO-CMJTJ6HG.js} +1 -1
- package/dist/index.html +7 -7
- package/dist-server/index.js +256 -257
- package/dist-server/mcp.js +126 -127
- package/package.json +1 -1
- package/dist/assets/channel-BGX9HSA2.js +0 -1
- package/dist/assets/classDiagram-ZZMXUADV-DVNkxqoU.js +0 -1
- package/dist/assets/classDiagram-v2-VYDZK3BY-DVNkxqoU.js +0 -1
- package/dist/assets/flowDiagram-HODETNUW-D1Hv-RPd.js +0 -1
- package/dist/assets/percentages-BXMCSKIN-4AEuIQp3.js +0 -1
- package/dist/assets/stateDiagram-v2-MP3YSRHH-DtsK32bg.js +0 -1
- package/dist/assets/subset-shared.chunk-vPzqxSBR.js +0 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-CmGvDn2V.js +0 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/event-C6gFlqUR.js","assets/core-5A5Ti_Rw.js","assets/app-Aufmny-7.js","assets/image-J9TY7xbU.js","assets/dist-js-CGfv5pu7.js","assets/rolldown-runtime-BCiCTKAo.js","assets/NoteEditorRoute-
|
|
2
|
-
import{a as e,i as t,n,o as r,r as i,t as a}from"./rolldown-runtime-BCiCTKAo.js";import{n as o,t as s}from"./jsx-runtime-Cl3nUQcN.js";import{d as c,i as l,r as u,s as d,t as f}from"./createLucideIcon-DCn6SI1F.js";import{a as p,c as m,d as h,f as g,i as _,l as v,n as y,o as b,r as x,s as S,t as C,u as w}from"./chunk-BV7QT456-B3UxAK3W.js";import{$ as T,B as E,F as D,G as O,H as k,J as A,K as j,N as M,Q as N,R as P,Tt as F,U as I,V as L,W as R,X as ee,Y as te,Z as ne,a as re,at as ie,et as z,ft as ae,ht as oe,mt as se,n as ce,nt as le,o as ue,ot as de,pt as B,r as fe,rt as pe,s as me,st as he,ut as ge,v as _e,vt as ve,w as V,wt as H,x as ye}from"./note-importer-Cq9PtnCB.js";import{a as be,c as xe,d as Se,f as Ce,i as we,it as Te,m as Ee,nt as De,p as Oe,r as ke,rt as Ae,s as je,t as U,u as Me}from"./button-CYI0LXM3.js";import{$t as Ne,B as Pe,Bt as Fe,H as Ie,Ht as Le,Kt as Re,Lt as ze,R as Be,Rt as Ve,S as He,St as Ue,Ut as We,V as Ge,Vt as Ke,Wt as qe,_ as Je,a as Ye,b as Xe,c as Ze,en as Qe,g as $e,gn as et,h as tt,l as nt,lt as rt,m as it,n as at,o as ot,p as st,pt as ct,qt as lt,s as ut,u as dt,ut as ft,v as pt,x as mt,y as ht,zt as gt}from"./useOpenInteractionType-BlKZ7jMy.js";import{a as _t,i as vt,n as yt,o as bt,r as xt,s as St,t as Ct}from"./useField-E2Vk7I_Z.js";import{a as wt,c as Tt,d as Et,f as Dt,i as Ot,l as kt,n as At,o as jt,r as Mt,s as Nt,t as Pt,u as Ft}from"./popover-Kuvm0AEy.js";import{a as It,c as Lt,d as Rt,f as zt,h as Bt,i as Vt,l as Ht,n as Ut,o as Wt,r as Gt,s as Kt,t as qt,u as Jt}from"./dropdown-menu-BoXeiuAZ.js";import{t as Yt}from"./check-BwjD7EK2.js";import{r as Xt}from"./getPseudoElementBounds-BEHunO5c.js";import{a as Zt,i as Qt,r as $t,t as en}from"./CompositeList-BqU8Qax7.js";import{$ as tn,B as nn,Ct as rn,D as an,F as on,H as sn,I as cn,K as ln,L as un,O as dn,P as fn,Q as pn,R as mn,U as hn,V as gn,W as _n,X as vn,Z as yn,at as bn,bt as xn,ct as Sn,dt as Cn,et as wn,ft as Tn,ht as En,it as Dn,k as On,lt as kn,mt as An,nt as jn,pt as Mn,rt as Nn,st as Pn,t as Fn,tt as In,ut as Ln,wt as Rn,xt as zn,yt as Bn,z as Vn}from"./ERDComments-Bz3nvfof.js";import{A as Hn,C as Un,D as Wn,E as Gn,O as Kn,S as qn,T as Jn,_ as Yn,b as Xn,c as Zn,g as Qn,h as $n,i as er,k as tr,l as nr,v as rr,w as ir,x as ar,y as or}from"./w3c-keyname-C1hBHVSi.js";import{n as sr,t as cr}from"./refresh-cw-DyBeWpoi.js";import{t as lr}from"./chevron-left-D_Hf28gP.js";import{a as ur,d as dr,i as fr,n as pr,o as mr,r as hr,s as gr,t as _r}from"./select-CdQCv8yP.js";import{n as vr,r as yr,t as br}from"./ConfirmModal-pEN41Kyx.js";import{i as xr,n as Sr,r as Cr,t as wr}from"./pen-tool-CoHyO7pC.js";import{t as Tr}from"./ellipsis-CfqIMSId.js";import{a as Er,i as Dr,n as Or,o as kr,r as Ar,t as jr}from"./field-BXvmJTfd.js";import{t as Mr}from"./hard-drive-Chd5URlA.js";import{t as Nr}from"./message-square-B1YYK_eY.js";import{_ as Pr,a as Fr,c as Ir,d as Lr,f as Rr,g as zr,h as Br,i as Vr,l as Hr,m as Ur,n as Wr,o as Gr,p as Kr,r as qr,s as Jr,t as Yr,u as Xr,v as Zr}from"./dialog-BIk9Y-3N.js";import{t as Qr}from"./sparkles-BTRhjhc4.js";import{t as $r}from"./trash-2-CV7XVyhd.js";import{C as ei,_ as ti,a as ni,b as ri,c as ii,g as ai,i as oi,l as si,n as ci,o as li,p as ui,r as di,s as fi,t as pi,u as mi,v as hi,y as gi}from"./alert-dialog-DXnJdv-M.js";import{t as _i}from"./preload-helper-BLdHbfdN.js";import{a as vi,c as yi,i as bi,l as xi,n as Si,s as Ci}from"./api-DuV0sTuY.js";import{t as wi}from"./input-CMgoax5D.js";import{D as Ti,E as Ei,T as Di,a as Oi,c as ki,d as Ai,f as ji,h as Mi,i as Ni,l as Pi,m as Fi,o as Ii,p as Li,s as Ri,u as zi,w as Bi}from"./useLeaveGuard-uyPAt3cT.js";import{t as Vi}from"./useCompositeItem-DK528yJL.js";import{i as Hi,n as Ui}from"./fileOwnership-CF3Bm_pU.js";import{B as Wi,H as Gi,N as Ki,O as qi,R as Ji,U as Yi,V as Xi,W as Zi,_ as Qi,c as $i,g as ea,i as ta,n as na,o as ra,s as ia,t as aa,v as oa,z as sa}from"./WorkspaceProvider-BM4_UNbD.js";import{t as ca}from"./localPersistence-CGAJ2Ky5.js";import{n as la,r as ua,t as da}from"./useAuth-splnWP_7.js";import{i as fa}from"./core-5A5Ti_Rw.js";import{n as pa,t as ma}from"./WorkspaceContext-CitlpD55.js";import{t as ha}from"./label-CfaCFYRS.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ga=a((e=>{var t=c();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot}))(),W=r(o(),1),_a=(e,t,n,r,i,a,o,s)=>{let c=document.documentElement,l=[`light`,`dark`];function u(t){(Array.isArray(e)?e:[e]).forEach(e=>{let n=e===`class`,r=n&&a?i.map(e=>a[e]||e):i;n?(c.classList.remove(...r),c.classList.add(a&&a[t]?a[t]:t)):c.setAttribute(e,t)}),d(t)}function d(e){s&&l.includes(e)&&(c.style.colorScheme=e)}function f(){return window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}if(r)u(r);else try{let e=localStorage.getItem(t)||n;u(o&&e===`system`?f():e)}catch{}},va=W.createContext(void 0),ya={setTheme:e=>{},themes:[]},ba=()=>W.useContext(va)??ya;W.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:i,defaultTheme:a,value:o,themes:s,nonce:c,scriptProps:l})=>{let u=JSON.stringify([n,t,a,e,s,o,r,i]).slice(1,-1);return W.createElement(`script`,{...l,suppressHydrationWarning:!0,nonce:typeof window>`u`?c:``,dangerouslySetInnerHTML:{__html:`(${_a.toString()})(${u})`}})});var xa=f(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),Sa=f(`arrow-up-down`,[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]),Ca=f(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),wa=f(`at-sign`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]),Ta=f(`badge-alert`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Ea=f(`book-text`,[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]),Da=f(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),Oa=f(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),ka=f(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),Aa=f(`calculator`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`line`,{x1:`8`,x2:`16`,y1:`6`,y2:`6`,key:`x4nwl0`}],[`line`,{x1:`16`,x2:`16`,y1:`14`,y2:`18`,key:`wjye3r`}],[`path`,{d:`M16 10h.01`,key:`1m94wz`}],[`path`,{d:`M12 10h.01`,key:`1nrarc`}],[`path`,{d:`M8 10h.01`,key:`19clt8`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}]]),ja=f(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),Ma=f(`chevrons-left`,[[`path`,{d:`m11 17-5-5 5-5`,key:`13zhaf`}],[`path`,{d:`m18 17-5-5 5-5`,key:`h8a8et`}]]),Na=f(`chevrons-right`,[[`path`,{d:`m6 17 5-5-5-5`,key:`xnjwq`}],[`path`,{d:`m13 17 5-5-5-5`,key:`17xmmf`}]]),Pa=f(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),Fa=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),Ia=f(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),La=f(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ra=f(`clock`,[[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),za=f(`cloud-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5.782 5.782A7 7 0 0 0 9 19h8.5a4.5 4.5 0 0 0 1.307-.193`,key:`yfwify`}],[`path`,{d:`M21.532 16.5A4.5 4.5 0 0 0 17.5 10h-1.79A7.008 7.008 0 0 0 10 5.07`,key:`jlfiyv`}]]),Ba=f(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),Va=f(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),Ha=f(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),Ua=f(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Wa=f(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ga=f(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),Ka=f(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),qa=f(`file-box`,[[`path`,{d:`M14.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`16lz6z`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M3 13.1a2 2 0 0 0-1 1.76v3.24a2 2 0 0 0 .97 1.78L6 21.7a2 2 0 0 0 2.03.01L11 19.9a2 2 0 0 0 1-1.76V14.9a2 2 0 0 0-.97-1.78L8 11.3a2 2 0 0 0-2.03-.01Z`,key:`99pj1s`}],[`path`,{d:`M7 17v5`,key:`1yj1jh`}],[`path`,{d:`M11.7 14.2 7 17l-4.7-2.8`,key:`1yk8tc`}]]),Ja=f(`file-down`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),Ya=f(`file-json`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),Xa=f(`file-pen`,[[`path`,{d:`M12.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v9.5`,key:`1couwa`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M13.378 15.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`1y4qbx`}]]),Za=f(`file-type-2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M2 13v-1h6v1`,key:`1dh9dg`}],[`path`,{d:`M5 12v6`,key:`150t9c`}],[`path`,{d:`M4 18h2`,key:`1xrofg`}]]),Qa=f(`file-type`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M9 13v-1h6v1`,key:`1bb014`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`M11 18h2`,key:`12mj7e`}]]),$a=f(`file`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}]]),eo=f(`folder-closed`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M2 10h20`,key:`1ir3d8`}]]),to=f(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),no=f(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),ro=f(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),io=f(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),ao=f(`git-compare-arrows`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`M12 18H7a2 2 0 0 1-2-2V9`,key:`16sdep`}],[`path`,{d:`m9 15 3 3-3 3`,key:`1m3kbl`}]]),oo=f(`github`,[[`path`,{d:`M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4`,key:`tonef`}],[`path`,{d:`M9 18c-4.51 2-5-2-7-2`,key:`9comsn`}]]),so=f(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),co=f(`hash`,[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]),lo=f(`heart`,[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}]]),uo=f(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),fo=f(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),po=f(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),mo=f(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),ho=f(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),go=f(`layout-panel-left`,[[`rect`,{width:`7`,height:`18`,x:`3`,y:`3`,rx:`1`,key:`2obqm`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}]]),_o=f(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),vo=f(`lightbulb`,[[`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`,key:`1gvzjb`}],[`path`,{d:`M9 18h6`,key:`x1upvd`}],[`path`,{d:`M10 22h4`,key:`ceow96`}]]),yo=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),bo=f(`list-checks`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]),xo=f(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),So=f(`lock`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]),Co=f(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),wo=f(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),To=f(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),Eo=f(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Do=f(`monitor`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]),Oo=f(`moon`,[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]),ko=f(`octagon-x`,[[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`,key:`2d38gg`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ao=f(`palette`,[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]),jo=f(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),Mo=f(`panels-top-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M9 21V9`,key:`1oto5p`}]]),No=f(`pen`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),Po=f(`replace`,[[`path`,{d:`M14 4a1 1 0 0 1 1-1`,key:`dhj8ez`}],[`path`,{d:`M15 10a1 1 0 0 1-1-1`,key:`1mnyi5`}],[`path`,{d:`M21 4a1 1 0 0 0-1-1`,key:`sfs9ap`}],[`path`,{d:`M21 9a1 1 0 0 1-1 1`,key:`mp6qeo`}],[`path`,{d:`m3 7 3 3 3-3`,key:`x25e72`}],[`path`,{d:`M6 10V5a2 2 0 0 1 2-2h2`,key:`15xut4`}],[`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1bkyp8`}]]),Fo=f(`rotate-ccw-key`,[[`path`,{d:`m14.5 9.5 1 1`,key:`159eiq`}],[`path`,{d:`m15.5 8.5-4 4`,key:`iirg3q`}],[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.74 9.74 0 0 0-6.74 2.74L3 8`,key:`g2jlw`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`circle`,{cx:`10`,cy:`14`,r:`2`,key:`1239so`}]]),Io=f(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Lo=f(`server-cog`,[[`path`,{d:`m10.852 14.772-.383.923`,key:`11vil6`}],[`path`,{d:`M13.148 14.772a3 3 0 1 0-2.296-5.544l-.383-.923`,key:`1v3clb`}],[`path`,{d:`m13.148 9.228.383-.923`,key:`t2zzyc`}],[`path`,{d:`m13.53 15.696-.382-.924a3 3 0 1 1-2.296-5.544`,key:`1bxfiv`}],[`path`,{d:`m14.772 10.852.923-.383`,key:`k9m8cz`}],[`path`,{d:`m14.772 13.148.923.383`,key:`1xvhww`}],[`path`,{d:`M4.5 10H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-.5`,key:`tn8das`}],[`path`,{d:`M4.5 14H4a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-.5`,key:`1g2pve`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M6 6h.01`,key:`1utrut`}],[`path`,{d:`m9.228 10.852-.923-.383`,key:`1wtb30`}],[`path`,{d:`m9.228 13.148-.923.383`,key:`1a830x`}]]),Ro=f(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),zo=f(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Bo=f(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Vo=f(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),Ho=f(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),Uo=f(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),Wo=f(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),Go=f(`sticky-note`,[[`path`,{d:`M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z`,key:`qazsjp`}],[`path`,{d:`M15 3v4a2 2 0 0 0 2 2h4`,key:`40519r`}]]),Ko=f(`sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),qo=f(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),Jo=f(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),Yo=f(`trash`,[[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),Xo=f(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),Zo=f(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Qo=f(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),$o=f(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),es=f(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),ts=f(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),G=s(),ns=({...e})=>{let{theme:t=`system`}=ba();return(0,G.jsx)(u,{theme:t,className:`toaster group`,richColors:!0,icons:{success:(0,G.jsx)(Rn,{className:`size-4`}),info:(0,G.jsx)(vr,{className:`size-4`}),warning:(0,G.jsx)(ei,{className:`size-4`}),error:(0,G.jsx)(ko,{className:`size-4`}),loading:(0,G.jsx)(xo,{className:`size-4 animate-spin`})},style:{"--border-radius":`var(--radius)`},toastOptions:{classNames:{toast:`cn-toast`}},...e})},rs=W.createContext({legendId:void 0,setLegendId:()=>{},disabled:void 0});function is(e=!1){let t=W.useContext(rs);if(!t&&!e)throw Error(De(86));return t}var as=W.createContext({disabled:!1});function os(){return W.useContext(as)}var ss=W.createContext(void 0);function cs(e=!0){let t=W.useContext(ss);if(t===void 0&&!e)throw Error(De(3));return t}function ls({configured:e,loginUrl:t,onLogin:n}){let[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let e=new URL(window.location.href);i(e.searchParams.get(`sso_link`)===`required`);let t=e.searchParams.get(`error`);t&&(l.error(t),e.searchParams.delete(`error`),window.history.replaceState({},document.title,`${e.pathname}${e.search}`))},[]);let u=()=>{i(!1),o(``);let e=new URL(window.location.href);e.searchParams.delete(`sso_link`),window.history.replaceState({},document.title,`${e.pathname}${e.search}`)};return(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(Lr,{className:`w-full max-w-sm`,children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(zr,{children:r?`Link your existing Cloud account`:`Sign in to ERD Builder Pro Cloud`}),(0,G.jsx)(Kr,{children:r?`This verified SSO email already belongs to a Cloud account. Enter that account's current password to confirm ownership.`:`Your account and subscription are managed by ERDBPro SaaS.`})]}),(0,G.jsx)(Rr,{children:r?(0,G.jsx)(`form`,{onSubmit:async e=>{e.preventDefault(),c(!0);try{let e=await Si(`/api/sso/link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:a})}),t=await e.json();if(!e.ok){l.error(t.error||`Unable to link the existing Cloud account`);return}u(),n(t.user),l.success(`Existing Cloud account linked successfully`)}catch{l.error(`Unable to link the existing Cloud account`)}finally{c(!1)}},children:(0,G.jsxs)(Ar,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`sso-link-password`,children:`Current Cloud password`}),(0,G.jsx)(wi,{id:`sso-link-password`,type:`password`,autoComplete:`current-password`,required:!0,value:a,onChange:e=>o(e.target.value)}),(0,G.jsx)(Or,{children:`Your ERDBPro SaaS password is not requested here.`})]}),(0,G.jsxs)(jr,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(U,{type:`submit`,disabled:s,className:`w-full`,children:s?`Verifying account...`:`Verify and link account`}),(0,G.jsx)(U,{type:`button`,variant:`outline`,className:`w-full`,onClick:u,children:`Cancel`})]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(U,{className:`w-full`,disabled:!e,onClick:()=>window.location.assign(`${vi()}${t}`),children:[(0,G.jsx)(Co,{"data-icon":`inline-start`}),`Continue with ERDBPro SSO`]}),!e&&(0,G.jsx)(`p`,{className:`mt-3 text-center text-sm text-destructive`,children:`SSO configuration is incomplete.`})]})})]})})}function us({onLogin:e,onGuestLogin:t}){let[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(`password`),[E,D]=(0,W.useState)(!0),[O,k]=(0,W.useState)(`/api/sso/login`);(0,W.useEffect)(()=>{Si(`/api/auth-config`,{cache:`no-store`}).then(e=>e.json()).then(e=>{x(e.guest_mode!==!1),C(e.needs_setup===!0||e.needsSetup===!0),T((e.auth_mode??e.authMode)===`sso`?`sso`:`password`),D((e.sso_configured??e.ssoConfigured)!==!1),k(e.sso_login_url??e.ssoLoginUrl??`/api/sso/login`)}).catch(()=>C(!1))},[]);let A=yi(),j=Ci()===`cli`,M=(0,W.useRef)(!0),N=(0,W.useRef)(0);if((0,W.useEffect)(()=>{if(!A)return;let t=!1;return(async()=>{for(;!t&&M.current;){try{let n=await Si(`/api/me`);if(n.ok){let r=await n.json();if(r.authenticated&&!t){r.token&&xi(r.token),e(r.user);return}}else if(n.status===503){let e=await n.json().catch(()=>({}));if(e.db_error&&!t){y(e.message||`Database initialization failed. Check logs for details.`);return}}}catch{}if(N.current++,N.current>=20&&!t){y(j?`Unable to connect to the CLI backend server. Check ~/.erdbpro/logs/ for server logs.`:`Unable to connect to the desktop backend server. Check the application logs.`);return}t||await new Promise(e=>setTimeout(e,1e3))}})(),()=>{t=!0}},[j,A,e]),A)return v?(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border border-red-800 bg-red-950/40 p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(`span`,{className:`text-red-400 text-lg`,children:`⚠️`}),(0,G.jsx)(`h2`,{className:`text-red-300 font-semibold`,children:`Startup Error`})]}),(0,G.jsx)(`p`,{className:`text-red-200/80 text-sm mb-4`,children:v}),(0,G.jsxs)(`div`,{className:`text-xs text-red-300/60 space-y-1`,children:[(0,G.jsxs)(`p`,{children:[`Log file: `,(0,G.jsx)(`code`,{className:`text-red-200/80`,children:j?`~/.erdbpro/logs/server-*.err.log`:`~/Library/Logs/com.erdbuilderpro.app/server-startup.log`})]}),(0,G.jsx)(`p`,{children:j?`Try restarting the CLI. If the issue persists, inspect the latest server error log.`:`Try restarting the app. If the issue persists, ensure Node.js is installed.`})]})]})}):(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4`,children:[(0,G.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connecting...`})]})});if(S===null)return(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6`,children:(0,G.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent`})});let P=S;return w===`sso`?(0,G.jsx)(ls,{configured:E,loginUrl:O,onLogin:e}):(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsx)(`div`,{className:`w-full max-w-sm`,children:(0,G.jsx)(`div`,{className:d(`flex flex-col gap-6`),children:(0,G.jsxs)(Lr,{children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(zr,{children:P?`Create administrator account`:`Login to your account`}),(0,G.jsx)(Kr,{children:P?`Set the first administrator email and password for this Self-host installation.`:`Enter your email below to login to your account`})]}),(0,G.jsx)(Rr,{children:(0,G.jsx)(`form`,{onSubmit:async t=>{if(t.preventDefault(),P&&o!==c)l.error(`Passwords do not match`);else{_(!0);try{let t=await Si(P?`/api/setup`:`/api/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(P?{name:n,email:i,password:o,confirmPassword:c}:{email:i,password:o})});if(t.ok){let n=await t.json();n.token&&xi(n.token),e(n.user),l.success(P?`Administrator account created!`:`Welcome back!`)}else{let e=await t.json();l.error(e.error||`Login failed`)}}catch(e){console.error(`Login error:`,e);let t=e instanceof Error?e.message:`An unexpected error occurred`;l.error(t)}finally{_(!1)}}},children:(0,G.jsxs)(Ar,{children:[P&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`name`,children:`Name`}),(0,G.jsx)(wi,{id:`name`,type:`text`,placeholder:`Enter administrator name`,required:!0,value:n,onChange:e=>r(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`email`,children:`Email`}),(0,G.jsx)(wi,{id:`email`,type:`email`,placeholder:`m@example.com`,required:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(`div`,{className:`flex items-center`,children:(0,G.jsx)(Dr,{htmlFor:`password`,children:`Password`})}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`password`,type:f?`text`:`password`,placeholder:P?`Create a password`:`Enter your password`,required:!0,value:o,onChange:e=>s(e.target.value),className:`pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground transition-colors hover:text-foreground focus:outline-none cursor-pointer`,"aria-label":f?`Hide password`:`Show password`,children:f?(0,G.jsx)(kr,{className:`h-4 w-4`}):(0,G.jsx)(Ka,{className:`h-4 w-4`})})]})]}),P&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`confirm-password`,children:`Confirm Password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`confirm-password`,type:m?`text`:`password`,placeholder:`Re-enter your password`,required:!0,value:c,onChange:e=>u(e.target.value),className:`pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(!m),className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground transition-colors hover:text-foreground focus:outline-none cursor-pointer`,"aria-label":m?`Hide confirm password`:`Show confirm password`,children:m?(0,G.jsx)(kr,{className:`h-4 w-4`}):(0,G.jsx)(Ka,{className:`h-4 w-4`})})]})]}),(0,G.jsxs)(jr,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(U,{type:`submit`,disabled:g,className:`w-full`,children:g?P?`Creating account...`:`Logging in...`:P?`Create administrator`:`Login`}),b&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative my-2`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`span`,{className:`w-full border-t`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,G.jsx)(`span`,{className:`bg-background px-2 text-muted-foreground`,children:`Or`})})]}),(0,G.jsx)(U,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>{t?.(),l.success(`Welcome! You're in Guest Mode.`)},children:`Try as Guest (Local Mode)`})]}),P&&(0,G.jsx)(Or,{className:`text-center`,children:`This setup is available only once for the empty database.`})]})]})})})]})})})})}var ds=(0,W.createContext)({});function fs(e){let t=(0,W.useRef)(null);return t.current===null&&(t.current=e()),t.current}var ps=(0,W.createContext)(null),ms=(0,W.createContext)({transformPagePoint:e=>e,isStatic:!1,reducedMotion:`never`}),hs=class extends W.Component{getSnapshotBeforeUpdate(e){let t=this.props.childRef.current;if(t&&e.isPresent&&!this.props.isPresent){let e=this.props.sizeRef.current;e.height=t.offsetHeight||0,e.width=t.offsetWidth||0,e.top=t.offsetTop,e.left=t.offsetLeft}return null}componentDidUpdate(){}render(){return this.props.children}};function gs({children:e,isPresent:t}){let n=(0,W.useId)(),r=(0,W.useRef)(null),i=(0,W.useRef)({width:0,height:0,top:0,left:0}),{nonce:a}=(0,W.useContext)(ms);return(0,W.useInsertionEffect)(()=>{let{width:e,height:o,top:s,left:c}=i.current;if(t||!r.current||!e||!o)return;r.current.dataset.motionPopId=n;let l=document.createElement(`style`);return a&&(l.nonce=a),document.head.appendChild(l),l.sheet&&l.sheet.insertRule(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/event-C6gFlqUR.js","assets/core-5A5Ti_Rw.js","assets/app-Aufmny-7.js","assets/image-J9TY7xbU.js","assets/dist-js-CGfv5pu7.js","assets/rolldown-runtime-BCiCTKAo.js","assets/NoteEditorRoute-OhCVPcxP.js","assets/jsx-runtime-Cl3nUQcN.js","assets/createLucideIcon-DCn6SI1F.js","assets/chunk-BV7QT456-B3UxAK3W.js","assets/preload-helper-BLdHbfdN.js","assets/WorkspaceProvider-BoxMDrjG.js","assets/note-importer-CUx3GQeV.js","assets/src-C_gRsKqw.js","assets/value-CHmTzbgv.js","assets/image-compression-su-JvgYP.js","assets/api-DuV0sTuY.js","assets/pen-tool-CoHyO7pC.js","assets/fileOwnership-CF3Bm_pU.js","assets/localPersistence-CGAJ2Ky5.js","assets/useAuth-splnWP_7.js","assets/diagramVersioning-DlDBcvq6.js","assets/WorkspaceContext-CitlpD55.js","assets/DiagramEditorRoute-D5Hde5-D.js","assets/DataViewerModeToolbar-DGt3QHeI.js","assets/button-CYI0LXM3.js","assets/useField-E2Vk7I_Z.js","assets/useOpenInteractionType-BlKZ7jMy.js","assets/popover-Bn5au7Co.js","assets/dropdown-menu-BoXeiuAZ.js","assets/check-BwjD7EK2.js","assets/getPseudoElementBounds-BEHunO5c.js","assets/CompositeList-BqU8Qax7.js","assets/useCompositeItem-DK528yJL.js","assets/ERDComments-CCD4R_nR.js","assets/select-CdQCv8yP.js","assets/ConfirmModal-pEN41Kyx.js","assets/alert-dialog-DXnJdv-M.js","assets/ellipsis-CfqIMSId.js","assets/dialog-BIk9Y-3N.js","assets/trash-2-CV7XVyhd.js","assets/w3c-keyname-C3urPNnY.js","assets/input-CMgoax5D.js","assets/refresh-cw-DyBeWpoi.js","assets/chevron-left-D_Hf28gP.js","assets/erdActions-DrayLKdF.js","assets/field-BXvmJTfd.js","assets/redo-2-CUB0gf4Y.js","assets/message-square-B1YYK_eY.js","assets/sparkles-BTRhjhc4.js","assets/undo-2-eBLOetyj.js","assets/useLeaveGuard-zmp_lcMN.js","assets/label-CfaCFYRS.js","assets/extends-CvVTau-c.js","assets/style-CHpVij2M.css","assets/FlowchartEditorRoute-DFGhMS9_.js","assets/move-DdEe66cP.js","assets/DrawingEditorRoute-D-2RJREu.js","assets/image-BbGqZ83-.js","assets/DbClientEditorRoute-Dh00hTFE.js","assets/TeamManagementRoute-Dk1qx63g.js","assets/user-x-Cas_SoSK.js","assets/TeamInventoryRoute-Df11PTDL.js","assets/LibraryRoute-BPXgAtDw.js","assets/file-image-BJtZ70LN.js","assets/UserManagementRoute-Bb-Hh32e.js","assets/user-cog-hquByiKk.js","assets/AdminRoute-Di7g34Fy.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"./rolldown-runtime-BCiCTKAo.js";import{n as o,t as s}from"./jsx-runtime-Cl3nUQcN.js";import{d as c,i as l,r as u,s as d,t as f}from"./createLucideIcon-DCn6SI1F.js";import{a as p,c as m,d as h,f as g,i as _,l as v,n as y,o as b,r as x,s as S,t as C,u as w}from"./chunk-BV7QT456-B3UxAK3W.js";import{$ as T,B as E,F as D,G as O,H as k,J as A,K as j,N as M,Q as N,R as P,Tt as F,U as I,V as L,W as R,X as ee,Y as te,Z as ne,a as re,at as ie,et as z,ft as ae,ht as oe,mt as se,n as ce,nt as le,o as ue,ot as de,pt as B,r as fe,rt as pe,s as me,st as he,ut as ge,v as _e,vt as ve,w as V,wt as H,x as ye}from"./note-importer-CUx3GQeV.js";import{a as be,c as xe,d as Se,f as Ce,i as we,it as Te,m as Ee,nt as De,p as Oe,r as ke,rt as Ae,s as je,t as U,u as Me}from"./button-CYI0LXM3.js";import{$t as Ne,B as Pe,Bt as Fe,H as Ie,Ht as Le,Kt as Re,Lt as ze,R as Be,Rt as Ve,S as He,St as Ue,Ut as We,V as Ge,Vt as Ke,Wt as qe,_ as Je,a as Ye,b as Xe,c as Ze,en as Qe,g as $e,gn as et,h as tt,l as nt,lt as rt,m as it,n as at,o as ot,p as st,pt as ct,qt as lt,s as ut,u as dt,ut as ft,v as pt,x as mt,y as ht,zt as gt}from"./useOpenInteractionType-BlKZ7jMy.js";import{a as _t,i as vt,n as yt,o as bt,r as xt,s as St,t as Ct}from"./useField-E2Vk7I_Z.js";import{a as wt,c as Tt,d as Et,f as Dt,i as Ot,l as kt,n as At,o as jt,r as Mt,s as Nt,t as Pt,u as Ft}from"./popover-Bn5au7Co.js";import{a as It,c as Lt,d as Rt,f as zt,h as Bt,i as Vt,l as Ht,n as Ut,o as Wt,r as Gt,s as Kt,t as qt,u as Jt}from"./dropdown-menu-BoXeiuAZ.js";import{t as Yt}from"./check-BwjD7EK2.js";import{r as Xt}from"./getPseudoElementBounds-BEHunO5c.js";import{a as Zt,i as Qt,r as $t,t as en}from"./CompositeList-BqU8Qax7.js";import{$ as tn,B as nn,Ct as rn,D as an,F as on,H as sn,I as cn,K as ln,L as un,O as dn,P as fn,Q as pn,R as mn,U as hn,V as gn,W as _n,X as vn,Z as yn,at as bn,bt as xn,ct as Sn,dt as Cn,et as wn,ft as Tn,ht as En,it as Dn,k as On,lt as kn,mt as An,nt as jn,pt as Mn,rt as Nn,st as Pn,t as Fn,tt as In,ut as Ln,wt as Rn,xt as zn,yt as Bn,z as Vn}from"./ERDComments-CCD4R_nR.js";import{A as Hn,C as Un,D as Wn,E as Gn,O as Kn,S as qn,T as Jn,_ as Yn,b as Xn,c as Zn,g as Qn,h as $n,i as er,k as tr,l as nr,v as rr,w as ir,x as ar,y as or}from"./w3c-keyname-C3urPNnY.js";import{n as sr,t as cr}from"./refresh-cw-DyBeWpoi.js";import{t as lr}from"./chevron-left-D_Hf28gP.js";import{a as ur,d as dr,i as fr,n as pr,o as mr,r as hr,s as gr,t as _r}from"./select-CdQCv8yP.js";import{n as vr,r as yr,t as br}from"./ConfirmModal-pEN41Kyx.js";import{i as xr,n as Sr,r as Cr,t as wr}from"./pen-tool-CoHyO7pC.js";import{t as Tr}from"./ellipsis-CfqIMSId.js";import{a as Er,i as Dr,n as Or,o as kr,r as Ar,t as jr}from"./field-BXvmJTfd.js";import{t as Mr}from"./hard-drive-Chd5URlA.js";import{t as Nr}from"./message-square-B1YYK_eY.js";import{_ as Pr,a as Fr,c as Ir,d as Lr,f as Rr,g as zr,h as Br,i as Vr,l as Hr,m as Ur,n as Wr,o as Gr,p as Kr,r as qr,s as Jr,t as Yr,u as Xr,v as Zr}from"./dialog-BIk9Y-3N.js";import{t as Qr}from"./sparkles-BTRhjhc4.js";import{t as $r}from"./trash-2-CV7XVyhd.js";import{C as ei,_ as ti,a as ni,b as ri,c as ii,g as ai,i as oi,l as si,n as ci,o as li,p as ui,r as di,s as fi,t as pi,u as mi,v as hi,y as gi}from"./alert-dialog-DXnJdv-M.js";import{t as _i}from"./preload-helper-BLdHbfdN.js";import{a as vi,c as yi,i as bi,l as xi,n as Si,s as Ci}from"./api-DuV0sTuY.js";import{t as wi}from"./input-CMgoax5D.js";import{D as Ti,E as Ei,T as Di,a as Oi,c as ki,d as Ai,f as ji,h as Mi,i as Ni,l as Pi,m as Fi,o as Ii,p as Li,s as Ri,u as zi,w as Bi}from"./useLeaveGuard-zmp_lcMN.js";import{t as Vi}from"./useCompositeItem-DK528yJL.js";import{i as Hi,n as Ui}from"./fileOwnership-CF3Bm_pU.js";import{B as Wi,H as Gi,N as Ki,O as qi,R as Ji,U as Yi,V as Xi,W as Zi,_ as Qi,c as $i,g as ea,i as ta,n as na,o as ra,s as ia,t as aa,v as oa,z as sa}from"./WorkspaceProvider-BoxMDrjG.js";import{t as ca}from"./localPersistence-CGAJ2Ky5.js";import{n as la,r as ua,t as da}from"./useAuth-splnWP_7.js";import{i as fa}from"./core-5A5Ti_Rw.js";import{n as pa,t as ma}from"./WorkspaceContext-CitlpD55.js";import{t as ha}from"./label-CfaCFYRS.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ga=a((e=>{var t=c();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot}))(),W=r(o(),1),_a=(e,t,n,r,i,a,o,s)=>{let c=document.documentElement,l=[`light`,`dark`];function u(t){(Array.isArray(e)?e:[e]).forEach(e=>{let n=e===`class`,r=n&&a?i.map(e=>a[e]||e):i;n?(c.classList.remove(...r),c.classList.add(a&&a[t]?a[t]:t)):c.setAttribute(e,t)}),d(t)}function d(e){s&&l.includes(e)&&(c.style.colorScheme=e)}function f(){return window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}if(r)u(r);else try{let e=localStorage.getItem(t)||n;u(o&&e===`system`?f():e)}catch{}},va=W.createContext(void 0),ya={setTheme:e=>{},themes:[]},ba=()=>W.useContext(va)??ya;W.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:i,defaultTheme:a,value:o,themes:s,nonce:c,scriptProps:l})=>{let u=JSON.stringify([n,t,a,e,s,o,r,i]).slice(1,-1);return W.createElement(`script`,{...l,suppressHydrationWarning:!0,nonce:typeof window>`u`?c:``,dangerouslySetInnerHTML:{__html:`(${_a.toString()})(${u})`}})});var xa=f(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),Sa=f(`arrow-up-down`,[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]),Ca=f(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),wa=f(`at-sign`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]),Ta=f(`badge-alert`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Ea=f(`book-text`,[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]),Da=f(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),Oa=f(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),ka=f(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),Aa=f(`calculator`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`line`,{x1:`8`,x2:`16`,y1:`6`,y2:`6`,key:`x4nwl0`}],[`line`,{x1:`16`,x2:`16`,y1:`14`,y2:`18`,key:`wjye3r`}],[`path`,{d:`M16 10h.01`,key:`1m94wz`}],[`path`,{d:`M12 10h.01`,key:`1nrarc`}],[`path`,{d:`M8 10h.01`,key:`19clt8`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}]]),ja=f(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),Ma=f(`chevrons-left`,[[`path`,{d:`m11 17-5-5 5-5`,key:`13zhaf`}],[`path`,{d:`m18 17-5-5 5-5`,key:`h8a8et`}]]),Na=f(`chevrons-right`,[[`path`,{d:`m6 17 5-5-5-5`,key:`xnjwq`}],[`path`,{d:`m13 17 5-5-5-5`,key:`17xmmf`}]]),Pa=f(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),Fa=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),Ia=f(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),La=f(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ra=f(`clock`,[[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),za=f(`cloud-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5.782 5.782A7 7 0 0 0 9 19h8.5a4.5 4.5 0 0 0 1.307-.193`,key:`yfwify`}],[`path`,{d:`M21.532 16.5A4.5 4.5 0 0 0 17.5 10h-1.79A7.008 7.008 0 0 0 10 5.07`,key:`jlfiyv`}]]),Ba=f(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),Va=f(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),Ha=f(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),Ua=f(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Wa=f(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ga=f(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),Ka=f(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),qa=f(`file-box`,[[`path`,{d:`M14.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`16lz6z`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M3 13.1a2 2 0 0 0-1 1.76v3.24a2 2 0 0 0 .97 1.78L6 21.7a2 2 0 0 0 2.03.01L11 19.9a2 2 0 0 0 1-1.76V14.9a2 2 0 0 0-.97-1.78L8 11.3a2 2 0 0 0-2.03-.01Z`,key:`99pj1s`}],[`path`,{d:`M7 17v5`,key:`1yj1jh`}],[`path`,{d:`M11.7 14.2 7 17l-4.7-2.8`,key:`1yk8tc`}]]),Ja=f(`file-down`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),Ya=f(`file-json`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),Xa=f(`file-pen`,[[`path`,{d:`M12.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v9.5`,key:`1couwa`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M13.378 15.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`1y4qbx`}]]),Za=f(`file-type-2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M2 13v-1h6v1`,key:`1dh9dg`}],[`path`,{d:`M5 12v6`,key:`150t9c`}],[`path`,{d:`M4 18h2`,key:`1xrofg`}]]),Qa=f(`file-type`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M9 13v-1h6v1`,key:`1bb014`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`M11 18h2`,key:`12mj7e`}]]),$a=f(`file`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}]]),eo=f(`folder-closed`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M2 10h20`,key:`1ir3d8`}]]),to=f(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),no=f(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),ro=f(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),io=f(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),ao=f(`git-compare-arrows`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`M12 18H7a2 2 0 0 1-2-2V9`,key:`16sdep`}],[`path`,{d:`m9 15 3 3-3 3`,key:`1m3kbl`}]]),oo=f(`github`,[[`path`,{d:`M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4`,key:`tonef`}],[`path`,{d:`M9 18c-4.51 2-5-2-7-2`,key:`9comsn`}]]),so=f(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),co=f(`hash`,[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]),lo=f(`heart`,[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}]]),uo=f(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),fo=f(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),po=f(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),mo=f(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),ho=f(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),go=f(`layout-panel-left`,[[`rect`,{width:`7`,height:`18`,x:`3`,y:`3`,rx:`1`,key:`2obqm`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}]]),_o=f(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),vo=f(`lightbulb`,[[`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`,key:`1gvzjb`}],[`path`,{d:`M9 18h6`,key:`x1upvd`}],[`path`,{d:`M10 22h4`,key:`ceow96`}]]),yo=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),bo=f(`list-checks`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]),xo=f(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),So=f(`lock`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]),Co=f(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),wo=f(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),To=f(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),Eo=f(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Do=f(`monitor`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]),Oo=f(`moon`,[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]),ko=f(`octagon-x`,[[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`,key:`2d38gg`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ao=f(`palette`,[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]),jo=f(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),Mo=f(`panels-top-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M9 21V9`,key:`1oto5p`}]]),No=f(`pen`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),Po=f(`replace`,[[`path`,{d:`M14 4a1 1 0 0 1 1-1`,key:`dhj8ez`}],[`path`,{d:`M15 10a1 1 0 0 1-1-1`,key:`1mnyi5`}],[`path`,{d:`M21 4a1 1 0 0 0-1-1`,key:`sfs9ap`}],[`path`,{d:`M21 9a1 1 0 0 1-1 1`,key:`mp6qeo`}],[`path`,{d:`m3 7 3 3 3-3`,key:`x25e72`}],[`path`,{d:`M6 10V5a2 2 0 0 1 2-2h2`,key:`15xut4`}],[`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1bkyp8`}]]),Fo=f(`rotate-ccw-key`,[[`path`,{d:`m14.5 9.5 1 1`,key:`159eiq`}],[`path`,{d:`m15.5 8.5-4 4`,key:`iirg3q`}],[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.74 9.74 0 0 0-6.74 2.74L3 8`,key:`g2jlw`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`circle`,{cx:`10`,cy:`14`,r:`2`,key:`1239so`}]]),Io=f(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Lo=f(`server-cog`,[[`path`,{d:`m10.852 14.772-.383.923`,key:`11vil6`}],[`path`,{d:`M13.148 14.772a3 3 0 1 0-2.296-5.544l-.383-.923`,key:`1v3clb`}],[`path`,{d:`m13.148 9.228.383-.923`,key:`t2zzyc`}],[`path`,{d:`m13.53 15.696-.382-.924a3 3 0 1 1-2.296-5.544`,key:`1bxfiv`}],[`path`,{d:`m14.772 10.852.923-.383`,key:`k9m8cz`}],[`path`,{d:`m14.772 13.148.923.383`,key:`1xvhww`}],[`path`,{d:`M4.5 10H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-.5`,key:`tn8das`}],[`path`,{d:`M4.5 14H4a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-.5`,key:`1g2pve`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M6 6h.01`,key:`1utrut`}],[`path`,{d:`m9.228 10.852-.923-.383`,key:`1wtb30`}],[`path`,{d:`m9.228 13.148-.923.383`,key:`1a830x`}]]),Ro=f(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),zo=f(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Bo=f(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Vo=f(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),Ho=f(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),Uo=f(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),Wo=f(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),Go=f(`sticky-note`,[[`path`,{d:`M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z`,key:`qazsjp`}],[`path`,{d:`M15 3v4a2 2 0 0 0 2 2h4`,key:`40519r`}]]),Ko=f(`sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),qo=f(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),Jo=f(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),Yo=f(`trash`,[[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),Xo=f(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),Zo=f(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Qo=f(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),$o=f(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),es=f(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),ts=f(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),G=s(),ns=({...e})=>{let{theme:t=`system`}=ba();return(0,G.jsx)(u,{theme:t,className:`toaster group`,richColors:!0,icons:{success:(0,G.jsx)(Rn,{className:`size-4`}),info:(0,G.jsx)(vr,{className:`size-4`}),warning:(0,G.jsx)(ei,{className:`size-4`}),error:(0,G.jsx)(ko,{className:`size-4`}),loading:(0,G.jsx)(xo,{className:`size-4 animate-spin`})},style:{"--border-radius":`var(--radius)`},toastOptions:{classNames:{toast:`cn-toast`}},...e})},rs=W.createContext({legendId:void 0,setLegendId:()=>{},disabled:void 0});function is(e=!1){let t=W.useContext(rs);if(!t&&!e)throw Error(De(86));return t}var as=W.createContext({disabled:!1});function os(){return W.useContext(as)}var ss=W.createContext(void 0);function cs(e=!0){let t=W.useContext(ss);if(t===void 0&&!e)throw Error(De(3));return t}function ls({configured:e,loginUrl:t,onLogin:n}){let[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let e=new URL(window.location.href);i(e.searchParams.get(`sso_link`)===`required`);let t=e.searchParams.get(`error`);t&&(l.error(t),e.searchParams.delete(`error`),window.history.replaceState({},document.title,`${e.pathname}${e.search}`))},[]);let u=()=>{i(!1),o(``);let e=new URL(window.location.href);e.searchParams.delete(`sso_link`),window.history.replaceState({},document.title,`${e.pathname}${e.search}`)};return(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(Lr,{className:`w-full max-w-sm`,children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(zr,{children:r?`Link your existing Cloud account`:`Sign in to ERD Builder Pro Cloud`}),(0,G.jsx)(Kr,{children:r?`This verified SSO email already belongs to a Cloud account. Enter that account's current password to confirm ownership.`:`Your account and subscription are managed by ERDBPro SaaS.`})]}),(0,G.jsx)(Rr,{children:r?(0,G.jsx)(`form`,{onSubmit:async e=>{e.preventDefault(),c(!0);try{let e=await Si(`/api/sso/link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:a})}),t=await e.json();if(!e.ok){l.error(t.error||`Unable to link the existing Cloud account`);return}u(),n(t.user),l.success(`Existing Cloud account linked successfully`)}catch{l.error(`Unable to link the existing Cloud account`)}finally{c(!1)}},children:(0,G.jsxs)(Ar,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`sso-link-password`,children:`Current Cloud password`}),(0,G.jsx)(wi,{id:`sso-link-password`,type:`password`,autoComplete:`current-password`,required:!0,value:a,onChange:e=>o(e.target.value)}),(0,G.jsx)(Or,{children:`Your ERDBPro SaaS password is not requested here.`})]}),(0,G.jsxs)(jr,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(U,{type:`submit`,disabled:s,className:`w-full`,children:s?`Verifying account...`:`Verify and link account`}),(0,G.jsx)(U,{type:`button`,variant:`outline`,className:`w-full`,onClick:u,children:`Cancel`})]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(U,{className:`w-full`,disabled:!e,onClick:()=>window.location.assign(`${vi()}${t}`),children:[(0,G.jsx)(Co,{"data-icon":`inline-start`}),`Continue with ERDBPro SSO`]}),!e&&(0,G.jsx)(`p`,{className:`mt-3 text-center text-sm text-destructive`,children:`SSO configuration is incomplete.`})]})})]})})}function us({onLogin:e,onGuestLogin:t}){let[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(`password`),[E,D]=(0,W.useState)(!0),[O,k]=(0,W.useState)(`/api/sso/login`);(0,W.useEffect)(()=>{Si(`/api/auth-config`,{cache:`no-store`}).then(e=>e.json()).then(e=>{x(e.guest_mode!==!1),C(e.needs_setup===!0||e.needsSetup===!0),T((e.auth_mode??e.authMode)===`sso`?`sso`:`password`),D((e.sso_configured??e.ssoConfigured)!==!1),k(e.sso_login_url??e.ssoLoginUrl??`/api/sso/login`)}).catch(()=>C(!1))},[]);let A=yi(),j=Ci()===`cli`,M=(0,W.useRef)(!0),N=(0,W.useRef)(0);if((0,W.useEffect)(()=>{if(!A)return;let t=!1;return(async()=>{for(;!t&&M.current;){try{let n=await Si(`/api/me`);if(n.ok){let r=await n.json();if(r.authenticated&&!t){r.token&&xi(r.token),e(r.user);return}}else if(n.status===503){let e=await n.json().catch(()=>({}));if(e.db_error&&!t){y(e.message||`Database initialization failed. Check logs for details.`);return}}}catch{}if(N.current++,N.current>=20&&!t){y(j?`Unable to connect to the CLI backend server. Check ~/.erdbpro/logs/ for server logs.`:`Unable to connect to the desktop backend server. Check the application logs.`);return}t||await new Promise(e=>setTimeout(e,1e3))}})(),()=>{t=!0}},[j,A,e]),A)return v?(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border border-red-800 bg-red-950/40 p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(`span`,{className:`text-red-400 text-lg`,children:`⚠️`}),(0,G.jsx)(`h2`,{className:`text-red-300 font-semibold`,children:`Startup Error`})]}),(0,G.jsx)(`p`,{className:`text-red-200/80 text-sm mb-4`,children:v}),(0,G.jsxs)(`div`,{className:`text-xs text-red-300/60 space-y-1`,children:[(0,G.jsxs)(`p`,{children:[`Log file: `,(0,G.jsx)(`code`,{className:`text-red-200/80`,children:j?`~/.erdbpro/logs/server-*.err.log`:`~/Library/Logs/com.erdbuilderpro.app/server-startup.log`})]}),(0,G.jsx)(`p`,{children:j?`Try restarting the CLI. If the issue persists, inspect the latest server error log.`:`Try restarting the app. If the issue persists, ensure Node.js is installed.`})]})]})}):(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4`,children:[(0,G.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connecting...`})]})});if(S===null)return(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6`,children:(0,G.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent`})});let P=S;return w===`sso`?(0,G.jsx)(ls,{configured:E,loginUrl:O,onLogin:e}):(0,G.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center p-6 md:p-10`,children:(0,G.jsx)(`div`,{className:`w-full max-w-sm`,children:(0,G.jsx)(`div`,{className:d(`flex flex-col gap-6`),children:(0,G.jsxs)(Lr,{children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(zr,{children:P?`Create administrator account`:`Login to your account`}),(0,G.jsx)(Kr,{children:P?`Set the first administrator email and password for this Self-host installation.`:`Enter your email below to login to your account`})]}),(0,G.jsx)(Rr,{children:(0,G.jsx)(`form`,{onSubmit:async t=>{if(t.preventDefault(),P&&o!==c)l.error(`Passwords do not match`);else{_(!0);try{let t=await Si(P?`/api/setup`:`/api/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(P?{name:n,email:i,password:o,confirmPassword:c}:{email:i,password:o})});if(t.ok){let n=await t.json();n.token&&xi(n.token),e(n.user),l.success(P?`Administrator account created!`:`Welcome back!`)}else{let e=await t.json();l.error(e.error||`Login failed`)}}catch(e){console.error(`Login error:`,e);let t=e instanceof Error?e.message:`An unexpected error occurred`;l.error(t)}finally{_(!1)}}},children:(0,G.jsxs)(Ar,{children:[P&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`name`,children:`Name`}),(0,G.jsx)(wi,{id:`name`,type:`text`,placeholder:`Enter administrator name`,required:!0,value:n,onChange:e=>r(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`email`,children:`Email`}),(0,G.jsx)(wi,{id:`email`,type:`email`,placeholder:`m@example.com`,required:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(`div`,{className:`flex items-center`,children:(0,G.jsx)(Dr,{htmlFor:`password`,children:`Password`})}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`password`,type:f?`text`:`password`,placeholder:P?`Create a password`:`Enter your password`,required:!0,value:o,onChange:e=>s(e.target.value),className:`pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground transition-colors hover:text-foreground focus:outline-none cursor-pointer`,"aria-label":f?`Hide password`:`Show password`,children:f?(0,G.jsx)(kr,{className:`h-4 w-4`}):(0,G.jsx)(Ka,{className:`h-4 w-4`})})]})]}),P&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`confirm-password`,children:`Confirm Password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`confirm-password`,type:m?`text`:`password`,placeholder:`Re-enter your password`,required:!0,value:c,onChange:e=>u(e.target.value),className:`pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(!m),className:`absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground transition-colors hover:text-foreground focus:outline-none cursor-pointer`,"aria-label":m?`Hide confirm password`:`Show confirm password`,children:m?(0,G.jsx)(kr,{className:`h-4 w-4`}):(0,G.jsx)(Ka,{className:`h-4 w-4`})})]})]}),(0,G.jsxs)(jr,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(U,{type:`submit`,disabled:g,className:`w-full`,children:g?P?`Creating account...`:`Logging in...`:P?`Create administrator`:`Login`}),b&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative my-2`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`span`,{className:`w-full border-t`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,G.jsx)(`span`,{className:`bg-background px-2 text-muted-foreground`,children:`Or`})})]}),(0,G.jsx)(U,{type:`button`,variant:`outline`,className:`w-full`,onClick:()=>{t?.(),l.success(`Welcome! You're in Guest Mode.`)},children:`Try as Guest (Local Mode)`})]}),P&&(0,G.jsx)(Or,{className:`text-center`,children:`This setup is available only once for the empty database.`})]})]})})})]})})})})}var ds=(0,W.createContext)({});function fs(e){let t=(0,W.useRef)(null);return t.current===null&&(t.current=e()),t.current}var ps=(0,W.createContext)(null),ms=(0,W.createContext)({transformPagePoint:e=>e,isStatic:!1,reducedMotion:`never`}),hs=class extends W.Component{getSnapshotBeforeUpdate(e){let t=this.props.childRef.current;if(t&&e.isPresent&&!this.props.isPresent){let e=this.props.sizeRef.current;e.height=t.offsetHeight||0,e.width=t.offsetWidth||0,e.top=t.offsetTop,e.left=t.offsetLeft}return null}componentDidUpdate(){}render(){return this.props.children}};function gs({children:e,isPresent:t}){let n=(0,W.useId)(),r=(0,W.useRef)(null),i=(0,W.useRef)({width:0,height:0,top:0,left:0}),{nonce:a}=(0,W.useContext)(ms);return(0,W.useInsertionEffect)(()=>{let{width:e,height:o,top:s,left:c}=i.current;if(t||!r.current||!e||!o)return;r.current.dataset.motionPopId=n;let l=document.createElement(`style`);return a&&(l.nonce=a),document.head.appendChild(l),l.sheet&&l.sheet.insertRule(`
|
|
3
3
|
[data-motion-pop-id="${n}"] {
|
|
4
4
|
position: absolute !important;
|
|
5
5
|
width: ${e}px !important;
|
|
@@ -45,7 +45,7 @@ import{a as e,i as t,n,o as r,r as i,t as a}from"./rolldown-runtime-BCiCTKAo.js"
|
|
|
45
45
|
`))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return fae(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=d(r[i],t,n);return o(),a}function d(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=c(r[i],e,t,n);return o(),a}function f(e,t,n){let r=tS.inlineCode(e,t,n);return n.stack.includes(`tableCell`)&&(r=r.replace(/\|/g,`\\$&`)),r}}function ioe(){return{exit:{taskListCheckValueChecked:iS,taskListCheckValueUnchecked:iS,paragraph:ooe}}}function aoe(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:soe}}}function iS(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function ooe(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function soe(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=tS.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function coe(){return[px(),nae(),oae(),Zae(),ioe()]}function loe(e){return{extensions:[mx(),rae(e),sae(),roe(e),aoe()]}}function uoe(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}var aS={}.hasOwnProperty;function doe(e){let t={},n=-1;for(;++n<e.length;)foe(t,e[n]);return t}function foe(e,t){let n;for(n in t){let r=(aS.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){aS.call(r,a)||(r[a]=[]);let e=i[a];poe(r[a],Array.isArray(e)?e:e?[e]:[])}}}function poe(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);uoe(e,0,0,r)}var oS=dS(/[A-Za-z]/),sS=dS(/[\dA-Za-z]/);function moe(e){return e!==null&&(e<32||e===127)}function cS(e){return e!==null&&(e<0||e===32)}var lS=dS(/\p{P}|\p{S}/u),uS=dS(/\s/);function dS(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}var hoe={tokenize:xoe,partial:!0},fS={tokenize:Soe,partial:!0},pS={tokenize:Coe,partial:!0},mS={tokenize:woe,partial:!0},goe={tokenize:Toe,partial:!0},hS={name:`wwwAutolink`,tokenize:yoe,previous:bS},gS={name:`protocolAutolink`,tokenize:boe,previous:xS},_S={name:`emailAutolink`,tokenize:voe,previous:SS},vS={};function _oe(){return{text:vS}}for(var yS=48;yS<123;)vS[yS]=_S,yS++,yS===58?yS=65:yS===91&&(yS=97);vS[43]=_S,vS[45]=_S,vS[46]=_S,vS[95]=_S,vS[72]=[_S,gS],vS[104]=[_S,gS],vS[87]=[_S,hS],vS[119]=[_S,hS];function voe(e,t,n){let r=this,i,a;return o;function o(t){return!CS(t)||!SS.call(r,r.previous)||wS(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return CS(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check(goe,u,l)(t):t===45||t===95||sS(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&oS(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function yoe(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!bS.call(r,r.previous)||wS(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(hoe,e.attempt(fS,e.attempt(pS,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function boe(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&xS.call(r,r.previous)&&!wS(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(oS(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||moe(t)||cS(t)||uS(t)||lS(t)?n(t):e.attempt(fS,e.attempt(pS,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function xoe(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function Soe(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(mS,c,s)(t):t===null||cS(t)||uS(t)||t!==45&&lS(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function Coe(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(mS,t,a)(o):o===null||cS(o)||uS(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function woe(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||cS(o)||uS(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||cS(e)||uS(e)?t(e):r(e)}function a(e){return oS(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):oS(t)?(e.consume(t),o):n(t)}}function Toe(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return sS(e)?n(e):t(e)}}function bS(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||cS(e)}function xS(e){return!oS(e)}function SS(e){return!(e===47||CS(e))}function CS(e){return e===43||e===45||e===46||e===95||sS(e)}function wS(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}function Eoe(e){return e!==null&&e<-2}function TS(e){return e!==null&&(e<0||e===32)}function ES(e){return e===-2||e===-1||e===32}function DS(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return ES(r)?(e.enter(n),s(r)):t(r)}function s(r){return ES(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var Doe={partial:!0,tokenize:Ooe};function Ooe(e,t,n){return r;function r(t){return ES(t)?DS(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||Eoe(e)?t(e):n(e)}}function OS(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var koe={tokenize:Loe,partial:!0};function Aoe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:Poe,continuation:{tokenize:Foe},exit:Ioe}},text:{91:{name:`gfmFootnoteCall`,tokenize:Noe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:joe,resolveTo:Moe}}}}function joe(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=OS(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function Moe(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function Noe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||TS(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(OS(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return TS(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Poe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||TS(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=OS(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return TS(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),DS(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function Foe(e,t,n){return e.check(Doe,t,e.attempt(koe,t,n))}function Ioe(e){e.exit(`gfmFootnoteDefinition`)}function Loe(e,t,n){let r=this;return DS(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function kS(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function Roe(e){return e!==null&&(e<0||e===32)}var zoe=AS(/\p{P}|\p{S}/u),Boe=AS(/\s/);function AS(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function jS(e){if(e===null||Roe(e)||Boe(e))return 1;if(zoe(e))return 2}function Voe(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}function Hoe(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&kS(o,o.length,0,Voe(s,e.slice(r+1,n),t)),kS(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),kS(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=jS(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=jS(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}function MS(e){return e!==null&&e<-2}function NS(e){return e!==null&&(e<0||e===32)}function PS(e){return e===-2||e===-1||e===32}function FS(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return PS(r)?(e.enter(n),s(r)):t(r)}function s(r){return PS(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var Uoe=class{constructor(){this.map=[]}add(e,t,n){Woe(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function Woe(e,t,n,r){let i=0;if(n!==0||r.length!==0){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Goe(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function Koe(){return{flow:{null:{name:`table`,tokenize:qoe,resolveAll:Joe}}}}function qoe(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124||(o=!0,a+=1),u(e)}function u(t){return t===null?n(t):MS(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):PS(t)?FS(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||NS(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,PS(t)?FS(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return PS(t)?FS(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||MS(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return PS(t)?FS(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||MS(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||MS(n)?(e.exit(`tableRow`),t(n)):PS(n)?FS(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||NS(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Joe(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Uoe;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&(LS(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=IS(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=IS(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=IS(f,t,o,i,n,d)):(o[0]=o[1],d=IS(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&LS(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=Goe(t.events,n))}return e}function IS(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},RS(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=RS(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=RS(t.events,n[2]),a=RS(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},RS(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function LS(e,t,n,r,i){let a=[],o=RS(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function RS(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}function Yoe(e){return e!==null&&e<-2}function Xoe(e){return e!==null&&(e<0||e===32)}function zS(e){return e===-2||e===-1||e===32}function BS(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return zS(r)?(e.enter(n),s(r)):t(r)}function s(r){return zS(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var VS={name:`tasklistCheck`,tokenize:US};function HS(){return{text:{91:VS}}}function US(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Xoe(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return Yoe(r)?t(r):zS(r)?e.check({tokenize:WS},t,n)(r):n(r)}}function WS(e,t,n){return BS(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function GS(e){return doe([_oe(),Aoe(),Hoe(e),Koe(),HS()])}var KS={};function qS(e){let t=this,n=e||KS,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(GS(n)),a.push(coe()),o.push(loe(n))}var JS=`hadziqmtqn/erd-builder-pro`,YS=5;function XS(e){return(e??``).replace(/<!--[\s\S]*?-->/g,``).trim()}function ZS(e){if(!e)return 1;let t=e.match(/page=(\d+)>;\s*rel="last"/);return t?parseInt(t[1],10):1}function QS(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(!0),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(null),[u,f]=(0,W.useState)(1),[p,m]=(0,W.useState)(1),h=(0,W.useRef)(null),g=async e=>{e===1?r(!0):a(!0);try{let n=await fetch(`https://api.github.com/repos/${JS}/releases?per_page=${YS}&page=${e}`);if(!n.ok)throw Error(`Failed to fetch releases`);let r=await n.json();t(r.map(e=>({...e,body:XS(e.body)}))),m(ZS(n.headers.get(`Link`)))}catch(e){s(e instanceof Error?e.message:`Unknown error`)}finally{r(!1),a(!1)}};(0,W.useEffect)(()=>{g(1)},[]),(0,W.useEffect)(()=>{g(u),h.current?.scrollTo({top:0,behavior:`smooth`})},[u]);let _=u===1?e.findIndex(e=>!e.prerelease):-1;return n&&e.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center space-y-4`,children:[(0,G.jsx)(xo,{className:`w-8 h-8 text-primary animate-spin`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground animate-pulse`,children:`Fetching latest updates...`})]}):o?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center space-y-4 p-8 text-center`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-destructive/10 flex items-center justify-center`,children:(0,G.jsx)(Kn,{className:`w-6 h-6 text-destructive`})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-bold text-lg`,children:`Gagal memuat Changelog`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-xs`,children:o})]}),(0,G.jsx)(U,{onClick:()=>window.location.reload(),variant:`outline`,children:`Coba Lagi`})]}):(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col h-full overflow-hidden bg-background`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-6 border-b bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`h2`,{className:`text-2xl font-bold tracking-tight flex items-center gap-2`,children:[(0,G.jsx)(uo,{className:`w-6 h-6 text-primary`}),`What's New`]}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Lacak pembaruan dan perubahan terbaru pada ERD Builder Pro.`})]}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,render:(0,G.jsx)(`a`,{href:`https://github.com/${JS}/releases`,target:`_blank`,rel:`noreferrer`}),children:[(0,G.jsx)(Ga,{className:`w-4 h-4 mr-2`}),`GitHub Releases`]})]}),(0,G.jsx)(`div`,{ref:h,className:`flex-1 overflow-y-auto px-6 py-8`,children:(0,G.jsxs)(`div`,{className:`max-w-3xl mx-auto relative pl-8 space-y-12`,children:[(0,G.jsx)(`div`,{className:`absolute left-[15px] top-2 bottom-0 w-px bg-border`}),(0,G.jsx)(ws,{mode:`popLayout`,children:e.map((e,t)=>(0,G.jsxs)(ph.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:t*.1},className:`relative`,children:[(0,G.jsx)(`div`,{className:d(`absolute -left-[32px] top-1.5 size-8 rounded-full border-4 border-background flex items-center justify-center transition-colors`,t===_&&_!==-1?`bg-primary shadow-[0_0_15px_rgba(var(--primary),0.5)]`:e.prerelease?`bg-amber-500/20 border-amber-500/30`:`bg-muted`),children:t===_&&_!==-1?(0,G.jsx)(Qr,{className:`w-4 h-4 text-primary-foreground`}):e.prerelease?(0,G.jsx)(qo,{className:`w-3 h-3 text-amber-400`}):(0,G.jsx)(qo,{className:`w-3 h-3 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(Vh,{variant:e.prerelease?`secondary`:`default`,className:`font-mono text-xs px-2 pointer-events-none`,children:[`v`,e.tag_name.replace(`v`,``)]}),e.prerelease&&(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] uppercase tracking-tighter bg-amber-500/10 text-amber-400 border-amber-500/30`,children:`Pre-release`}),(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[(0,G.jsx)(tr,{className:`w-3 h-3`}),er(new Date(e.published_at),`MMMM d, yyyy`)]}),t===_&&_!==-1&&(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] uppercase tracking-tighter bg-primary/5 text-primary border-primary/20`,children:`Latest`})]}),(0,G.jsx)(Lr,{className:d(`group transition-all duration-300 hover:border-primary/50 cursor-pointer overflow-hidden backdrop-blur-sm`,t===_&&_!==-1?`bg-primary/5 border-primary/20 shadow-lg shadow-primary/5`:e.prerelease?`bg-card/30 border-amber-500/10`:`bg-card/50`),onClick:()=>l(e),children:(0,G.jsxs)(Br,{className:`p-4 flex flex-row items-center justify-between space-y-0`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(zr,{className:`text-base font-bold group-hover:text-primary transition-colors`,children:e.name||`Release ${e.tag_name}`}),(0,G.jsx)(Kr,{className:`line-clamp-2 text-sm leading-relaxed`,children:e.body.split(`
|
|
46
46
|
`)[0].replace(/#+\s*/,``)||`Lihat detail pembaruan...`})]}),(0,G.jsx)(St,{className:`w-5 h-5 text-muted-foreground group-hover:text-primary group-hover:translate-x-1 transition-all`})]})})]})]},e.id))}),i&&(0,G.jsx)(`div`,{className:`flex justify-center pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsx)(xo,{className:`w-3.5 h-3.5 animate-spin`}),`Loading page...`]})}),p>1&&!i&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-8 pb-4`,children:[(0,G.jsx)(U,{variant:`ghost`,size:`sm`,disabled:u===1,onClick:()=>f(1),className:`size-9 p-0`,children:(0,G.jsx)(Ma,{className:`w-4 h-4`})}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,disabled:u===1,onClick:()=>f(e=>e-1),className:`size-9 p-0`,children:(0,G.jsx)(lr,{className:`w-4 h-4`})}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 px-2`,children:(()=>{let e=[];for(let t=1;t<=p;t++)t===1||t===p||t>=u-1&&t<=u+1?e.push(t):e[e.length-1]!==`ellipsis`&&e.push(`ellipsis`);return e.map((e,t)=>e===`ellipsis`?(0,G.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`},`e-${t}`):(0,G.jsx)(U,{variant:e===u?`default`:`ghost`,size:`sm`,onClick:()=>f(e),className:`min-w-9 h-9 p-0 text-xs font-mono`,children:e},e))})()}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,disabled:u===p,onClick:()=>f(e=>e+1),className:`size-9 p-0`,children:(0,G.jsx)(St,{className:`w-4 h-4`})}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,disabled:u===p,onClick:()=>f(p),className:`size-9 p-0`,children:(0,G.jsx)(Na,{className:`w-4 h-4`})})]}),p>1&&!i&&(0,G.jsxs)(`p`,{className:`text-center text-[11px] text-muted-foreground/60 pb-2`,children:[`Page `,u,` of `,p]})]})}),(0,G.jsx)(Yr,{open:!!c,onOpenChange:e=>!e&&l(null),children:(0,G.jsx)(Vr,{className:`sm:max-w-2xl`,children:c&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Jr,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,G.jsxs)(Vh,{className:`font-mono text-xs`,children:[`v`,c.tag_name.replace(`v`,``)]}),c.prerelease?(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] uppercase tracking-tighter bg-amber-500/10 text-amber-700 border-amber-500/30 dark:text-amber-400`,children:`Pre-release`}):(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] uppercase tracking-tighter bg-emerald-500/10 text-emerald-700 border-emerald-500/30 dark:text-emerald-400`,children:`Stable`}),(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[(0,G.jsx)(tr,{className:`w-3 h-3`}),er(new Date(c.published_at),`MMMM d, yyyy`)]})]}),(0,G.jsx)(Hr,{className:`text-2xl`,children:c.name||`Release ${c.tag_name}`})]}),(0,G.jsx)(Wr,{className:`bg-muted/50`,children:(0,G.jsx)(`div`,{className:`prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-pre:border-border dark:prose-pre:bg-black/50`,children:(0,G.jsx)(Zb,{remarkPlugins:[qS],children:c.body})})}),(0,G.jsx)(Gr,{children:(0,G.jsxs)(U,{variant:`secondary`,size:`sm`,render:(0,G.jsx)(`a`,{href:c.html_url,target:`_blank`,rel:`noreferrer`}),children:[(0,G.jsx)(Ga,{className:`w-4 h-4 mr-2`}),`View on GitHub`]})})]})})})]})}function $S(e){let t=e?.data;if(!t)return{projects:0,notes:0,diagrams:0,entities:0,columns:0,relationships:0,flowcharts:0,drawings:0,ai_chat_sessions:0,ai_chat_messages:0,skipped_existing:0};let n=0,r=0,i=0;for(let e of t.diagrams||[]){n+=(e.entities||[]).length;for(let t of e.entities||[])r+=(t.columns||[]).length;i+=(e.relationships||[]).length}let a=0;for(let e of t.ai_chat_sessions||[])a+=(e.messages||[]).length;return{projects:(t.projects||[]).length,notes:(t.notes||[]).length,diagrams:(t.diagrams||[]).length,entities:n,columns:r,relationships:i,flowcharts:(t.flowcharts||[]).length,drawings:(t.drawings||[]).length,ai_chat_sessions:(t.ai_chat_sessions||[]).length,ai_chat_messages:a,skipped_existing:0}}function eC(e){let t=e?.data;if(!t)return 1;let n=0;n+=(t.projects||[]).length,n+=(t.notes||[]).length;for(let e of t.diagrams||[]){n+=1;let t=e.entities||[];n+=t.length;for(let e of t)n+=(e.columns||[]).length;n+=(e.relationships||[]).length}n+=(t.flowcharts||[]).length,n+=(t.drawings||[]).length;for(let e of t.ai_chat_sessions||[])n+=1,n+=(e.messages||[]).length;return Math.max(n,1)}function tC(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function nC(){return sessionStorage.getItem(`auth_mode`)===`guest`?`guest`:typeof window<`u`&&(window.__TAURI__||window.__TAURI_INTERNALS__)?`desktop`:`web`}function rC(){let e=(0,W.useRef)(null),t=(0,W.useRef)(null),n=(0,W.useRef)(null),r=(0,W.useRef)(null),i=(0,W.useRef)(null),[a,o]=(0,W.useState)(`idle`),[s,c]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(``),[v,y]=(0,W.useState)({current:0,total:1,phase:``}),b=nC();(0,W.useEffect)(()=>(a===`done`&&(t.current=setTimeout(()=>{window.location.reload()},2500)),()=>{t.current&&=(clearTimeout(t.current),null)}),[a]);let x=(0,W.useCallback)(async t=>{let n=t.target.files?.[0];if(!n)return;let a=n.name.split(`.`).pop()?.toLowerCase();if(a===`db`||a===`sqlite`||a===`sqlite3`){if(nC()!==`desktop`){l.error(`Database file restore is only available in the Desktop app.`),e.current&&(e.current.value=``);return}c(`db`),p({fileName:n.name,fileSize:tC(n.size)}),d(null),_(``),o(`preview`),i.current=n,e.current&&(e.current.value=``)}else if(a===`json`){let t;try{t=JSON.parse(await n.text())}catch{l.error(`Invalid JSON file. Please select a valid export file.`),e.current&&(e.current.value=``);return}if(!t.data||typeof t.data!=`object`){l.error(`Invalid export format. Missing "data" field.`),e.current&&(e.current.value=``);return}let i=$S(t);if(Object.values(i).reduce((e,t)=>e+(t||0),0)<=1){l.info(`The export file contains no data to import.`),e.current&&(e.current.value=``);return}r.current=t,c(`json`),d(i),p(null),_(``),o(`preview`),e.current&&(e.current.value=``)}else l.error(`Unsupported file type ".${a}". Please select a .json, .db, or .sqlite file.`),e.current&&(e.current.value=``)},[]),S=(0,W.useCallback)(async()=>{let e=r.current;if(!e)return;let t=eC(e);o(`importing`),_(``),y({current:0,total:t,phase:`Preparing import…`});try{let r=new AbortController;n.current=r;let i=await Si(`/api/guest/import`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:r.signal});if(!i.ok){let e=`Server returned ${i.status}`;try{e=(await i.json()).error||e}catch{}throw Error(e)}let a=i.body?.getReader();if(!a)throw Error(`Browser does not support streaming responses.`);let s=new TextDecoder,c=``;for(;;){let{done:e,value:r}=await a.read();if(e)break;c+=s.decode(r,{stream:!0});let i=c.split(`
|
|
47
47
|
`);c=i.pop()||``;for(let e of i)if(e.trim())try{let r=JSON.parse(e);if(r.type===`progress`)y({current:Number(r.current)||0,total:Number(r.total)||t,phase:String(r.phase||``)});else if(r.type===`complete`){h(r.summary),o(`done`),l.success(r.message||`Import completed successfully!`),n.current=null;return}else if(r.type===`error`)throw Error(r.error||`Import failed on server.`)}catch(e){if(e instanceof SyntaxError)continue;throw e}}throw Error(`Stream ended unexpectedly. Import may be incomplete.`)}catch(e){if(e.name===`AbortError`)return;o(`error`),_(e.message||`Import failed`),l.error(`Import failed: `+(e.message||`Unknown error`))}n.current=null},[b]),C=(0,W.useCallback)(async()=>{let e=i.current;if(e){o(`importing`),_(``),y({current:0,total:5,phase:`Uploading database file…`});try{let t=new AbortController;n.current=t;let r=new FormData;r.append(`database`,e);let i=await Si(`/api/desktop/restore/database`,{method:`POST`,body:r,signal:t.signal});if(!i.ok){let e=`Server returned ${i.status}`;try{e=(await i.json()).error||e}catch{}throw Error(e)}let a=i.body?.getReader();if(!a)throw Error(`Browser does not support streaming responses.`);let s=new TextDecoder,c=``;for(;;){let{done:e,value:t}=await a.read();if(e)break;c+=s.decode(t,{stream:!0});let r=c.split(`
|
|
48
|
-
`);c=r.pop()||``;for(let e of r)if(e.trim())try{let t=JSON.parse(e);if(t.type===`progress`)y({current:Number(t.current)||0,total:Number(t.total)||5,phase:String(t.phase||``)});else if(t.type===`complete`){await ca.clearAllPendingSyncs(),o(`done`),l.success(t.message||`Database restored successfully!`),n.current=null;return}else if(t.type===`error`)throw Error(t.error||`Restore failed on server.`)}catch(e){if(e instanceof SyntaxError)continue;throw e}}throw Error(`Stream ended unexpectedly. Restore may be incomplete.`)}catch(e){if(e.name===`AbortError`)return;o(`error`),_(e.message||`Restore failed`),l.error(`Restore failed: `+(e.message||`Unknown error`))}n.current=null}},[]),w=(0,W.useCallback)(()=>{t.current&&=(clearTimeout(t.current),null),r.current=null,i.current=null,o(`idle`),c(null),h(null),d(null),p(null),_(``),y({current:0,total:1,phase:``})},[]),T=(0,W.useCallback)(()=>{r.current=null,i.current=null,d(null),p(null),o(`idle`),c(null)},[]),E=(0,W.useCallback)(()=>{t.current&&=(clearTimeout(t.current),null),window.location.reload()},[]),D=(0,W.useCallback)(()=>{n.current&&=(n.current.abort(),null),r.current=null,i.current=null,o(`idle`),c(null),y({current:0,total:1,phase:``})},[]),O=(0,W.useCallback)(()=>{s===`db`?C():S()},[s,C,S]),k=Math.min(Math.round(v.current/v.total*100),100),{accept:A,acceptLabel:j}=b===`desktop`?{accept:`.json,.db,.sqlite,.sqlite3`,acceptLabel:`.json (data) or .db / .sqlite (database restore)`}:{accept:`.json`,acceptLabel:`.json format from Guest Mode export`};if(a===`done`)return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-emerald-500/10 border border-emerald-500/20 rounded-xl`,children:[(0,G.jsx)(yr,{className:`size-6 text-emerald-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:s===`db`?`Database Restored`:`Import Completed`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:s===`db`?`The database file has been restored. The app will reload to apply the changes.`:`Data has been added to your workspace.`})]})]}),m&&(0,G.jsx)(iC,{summary:m}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:E,children:[(0,G.jsx)(cr,{className:`size-3.5 mr-1.5`}),`Reload App Now`]}),(0,G.jsx)(U,{variant:`outline`,size:`sm`,onClick:w,children:`Import Another File`})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`App will reload automatically in a few seconds…`})]});if(a===`preview`){if(s===`db`&&f)return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Za,{className:`size-5 text-blue-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:`Restore Database File`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`This will `,(0,G.jsx)(`strong`,{className:`text-amber-500`,children:`replace`}),` your current local database with the selected file. A safety backup will be created automatically before the restore.`]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[`Use this if you reinstalled the app and want to restore from a previous`,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px] mx-0.5`,children:`.db`}),` file that you saved manually.`]})]})]}),(0,G.jsxs)(`div`,{className:`bg-muted/20 border border-border/40 rounded-lg p-4 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`File`}),(0,G.jsx)(`span`,{className:`font-medium`,children:f.fileName})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Size`}),(0,G.jsx)(`span`,{className:`font-medium`,children:f.fileSize})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:O,children:[(0,G.jsx)(Hn,{className:`size-3.5 mr-1.5`}),`Restore Database`]}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:T,children:[(0,G.jsx)(Pr,{className:`size-3.5 mr-1.5`}),`Cancel`]})]})]});if(s===`json`&&u){let e=Object.values(u).reduce((e,t)=>e+(t||0),0);return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Ya,{className:`size-5 text-blue-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:`Import Preview`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e,` items found in the export file. Click `,(0,G.jsx)(`strong`,{children:`Submit`}),` to import the data.`]})]})]}),(0,G.jsx)(iC,{summary:u}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:O,children:[(0,G.jsx)(Hn,{className:`size-3.5 mr-1.5`}),`Submit`]}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:T,children:[(0,G.jsx)(Pr,{className:`size-3.5 mr-1.5`}),`Cancel`]})]})]})}}return a===`error`?(0,G.jsx)(`div`,{className:`space-y-5`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-3 bg-red-500/10 border border-red-500/20 rounded-lg`,children:[(0,G.jsx)(Kn,{className:`size-4 text-red-500 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-red-600`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:s===`db`?`Database restore failed`:`Import failed`}),(0,G.jsx)(`p`,{className:`mt-0.5`,children:g}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,className:`mt-2 h-auto py-1 text-xs`,onClick:w,children:`Try again`})]})]})}):(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Mr,{className:`size-5 text-blue-500 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm space-y-1`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`Import Data`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Upload a `,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px]`,children:`.json`}),` file exported from Guest Mode. All data will be `,(0,G.jsx)(`strong`,{children:`added`}),` to your workspace — existing items with the same ID will be skipped. New projects will be created for any project‑scoped items.`]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Supports: Notes, ERD Diagrams (entities, columns, relationships), Flowcharts, Drawings, AI Chat sessions & messages, and Projects.`}),b===`desktop`&&(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-2 pt-2 border-t border-border/40`,children:[(0,G.jsx)(`strong`,{className:`text-amber-500`,children:`Desktop only:`}),` You can also restore a`,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px] mx-0.5`,children:`.db`}),` database file — useful after reinstalling the app to recover data from a manually saved copy. A safety backup is created automatically.`]})]})]}),(0,G.jsxs)(`div`,{onClick:()=>{a!==`importing`&&e.current?.click()},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&a!==`importing`&&e.current?.click()},role:`button`,tabIndex:0,className:`border-2 border-dashed border-border/50 hover:border-primary/40 rounded-xl p-8 text-center cursor-pointer transition-colors`,children:[(0,G.jsx)(`input`,{ref:e,type:`file`,accept:A,className:`hidden`,onChange:x}),a===`importing`?(0,G.jsxs)(`div`,{className:`w-full max-w-sm mx-auto space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground truncate mr-2`,children:v.phase||`Importing…`}),(0,G.jsxs)(`span`,{className:`text-muted-foreground shrink-0 tabular-nums`,children:[k,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full h-2 bg-muted/50 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full bg-primary rounded-full transition-all duration-300 ease-out`,style:{width:`${k}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground tabular-nums`,children:[v.current.toLocaleString(),` / `,v.total.toLocaleString(),` items`]})]}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,onClick:e=>{e.stopPropagation(),D()},className:`text-xs`,children:`Cancel`})]}):(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-muted/30 rounded-full`,children:(0,G.jsx)(Yn,{className:`size-6 text-muted-foreground`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`Click to select a file`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:j})]})]})]})]})}function iC({summary:e}){return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-3`,children:[(0,G.jsx)(aC,{label:`Projects`,value:e.projects}),(0,G.jsx)(aC,{label:`Notes`,value:e.notes}),(0,G.jsx)(aC,{label:`ERD Diagrams`,value:e.diagrams}),(0,G.jsx)(aC,{label:`Tables (Entities)`,value:e.entities}),(0,G.jsx)(aC,{label:`Columns`,value:e.columns}),(0,G.jsx)(aC,{label:`Relationships`,value:e.relationships}),(0,G.jsx)(aC,{label:`Flowcharts`,value:e.flowcharts}),(0,G.jsx)(aC,{label:`Drawings`,value:e.drawings}),(0,G.jsx)(aC,{label:`AI Sessions`,value:e.ai_chat_sessions})]}),e.ai_chat_messages>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground px-0.5`,children:[`Includes `,e.ai_chat_messages.toLocaleString(),` AI chat messages.`]}),e.skipped_existing>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-amber-500 px-0.5`,children:[e.skipped_existing.toLocaleString(),` item(s) already existed and were skipped.`]})]})}function aC({label:e,value:t}){return(0,G.jsxs)(`div`,{className:`bg-muted/20 border border-border/40 rounded-lg p-3 text-center`,children:[(0,G.jsx)(`p`,{className:`text-lg font-bold`,children:t.toLocaleString()}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:e})]})}function oC(){return sessionStorage.getItem(`auth_mode`)===`guest`}function sC(e){if(!e||typeof e!=`string`)return null;try{let t=JSON.parse(e);return t?.dbml_source??t?.dbmlSource??null}catch{return null}}function cC(e){let t=e.dbml_source??e.dbmlSource??sC(e.data);return{...e,dbml_source:t??null,dbmlSource:t??null}}async function lC(e){try{return(await ca.getAllResources(e)||[]).filter(e=>!e.is_deleted)}catch{return[]}}function uC(e){return!e.messages||!Array.isArray(e.messages)?[]:e.messages.map(e=>({id:e.id||e.uid,role:e.role,content:e.content,selection_text:e.selection_text||null,created_at:e.created_at||null}))}async function dC(){if(!oC()){let e=await Si(`/api/guest/export`);if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Failed to export data`)}return e.json()}let[e,t,n,r,i,a]=await Promise.all([lC(`project`),lC(`notes`),lC(`erd`),lC(`flowchart`),lC(`drawings`),lC(`ai_chat_session`)]),o=a.map(e=>({uid:e.uid||e.id,title:e.title||`Untitled`,entity_type:e.entity_type||null,entity_uid:e.entity_uid||null,project_id:e.project_id??null,created_at:e.created_at||null,updated_at:e.updated_at||null,messages:uC(e)})),s={projects:e.length,notes:t.length,diagrams:n.length,flowcharts:r.length,drawings:i.length,ai_chat_sessions:o.length};return{version:`1.0`,exported_at:new Date().toISOString(),application:`ERD Builder Pro`,total_items:s,data:{projects:e,notes:t,diagrams:n.map(cC),flowcharts:r,drawings:i,ai_chat_sessions:o}}}function fC(e){let t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`erd-data-export-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}async function pC(){fC(await dC())}function mC(){let[e,t]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Export Data`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Download projects, notes, ERDs, DBML, flowcharts, drawings, and AI chats as JSON.`})]}),(0,G.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-muted/10 p-5 max-w-xl`,children:(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold`,children:`JSON Backup`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Use this file with Import Data to restore or migrate your workspace data.`})]}),(0,G.jsxs)(U,{onClick:async()=>{t(!0);try{await pC(),l.success(`Data exported successfully`)}catch(e){l.error(`Export failed: `+(e.message||`Unknown error`))}finally{t(!1)}},disabled:e,className:`shrink-0`,children:[e?(0,G.jsx)(xo,{className:`size-3.5 mr-2 animate-spin`}):(0,G.jsx)(rn,{className:`size-3.5 mr-2`}),e?`Exporting...`:`Export JSON`]})]})})]})}function hC(){if(typeof window>`u`||!window.__TAURI__&&!window.__TAURI_INTERNALS__&&window.ERD_INSTALL_MODE!==`cli`)return(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(Lr,{className:`border-border/50 bg-background/50 backdrop-blur-sm`,children:(0,G.jsxs)(Rr,{className:`py-12 text-center`,children:[(0,G.jsx)(Mr,{className:`w-8 h-8 mx-auto text-muted-foreground/40`}),(0,G.jsx)(`p`,{className:`text-muted-foreground mt-4 text-sm`,children:`Storage configuration is only available in the desktop app or CLI mode.`})]})})});let[e,t]=(0,W.useState)({type:`r2`,accountId:``,endpoint:``,region:`auto`,accessKeyId:``,secretAccessKey:``,bucketName:``,publicUrl:``}),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(`none`),[o,s]=(0,W.useState)(!0),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)({type:``,message:``}),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(!1),v=(0,W.useCallback)(async()=>{s(!0);try{let e=await Si(`/api/storage/config`,{credentials:`include`});if(e.ok){let n=await e.json();a(n.source),n.config&&(r(n.config),t({type:n.config.type||`r2`,accountId:n.config.accountId||``,endpoint:n.config.endpoint||``,region:n.config.region||`auto`,accessKeyId:n.config.accessKeyId||``,secretAccessKey:n.config.secretAccessKey||``,bucketName:n.config.bucketName||``,publicUrl:n.config.publicUrl||``}))}}catch(e){console.error(`Failed to load storage config:`,e)}finally{s(!1)}},[]);(0,W.useEffect)(()=>{v()},[v]);let y=async()=>{l(!0),p({type:``,message:``});try{let t=await Si(`/api/storage/config`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),credentials:`include`});if(t.ok)p({type:`success`,message:`Storage configuration saved successfully.`}),r({...e}),await v();else{let e=await t.json();p({type:`error`,message:e.error||`Failed to save configuration`})}}catch(e){p({type:`error`,message:e.message||`Network error`})}finally{l(!1)}},b=async()=>{d(!0),p({type:``,message:``});try{let t=await Si(`/api/storage/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),credentials:`include`});if(t.ok)p({type:`success`,message:`Successfully connected to storage.`});else{let e=await t.json();p({type:`error`,message:e.error||`Connection failed`})}}catch(e){p({type:`error`,message:e.message||`Network error`})}finally{d(!1)}},x=(e,n)=>{t(t=>({...t,[e]:n})),p({type:``,message:``})};return o?(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(Lr,{className:`border-border/50 bg-background/50 backdrop-blur-sm`,children:(0,G.jsxs)(Rr,{className:`py-12 text-center`,children:[(0,G.jsx)(cr,{className:`w-6 h-6 animate-spin mx-auto text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-muted-foreground mt-4 text-sm`,children:`Loading storage configuration...`})]})})}):(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsxs)(Lr,{className:`border border-border/50 bg-background/50 backdrop-blur-sm shadow-lg`,children:[(0,G.jsxs)(Br,{className:`border-b border-border/30 pb-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Ba,{className:`w-6 h-6 text-blue-500`}),(0,G.jsx)(zr,{className:`text-xl md:text-2xl font-bold`,children:`Storage Configuration`})]}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Configure Cloudflare R2 or S3-compatible storage for image uploads in Notes and Drawings.`})]}),(0,G.jsxs)(Rr,{className:`space-y-6 p-4 md:p-6`,children:[i===`env`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-blue-500/10 border border-blue-500/20`,children:[(0,G.jsx)(vr,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,G.jsx)(`p`,{className:`text-xs text-blue-600 dark:text-blue-400`,children:`Pre-filled from environment variables. Save to override with custom settings.`})]}),f.type&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 rounded-lg border ${f.type===`success`?`bg-green-500/10 border-green-500/20 text-green-600 dark:text-green-400`:`bg-red-500/10 border-red-500/20 text-red-600 dark:text-red-400`}`,children:[f.type===`success`?(0,G.jsx)(Rn,{className:`w-5 h-5 shrink-0`}):(0,G.jsx)(La,{className:`w-5 h-5 shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm`,children:f.message})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(Mr,{className:`size-3`}),`Storage Provider`]}),(0,G.jsxs)(_r,{value:e.type,onValueChange:(e,t)=>e&&x(`type`,e),children:[(0,G.jsx)(mr,{className:`h-9 text-sm`,children:(0,G.jsx)(gr,{children:e.type===`r2`?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ba,{className:`w-4 h-4`}),`Cloudflare R2`]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mr,{className:`w-4 h-4`}),`S3-Compatible`]})})}),(0,G.jsxs)(pr,{children:[(0,G.jsx)(fr,{value:`r2`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ba,{className:`w-4 h-4`}),`Cloudflare R2`]})}),(0,G.jsx)(fr,{value:`s3-compatible`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mr,{className:`w-4 h-4`}),`S3-Compatible`]})})]})]})]}),e.type===`r2`&&(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Account ID`]}),(0,G.jsx)(wi,{placeholder:`Your Cloudflare R2 Account ID`,value:e.accountId||``,onChange:e=>x(`accountId`,e.target.value),className:`h-9 text-sm font-mono`}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-1 px-1`,children:`Found in your Cloudflare dashboard under R2 → Account ID.`})]}),e.type===`s3-compatible`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Endpoint URL`]}),(0,G.jsx)(wi,{placeholder:`https://s3.us-east-1.amazonaws.com`,value:e.endpoint||``,onChange:e=>x(`endpoint`,e.target.value),className:`h-9 text-sm font-mono`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Region`]}),(0,G.jsx)(wi,{placeholder:`us-east-1`,value:e.region||``,onChange:e=>x(`region`,e.target.value),className:`h-9 text-sm font-mono`})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(po,{className:`size-3`}),`Access Key ID`]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{type:g?`text`:`password`,placeholder:`Your access key ID`,value:e.accessKeyId,onChange:e=>x(`accessKeyId`,e.target.value),className:`h-9 text-sm font-mono pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors`,children:g?(0,G.jsx)(kr,{className:`w-4 h-4`}):(0,G.jsx)(Ka,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(po,{className:`size-3`}),`Secret Access Key`]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{type:m?`text`:`password`,placeholder:`Your secret access key`,value:e.secretAccessKey,onChange:e=>x(`secretAccessKey`,e.target.value),className:`h-9 text-sm font-mono pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(!m),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors`,children:m?(0,G.jsx)(kr,{className:`w-4 h-4`}):(0,G.jsx)(Ka,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(no,{className:`size-3`}),`Bucket Name`]}),(0,G.jsx)(wi,{placeholder:`your-bucket-name`,value:e.bucketName,onChange:e=>x(`bucketName`,e.target.value),className:`h-9 text-sm font-mono`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(yo,{className:`size-3`}),`Public URL (optional)`]}),(0,G.jsx)(wi,{placeholder:`https://cdn.yourdomain.com`,value:e.publicUrl||``,onChange:e=>x(`publicUrl`,e.target.value),className:`h-9 text-sm font-mono`}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-1 px-1`,children:e.type===`s3-compatible`?`Optional. If set, overrides the auto-constructed endpoint URL. Useful for custom CDN/domain. If empty, URL is built from Endpoint + Bucket.`:`Optional public URL prefix for direct image access (e.g., custom domain or CDN). If empty, R2 public URL is auto-constructed.`})]})]}),(0,G.jsxs)(Ur,{className:`bg-muted/5 border-t border-border/30 p-4 md:px-6 md:py-4 flex flex-col sm:flex-row gap-3 sm:justify-end`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:b,disabled:u||!e.bucketName||!e.accessKeyId||!e.secretAccessKey,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border text-sm font-medium whitespace-nowrap transition-colors h-10 px-4 bg-background hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50 cursor-pointer select-none`,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 shrink-0 animate-spin pointer-events-none`}),(0,G.jsx)(`span`,{className:`pointer-events-none`,children:`Testing...`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 shrink-0 pointer-events-none`}),(0,G.jsx)(`span`,{className:`pointer-events-none`,children:`Test Connection`})]})}),(0,G.jsxs)(U,{onClick:y,className:`gap-2 px-6`,disabled:c,children:[c?(0,G.jsx)(cr,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xn,{className:`w-4 h-4`}),c?`Saving...`:`Save Configuration`]})]})]})})}var gC=[{title:`General`,rows:[[`Sync pending changes`,`⌘S`,`Ctrl+S`],[`Focus file search`,`⌘K`,`Ctrl+K`],[`Open or close AI Assistant`,`⌘J`,`Ctrl+J`],[`Open Settings (desktop)`,`⌘,`,`Ctrl+,`]]},{title:`Notes`,rows:[[`Bold`,`⌘B`,`Ctrl+B`],[`Italic`,`⌘I`,`Ctrl+I`],[`Underline`,`⌘U`,`Ctrl+U`],[`Strikethrough`,`⇧⌘S`,`Ctrl+Shift+S`],[`Inline code`,`⌘E`,`Ctrl+E`],[`Heading 1–4`,`⌥⌘1–4`,`Ctrl+Alt+1–4`],[`Bulleted list`,`⇧⌘8`,`Ctrl+Shift+8`],[`Numbered list`,`⇧⌘7`,`Ctrl+Shift+7`],[`Task list`,`⇧⌘9`,`Ctrl+Shift+9`],[`Blockquote`,`⇧⌘B`,`Ctrl+Shift+B`],[`Code block`,`⌥⌘C`,`Ctrl+Alt+C`],[`Insert table`,`⌥⌘T`,`Ctrl+Alt+T`],[`Toggle badge`,`⌥⌘B`,`Ctrl+Alt+B`],[`Align left / center / right`,`⇧⌘L / C / R`,`Ctrl+Shift+L / C / R`],[`Undo / redo`,`⌘Z / ⌘Y`,`Ctrl+Z / Ctrl+Y`],[`Export note`,`⇧⌘E`,`Ctrl+Shift+E`],[`Import note`,`⇧⌘I`,`Ctrl+Shift+I`]]},{title:`ERD Builder`,rows:[[`Open Explorer (tables and relationships)`,`⇧⌘F`,`Ctrl+Shift+F`],[`Close the table editor`,`Esc`,`Esc`],[`Undo / redo`,`⌘Z / ⇧⌘Z`,`Ctrl+Z / Ctrl+Y`],[`Add or remove from selection`,`⌘-click`,`Ctrl+click`]]},{title:`Flowchart`,rows:[[`Undo / redo`,`⌘Z / ⇧⌘Z`,`Ctrl+Z / Ctrl+Shift+Z`],[`Delete selected node or edge`,`Delete / Backspace`,`Delete / Backspace`]]}],_C=[[`Focus table search`,`⌘P`,`Ctrl+P`],[`Toggle filters`,`⌘F`,`Ctrl+F`],[`Refresh records`,`⌘R`,`Ctrl+R`],[`Select all records`,`⌘A`,`Ctrl+A`],[`Add or remove a record from selection`,`⌘-click`,`Ctrl+click`],[`Save record or structure`,`⌘S`,`Ctrl+S`],[`Run SQL query`,`⌘Enter`,`Ctrl+Enter`],[`Format SQL query`,`⌘I`,`Ctrl+I`],[`Cancel inline changes`,`Esc`,`Esc`]];function vC(){let e=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform),t=typeof window<`u`&&(window.__TAURI__||window.__TAURI_INTERNALS__||window.ERD_INSTALL_MODE===`cli`)?[...gC,{title:`DB Client`,rows:_C}]:gC;return(0,G.jsxs)(`div`,{className:`p-4 md:p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Keymap`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Keyboard shortcuts available in ERD Builder Pro.`})]}),t.map(({title:t,rows:n})=>(0,G.jsxs)(`section`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,G.jsx)(`h3`,{className:`border-b border-border bg-muted/40 px-4 py-2.5 text-sm font-medium`,children:t}),(0,G.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(([t,n,r])=>(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3 px-4 py-2.5 text-sm`,children:[(0,G.jsx)(`span`,{children:t}),(0,G.jsx)(Di,{className:`h-6 px-2 text-xs`,children:e?n:r})]},t))})]},t)),(0,G.jsxs)(`section`,{className:`rounded-lg border border-border p-4 text-sm`,children:[(0,G.jsx)(`h3`,{className:`font-medium`,children:`Drawings`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Drawings use Excalidraw’s built-in keymap. Open Help from its menu to view the shortcuts available for the current editor version.`})]})]})}var yC=e=>JSON.stringify(e,null,2);function bC(e,t){return/[\s"']/.test(e)?t?`"${e.replace(/"/g,`\\"`)}"`:`'${e.replace(/'/g,`'\\''`)}'`:e}function xC(e){let t={command:e.command,...e.args.length?{args:e.args}:{}},n=e.args.map(t=>bC(t,e.platform===`win32`)).join(` `),r=[`codex`,`mcp`,`add`,`erdbpro`,`--`,e.command,...e.args].map(t=>bC(t,e.platform===`win32`)).join(` `);return[{id:`jetbrains`,label:`JetBrains AI`,description:`Paste into the MCP server JSON configuration.`,language:`json`,content:yC({mcpServers:{erdbpro:t}})},{id:`vscode`,label:`VS Code`,description:`Save as .vscode/mcp.json or paste into the MCP configuration.`,language:`json`,content:yC({servers:{erdbpro:{type:`stdio`,...t}}})},{id:`codex`,label:`Codex`,description:`Run once in a terminal to register the local MCP server.`,language:`bash`,content:r},{id:`hermes`,label:`Hermes Agent`,description:`Enter these values in Add MCP Server. Leave Environment empty.`,language:`text`,content:`Name: erdbpro\nTransport: stdio\nCommand: ${e.command}\nArgs: ${n||`(leave empty)`}\nEnvironment: (leave empty)`},{id:`generic`,label:`Generic MCP (STDIO)`,description:`Use for clients that accept a standard STDIO command definition.`,language:`json`,content:yC({transport:`stdio`,...t})}]}function SC(){let[e,t]=W.useState(null),[n,r]=W.useState(``),[i,a]=W.useState(``),[o,s]=W.useState(`jetbrains`);W.useEffect(()=>{let e=!1;return Si(`/api/mcp/client-config`).then(async n=>{let r=await n.json();if(!n.ok)throw Error(r.error||`Failed to load MCP configuration.`);e||t(r)}).catch(t=>{e||r(t instanceof Error?t.message:`Failed to load MCP configuration.`)}),()=>{e=!0}},[]);let c=async(e,t)=>{await navigator.clipboard.writeText(t),a(e),l.success(`MCP configuration copied`),window.setTimeout(()=>a(``),1500)};if(n)return(0,G.jsxs)(`div`,{className:`p-6`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`MCP Integration`}),(0,G.jsx)(`p`,{className:`mt-4 rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive`,children:n})]});if(!e)return(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,G.jsx)(xo,{className:`size-5 animate-spin text-muted-foreground`})});if(e.mode===`web`)return(0,G.jsxs)(`div`,{className:`space-y-5 p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-semibold`,children:[(0,G.jsx)(Wa,{className:`size-5`}),`Public MCP Integration`]}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Detected mode: Web App. This page automatically shows the matching MCP connection for the current installation mode.`})]}),e.configured&&e.url?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`Public MCP URL (Streamable HTTP)`}),(0,G.jsxs)(U,{variant:`ghost`,size:`xs`,onClick:()=>void c(`public-url`,e.url),children:[i===`public-url`?(0,G.jsx)(Yt,{}):(0,G.jsx)(Ua,{}),i===`public-url`?`Copied`:`Copy`]})]}),(0,G.jsx)(`code`,{className:`mt-1 block break-all text-xs`,children:e.url})]}),(0,G.jsx)(`div`,{className:`rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground`,children:`Add this URL as a custom connector in Claude Web or Claude Desktop. Authentication uses OAuth and grants user-scoped, read-only access.`})]}):(0,G.jsx)(`p`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm text-amber-700 dark:text-amber-300`,children:`Public MCP is not configured. Set MCP_PUBLIC_URL on the Web App server and restart it to publish the connection URL.`})]});let u=xC(e),d=u.find(e=>e.id===o)||u[0];return(0,G.jsxs)(`div`,{className:`space-y-5 p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-semibold`,children:[(0,G.jsx)(or,{className:`size-5`}),`Connect AI Clients`]}),(0,G.jsxs)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:[`Detected mode: `,e.mode===`cli`?`CLI`:`Desktop App`,`. Use ERD Builder Pro as a local MCP Server (STDIO) with an external AI client. The launcher runs headlessly without opening another app window.`]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-4 py-3`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`MCP Server (STDIO) launcher`}),(0,G.jsx)(`code`,{className:`mt-1 block break-all text-xs`,children:e.command})]}),(0,G.jsx)(`div`,{role:`tablist`,"aria-label":`MCP client`,className:`flex w-full flex-wrap gap-1 rounded-lg border bg-muted p-1`,children:u.map(e=>{let t=e.id===d.id;return(0,G.jsx)(U,{type:`button`,size:`sm`,variant:t?`default`:`ghost`,role:`tab`,"aria-selected":t,onClick:()=>s(e.id),className:`flex-1 text-xs`,children:e.label},e.id)})}),(0,G.jsxs)(`div`,{role:`tabpanel`,"aria-label":d.label,className:`space-y-3 pt-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d.description}),(0,G.jsxs)(`div`,{className:`overflow-hidden rounded-lg border bg-muted/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground`,children:d.language}),(0,G.jsxs)(U,{variant:`ghost`,size:`xs`,onClick:()=>void c(d.id,d.content),children:[i===d.id?(0,G.jsx)(Yt,{}):(0,G.jsx)(Ua,{}),i===d.id?`Copied`:`Copy`]})]}),(0,G.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre p-4 text-xs leading-relaxed`,children:(0,G.jsx)(`code`,{children:d.content})})]})]})]})}function CC(e){return{active:e.active===!0,planCode:e.planCode??e.plan_code,expiresAt:e.expiresAt??e.expires_at,lastCheckedAt:e.lastCheckedAt??e.last_checked_at,maxTeams:e.maxTeams??e.max_teams,maxMembers:e.maxMembers??e.max_members,usage:{teamCount:e.usage?.teamCount??e.usage?.team_count??0,memberCount:e.usage?.memberCount??e.usage?.member_count??0}}}function wC(e,t){return{message:e.error||t,...e.code?{code:e.code}:{}}}async function TC(e){return e.json().catch(()=>({}))}function EC(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),[c,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),h=(0,W.useCallback)(async()=>{try{let e=await Si(`/api/license/status`),n=await TC(e);if(!e.ok){s(wC(n,`Failed to load license status.`));return}t(CC(n))}catch(e){s({message:e instanceof Error?e.message:`Failed to load license status.`})}},[]);(0,W.useEffect)(()=>{h()},[h]);let g=async()=>{s(null),f(!0);try{let e={license_key:n.trim()},o=i.trim();o&&(e.activation_grant=o);let c=await Si(`/api/license/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),u=await TC(c);if(!c.ok){s(wC(u,`License activation failed.`));return}r(``),a(``),t(CC(u)),l.success(`License activated`)}catch(e){s({message:e instanceof Error?e.message:`License activation failed.`})}finally{f(!1)}},_=async()=>{s(null),u(!0);try{let e=await Si(`/api/license/check`,{method:`POST`}),n=await TC(e);if(!e.ok){s(wC(n,`License check failed.`));return}t(CC(n)),l.success(`License checked successfully`)}catch(e){s({message:e instanceof Error?e.message:`License check failed.`})}finally{u(!1)}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-6 p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Application License`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`This instance license controls commercial Team capacity. Personal use does not require activation.`})]}),e&&(0,G.jsxs)(`div`,{className:`rounded-lg border p-4 text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:e.active?`Active: ${e.planCode}`:`No commercial license is active`}),(0,G.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Active Teams: `,e.usage.teamCount,` /`,` `,e.maxTeams??(e.active?`No limit`:`N/A`),` · Active members: `,e.usage.memberCount,` /`,` `,e.maxMembers??(e.active?`No limit`:`N/A`)]}),e.active&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(U,{variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>void _(),disabled:c||d,children:[c?(0,G.jsx)(cr,{className:`animate-spin`}):(0,G.jsx)(cr,{}),`Check license`]}),e.lastCheckedAt&&(0,G.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Last checked: `,new Date(e.lastCheckedAt).toLocaleString()]})]})]}),(0,G.jsxs)(Ar,{className:`gap-4`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`instance-license-key`,children:`Instance license key`}),(0,G.jsx)(wi,{id:`instance-license-key`,type:`password`,autoComplete:`off`,disabled:d,value:n,onChange:e=>{r(e.target.value),s(null)}})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`instance-activation-grant`,children:`Activation grant`}),(0,G.jsx)(wi,{id:`instance-activation-grant`,type:`password`,autoComplete:`off`,disabled:d,"aria-describedby":`activation-grant-description`,value:i,onChange:e=>{a(e.target.value),s(null)}}),(0,G.jsx)(Or,{id:`activation-grant-description`,children:`Only needed after resetting a deployment binding. Enter the one-time grant from SaaS with the same license key.`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(U,{onClick:()=>m(!0),disabled:!n.trim()||c||d,children:[(0,G.jsx)(po,{}),d?`Activating...`:`Activate license`]}),o&&(0,G.jsxs)(`div`,{id:`license-activation-error`,role:`alert`,children:[(0,G.jsx)(`p`,{className:`text-sm text-destructive`,children:o.message}),o.code&&(0,G.jsxs)(`p`,{className:`font-mono text-xs text-muted-foreground`,children:[`Code: `,o.code]}),o.code===`LICENSE_ALREADY_BOUND`&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Reset the old deployment binding in SaaS, then enter its activation grant above.`})]})]})]}),(0,G.jsx)(br,{isOpen:p,title:`Activate license?`,message:`This will activate the license for this Self-host instance and update its Team and member capacity.`,confirmText:`Activate license`,cancelText:`Cancel`,variant:`info`,onCancel:()=>m(!1),onConfirm:()=>{m(!1),g()}})]})}function DC(){let{isSettingsOpen:e,setIsSettingsOpen:t,settingsTab:n,setSettingsTab:r}=pa(),i=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),a=i||typeof window<`u`&&window.ERD_INSTALL_MODE===`cli`,[o,s]=W.useState(`configuration`);W.useEffect(()=>{if(!i)return;let e,n=!1;return(async()=>{let{listen:i}=await _i(async()=>{let{listen:e}=await import(`./event-C6gFlqUR.js`);return{listen:e}},__vite__mapDeps([0,1]));n||(e=await i(`menu-settings`,()=>{r(`account`),t(!0)}))})(),()=>{n=!0,e?.()}},[i,t,r]);let{isGuest:c,user:l}=la(),u=!!l?.isSso,d=!u&&(a||!!(l?.isSuperAdmin||l?.is_super_admin)),f=d&&!a,{providers:p,configs:m,isTesting:h,isSaving:g,handleSaveConfig:_,handleTestConnection:v,handleInitializeProviders:y,updateProviderLocal:b,updateConfigLocal:x}=fne(d),{models:S,newModel:C,editingModelId:w,isSaving:T,setNewModel:E,handleAddModel:D,handleDeleteModel:O,ensureModel:k,startEditingModel:A,cancelEdit:j,refresh:M}=pne(d),{prompts:N,isSaving:P,handleSavePrompt:F,handleDeletePrompt:I,togglePromptDefault:L}=mne(),R=W.useMemo(()=>c?[{label:`General`,items:[{id:`appearance`,label:`Appearance`,icon:(0,G.jsx)(Ao,{className:`size-4`})}]},{label:`More`,items:[{id:`keymap`,label:`Keymap`,icon:(0,G.jsx)(mo,{className:`size-4`})},{id:`changelog`,label:`What's New`,icon:(0,G.jsx)(uo,{className:`size-4`})}]}]:[{label:`General`,items:[...u?[]:[{id:`account`,label:`Account`,icon:(0,G.jsx)(Qo,{className:`size-4`})}],{id:`appearance`,label:`Appearance`,icon:(0,G.jsx)(Ao,{className:`size-4`})},...a&&!u?[{id:`storage`,label:`Storage`,icon:(0,G.jsx)(Mr,{className:`size-4`})}]:[],...u?[{id:`usage`,label:`Usage`,icon:(0,G.jsx)(io,{className:`size-4`})}]:[]]},{label:`Feature`,items:[...d?[{id:`ai-config`,label:`AI Configuration`,icon:(0,G.jsx)(Qr,{className:`size-4`})}]:[],...f?[{id:`license`,label:`Application License`,icon:(0,G.jsx)(po,{className:`size-4`})}]:[],{id:`mcp-server`,label:`MCP Integration`,icon:(0,G.jsx)(Lo,{className:`size-4`})},{id:`ai-rules`,label:`AI Rules`,icon:(0,G.jsx)(bo,{className:`size-4`})},{id:`ai-prompts`,label:`System Prompts`,icon:(0,G.jsx)(Oa,{className:`size-4`})}]},{label:`More`,items:[{id:`keymap`,label:`Keymap`,icon:(0,G.jsx)(mo,{className:`size-4`})},...d?[{id:`export-data`,label:`Export Data`,icon:(0,G.jsx)(rn,{className:`size-4`})},{id:`import-data`,label:`Import Data`,icon:(0,G.jsx)(Yn,{className:`size-4`})},{id:`backups`,label:`Database Backup`,icon:(0,G.jsx)(Cr,{className:`size-4`})}]:[],{id:`changelog`,label:`What's New`,icon:(0,G.jsx)(uo,{className:`size-4`})}]}],[f,c,a,u,d]);W.useEffect(()=>{(!d&&[`ai-config`,`license`,`export-data`,`import-data`,`backups`].includes(n)||u&&n===`account`||n===`license`&&!f)&&r(c||u?`appearance`:`account`)},[f,c,u,d,n,r]);let ee=R.flatMap(e=>e.items),te=e=>ee.find(t=>t.id===e)?.label||``;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`overflow-hidden p-0 md:max-h-150 md:max-w-175 lg:max-w-237.5 bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`Settings`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Manage your application settings and AI configuration.`}),(0,G.jsxs)(Th,{className:`items-start min-h-0! h-full`,children:[(0,G.jsx)(Eh,{collapsible:`none`,className:`w-55 border-r border-border/40 bg-muted/5 hidden md:flex h-full`,children:(0,G.jsxs)(Dh,{className:`pt-4 px-2 pb-0`,children:[(0,G.jsx)(`div`,{className:`px-4 py-2 mb-2`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-bold flex items-center gap-2`,children:[(0,G.jsx)(zo,{className:`size-4`}),`Settings`]})}),R.map(e=>(0,G.jsxs)(Oh,{className:`py-1`,children:[(0,G.jsx)(kh,{className:`text-[10px] uppercase tracking-widest text-muted-foreground/60 px-4 mb-0.5`,children:e.label}),(0,G.jsx)(Ah,{children:(0,G.jsx)(jh,{children:e.items.map(e=>(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{isActive:n===e.id,onClick:()=>r(e.id),className:`transition-all duration-200 px-4 py-2 rounded-md ${n===e.id?`bg-sidebar-accent text-sidebar-accent-foreground font-medium`:`text-muted-foreground hover:bg-sidebar-accent/50`}`,children:[e.icon,(0,G.jsx)(`span`,{className:`text-xs`,children:e.label})]})},e.id))})})]},e.label))]})}),(0,G.jsxs)(`main`,{className:`flex-1 flex flex-col h-150 overflow-hidden`,children:[(0,G.jsx)(`header`,{className:`flex h-14 shrink-0 items-center gap-2 border-b border-border/40 px-6 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Ph,{className:`hidden md:flex`,children:(0,G.jsxs)(Fh,{children:[(0,G.jsx)(Ih,{children:(0,G.jsx)(dne,{href:`#`,className:`text-[11px] text-muted-foreground`,children:`Settings`})}),(0,G.jsx)(Rh,{}),(0,G.jsx)(Ih,{children:(0,G.jsx)(Lh,{className:`text-[11px] font-semibold`,children:te(n)})})]})}),(0,G.jsx)(`div`,{className:`md:hidden`,children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`-ml-2 h-8 gap-2 text-xs font-semibold`,children:[(0,G.jsx)(zo,{className:`size-3.5`}),te(n),(0,G.jsx)(Xt,{className:`size-3 opacity-50`})]})}),(0,G.jsx)(Gt,{align:`start`,className:`w-56`,children:R.map(e=>(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`text-[10px] uppercase tracking-widest text-muted-foreground/60 px-2 py-1.5`,children:e.label}),e.items.map(e=>(0,G.jsxs)(It,{onClick:()=>r(e.id),className:n===e.id?`bg-accent`:``,children:[e.icon,(0,G.jsx)(`span`,{className:`ml-2`,children:e.label})]},e.id)),(0,G.jsx)(Kt,{})]},e.label))})]})})]})}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar`,children:[d&&n===`ai-config`&&(0,G.jsxs)(`div`,{className:`p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 bg-muted border border-border rounded-lg p-1 w-full mb-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(`configuration`),className:`flex-1 flex items-center justify-center gap-1.5 px-3.5 py-2 rounded-md text-xs font-semibold transition-all ${o===`configuration`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,G.jsx)(zo,{className:`w-3.5 h-3.5`}),`Configuration`]}),(0,G.jsxs)(`button`,{onClick:()=>s(`models`),className:`flex-1 flex items-center justify-center gap-1.5 px-3.5 py-2 rounded-md text-xs font-semibold transition-all ${o===`models`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,G.jsx)(Oa,{className:`w-3.5 h-3.5`}),`AI Models`]})]}),o===`configuration`&&(0,G.jsx)(hne,{providers:p,configs:m,models:S,isSaving:g,isTesting:h,onSave:_,onTest:e=>v(e,Object.values(S).flat()),onUpdateProvider:b,onUpdateConfig:x,onEnsureModel:k,onRefreshModels:M,onInitialize:y}),o===`models`&&(0,G.jsx)(vne,{providers:p,models:Object.values(S).flat(),newModel:C,editingModelId:w,isSaving:T,onSetNewModel:E,onAddModel:D,onEditModel:A,onDeleteModel:O,onCancelEdit:j})]}),n===`ai-prompts`&&(0,G.jsx)(Tne,{prompts:N,isSaving:P,onSave:F,onDelete:I,onToggleDefault:L}),n===`ai-rules`&&(0,G.jsx)(One,{}),n===`mcp-server`&&(0,G.jsx)(SC,{}),f&&n===`license`&&(0,G.jsx)(EC,{}),d&&n===`backups`&&(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsx)(Wne,{})}),!u&&n===`account`&&(0,G.jsx)(kne,{}),n===`changelog`&&(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsx)(QS,{})}),n===`keymap`&&(0,G.jsx)(vC,{}),d&&n===`export-data`&&(0,G.jsx)(`div`,{className:`p-4 md:p-6 overflow-y-auto h-full`,children:(0,G.jsx)(mC,{})}),d&&n===`import-data`&&(0,G.jsxs)(`div`,{className:`p-4 md:p-6 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Import Data`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restore data from a JSON backup or replace the local database from a .db file.`})]}),(0,G.jsx)(rC,{})]}),n===`appearance`&&(0,G.jsx)(Mne,{}),n===`storage`&&(0,G.jsx)(hC,{}),u&&n===`usage`&&(0,G.jsx)(gne,{onClose:()=>t(!1)})]})]})]})]})})}async function OC(){try{let{getVersion:e}=await _i(async()=>{let{getVersion:e}=await import(`./app-Aufmny-7.js`);return{getVersion:e}},__vite__mapDeps([2,1,3]));return await e()}catch{return`0.0.0`}}function kC({open:e,onOpenChange:t,hasUpdate:n=!1,latestVersion:r=null,isChecking:i=!1,isDownloading:a=!1,onCheckUpdate:o,onDownload:s}){let c=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),[u,d]=(0,W.useState)(`...`),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(null),S=n||f,C=r||m,w=i||g,T=a||v;(0,W.useEffect)(()=>{c?OC().then(d):d(`3.5.3`)},[c]),(0,W.useEffect)(()=>{if(!e||!c||n||i||a)return;if(o){o();return}if(s)return;_(!0);let t=!1;return(async()=>{try{let{check:e}=await _i(async()=>{let{check:e}=await import(`./dist-js-CGfv5pu7.js`).then(e=>e.n);return{check:e}},__vite__mapDeps([4,5,1])),n=await e();if(t)return;n?(p(!0),h(n.version),x(n)):(p(!1),h(null),x(null))}catch{}finally{t||_(!1)}})(),()=>{t=!0}},[e,c]);let E=(0,W.useCallback)(()=>{if(s)s();else if(b){if(v)return;y(!0),b.downloadAndInstall(()=>{}).catch(e=>{let t=typeof e==`string`?e:e?.message?e.message:JSON.stringify(e);l.error(`Update failed`,{description:t||`An error occurred while downloading the update.`,duration:12e3,action:{label:`Copy Error`,onClick:()=>navigator.clipboard.writeText(t).catch(()=>{})}})}).finally(()=>y(!1))}},[s,b,v]),D=(0,W.useCallback)(()=>{T||(o?o():(_(!0),p(!1),h(null),(async()=>{try{let{check:e}=await _i(async()=>{let{check:e}=await import(`./dist-js-CGfv5pu7.js`).then(e=>e.n);return{check:e}},__vite__mapDeps([4,5,1])),t=await e();t?(p(!0),h(t.version),x(t)):(p(!1),h(null),x(null))}catch{}finally{_(!1)}})()))},[o,T]);return(0,W.useEffect)(()=>{e||(p(!1),h(null),_(!1),x(null))},[e]),(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`max-w-sm bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`About ERD Builder Pro`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Application information and credits.`}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-6 gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex size-14 items-center justify-center`,children:[(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Light-1.svg`,alt:``,"aria-hidden":`true`,className:`size-full dark:hidden`}),(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Dark-1.svg`,alt:``,"aria-hidden":`true`,className:`hidden size-full dark:block`})]}),(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:`ERD Builder Pro`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`Version `,u]})]}),(0,G.jsx)(`p`,{className:`text-xs text-center text-muted-foreground max-w-60 leading-relaxed`,children:`Entity-Relationship Diagram builder, flowcharts, notes, and AI-powered assistance — all in one desktop app.`}),c&&(0,G.jsxs)(`div`,{className:`w-full`,children:[(0,G.jsx)(`div`,{className:`w-full border-t border-border/40 mb-3`}),w?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-xs text-muted-foreground py-1`,children:[(0,G.jsx)(xo,{className:`size-3.5 animate-spin`}),`Checking for updates...`]}):S&&C?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-amber-500`,children:[(0,G.jsx)(rn,{className:`size-3.5`}),(0,G.jsxs)(`span`,{children:[`Update `,(0,G.jsxs)(`strong`,{children:[`v`,C]}),` available`]})]}),(0,G.jsxs)(U,{variant:`default`,size:`sm`,className:`h-8 text-xs gap-1.5`,onClick:E,disabled:T,children:[T?(0,G.jsx)(xo,{className:`size-3.5 animate-spin`}):(0,G.jsx)(rn,{className:`size-3.5`}),T?`Downloading...`:`Download Update`]})]}):(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-emerald-500`,children:[(0,G.jsx)(Rn,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`You're up to date`})]}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-muted-foreground hover:text-foreground`,onClick:D,children:[(0,G.jsx)(cr,{className:`size-3`}),`Check Again`]})]})]}),(0,G.jsx)(`div`,{className:`w-full border-t border-border/40`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-center text-muted-foreground/60 leading-relaxed`,children:[(0,G.jsx)(`p`,{children:`Built with React, Tauri, Express & Prisma.`}),(0,G.jsxs)(`p`,{className:`mt-0.5`,children:[`© `,new Date().getFullYear(),` Bekenweb.`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-muted-foreground hover:text-foreground`,onClick:()=>{ia(`https://github.com/hadziqmtqn/erd-builder-pro`)},children:[(0,G.jsx)(Ga,{className:`size-3`}),`GitHub`]}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-rose-500 hover:text-rose-600`,onClick:()=>{ia(`https://trakteer.id/khadziq_muttaqin/tip`)},children:[(0,G.jsx)(lo,{className:`size-3`}),`Support`]})]})]})]})})}function AC(e){let[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null),{setViewport:u,fitView:d}=ve();return{isPublicView:t,setIsPublicView:n,publicData:r,isPublicLoading:a,forbiddenDoc:s,fetchPublicDocument:async(t,n,r,a,s)=>{o(!0),c(null);try{let o=t===`erd`?`files`:t===`flowchart`?`flowcharts`:t,l={"Content-Type":`application/json`};s&&(l[`x-share-token`]=s);let f=await Si(`/api/${o}/public/${n}`,{headers:l,credentials:`include`});if(!f.ok){let e=`Document not found or access denied`,t=`Access Denied`;try{e=(await f.json()).error||e,f.status===404?t=`Not Found`:(f.status===401||f.status===403)&&(t=`Access Denied`)}catch{}if(f.status===401||f.status===403||f.status===404)return c({title:t,message:e,status:f.status}),!1;throw Error(e)}let p=f.headers.get(`content-type`);if(!p||!p.includes(`application/json`))throw Error(`Received invalid response from server`);let m=await f.json();if(i(m),e(t),t===`erd`){let e=m.entities.map(e=>({id:e.id,type:`entity`,position:{x:e.x,y:e.y},data:e})),t=m.relationships.map(e=>{let t=m.entities.find(t=>String(t.id)===String(e.source_entity_id)),n=m.entities.find(t=>String(t.id)===String(e.target_entity_id)),r=e.source_handle,i=e.target_handle;if(t&&n){let a=Number(t.x)||0,o=Number(n.x)||0,s=(e.source_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),c=(e.target_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);s&&(r=a<o?`col-${s}-source`:`col-${s}-source-l`),c&&(i=a<o?`col-${c}-target`:`col-${c}-target-r`)}let a=(e.source_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),o=(e.target_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);return{id:e.id,source:e.source_entity_id,target:e.target_entity_id,sourceHandle:r||(a?`col-${a}-source`:void 0),targetHandle:i||(o?`col-${o}-target`:void 0),label:e.label,type:`smoothstep`,animated:!0}});r(e),a(t);let n=(t=0)=>{let n=qi(m);n?u(n,{duration:t}):e.length>0&&d({padding:.2,duration:t})};setTimeout(()=>n(0),100)}else if(t===`flowchart`)try{let e=typeof m.data==`string`?JSON.parse(m.data):m.data;r(e.nodes||[]),a(e.edges||[]);let t=(t=0)=>{let n=qi(m);n?u(n,{duration:t}):e.nodes?.length>0&&d({padding:.2,duration:t})};setTimeout(()=>t(0),100)}catch(e){console.error(`Failed to parse flowchart data:`,e)}else r([]),a([]);return!0}catch(e){return l.error(e.message||`Failed to load shared document`),setTimeout(()=>window.location.href=`/`,3e3),!1}finally{o(!1)}}}}var jC=(0,W.createContext)(null),MC=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),NC={checked(e){return e?{[MC.checked]:``}:{[MC.unchecked]:``}},...Ge,...bt},PC=`data-composite-item-active`,FC=W.createContext(void 0);function IC(){return W.useContext(FC)}var LC=W.createContext(void 0);function RC(){let e=W.useContext(LC);if(e===void 0)throw Error(De(52));return e}var zC=W.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,readOnly:a=!1,required:o=!1,"aria-labelledby":s,value:c,inputRef:l,nativeButton:u=!1,id:d,...f}=e,p=IC(),{disabled:m,readOnly:h,required:g,checkedValue:_,touched:v=!1,validation:y,name:b}=p??{},x=p?.setCheckedValue??Ee,S=p?.setTouched??Ee,C=p?.registerControlRef??Ee,w=p?.registerInputRef??Ee,{setDirty:T,validityData:E,setTouched:D,setFilled:O,state:k,disabled:A}=_t(),j=os(),{labelId:M,getDescriptionProps:N}=xt(),P=A||j.disabled||m||i,F=h||a,I=g||o,L=p?_===c:c===``,R=W.useMemo(()=>dr(c),[c]),ee=W.useRef(null),te=W.useRef(null),ne=Me(e=>{e&&C(e,P)}),re=Se(l,te,w);Ae(()=>{te.current?.checked&&O(!0)},[O]),Ae(()=>{te.current&&(P&&L?w(null):(ee.current&&C(ee.current,P),w(te.current)))},[L,P,C,w]);let ie=He(),z=yt({id:d,implicit:!1,controlRef:ee}),ae=u?void 0:z,oe=Wh(s,M,te,!u,ae),se={role:`radio`,"aria-checked":L,"aria-required":I||void 0,"aria-readonly":F||void 0,"aria-labelledby":oe,[PC]:L?``:void 0,id:u?z:ie,onKeyDown(e){e.key===`Enter`&&e.preventDefault()},onClick(e){e.defaultPrevented||P||F||(e.preventDefault(),te.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))},onFocus(e){e.defaultPrevented||P||F||!v||(te.current?.click(),S(!1))}},{getButtonProps:ce,buttonRef:le}=we({disabled:P,native:u}),ue={type:`radio`,ref:re,id:ae,name:b,tabIndex:-1,style:b?ft:rt,"aria-hidden":!0,...c===void 0?Oe:{value:R},disabled:P,checked:L,required:I,readOnly:F,onChange(e){if(e.nativeEvent.defaultPrevented||P||F||c===void 0)return;let t=ct(Ue,e.nativeEvent);t.isCanceled||(D(!0),T(c!==E.initialValue),O(!0),x(c,t))},onFocus(){ee.current?.focus()}},de=W.useMemo(()=>({...k,required:I,disabled:P,readOnly:F,checked:L}),[k,P,F,L,I]),B=de,fe=p!==void 0,pe=[t,ee,le,ne],me=[se,N,y?.getValidationProps??Oe,f,ce],he=je(`span`,e,{enabled:!fe,state:de,ref:pe,props:me,stateAttributesMapping:NC});return(0,G.jsxs)(LC.Provider,{value:B,children:[fe?(0,G.jsx)(Bt,{tag:`span`,render:n,className:r,state:de,refs:pe,props:me,stateAttributesMapping:NC}):he,(0,G.jsx)(`input`,{...ue})]})}),BC=W.forwardRef(function(e,t){let{render:n,className:r,keepMounted:i=!1,...a}=e,o=RC(),s=o.checked,{mounted:c,transitionStatus:l,setMounted:u}=Ie(s),d={...o,transitionStatus:l},f=W.useRef(null),p=i||c,m=je(`span`,e,{ref:[t,f],state:d,props:a,stateAttributesMapping:NC});return Be({open:s,ref:f,onComplete(){s||u(!1)}}),p?m:null});function VC(e){return e==null||e.hasAttribute(`disabled`)||e.getAttribute(`aria-disabled`)===`true`}var HC=[];function UC(e){let{itemSizes:t,cols:n=1,loopFocus:r=!0,dense:i=!1,orientation:a=`both`,direction:o,highlightedIndex:s,onHighlightedIndexChange:c,rootRef:l,enableHomeAndEndKeys:u=!1,stopEventPropagation:d=!1,disabledIndices:f,modifierKeys:p=HC}=e,[m,h]=W.useState(0),g=n>1,_=W.useRef(null),v=Se(_,l),y=W.useRef([]),b=W.useRef(!1),x=s??m,S=Me((e,t=!1)=>{if((c??h)(e),t){let t=y.current[e];Xe(_.current,t,o,a)}}),C=Me(e=>{if(e.size===0||b.current)return;b.current=!0;let t=Array.from(e.keys()),n=t.find(e=>e?.hasAttribute(`data-composite-item-active`))??null,r=n?t.indexOf(n):-1;r!==-1&&S(r),Xe(_.current,n,o,a)}),w=W.useMemo(()=>({"aria-orientation":a===`both`?void 0:a,ref:v,onFocus(e){_.current&&ht(e.target)&&e.target.setSelectionRange(0,e.target.value.length??0)},onKeyDown(e){let s=u?Ye:ut;if(!s.has(e.key)||WC(e,p)||!_.current)return;let c=o===`rtl`,l=c?Ze:nt,m={horizontal:l,vertical:ot,both:l}[a],h=c?nt:Ze,v={horizontal:h,vertical:dt,both:h}[a];if(ht(e.target)&&!VC(e.target)){let t=e.target.selectionStart,n=e.target.selectionEnd,r=e.target.value??``;if(t==null||e.shiftKey||t!==n||e.key!==v&&t<r.length||e.key!==m&&t>0)return}let b=x,C=qe(y,f),w=We(y,f);if(g){let o=t||Array.from({length:y.current.length},()=>({width:1,height:1})),s=Ve(o,n,i),l=s.findIndex(e=>e!=null&&!lt(y,e,f)),u=s.reduce((e,t,n)=>t!=null&&!lt(y,t,f)?n:e,-1);b=s[Le({current:s.map(e=>e?y.current[e]:null)},{event:e,orientation:a,loopFocus:r,cols:n,disabledIndices:Ke([...f||y.current.map((e,t)=>lt(y,t)?t:void 0),void 0],s),minIndex:l,maxIndex:u,prevIndex:Fe(x>w?C:x,o,s,n,e.key===`ArrowDown`?`bl`:e.key===`ArrowRight`?`tr`:`tl`),rtl:c})]}let T={horizontal:[l],vertical:[ot],both:[l,ot]}[a],E={horizontal:[h],vertical:[dt],both:[h,dt]}[a],D=g?s:{horizontal:u?it:st,vertical:u?pt:Je,both:s}[a];u&&(e.key===`Home`?b=C:e.key===`End`&&(b=w)),b===x&&(T.includes(e.key)||E.includes(e.key))&&(b=r&&b===w&&T.includes(e.key)?C:r&&b===C&&E.includes(e.key)?w:gt(y,{startingIndex:b,decrement:E.includes(e.key),disabledIndices:f})),b!==x&&!Re(y,b)&&(d&&e.stopPropagation(),D.has(e.key)&&e.preventDefault(),S(b,!0),queueMicrotask(()=>{y.current[b]?.focus()}))}}),[n,i,o,f,y,u,x,g,t,r,v,p,S,a,d]);return W.useMemo(()=>({props:w,highlightedIndex:x,onHighlightedIndexChange:S,elementsRef:y,disabledIndices:f,onMapChange:C,relayKeyboardEvent:w.onKeyDown}),[w,x,S,y,f,C])}function WC(e,t){for(let n of tt.values())if(!t.includes(n)&&e.getModifierState(n))return!0;return!1}function GC(e){let{render:t,className:n,refs:r=Ce,props:i=Ce,state:a=Oe,stateAttributesMapping:o,highlightedIndex:s,onHighlightedIndexChange:c,orientation:l,dense:u,itemSizes:d,loopFocus:f,cols:p,enableHomeAndEndKeys:m,onMapChange:h,stopEventPropagation:g=!0,rootRef:_,disabledIndices:v,modifierKeys:y,highlightItemOnHover:b=!1,tag:x=`div`,...S}=e,{props:C,highlightedIndex:w,onHighlightedIndexChange:T,elementsRef:E,onMapChange:D,relayKeyboardEvent:O}=UC({itemSizes:d,cols:p,loopFocus:f,dense:u,orientation:l,highlightedIndex:s,onHighlightedIndexChange:c,rootRef:_,stopEventPropagation:g,enableHomeAndEndKeys:m,direction:Zt(),disabledIndices:v,modifierKeys:y}),k=je(x,e,{state:a,ref:r,props:[C,...i,S],stateAttributesMapping:o}),A=W.useMemo(()=>({highlightedIndex:w,onHighlightedIndexChange:T,highlightItemOnHover:b,relayKeyboardEvent:O}),[w,T,b,O]);return(0,G.jsx)(be.Provider,{value:A,children:(0,G.jsx)(en,{elementsRef:E,onMapChange:e=>{h?.(e),D(e)},children:k})})}var KC=[$e],qC=W.forwardRef(function(e,t){let{render:n,className:r,disabled:i,readOnly:a,required:o,onValueChange:s,value:c,defaultValue:l,name:u,inputRef:d,id:f,...p}=e,{setTouched:m,setFocused:h,shouldValidateOnChange:g,validationMode:_,name:v,disabled:y,state:b,validation:x,setDirty:S,setFilled:C,validityData:w}=_t(),{labelId:T}=xt(),{clearErrors:E}=vt(),D=is(!0),O=y||i,k=v??u,A=He(f),[j,M]=Qt({controlled:c,default:l,name:`RadioGroup`,state:`value`}),N=Me(s),P=Me((e,t)=>{N(e,t),!t.isCanceled&&M(e)}),F=W.useRef(null),I=W.useRef(null),L=W.useRef(null);function R(e){let t;return d&&(typeof d==`function`?t=d(e):d.current=e),I.current=e,x.inputRef.current=e,t}let ee=Me((e,t=!1)=>{e&&(t?F.current===e&&(F.current=null):F.current??=e)}),te=Me(e=>{if(!e||e.disabled)return;L.current||=e;let t=I.current;if(e.checked||t==null||t.disabled)return R(e)});Ct({id:A,commit:x.commit,value:j,controlRef:F,name:k,getValue:()=>j??null}),at(j,()=>{E(k),S(j!==w.initialValue),C(j!=null),g()?x.commit(j):x.commit(j,!0);let e=L.current;j==null&&e&&!e.disabled&&R(e)});let[ne,re]=W.useState(!1),ie=p[`aria-labelledby`]??T??D?.legendId,z={...b,disabled:O??!1,required:o??!1,readOnly:a??!1},ae=W.useMemo(()=>({...b,checkedValue:j,disabled:O,validation:x,name:k,onValueChange:N,readOnly:a,registerControlRef:ee,registerInputRef:te,required:o,setCheckedValue:P,setTouched:re,touched:ne}),[j,O,x,b,k,N,a,ee,te,o,P,re,ne]),oe={role:`radiogroup`,"aria-required":o||void 0,"aria-disabled":O||void 0,"aria-readonly":a||void 0,"aria-labelledby":ie,onFocus(){h(!0)},onBlur(e){Qe(e.currentTarget,e.relatedTarget)||(m(!0),h(!1),_===`onBlur`&&x.commit(j))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(m(!0),re(!0),h(!0))}};return(0,G.jsx)(FC.Provider,{value:ae,children:(0,G.jsx)(GC,{render:n,className:r,state:z,props:[oe,x.getValidationProps,p],refs:[t],stateAttributesMapping:bt,enableHomeAndEndKeys:!1,modifierKeys:KC})})});async function JC(e,t,n){if(await e(),await t(),(await ca.getAllPendingSyncs()).some(e=>e.type===n.type&&[n.id,n.uid].some(t=>t!=null&&String(t)===String(e.id))))throw Error(`Save your pending changes before switching workspaces.`)}async function YC(e,t=document){R(t),O(t);let{view:n,activeNote:r,activeDiagram:i,activeFlowchart:a,activeDrawing:o}=e,s=n===`notes`?r:n===`erd`?i:n===`flowchart`?a:o,c=!1;if(n===`notes`&&r&&!e.isReadOnlyFile(r)){let t={uid:String(r.uid??r.id),content:null};if(window.dispatchEvent(new CustomEvent(L,{detail:t})),t.content!==null){if(c=!0,e.cancelPendingNoteSaves(),t.content!==r.content&&!await e.saveNote({...r,content:t.content}))throw Error(`Could not save the note. Keep this panel open and try again.`);e.setIsLocalSaving(!1)}}await JC(c?async()=>{}:e.flushPendingSaves,e.syncDrafts,{type:n,id:s?.id,uid:s?.uid})}var XC={erd_builder:`ERD Builder`,notes:`Notes`,drawings:`Drawings`,flowcharts:`Flowcharts`,desktop_only:`DB Client`};function ZC({capability:e,teamName:t,ssoPortalUrl:n}){let r=v(),i=XC[e];return(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 py-10`,children:(0,G.jsxs)(`section`,{className:`w-full max-w-md rounded-lg border border-border bg-card p-6 shadow-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground`,children:(0,G.jsx)(Kn,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`h1`,{className:`text-base font-semibold text-foreground`,children:[`Unlock `,i]}),(0,G.jsxs)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:[i,` is not included in `,t||`this Team`,`'s current Cloud plan. Upgrade to continue using it.`]})]})]}),(0,G.jsx)(`div`,{className:`mt-5 flex justify-end border-t border-border pt-4`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(U,{variant:`outline`,onClick:()=>r(`/`),children:`Return to dashboard`}),n&&(0,G.jsx)(U,{onClick:()=>{if(n)try{window.location.assign(new URL(`/pricing#cloud-saas`,n).toString())}catch{}},children:`View Cloud plans`})]})})]})})}function QC({capability:e,children:t}){let{user:n}=la(),{activeTeamId:r,activeTeam:i,isLoading:a}=w();return!n?.isSso||!r?(0,G.jsx)(G.Fragment,{children:t}):a?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Checking Team plan…`}):e!==`desktop_only`&&i?.capabilities?.[e]===!0?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(ZC,{capability:e,teamName:i?.name,ssoPortalUrl:n?.ssoPortalUrl??n?.sso_portal_url})}var $C=W.createContext(void 0);function ew(){let e=W.useContext($C);if(e===void 0)throw Error(De(64));return e}var tw=function(e){return e.activationDirection=`data-activation-direction`,e.orientation=`data-orientation`,e}({}),nw={tabActivationDirection:e=>({[tw.activationDirection]:e})},rw=W.forwardRef(function(e,t){let{className:n,defaultValue:r=0,onValueChange:i,orientation:a=`horizontal`,render:o,value:s,...c}=e,l=Zt(),u=Object.hasOwn(e,`defaultValue`),d=W.useRef([]),[f,p]=W.useState(()=>new Map),[m,h]=Qt({controlled:s,default:r,name:`Tabs`,state:`value`}),g=s!==void 0,[_,v]=W.useState(()=>new Map),[y,b]=W.useState(`none`),x=Me((e,t)=>{i?.(e,t),!t.isCanceled&&(h(e),b(t.activationDirection))}),S=Me((e,t)=>{p(n=>{if(n.get(e)===t)return n;let r=new Map(n);return r.set(e,t),r})}),C=Me((e,t)=>{p(n=>{if(!n.has(e)||n.get(e)!==t)return n;let r=new Map(n);return r.delete(e),r})}),w=W.useCallback(e=>f.get(e),[f]),T=W.useCallback(e=>{for(let t of _.values())if(e===t?.value)return t?.id},[_]),E=W.useCallback(e=>{if(e===void 0)return null;for(let[t,n]of _.entries())if(n!=null&&e===(n.value??n.index))return t;return null},[_]),D=W.useMemo(()=>({direction:l,getTabElementBySelectedValue:E,getTabIdByPanelValue:T,getTabPanelIdByValue:w,onValueChange:x,orientation:a,registerMountedTabPanel:S,setTabMap:v,unregisterMountedTabPanel:C,tabActivationDirection:y,value:m}),[l,E,T,w,x,a,S,v,C,y,m]),O=W.useMemo(()=>{for(let e of _.values())if(e!=null&&e.value===m)return e},[_,m]),k=W.useMemo(()=>{for(let e of _.values())if(e!=null&&!e.disabled)return e.value},[_]);Ae(()=>{if(g||_.size===0)return;let e=O?.disabled;if(u&&e&&m===r||!e&&(O!=null||m===null))return;let t=k??null;m!==t&&(h(t),b(`none`))},[r,k,u,g,O,b,h,_,m]);let A=je(`div`,e,{state:{orientation:a,tabActivationDirection:y},ref:t,props:c,stateAttributesMapping:nw});return(0,G.jsx)($C.Provider,{value:D,children:(0,G.jsx)(en,{elementsRef:d,children:A})})}),iw=W.createContext(void 0);function aw(){let e=W.useContext(iw);if(e===void 0)throw Error(De(65));return e}var ow=W.forwardRef(function(e,t){let{className:n,disabled:r=!1,render:i,value:a,id:o,nativeButton:s=!0,...c}=e,{value:l,getTabPanelIdByValue:u,orientation:d}=ew(),{activateOnFocus:f,highlightedTabIndex:p,onTabActivation:m,registerTabResizeObserverElement:h,setHighlightedTabIndex:g,tabsListElement:_}=aw(),v=He(o),y=W.useMemo(()=>({disabled:r,id:v,value:a}),[r,v,a]),{compositeProps:b,compositeRef:x,index:S}=Vi({metadata:y}),C=a===l,w=W.useRef(!1),T=W.useRef(null);W.useEffect(()=>{let e=T.current;if(e)return h(e)},[h]),Ae(()=>{if(w.current){w.current=!1;return}if(!(C&&S>-1&&p!==S))return;let e=_;if(e!=null){let t=Ne(ze(e));if(t&&Qe(e,t))return}r||g(S)},[C,S,p,g,r,_]);let{getButtonProps:E,buttonRef:D}=we({disabled:r,native:s,focusableWhenDisabled:!0}),O=u(a),k=W.useRef(!1),A=W.useRef(!1);function j(e){C||r||m(a,ct(Ue,e.nativeEvent,void 0,{activationDirection:`none`}))}function M(e){C||(S>-1&&!r&&g(S),!r&&f&&(!k.current||k.current&&A.current)&&m(a,ct(Ue,e.nativeEvent,void 0,{activationDirection:`none`})))}function N(e){if(C||r)return;k.current=!0;function t(){k.current=!1,A.current=!1}e.button&&e.button!==0||(A.current=!0,ze(e.currentTarget).addEventListener(`pointerup`,t,{once:!0}))}return je(`button`,e,{state:{disabled:r,active:C,orientation:d},ref:[t,D,x,T],props:[b,{role:`tab`,"aria-controls":O,"aria-selected":C,id:v,onClick:j,onFocus:M,onPointerDown:N,[PC]:C?``:void 0,onKeyDownCapture(){w.current=!0}},c,E]})}),sw=function(e){return e.index=`data-index`,e.activationDirection=`data-activation-direction`,e.orientation=`data-orientation`,e.hidden=`data-hidden`,e[e.startingStyle=Pe.startingStyle]=`startingStyle`,e[e.endingStyle=Pe.endingStyle]=`endingStyle`,e}({}),cw={...nw,...Ge},lw=W.forwardRef(function(e,t){let{className:n,value:r,render:i,keepMounted:a=!1,...o}=e,{value:s,getTabIdByPanelValue:c,orientation:l,tabActivationDirection:u,registerMountedTabPanel:d,unregisterMountedTabPanel:f}=ew(),p=He(),m=W.useMemo(()=>({id:p,value:r}),[p,r]),{ref:h,index:g}=$t({metadata:m}),_=r===s,{mounted:v,transitionStatus:y,setMounted:b}=Ie(_),x=!v,S=c(r),C={hidden:x,orientation:l,tabActivationDirection:u,transitionStatus:y},w=W.useRef(null),T=je(`div`,e,{state:C,ref:[t,h,w],props:[{"aria-labelledby":S,hidden:x,id:p,role:`tabpanel`,tabIndex:_?0:-1,inert:mt(!_),[sw.index]:g},o],stateAttributesMapping:cw});return Be({open:_,ref:w,onComplete(){_||b(!1)}}),Ae(()=>{if((!x||a)&&p!=null)return d(r,p),()=>{f(r,p)}},[x,a,r,p,d,f]),a||v?T:null}),uw=W.forwardRef(function(e,t){let{activateOnFocus:n=!1,className:r,loopFocus:i=!0,render:a,...o}=e,{getTabElementBySelectedValue:s,onValueChange:c,orientation:l,value:u,setTabMap:d,tabActivationDirection:f}=ew(),[p,m]=W.useState(0),[h,g]=W.useState(null),_=W.useRef(new Set),v=W.useRef(new Set),y=W.useRef(null),b=Me(()=>{_.current.forEach(e=>{e()})});W.useEffect(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>{_.current.size&&b()});return y.current=e,h&&e.observe(h),v.current.forEach(t=>{e.observe(t)}),()=>{e.disconnect(),y.current=null}},[h,b]);let x=Me(e=>(_.current.add(e),()=>{_.current.delete(e)})),S=Me(e=>(v.current.add(e),y.current?.observe(e),()=>{v.current.delete(e),y.current?.unobserve(e)})),C=fw(u,l,h,s),w=Me((e,t)=>{e!==u&&(t.activationDirection=C(e),c(e,t))}),T={orientation:l,tabActivationDirection:f},E={"aria-orientation":l===`vertical`?`vertical`:void 0,role:`tablist`},D=W.useMemo(()=>({activateOnFocus:n,highlightedTabIndex:p,registerIndicatorUpdateListener:x,registerTabResizeObserverElement:S,onTabActivation:w,setHighlightedTabIndex:m,tabsListElement:h}),[n,p,x,S,w,m,h]);return(0,G.jsx)(iw.Provider,{value:D,children:(0,G.jsx)(GC,{render:a,className:r,state:T,refs:[t,g],props:[E,o],stateAttributesMapping:nw,highlightedIndex:p,enableHomeAndEndKeys:!0,loopFocus:i,orientation:l,onHighlightedIndexChange:m,onMapChange:d,disabledIndices:Ce})})});function dw(e,t){let{left:n,top:r}=e.getBoundingClientRect(),{left:i,top:a}=t.getBoundingClientRect();return{left:n-i,top:r-a}}function fw(e,t,n,r){let[i,a]=W.useState(null);return Ae(()=>{if(e==null||n==null){a(null);return}let i=r(e);if(i==null){a(null);return}let{left:o,top:s}=dw(i,n);a(t===`horizontal`?o:s)},[t,r,n,e]),W.useCallback(o=>{if(o===e)return`none`;if(o==null)return a(null),`none`;if(o!=null&&n!=null){let e=r(o);if(e!=null){let{left:r,top:o}=dw(e,n);if(i==null)return a(t===`horizontal`?r:o),`none`;if(t===`horizontal`){if(r<i)return a(r),`left`;if(r>i)return a(r),`right`}else if(o<i)return a(o),`up`;else if(o>i)return a(o),`down`}}return`none`},[r,t,i,n,e])}var pw=r(c(),1);function mw({className:e,orientation:t=`horizontal`,...n}){return(0,G.jsx)(rw,{"data-slot":`tabs`,"data-orientation":t,className:d(`group/tabs flex gap-2 data-horizontal:flex-col`,e),...n})}var hw=ke(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function gw({className:e,variant:t=`default`,...n}){return(0,G.jsx)(uw,{"data-slot":`tabs-list`,"data-variant":t,className:d(hw({variant:t}),e),...n})}function _w({className:e,...t}){return(0,G.jsx)(ow,{"data-slot":`tabs-trigger`,className:d(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent`,`data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100`,e),...t})}function vw({className:e,...t}){return(0,G.jsx)(lw,{"data-slot":`tabs-content`,className:d(`flex-1 text-sm outline-none`,e),...t})}function yw({userName:e,value:t,onChange:n,onSubmit:r,disabled:i=!1,placeholder:a=`Reply…`,submitLabel:o=`Send reply`}){let[s,c]=(0,W.useState)(!1),l=(0,W.useRef)(null),u=s||t.length>0;(0,W.useEffect)(()=>{s&&l.current?.focus()},[s]),(0,W.useEffect)(()=>{let e=l.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,128)}px`)},[t,u]);let d=()=>{n(``),c(!1)},f=()=>{t.trim()&&!i&&(r(),c(!1))};return u?(0,G.jsx)(`form`,{onSubmit:e=>{e.preventDefault(),f()},className:`shrink-0 border-t border-border p-3`,children:(0,G.jsxs)(`div`,{className:`flex items-end gap-1.5 rounded-lg border border-primary/60 bg-background px-2.5 py-1.5 ring-2 ring-primary/20`,children:[(0,G.jsx)(`textarea`,{"data-comment-draft":!0,ref:l,rows:1,maxLength:4e3,value:t,disabled:i,"aria-label":o,placeholder:a,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),f())},className:`min-h-6 max-h-32 flex-1 resize-none bg-transparent py-0.5 text-sm outline-none placeholder:text-muted-foreground`}),(0,G.jsx)(U,{type:`button`,variant:`secondary`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Cancel reply`,onClick:d,disabled:i,children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-3.5`})}),(0,G.jsx)(U,{type:`submit`,size:`icon-xs`,className:`rounded-full`,"aria-label":o,disabled:!t.trim()||i,children:(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-3.5`})})]})}):(0,G.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`flex w-full shrink-0 items-center gap-2.5 border-t border-border px-4 py-2.5 text-left text-sm text-muted-foreground transition-colors hover:bg-muted/50`,children:[(0,G.jsx)(_n,{name:e,className:`size-7`}),a]})}function bw(e,t=144){e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,t)}px`}function xw({value:e,onChange:t,className:n,...r}){let i=(0,W.useRef)(null);return(0,W.useEffect)(()=>{i.current&&bw(i.current)},[e]),(0,G.jsx)(Bi,{"data-comment-draft":!0,...r,ref:i,rows:1,value:e,onChange:e=>{t(e.target.value),bw(e.currentTarget)},maxLength:4e3,className:n})}function Sw({id:e,value:t,onChange:n,onSubmit:r,placeholder:i,disabled:a,submitLabel:o}){return(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border p-3`,children:(0,G.jsxs)(`form`,{onSubmit:r,className:`relative`,children:[(0,G.jsx)(`label`,{htmlFor:e,className:`sr-only`,children:o}),(0,G.jsx)(xw,{id:e,value:t,onChange:n,placeholder:i,className:`min-h-11! max-h-36 resize-none overflow-y-auto rounded-2xl bg-muted/40 px-3 py-2 pr-12 shadow-none`,required:!0}),(0,G.jsx)(U,{type:`submit`,size:`icon`,className:`absolute right-1 bottom-1 size-9 rounded-full`,"aria-label":o,disabled:!t.trim()||a,children:(0,G.jsx)(Io,{"aria-hidden":`true`})})]})})}function Cw(e,t){let n=new URLSearchParams;for(let[e,r]of Object.entries(t))r&&n.set(e,r);let r=n.toString();return r?`${e}?${r}`:e}async function ww(e,t){let n=await Si(e,t),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error||`The request could not be completed.`);return r}function Tw({message:e,canEdit:t,canDelete:n=t,editing:r,editDraft:i,editOriginalBody:a,disabled:o,onEdit:s,onDelete:c,onEditDraftChange:l,onCancelEdit:u,onSaveEdit:d}){let f=e.body!==a;return(0,G.jsxs)(`div`,{className:`group/message relative flex gap-2.5 rounded-md px-1.5 py-1.5 hover:bg-muted/40 focus-within:bg-muted/40`,children:[(0,G.jsx)(_n,{name:e.authorName,className:`mt-0.5 size-7`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:e.authorName}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:Fw(e.createdAt),children:ln(e.createdAt)})]}),r&&t?(0,G.jsxs)(`form`,{onSubmit:d,className:`mt-1 flex flex-col gap-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-end gap-1.5 rounded-lg border border-primary/60 bg-background px-2.5 py-1.5 ring-2 ring-primary/20`,children:[(0,G.jsx)(xw,{autoFocus:!0,onFocus:e=>{let t=e.currentTarget.value.length;e.currentTarget.setSelectionRange(t,t)},"aria-label":`Edit your message`,value:i,onChange:l,className:`min-h-6! max-h-32 flex-1 resize-none overflow-y-auto border-0 bg-transparent p-0 py-0.5 text-sm shadow-none focus-visible:ring-0`,disabled:o}),(0,G.jsx)(U,{type:`button`,variant:`secondary`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Cancel edit`,onClick:u,disabled:o,children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-3.5`})}),(0,G.jsx)(U,{type:`submit`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Save message`,disabled:o||!i.trim()||f,children:(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-3.5`})})]}),f&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:`This message changed. Cancel and edit the latest version.`})]}):(0,G.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-sm`,children:e.body})]}),t&&!r&&(0,G.jsxs)(`div`,{className:`absolute -top-3 right-1 z-10 hidden rounded-md border bg-popover shadow-sm group-hover/message:flex group-focus-within/message:flex [@media(hover:none)]:flex`,children:[(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Edit message`,onClick:s,children:(0,G.jsx)(ar,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,children:`Edit`})]}),n&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`text-destructive hover:text-destructive`,"aria-label":`Delete message`,onClick:c,children:(0,G.jsx)($r,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,children:`Delete`})]})]})]})}function Ew(e,t){let n=e.featureType??e.feature_type??t?.featureType,r=e.anchorType??e.anchor_type??t?.anchorType;if(![`diagram`,`note`,`drawing`,`flowchart`].includes(String(n))||r!=null&&![`general`,`table`,`relationship`,`block`,`shape`,`point`].includes(String(r)))return null;let i=e.fileId??e.file_id??t?.fileId;return i==null?null:{featureType:n,fileId:String(i),fileName:e.fileName==null&&e.file_name==null?t?.fileName??null:String(e.fileName??e.file_name),anchorType:r??`general`,anchorId:e.anchorId==null&&e.anchor_id==null&&t?.anchorId==null?null:String(e.anchorId??e.anchor_id??t?.anchorId),anchorLabel:String(e.anchorLabel??e.anchor_label??t?.anchorLabel??`General`)}}function Dw(e){let t=Array.isArray(e.contexts)?e.contexts.map(e=>Ew(e)).filter(Boolean):[],n=Ew(e,t[0])||t[0]||null,r=e.anchorType??e.anchor_type,i=[`general`,`table`,`relationship`,`block`,`shape`,`point`].includes(String(r))?r:`general`,a=e.status,o=e.previewMessages??e.preview_messages,s=Array.isArray(o)?o.map(e=>Ow(e)):typeof o==`string`?(()=>{try{let e=JSON.parse(o);return Array.isArray(e)?e.map(e=>Ow(e)):[]}catch{return[]}})():[],c=e.latestMessage==null&&e.latest_message==null?null:{id:String(e.latestMessageId??e.latest_message_id??`latest`),authorId:String(e.latestAuthorId??e.latest_author_id??``),authorName:`Team member`,body:String(e.latestMessage??e.latest_message??``),createdAt:String(e.lastMessageAt??e.last_message_at??``)};return{id:String(e.id??``),featureType:n?.featureType??null,fileId:n?.fileId??(e.fileId==null&&e.file_id==null?null:String(e.fileId??e.file_id)),anchorType:n?.anchorType??i,anchorId:n?.anchorId??(e.anchorId==null&&e.anchor_id==null?null:String(e.anchorId??e.anchor_id)),anchorLabel:n?.anchorLabel??String(e.anchorLabel??e.anchor_label??`General`),contexts:t.length>0?t:n?[n]:[],status:a===`resolved`?`resolved`:`open`,canDelete:!!(e.canDelete??e.can_delete),unread:!!e.unread,latestMessageId:e.latestMessageId==null&&e.latest_message_id==null?null:String(e.latestMessageId??e.latest_message_id),latestMessage:e.latestMessage==null&&e.latest_message==null?null:String(e.latestMessage??e.latest_message),latestAuthorId:e.latestAuthorId==null&&e.latest_author_id==null?null:String(e.latestAuthorId??e.latest_author_id),lastMessageAt:e.lastMessageAt==null&&e.last_message_at==null?null:String(e.lastMessageAt??e.last_message_at),previewMessages:s.length>0?s:c?[c]:[]}}function Ow(e){return{id:String(e.id??``),threadId:e.threadId==null&&e.thread_id==null?void 0:String(e.threadId??e.thread_id),authorId:String(e.authorId??e.author_id??``),authorName:String(e.authorName??e.author_name??`Team member`),body:String(e.body??``),createdAt:String(e.createdAt??e.created_at??``)}}function kw(e){let t=e.nextCursor;return{hasMore:e.hasMore===!0,nextCursor:t?.createdAt&&t.id?{createdAt:String(t.createdAt),id:String(t.id)}:null}}function Aw(e,t){let n=new Map(e.map(e=>[e.id,e]));for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>Date.parse(e.createdAt)-Date.parse(t.createdAt)||e.id.localeCompare(t.id))}function jw(e,t,n){let r=Aw(e.messages,t).slice(-Math.max(50,e.messages.length)),i=r[0],a=e.hasMore||n.hasMore;return{messages:r,hasMore:a,nextCursor:a&&i?{createdAt:i.createdAt,id:i.id}:null}}function Mw(e,t,n,r){return e===`thread`?t===`comments`&&n?{kind:`anchor`,anchor:n,threadId:r}:r?{kind:`thread`,threadId:r}:null:null}function Nw(e){return[e.featureType||`diagram`,e.fileId||``,e.anchorType,e.anchorId||``].join(`:`)}function Pw(e){let t=new Map;for(let n of e){let e=Nw(n),r=t.get(e);r?(r.threads.push(n),r.previewMessages.push(...n.previewMessages)):t.set(e,{key:e,representative:n,threads:[n],previewMessages:[...n.previewMessages]})}return[...t.values()].map(e=>({...e,previewMessages:e.previewMessages.sort((e,t)=>new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime()).slice(-3)}))}function Fw(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}function Iw(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:Pn(t,{addSuffix:!0})}function Lw(e){return e===`diagram`?`ERD`:e===`note`?`Notes`:e===`drawing`?`Drawing`:e===`flowchart`?`Flowchart`:`File`}var Rw={diagram:{Icon:Cr,className:`bg-feature-erd/10 text-feature-erd`},note:{Icon:de,className:`bg-feature-notes/10 text-feature-notes`},drawing:{Icon:wr,className:`bg-feature-drawing/10 text-feature-drawing`},flowchart:{Icon:Sr,className:`bg-feature-flowchart/10 text-feature-flowchart`}},zw={diagram:new Set([`table`,`relationship`]),note:new Set([`block`]),drawing:new Set([`point`]),flowchart:new Set([`shape`])};function Bw(e,t){return typeof t==`string`&&zw[e].has(t)}function Vw({projectId:e,teamId:t,userId:n,userName:r,fileContext:i,anchorContext:a,onContextSelected:o,anchorPreview:s,readOnly:c=!1}){let u=ie(),f=(0,W.useId)(),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(`discussions`),_=h===`comments`,[v,y]=(0,W.useState)(`file`),[b,x]=(0,W.useState)(`list`),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)([]),[E,D]=(0,W.useState)(0),[O,k]=(0,W.useState)({messages:[],hasMore:!1,nextCursor:null}),[A,j]=(0,W.useState)(!1),[M,N]=(0,W.useState)(``),[P,F]=(0,W.useState)(!0),[I,L]=(0,W.useState)(!1),[R,ee]=(0,W.useState)(``),[te,ne]=(0,W.useState)(``),[re,z]=(0,W.useState)(null),[ae,oe]=(0,W.useState)(``),[se,ce]=(0,W.useState)(``),[le,ue]=(0,W.useState)(null),[de,B]=(0,W.useState)(!1),[fe,pe]=(0,W.useState)(``),[me,he]=(0,W.useState)(null),[ge,_e]=(0,W.useState)(null),[ve,V]=(0,W.useState)(null),H=O.messages,ye=(0,W.useRef)(0),be=(0,W.useRef)(0),xe=(0,W.useRef)(0),Se=(0,W.useRef)(new Map),Ce=(0,W.useRef)(!1),we=(0,W.useRef)({screen:b,selectedThreadId:S});we.current={screen:b,selectedThreadId:S};let Te=(0,W.useCallback)(()=>{we.current={screen:`list`,selectedThreadId:null},be.current++,xe.current++,x(`list`),C(null),k({messages:[],hasMore:!1,nextCursor:null}),j(!1),N(``),ne(``),z(null),oe(``),ce(``),ue(null),V(null)},[]),Ee=(0,W.useCallback)(e=>{let t=e;t!==h&&(Te(),he(null),pe(``),g(t))},[h,Te]),De=`/api/projects/${encodeURIComponent(e)}/${h===`comments`?`comments`:`discussions`}`,Oe=(0,W.useMemo)(()=>Cw(De,{scope:h===`discussions`?v:void 0,feature_type:i.featureType,file_id:i.fileId,anchor_type:h===`comments`&&!_&&a?a.type:void 0,anchor_id:h===`comments`&&!_&&a?a.id:void 0}),[h,a,v,De,i.featureType,i.fileId,_]),ke=(0,W.useCallback)(e=>Cw(`${De}/${encodeURIComponent(e)}`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),[h,De,i.featureType,i.fileId]),Ae=(0,W.useCallback)(async(e=!1)=>{let t=++ye.current;ee(``),Ce.current||F(!0);try{let r=await ww(Oe);if(t!==ye.current)return[];let i=Array.isArray(r.threads)?r.threads.map(e=>Dw(e)):[];if(e&&Ce.current)for(let e of i){let t=Se.current.get(e.id);e.latestMessageId&&e.latestAuthorId!==n&&(t&&e.latestMessageId!==t||!t&&e.unread)&&l.info(`New activity in ${e.contexts[0]?.fileName||`Project discussion`}`)}Se.current=new Map(i.filter(e=>e.latestMessageId).map(e=>[e.id,e.latestMessageId])),Ce.current=!0,T(i);let a=we.current;return a.screen===`thread`&&a.selectedThreadId&&!i.some(e=>e.id===a.selectedThreadId)&&Te(),D(Number(r.unreadCount??r.unread_count)||0),i}catch{return t===ye.current&&ee(`Couldn't load ${h}. Try again.`),[]}finally{t===ye.current&&F(!1)}},[h,Te,Oe,n]),je=(0,W.useCallback)(e=>{o?.({featureType:i.featureType,fileId:i.fileId,anchorType:e.type,anchorId:e.id,anchorLabel:e.type===`table`?`Table`:e.type===`relationship`?`Relationship`:e.type[0].toUpperCase()+e.type.slice(1)})},[i.featureType,i.fileId,o]),Me=(0,W.useCallback)(async(e,t,n=!1)=>{let r=++be.current;n||ne(``);try{let a=await ww(ke(e));if(r!==be.current)return!1;let s=Array.isArray(a.messages)?a.messages.map(e=>Ow(e)):[],c=kw(a);k(e=>n?jw(e,s,c):{...c,messages:s}),n||N(``),t&&ww(Cw(`${ke(e)}/read`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`POST`}).then(()=>Ae()).catch(()=>{});let l=Array.isArray(a.contexts)?a.contexts.map(e=>Ew(e)).filter(Boolean):[];return l[0]&&o?.(l[0]),!0}catch{return!n&&r===be.current&&ne(`Couldn't load this ${h===`comments`?`comment`:`discussion`}. Try again.`),!1}},[h,i.fileId,i.featureType,Ae,o,ke]),Ne=(0,W.useCallback)(async(e,t,n=!1,r)=>{let a=++be.current;n||ne(``);try{let s=await ww(Cw(`${De}/anchor`,{feature_type:i.featureType,file_id:i.fileId,anchor_type:e.type,anchor_id:e.id}));if(a!==be.current)return!1;let c=Array.isArray(s.threads)?s.threads.map(e=>Dw(e)):[];if(!c.length)return Te(),!0;let l=Array.isArray(s.messages)?s.messages.map(e=>Ow(e)):[];T(e=>{let t=new Map(c.map(e=>[e.id,e]));return e.map(e=>{let n=t.get(e.id);return n?{...e,...n}:e})});let u=kw(s);k(e=>n?jw(e,l,u):{...u,messages:l}),n||N(``);let d=c.some(e=>e.id===r)?r:c[0].id;C(d);let f=Array.isArray(s.contexts)?s.contexts.map(e=>Ew(e)).filter(Boolean):[];return f[0]?o?.(f[0]):je(e),t&&Promise.all(c.map(e=>ww(Cw(`${De}/${encodeURIComponent(e.id)}/read`,{feature_type:i.featureType,file_id:i.fileId}),{method:`POST`}).catch(()=>null))).then(()=>Ae()),!0}catch{return!n&&a===be.current&&ne(`Couldn't load the full comment history. Try again.`),!1}},[Te,De,i.fileId,i.featureType,je,Ae,o]),Pe=(0,W.useCallback)(e=>{if(!p)return;let t=Mw(b,h,ve,S);t&&(t.kind===`anchor`?Ne(t.anchor,e,!0,t.threadId||void 0):Me(t.threadId,e,!0))},[ve,h,Ne,Me,p,b,S]),Fe=(0,W.useCallback)(async()=>{let e=O.nextCursor,t=S;if(!O.hasMore||!e||!t||A)return;let n=++xe.current,r=be.current;j(!0),N(``);try{let a={before_created_at:e.createdAt,before_id:e.id},o=await ww(_&&ve?Cw(`${De}/anchor`,{feature_type:i.featureType,file_id:i.fileId,anchor_type:ve.type,anchor_id:ve.id,...a}):Cw(ke(t),a));if(n!==xe.current||r!==be.current)return;let s=Array.isArray(o.messages)?o.messages.map(e=>Ow(e)):[],c=kw(o);k(e=>({...c,messages:Aw(e.messages,s)}))}catch{n===xe.current&&N(`Could not load earlier messages.`)}finally{n===xe.current&&j(!1)}},[ve,De,i.featureType,i.fileId,_,A,O,S,ke]);(0,W.useEffect)(()=>{Ce.current=!1,x(`list`),C(null),k({messages:[],hasMore:!1,nextCursor:null}),T([]),Ae()},[Ae]),(0,W.useEffect)(()=>{let n=e=>{let n=e.detail;n?.teamId!==t||n.eventType&&n.eventType!==`cloud.workspace.sync`||(Ae(!0),Pe(document.visibilityState===`visible`))},r=e=>{e.detail?.teamId===t&&(Ae(),Pe(document.visibilityState===`visible`))},i=n=>{let r=n.detail;r?.teamId===t&&String(r.projectId)===String(e)&&Ae(!0)};return window.addEventListener(`cloud-workspace-sync`,n),window.addEventListener(`cloud-live-sync-reconnected`,r),window.addEventListener(`collaboration-updated`,i),()=>{window.removeEventListener(`cloud-workspace-sync`,n),window.removeEventListener(`cloud-live-sync-reconnected`,r),window.removeEventListener(`collaboration-updated`,i)}},[Ae,e,Pe,t]),(0,W.useEffect)(()=>{if(!p)return;let e=window.setInterval(()=>{Ae(!0),document.hidden||Pe(!0)},15e3);return()=>window.clearInterval(e)},[Ae,p,Pe]),(0,W.useEffect)(()=>{let e=e=>{let t=e.detail;!t?.id||t.featureType!==i.featureType||t.fileId&&String(t.fileId)!==i.fileId||!Bw(i.featureType,t.type)||(he({type:t.type,id:t.id}),pe(``),ne(``),g(`comments`),m(!0))};return window.addEventListener(`project-comment-open-request`,e),()=>window.removeEventListener(`project-comment-open-request`,e)},[i.fileId,i.featureType]),(0,W.useEffect)(()=>{if(h!==`comments`||!me)return;let e=!1,t=me;return V(t),_e(t),(async()=>{let n=await Ae();if(e)return;let r=Pw(n).find(e=>e.representative.anchorType===t.type&&e.representative.anchorId===t.id);r?(x(`thread`),C(r.representative.id),await Ne(t,!0,!1,r.representative.id)):x(c?`list`:`compose`),e||he(null)})(),()=>{e=!0}},[h,Ne,Ae,me]);let Ie=(b===`thread`||b===`compose`)&&fe.trim()!==``||re!==null&&ae!==se,Le=(e,t)=>{if(!e&&(le||de))return;let n=t?.event?.target;!e&&u&&t?.reason===`outside-press`&&n instanceof Element&&!u.host.current?.contains(n)||!e&&t?.reason===`outside-press`&&n instanceof Element&&n.closest(`[data-slot="dropdown-menu-content"]`)||(!e&&Ie?B(!0):(m(e),e?(Ae(),b===`thread`&&_&&ve?Ne(ve,!0,!1,S||void 0):b===`thread`&&S&&Me(S,!0)):(qe(),ue(null))))},Re=async e=>{pe(``),qe(),ue(null);let t=e.contexts[0]||Ew(e),n=t?.anchorType??e.anchorType,r=t?.anchorId??e.anchorId,a=t?.featureType??e.featureType??i.featureType,s=r&&Bw(a,n)?{type:n,id:r}:null;_&&s?(V(s),x(`thread`),C(e.id),k({messages:[],hasMore:!1,nextCursor:null}),je(s),await Ne(s,!0,!1,e.id)):(x(`thread`),C(e.id),k({messages:[],hasMore:!1,nextCursor:null}),await Me(e.id,!0)&&t&&o?.(t))},ze=async e=>{let t=e.representative.featureType??i.featureType;e.representative.anchorType&&e.representative.anchorId&&Bw(t,e.representative.anchorType)&&{type:e.representative.anchorType,id:e.representative.anchorId}&&await Re(e.representative)},Be=()=>{let e=h===`comments`?(_?ve:a)??null:null;h===`comments`&&!e?l.info(`Select an item on this file before adding a comment.`):(_e(e),pe(``),ne(``),qe(),x(`compose`))},Ve=()=>window.dispatchEvent(new CustomEvent(`collaboration-updated`,{detail:{teamId:t,projectId:e}})),He=async e=>{e.preventDefault();let t=fe.trim();if(t&&!I){L(!0),ne(``);try{let e=await ww(De,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:t,context:{type:h===`comments`?ge?.type:`general`,...h===`comments`?{id:ge?.id}:{},featureType:i.featureType,fileId:i.fileId}})});pe(``),_e(null),C(e.id),x(`thread`),Ve(),await Ae(),_&&ge?await Ne(ge,!0,!1,e.id):await Me(e.id,!0)}catch{ne(`Couldn't start the ${h===`comments`?`comment`:`discussion`}. Try again.`)}finally{L(!1)}}},Ue=async()=>{let e=fe.trim();if(e&&S&&!I){L(!0),ne(``);try{await ww(Cw(`${De}/${encodeURIComponent(S)}/messages`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:e})}),pe(``),Ve(),_&&ve?await Ne(ve,!0,!0,S):await Me(S,!0,!0),await Ae()}catch{ne(`Couldn't send the reply. Reopen the ${h===`comments`?`comment`:`discussion`} if it was resolved.`)}finally{L(!1)}}},We=_?{feature_type:i.featureType,file_id:i.fileId}:{},Ge=e=>_&&ve?Ne(ve,!0,!0,e):Me(e,!0,!0),Ke=e=>{e.authorId===n&&(z(e.id),oe(e.body),ce(e.body))},qe=()=>{z(null),oe(``),ce(``)},Je=async(e,t)=>{t.preventDefault();let r=ae.trim(),i=S;if(e.authorId===n&&i&&r&&e.body===se&&!I){L(!0);try{await ww(Cw(`${De}/${encodeURIComponent(i)}/messages/${encodeURIComponent(e.id)}`,We),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:r,expectedBody:se})}),k(t=>({...t,messages:t.messages.map(t=>t.id===e.id?{...t,body:r}:t)})),qe(),Ve()}catch(e){await Ge(i),l.error(e instanceof Error?e.message:`Couldn't update this message. Try again.`)}finally{L(!1)}}},Ye=async e=>{let t=w.find(t=>t.id===e);if(t?.canDelete&&!I){L(!0);try{await ww(Cw(`${De}/${encodeURIComponent(t.id)}`,We),{method:`DELETE`}),ue(null),S===e&&Te(),Ve(),_&&await Ae()}catch(e){l.error(e instanceof Error?e.message:`Couldn't delete this ${_?`comment`:`discussion`}. Try again.`)}finally{L(!1)}}},Xe=async(e,t)=>{if(!(h!==`discussions`||S!==e||t.authorId!==n||I)){L(!0);try{await ww(`${De}/${encodeURIComponent(e)}/messages/${encodeURIComponent(t.id)}`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({expectedBody:t.body})}),k(e=>({...e,messages:e.messages.filter(e=>e.id!==t.id)})),re===t.id&&qe(),ue(null),await Ae(),Ve()}catch(t){await Me(e,!0,!0),l.error(t instanceof Error?t.message:`Couldn't delete this message. Try again.`)}finally{L(!1)}}},Ze=async()=>{let e=w.find(e=>e.id===S);if(!e||I)return;L(!0);let t=e.status;try{await ww(Cw(`${De}/${encodeURIComponent(e.id)}`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({status:t===`open`?`resolved`:`open`,expectedStatus:t})}),Ve(),await Ae()}catch(e){ne(e instanceof Error?e.message:`Couldn't update this ${h===`comments`?`comment`:`discussion`}. Try again.`),await Ae()}finally{L(!1)}},Qe=w.find(e=>e.id===S),$e=(0,W.useMemo)(()=>Pw(w),[w]),et=h===`discussions`?`Discussions`:b===`compose`?`New comment`:b===`thread`?Qe?.anchorLabel||`Comment`:`Comments`,tt=b===`list`?v===`file`?i.label:null:b===`compose`?i.label:Qe?.contexts[0]?.fileName||(Qe?.fileId===i.fileId?i.label:null),nt=h===`comments`?_?`Latest activity on ${i.label}`:`Comments on ${i.label}`:tt?`Related to ${tt}`:b===`list`?`All project discussions`:`Project discussion`,rt=`${f}-description`;return(0,G.jsxs)(Pt,{open:p,onOpenChange:Le,children:[(0,G.jsx)(Mt,{render:(0,G.jsxs)(U,{type:`button`,variant:`ghost`,size:`icon`,className:`relative shrink-0 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`${_?`Open comments`:`Open discussions`}${E?`, ${E} unread`:``}`,title:_?`Comments`:`Discussions`,children:[_?(0,G.jsx)(qn,{"aria-hidden":`true`}):(0,G.jsx)(Eo,{"aria-hidden":`true`}),E>0&&(0,G.jsx)(Vh,{variant:`default`,className:`absolute -right-1 -top-1 h-4 min-w-4 px-1 text-[10px] leading-none`,children:E})]})}),(0,G.jsxs)(At,{anchor:u?()=>{let e=u.host.current;return e?{contextElement:e,getBoundingClientRect:()=>{let t=e.getBoundingClientRect();return new DOMRect(t.right-8,t.top+8,0,0)}}:null}:void 0,side:u?`bottom`:`left`,align:u?`end`:`start`,sideOffset:8,"data-discussions-panel":``,className:d(`flex h-[min(42rem,calc(100svh-5rem))] w-[min(24rem,calc(100vw-1rem))] max-w-[calc(100vw-1rem)] flex-col gap-0 overflow-hidden p-0`,u&&`max-h-(--available-height)`),"aria-describedby":rt,children:[(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b!==`list`&&(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Back to list`,onClick:()=>x(`list`),children:(0,G.jsx)(sr,{"aria-hidden":`true`,className:`size-4`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`h2`,{className:`truncate text-sm font-semibold`,children:et}),(0,G.jsx)(`p`,{id:rt,className:`truncate text-xs text-muted-foreground`,children:nt})]}),h===`discussions`&&b===`thread`&&Qe&&!c&&(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Discussion actions`,children:(0,G.jsx)(Tr,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(Gt,{align:`end`,className:`w-44`,positionerClassName:`z-[210]`,children:(0,G.jsxs)(Vt,{children:[(0,G.jsxs)(It,{onClick:()=>void Ze(),disabled:I,children:[Qe.status===`open`?(0,G.jsx)(Yt,{"aria-hidden":`true`}):(0,G.jsx)(zn,{"aria-hidden":`true`}),Qe.status===`open`?`Resolve`:`Reopen`]}),Qe.canDelete&&(0,G.jsxs)(It,{variant:`destructive`,onClick:()=>ue({type:`thread`,threadId:Qe.id}),children:[(0,G.jsx)($r,{"aria-hidden":`true`}),`Delete Thread`]})]})})]}),(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${h}`,onClick:()=>Le(!1),children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-4`})})]})}),(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-2`,children:(0,G.jsx)(mw,{value:h,onValueChange:Ee,className:`w-full`,children:(0,G.jsxs)(gw,{className:`mx-auto`,children:[(0,G.jsx)(_w,{value:`discussions`,children:`Discussions`}),(0,G.jsx)(_w,{value:`comments`,children:`Comments`})]})})}),b===`list`&&(0,G.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden`,children:[h===`discussions`?(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-2`,children:(0,G.jsx)(mw,{value:v,onValueChange:e=>y(e),className:`w-full`,children:(0,G.jsxs)(gw,{className:`mx-auto`,children:[(0,G.jsx)(_w,{value:`file`,children:`This File`}),(0,G.jsx)(_w,{value:`project`,children:`All Project`})]})})}):_?(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-1.5 text-[11px] text-muted-foreground`,children:`Latest messages. Open a card for the full history.`}):(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-4 py-2 text-xs text-muted-foreground`,children:a?`Selected ${a.type}`:`Select a table or relationship to add a comment.`}),(0,G.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-24`,children:[P&&(0,G.jsxs)(`p`,{role:`status`,className:`px-4 py-5 text-center text-sm text-muted-foreground`,children:[`Loading `,h,`…`]}),!P&&R&&(0,G.jsxs)(`div`,{className:`m-4 rounded-lg border border-destructive/40 p-4 text-sm`,children:[(0,G.jsx)(`p`,{children:R}),(0,G.jsx)(U,{variant:`outline`,className:`mt-3 min-h-11`,onClick:()=>void Ae(),children:`Retry`})]}),!P&&!R&&(_?$e.length:w.length)===0&&(0,G.jsxs)(`div`,{className:`mx-4 mt-4 rounded-lg border border-dashed border-border px-4 py-8 text-center`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:h===`comments`?`No comments on this file yet.`:`No discussions in this view yet.`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:c?`You can read threads here, but only members with comment access can start one.`:h===`comments`?`Use the node context menu to start one.`:`Start a thread to capture a question or design decision.`})]}),!R&&_&&$e.map(e=>{let t=e.representative,n=e.previewMessages[e.previewMessages.length-1],r=t.anchorId?s?.(t.anchorId):void 0,i=n?.authorName||`Team member`;return(0,G.jsxs)(`button`,{type:`button`,className:d(`w-full border-b border-border/70 px-3 py-2 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,t.unread&&`bg-primary/5`),onClick:()=>void ze(e),children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`relative shrink-0`,children:[(0,G.jsx)(_n,{name:i}),t.unread&&(0,G.jsx)(`span`,{role:`img`,"aria-label":`New activity`,className:`absolute -right-0.5 -top-0.5 size-2 rounded-full bg-primary ring-2 ring-popover`})]}),(0,G.jsx)(`span`,{className:`min-w-0 truncate text-xs font-semibold`,children:i}),t.status===`resolved`&&(0,G.jsx)(Rn,{role:`img`,"aria-label":`Resolved`,className:`size-3.5 shrink-0 text-emerald-500`}),(0,G.jsx)(`span`,{className:`ml-auto shrink-0 text-[11px] text-muted-foreground`,children:ln(t.lastMessageAt??``)})]}),(0,G.jsxs)(`span`,{className:`mt-1 block space-y-0.5 pl-8`,children:[r?(0,G.jsx)(`span`,{className:`line-clamp-2 border-l-2 border-yellow-500/70 pl-2 text-xs leading-snug text-muted-foreground`,children:r.length>50?`${r.slice(0,50).trimEnd()}…`:r}):(0,G.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:r===null?`Deleted block`:t.anchorLabel||`Comment`}),n&&(0,G.jsx)(`span`,{className:`block truncate text-xs`,children:n.body})]})]},e.key)}),!R&&!_&&w.map(e=>{let t=e.featureType?Rw[e.featureType]:null,n=t?.Icon??Eo,r=e.contexts[0]?.fileName||(e.fileId===i.fileId?i.label:`Project discussion`);return(0,G.jsxs)(`button`,{type:`button`,className:d(`flex min-h-18 w-full items-center gap-3 border-b border-border/70 px-4 py-3 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,e.unread&&`bg-primary/5`),onClick:()=>void Re(e),children:[(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:d(`relative flex size-10 shrink-0 items-center justify-center rounded-full`,t?.className??`bg-muted text-muted-foreground`),children:[(0,G.jsx)(n,{}),e.unread&&(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`absolute right-0.5 top-0.5 size-2 rounded-full bg-primary ring-2 ring-popover`})]}),(0,G.jsxs)(`span`,{className:`sr-only`,children:[Lw(e.featureType),` file`]}),(0,G.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-sm`,e.unread?`font-semibold text-foreground`:`font-medium`),children:r}),(0,G.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:Iw(e.lastMessageAt)})]}),(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-sm`,e.unread?`text-foreground`:`text-muted-foreground`),children:e.latestMessage||``}),e.status===`resolved`&&(0,G.jsxs)(Vh,{variant:`outline`,className:`shrink-0 gap-1 font-normal text-muted-foreground`,children:[(0,G.jsx)(Rn,{"aria-hidden":`true`}),`Resolved`]})]}),e.unread&&(0,G.jsx)(`span`,{className:`sr-only`,children:`New activity`})]})]},e.id)})]}),!c&&(0,G.jsx)(Ft,{delay:250,children:(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,size:`icon-lg`,className:`absolute bottom-4 right-4 z-10 min-h-11 min-w-11 rounded-full shadow-lg`,"aria-label":h===`comments`?`Add a comment`:`Start a discussion`,onClick:Be,children:(0,G.jsx)(jt,{"aria-hidden":`true`})})}),(0,G.jsx)(kt,{side:`left`,children:h===`comments`?`Add a comment`:`Start a discussion`})]})})]}),b===`compose`&&(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4`,children:[h===`comments`&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/30 p-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:`Context`}),(0,G.jsx)(`p`,{className:`mt-1 font-medium`,children:`${ge?.type||`node`} · ${i.label}`})]}),te&&(0,G.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:te})]}),(0,G.jsx)(Sw,{id:`${f}-composer`,value:fe,onChange:pe,onSubmit:He,placeholder:h===`comments`?`Write a comment...`:`Write a question or design decision...`,disabled:I,submitLabel:I?`Sending…`:h===`comments`?`Add comment`:`Start discussion`})]}),b===`thread`&&Qe&&(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[h===`comments`&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-border px-3 py-1.5`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:(()=>{let e=Qe.anchorId&&(_||Qe.fileId===i.fileId)?s?.(Qe.anchorId):void 0;return e===null?(0,G.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[`Deleted block · `,Lw(Qe.featureType??`note`)]}):e?(0,G.jsx)(`p`,{className:`line-clamp-2 border-l-2 border-yellow-500/70 pl-2 text-xs leading-snug text-muted-foreground`,children:e}):(0,G.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[Qe.anchorType===`general`?`General`:Qe.anchorType,Qe.featureType&&` · ${Lw(Qe.featureType)}`]})})()}),!c&&(0,G.jsxs)(Ft,{delay:250,children:[(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`shrink-0`,"aria-label":Qe.status===`open`?`Resolve`:`Reopen`,onClick:()=>void Ze(),disabled:I,children:Qe.status===`open`?(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-4`}):(0,G.jsx)(zn,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(kt,{side:`left`,children:Qe.status===`open`?`Resolve`:`Reopen`})]}),Qe.canDelete&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`shrink-0 text-destructive hover:text-destructive`,"aria-label":`Delete thread`,onClick:()=>ue({type:`thread`,threadId:Qe.id}),disabled:I,children:(0,G.jsx)($r,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(kt,{side:`left`,children:`Delete thread`})]})]})]}),te&&(0,G.jsxs)(`div`,{className:`m-4 rounded-lg border border-destructive/40 p-4 text-sm`,role:`alert`,children:[(0,G.jsx)(`p`,{children:te}),(0,G.jsx)(U,{variant:`outline`,className:`mt-3 min-h-11`,onClick:()=>void(_&&ve?Ne(ve,!0):Me(Qe.id,!0)),children:`Retry`})]}),!te&&(0,G.jsx)(Ft,{delay:250,children:(0,G.jsx)(wn,{defaultScrollPosition:`end`,children:(0,G.jsxs)(vn,{className:`flex-1`,children:[(0,G.jsx)(In,{"aria-label":`${h===`comments`?`Comment`:`Discussion`} messages`,children:(0,G.jsxs)(pn,{className:`gap-1 p-3`,children:[O.hasMore&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Fe(),disabled:A,children:A?`Loading…`:`Load earlier messages`}),M&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:M})]}),H.map(e=>(0,G.jsx)(tn,{messageId:e.id,scrollAnchor:!0,children:(0,G.jsx)(Tw,{message:e,canEdit:e.authorId===n&&!c,canDelete:!_,editing:re===e.id,editDraft:ae,editOriginalBody:se,disabled:I,onEdit:()=>Ke(e),onDelete:()=>ue({type:`message`,threadId:Qe.id,message:e}),onEditDraftChange:oe,onCancelEdit:qe,onSaveEdit:t=>{Je(e,t)}})},e.id))]})}),(0,G.jsx)(yn,{})]})},Qe.id)}),Qe.status===`open`&&!te&&!c&&(0,G.jsx)(yw,{userName:r||`You`,value:fe,onChange:pe,onSubmit:()=>void Ue(),disabled:I,submitLabel:I?`Sending…`:`Send reply`}),Qe.status===`resolved`&&!c&&(0,G.jsx)(`p`,{className:`border-t border-border px-4 py-3 text-sm text-muted-foreground`,children:`Reopen this thread to reply.`}),c&&(0,G.jsx)(`p`,{className:`border-t border-border px-4 py-3 text-sm text-muted-foreground`,children:`You can read this thread but not reply to it.`})]})]}),(0,G.jsx)(br,{isOpen:de,title:`Discard unsent changes?`,message:`You have text that hasn't been sent or saved. If you close this panel now, it will be lost.`,confirmText:`Discard`,cancelText:`Cancel`,variant:`warning`,onCancel:()=>{B(!1),window.setTimeout(()=>document.querySelector(`[data-discussions-panel] textarea`)?.focus(),150)},onConfirm:()=>{B(!1),pe(``),qe(),m(!1)}}),(0,G.jsx)(br,{isOpen:le!==null,title:le?.type===`message`?`Delete message?`:_?`Delete thread?`:`Delete discussion?`,message:le?.type===`message`?`This message will be permanently deleted.`:`This permanently deletes the ${_?`thread and all of its comments`:`discussion and all its messages`}. This action cannot be undone.`,confirmText:le?.type===`message`?`Delete message`:`Delete Thread`,cancelText:`Cancel`,variant:`danger`,onCancel:()=>ue(null),onConfirm:()=>{le?.type===`message`?Xe(le.threadId,le.message):le&&Ye(le.threadId)}})]})}function Hw({file:e,active:t,target:n,teamId:r}){let i=pa(),a=v(),o=i.activeDocument,s=o?.project_id??o?.projectId,c=i.projects.find(e=>String(e.id)===String(s)),l=c?.team_id??c?.teamId;if(!n||!o||i.isGuest||!l||String(l)!==String(r))return null;let u=e.type===`erd`?`diagram`:e.type===`notes`?`note`:e.type===`drawings`?`drawing`:`flowchart`,d=t=>{t.featureType===u&&String(t.fileId)===e.uid?u===`diagram`&&t.anchorId&&window.dispatchEvent(new CustomEvent(`erd-discussion-anchor-selected`,{detail:{fileId:e.uid,type:t.anchorType,id:t.anchorId}})):a(`/${{diagram:`diagrams`,note:`notes`,drawing:`drawings`,flowchart:`flowcharts`}[t.featureType]}/${encodeURIComponent(t.fileId)}`)},f=i.selectedEdgeId?{type:`relationship`,id:i.selectedEdgeId}:i.selectedNodeId?{type:`table`,id:i.selectedNodeId}:null;return(0,pw.createPortal)((0,G.jsx)(`span`,{hidden:!t,children:(0,G.jsx)(Vw,{projectId:String(s),teamId:String(r),fileContext:{featureType:u,fileId:e.uid,label:o.title||o.name||e.title},userId:i.user?.id?String(i.user.id):void 0,userName:i.user?.name||i.user?.email,readOnly:i.getFileAccessRole(o)===`viewer`,anchorContext:f,onContextSelected:d,anchorPreview:u===`note`?e=>Ki(o.content,e):void 0})}),n)}function Uw(){let{activeDocument:e,isReadOnlyFile:t,getFileAccessRole:n,handleDuplicate:r,isGuest:i,isPublicView:a,view:o,user:s}=pa();if(a||!e||!t(e))return null;let c=Hi(n(e),e.user?.name||e.user?.email||`another member`,Ui(e,s?.id));if(!c)return null;let l=c.indexOf(` · `),u=c.slice(0,l),d=c.slice(l+3);return(0,G.jsxs)(`div`,{role:`status`,className:`flex shrink-0 items-center gap-2 border-b bg-muted/40 px-3 py-1 text-xs text-muted-foreground`,children:[(0,G.jsx)(Ka,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:u}),` · `,d]}),!i&&(o===`notes`||o===`drawings`)&&(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`xs`,onClick:r,children:`Duplicate to edit`})]})}var Ww=(0,W.lazy)(()=>_i(()=>import(`./NoteEditorRoute-CFk0YU66.js`).then(e=>({default:e.NoteEditorRoute})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,4,1,22]))),Gw=(0,W.lazy)(()=>_i(()=>import(`./DiagramEditorRoute-pw5JFieq.js`).then(e=>({default:e.DiagramEditorRoute})),__vite__mapDeps([23,5,7,9,12,8,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54]))),Kw=(0,W.lazy)(()=>_i(()=>import(`./FlowchartEditorRoute-DdgCEBK6.js`).then(e=>({default:e.FlowchartEditorRoute})),__vite__mapDeps([55,5,7,8,9,12,13,14,15,10,16,25,28,27,26,29,30,31,32,33,34,35,36,37,38,39,40,20,56,47,50,42,11,17,18,19,21,4,1,22,52,54]))),qw=(0,W.lazy)(()=>_i(()=>import(`./DrawingEditorRoute-D0jtN-sA.js`).then(e=>({default:e.DrawingEditorRoute})),__vite__mapDeps([57,5,7,9,30,8,25,58,48,10,16,11,12,13,14,15,17,18,19,20,21,4,1,22])));function Jw({file:e,scope:t,root:n,discussionTarget:r,onUpdate:i,teamState:a}){let o=pa(),s=(0,W.useMemo)(()=>({...o,theme:n.theme,resolvedTheme:n.resolvedTheme,setTheme:n.setTheme,setIsSettingsOpen:n.setIsSettingsOpen,setSettingsTab:n.setSettingsTab}),[o,n.theme,n.resolvedTheme,n.setTheme,n.setIsSettingsOpen,n.setSettingsTab]),c=bn(),l=ta(),u=(0,W.useRef)(s),d=(0,W.useRef)(null);u.current=s;let f=(0,W.useMemo)(()=>()=>YC(u.current,t.host.current??document),[t]);return(0,W.useEffect)(()=>{i(N(e),{file:e,scope:t,workspace:s,ai:c,canvas:l,flush:f})},[e,t,s,c,l,f,i]),(0,W.useEffect)(()=>{e.previewSchema&&d.current!==e&&!s.isERDItemLoading&&s.activeDiagram&&!s.isReadOnlyFile(s.activeDiagram)&&c.applyContent(e.previewSchema,`append`,`erd-generate-sql`)&&(d.current=e)},[e.previewSchema,s.isERDItemLoading,!!s.activeDiagram,c.applyContent]),(0,G.jsxs)(ma.Provider,{value:s,children:[(0,G.jsx)(Hw,{file:e,active:t.active.current,target:r,teamId:a?.activeTeamId}),(0,G.jsx)(Uw,{}),(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{role:`status`,className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Loading editor…`}),children:(0,G.jsx)(p,{context:a})})]})}var Yw=(0,W.memo)(function({file:e,active:t,scope:n,root:r,mainAI:i,teamState:a,discussionTarget:o,onUpdate:s,onNavigate:c}){n.active.current=t;let l=(0,W.useContext)(_),u=(0,W.useRef)(c);u.current=c;let d=(0,W.useMemo)(()=>({...l,navigator:{...l.navigator,push:e=>u.current(typeof e==`string`?e:`${e.pathname??``}${e.search??``}`),replace:t=>{let n=typeof t==`string`?t:`${t.pathname??``}${t.search??``}`;n.split(`?`)[0]!==z(e).split(`?`)[0]&&u.current(n)}}}),[l,e.type,e.uid]);return(0,G.jsx)(pe.Provider,{value:n,children:(0,G.jsx)(_.Provider,{value:d,children:(0,G.jsx)(S,{location:z(e),children:(0,G.jsxs)(b,{element:(e=>(0,G.jsx)(se,{children:(0,G.jsx)(aa,{isPublicView:!1,publicData:null,isPublicLoading:!1,forbiddenDoc:null,fetchPublicDocument:void 0,setIsPublicView:r.setIsPublicView,handleLogout:async()=>{await r.handleLogout()},children:(0,G.jsx)(Nn,{panelMode:i.rightPanelMode,onPanelModeChange:i.setRightPanelMode,children:e})})}))((0,G.jsx)(Jw,{file:e,scope:n,root:r,discussionTarget:o,onUpdate:s,teamState:a})),children:[(0,G.jsx)(b,{path:`notes/:id`,element:(0,G.jsx)(QC,{capability:`notes`,children:(0,G.jsx)(Ww,{})})}),(0,G.jsx)(b,{path:`diagrams/:id`,element:(0,G.jsx)(QC,{capability:`erd_builder`,children:(0,G.jsx)(Gw,{})})}),(0,G.jsx)(b,{path:`flowcharts/:id`,element:(0,G.jsx)(QC,{capability:`flowcharts`,children:(0,G.jsx)(Kw,{})})}),(0,G.jsx)(b,{path:`drawings/:id`,element:(0,G.jsx)(QC,{capability:`drawings`,children:(0,G.jsx)(qw,{})})})]})})})})});function Xw({className:e,...t}){return(0,G.jsx)(`div`,{role:`group`,"data-slot":`button-group`,className:d(`inline-flex items-center rounded-lg shadow-xs [&>button:not(:first-child)]:rounded-l-none [&>button:not(:first-child)]:border-l-0 [&>button:not(:last-child)]:rounded-r-none`,e),...t})}function Zw({file:e,title:t,feature:n,icon:r,active:i,onSelect:a}){let o=wt(),s=e&&o?.files.some(t=>N(t)===N(e)),c=o?.files.length?!!s:i;return(0,G.jsxs)(Xw,{"aria-label":t,children:[(0,G.jsxs)(U,{variant:c?`default`:`outline`,size:`sm`,"aria-current":c?`page`:void 0,"data-state":c?`active`:`inactive`,onClick:a,className:`max-w-44 border-input`,title:`${n}: ${t}`,children:[(0,G.jsx)(r,{"data-icon":`inline-start`}),(0,G.jsx)(`span`,{className:`truncate`,children:t})]}),o?.desktop&&o.canSplit&&e&&(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:c?`default`:`outline`,size:`icon-sm`,className:`rounded-r-lg! border border-input data-open:rounded-r-lg!`,"aria-label":`File options: ${t}`,children:(0,G.jsx)(Xt,{})})}),(0,G.jsx)(Gt,{align:`start`,className:`w-60`,children:(0,G.jsx)(Vt,{children:(0,G.jsx)(It,{className:`whitespace-nowrap`,disabled:o.files.length<2&&c,onClick:()=>s&&o.files.length===2?o.close(e):o.open(e),children:s&&o.files.length===2?`Close pane`:`Open side by side`})})})]})]})}var Qw=[{id:`notes`,label:`Notes`,icon:de,route:`/notes`},{id:`erd`,label:`ERD Builder`,icon:Cr,route:`/diagrams`},{id:`db-client`,label:`DB Client`,icon:xr,route:`/db-client`},{id:`flowchart`,label:`Flowchart`,icon:Nt,route:`/flowcharts`},{id:`drawings`,label:`Drawings`,icon:wr,route:`/drawings`}],$w=e=>e.title||e.name||`Untitled`,eT=e=>e.uid||e.id,tT=e=>new Date(e.created_at||e.createdAt||0).getTime(),nT=3e4,rT=new Map,iT=new Map,aT=(e,t)=>{let n=e?.uid??e?.id;return n==null?null:{type:t,uid:String(n),title:$w(e),createdAt:e.created_at??e.createdAt}};function oT(e,t){let n=t=>!t.is_deleted&&!t.isDeleted&&String(t.project_id??t.projectId)===String(e),r=(e,t)=>e.filter(n).map(e=>aT(e,t)).filter(e=>e!==null);return[...r(t.notes,`notes`),...r(t.diagrams.filter(e=>(e.source_type??e.sourceType)!==`production_db`),`erd`),...r(t.flowcharts,`flowchart`),...r(t.drawings,`drawings`)]}function sT(...e){return[...new Map(e.flatMap(e=>e.map(e=>[`${e.type}-${e.uid}`,e]))).values()].sort((e,t)=>tT(e)-tT(t))}async function cT(e,t){let n=String(e),r=`${t}:${n}`,i=rT.get(r);if(i&&i.expiresAt>Date.now())return i;let a=iT.get(r);if(a)return a;let o=Si(`/api/projects/${encodeURIComponent(n)}/files`).then(async e=>{if(!e.ok)throw Error(`Failed to load project files`);let t=await e.json(),n={files:Array.isArray(t.data)?t.data:[]};return rT.set(r,{...n,expiresAt:Date.now()+nT}),n}).finally(()=>iT.delete(r));return iT.set(r,o),o}function lT({currentView:e,currentFile:t,host:n=!1}){let r=(0,W.useContext)(jC),i=wt(),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(`notes`),[l,u]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)({projectKey:``,files:[]}),_=(0,W.useRef)(null),y=v(),[b]=g(),{user:x,isGuest:S,activeProjectId:C,notes:w,diagrams:T,drawings:E,flowcharts:D,activeDiagram:O,activeNote:k,activeDrawing:A,activeFlowchart:j,activeDiagramId:M,activeNoteUid:N,activeDrawingId:P,activeFlowchartId:F,handleDiagramSelect:I,handleSidebarDiagramCreate:L,handleSidebarNoteCreate:R,handleSidebarDrawingCreate:ee,handleSidebarFlowchartCreate:te}=pa();(0,W.useEffect)(()=>{a&&setTimeout(()=>_.current?.focus(),0)},[a,s]);let ne=(0,W.useMemo)(()=>{let n=t??(e===`notes`?k:e===`erd`?O:e===`flowchart`?j:A);return n?.project_id??n?.projectId??(C&&C!==`all`?C:b.get(`pid`))},[C,k,O,j,A,t,e,b]),re=ne==null?``:String(ne),ie=m.projectKey===re?m.files:[],z=(0,W.useMemo)(()=>ne?oT(ne,{notes:w,diagrams:T,drawings:E,flowcharts:D}):[],[ne,w,T,E,D]);(0,W.useEffect)(()=>{if(!ne){h({projectKey:``,files:[]});return}if(!S&&x?.id==null)return;let e=!1,t=String(ne);return(async()=>{try{let n;if(S){let[e,t,r,i]=await Promise.all([ca.getAllResources(`notes`),ca.getAllResources(`erd`),ca.getAllResources(`flowchart`),ca.getAllResources(`drawings`)]);n=oT(ne,{notes:e,diagrams:t,flowcharts:r,drawings:i})}else n=(await cT(ne,x.id)).files;e||h({projectKey:t,files:n})}catch{e||h({projectKey:t,files:[]})}})(),()=>{e=!0}},[ne,S,x?.id]);let ae=(0,W.useMemo)(()=>{if(!ne)return[];let n=t??(e===`notes`?k:e===`erd`?O:e===`flowchart`?j:A),r=n?aT(n,e):null;return sT(ie,z,r?[r]:[]).map(e=>({file:e,type:e.type}))},[ne,ie,z,e,t,k,O,j,A]),oe=t?eT(t):e===`notes`?N:e===`erd`?O?.uid||M:e===`flowchart`?j?.uid||F:A?.uid||P,se=(e,t)=>{if(i&&e!==`db-client`){i.select({type:e,uid:String(eT(t)),title:$w(t),projectId:String(ne)});return}if(e===`erd`){I(String(eT(t)));return}let n=Qw.find(t=>t.id===e);if(!n)return;let r=new URLSearchParams({pid:String(ne)});y(`${n.route}/${eT(t)}?${r}`)},ce=async()=>{let e=l.trim();if(e&&!f&&ne){p(!0);try{let t=String(ne);s===`notes`?await R(e,t):s===`erd`?await L(e,t):s===`flowchart`?await te(e,t):await ee(e,t),o(!1),u(``)}finally{p(!1)}}},le=(0,W.useRef)(null),[ue,de]=(0,W.useState)({before:!1,after:!1}),B=(0,W.useCallback)(()=>{let e=le.current;if(!e)return;let t=e.scrollLeft>1,n=e.scrollLeft+e.clientWidth<e.scrollWidth-1;de(e=>e.before===t&&e.after===n?e:{before:t,after:n})},[]);(0,W.useEffect)(()=>{let e=le.current;if(!e)return;let t=()=>{let t=e.querySelector(`[aria-current="page"]`);if(t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();n.left<r.left?e.scrollLeft-=r.left-n.left+8:n.right>r.right&&(e.scrollLeft+=Math.min(n.right-r.right+8,n.left-r.left))}B()};if(t(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t);let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[oe,ae.length,B,r]);let fe=e=>{let t=le.current;t&&t.scrollBy({left:e*Math.max(t.clientWidth*.6,160),behavior:`smooth`})};return!ne||i&&!n||!r?null:(0,pw.createPortal)((0,G.jsxs)(`nav`,{"aria-label":`Project files`,className:`flex w-full min-w-0 items-center gap-1 py-1`,children:[(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[ue.before&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(-1),className:`absolute inset-y-0 left-0 z-10 flex items-center bg-gradient-to-r from-background from-60% to-transparent pl-0.5 pr-3 text-muted-foreground hover:text-foreground`,"aria-label":`Scroll files left`,children:(0,G.jsx)(lr,{className:`size-4`})}),ue.after&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(1),className:`absolute inset-y-0 right-0 z-10 flex items-center bg-gradient-to-l from-background from-60% to-transparent pl-3 pr-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Scroll files right`,children:(0,G.jsx)(St,{className:`size-4`})}),(0,G.jsx)(`div`,{ref:le,onScroll:B,onWheel:e=>{Math.abs(e.deltaY)>Math.abs(e.deltaX)&&(e.currentTarget.scrollLeft+=e.deltaY)},className:`overflow-x-auto scrollbar-hide`,children:(0,G.jsx)(`div`,{className:`flex w-max items-center justify-start gap-1 py-1`,children:ae.map(({file:t,type:n})=>{let r=Qw.find(e=>e.id===n),i=r.icon,a=eT(t),o=n===`db-client`?null:{type:n,uid:String(a),title:$w(t),projectId:String(ne)};return(0,G.jsx)(Zw,{file:o,title:$w(t),feature:r.label,icon:i,active:e===n&&String(oe)===String(a),onSelect:()=>se(n,t)},`${n}-${a}`)})})})]}),(0,G.jsxs)(Pt,{open:a,onOpenChange:e=>{o(e),e||u(``)},children:[(0,G.jsx)(Ft,{children:(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(`span`,{className:`inline-flex shrink-0`}),children:(0,G.jsx)(Mt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,"aria-label":`Create file`,children:(0,G.jsx)(jt,{})})})}),(0,G.jsx)(kt,{side:`bottom`,children:`Create file`})]})}),(0,G.jsxs)(At,{align:`end`,className:`w-72 max-w-[calc(100vw-1rem)] overflow-hidden p-0`,children:[(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto p-1`,children:Qw.filter(e=>e.id!==`db-client`).map(e=>{let t=e.icon;return(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:d(`flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm hover:bg-accent`,s===e.id&&`bg-accent text-accent-foreground`),children:[(0,G.jsx)(t,{className:`size-4`}),(0,G.jsx)(`span`,{className:`flex-1`,children:e.label}),s===e.id&&(0,G.jsx)(Yt,{className:`size-4`})]},e.id)})}),(0,G.jsxs)(`div`,{className:`sticky bottom-0 flex gap-2 border-t bg-popover p-2`,children:[(0,G.jsx)(wi,{ref:_,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&(o(!1),u(``))},placeholder:`New file name`,className:`h-8 text-xs`,disabled:f}),(0,G.jsx)(`button`,{onClick:ce,disabled:!l.trim()||f,className:`h-8 shrink-0 rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-40`,children:`Create`})]})]})]})]}),r)}function uT({children:e,root:t,mainAI:n,teamState:r,discussionTarget:i,onFocusedSession:a,onPairChange:o,paneAIRef:s}){let c=m(),u=v(),[d,f]=(0,W.useState)(()=>window.matchMedia(`(min-width: 1024px)`).matches),[p,h]=(0,W.useState)([]),g=d&&p.length===2;(0,W.useLayoutEffect)(()=>(o(g),()=>o(!1)),[g,o]);let[_,y]=(0,W.useState)(``),b=(0,W.useRef)(_);b.current=_;let[x,S]=(0,W.useState)(null),[C,w]=(0,W.useState)({}),E=e=>C[N(e)]||e.title,[D,O]=(0,W.useState)(``),[M,P]=(0,W.useState)(!1),F=(0,W.useRef)(!1),L=(0,W.useRef)(c.pathname+c.search),R=(0,W.useRef)(null),re=(0,W.useRef)(new Map),ie=(0,W.useRef)(new Map),ae=(0,W.useRef)(null),[oe,se]=(0,W.useState)(50),ce=(0,W.useRef)(!1),ue=r,de=(0,W.useMemo)(()=>({activeTeamId:ue.activeTeamId,activeTeam:ue.activeTeam,isLoading:ue.isLoading}),[ue.activeTeamId,ue.activeTeam,ue.isLoading]),B=c.pathname.match(/^\/(notes|diagrams|flowcharts|drawings)\/([^/]+)$/),fe={notes:`notes`,diagrams:`erd`,flowcharts:`flowchart`,drawings:`drawings`},pe=B?fe[B[1]]:null,me=pe===`notes`?t.activeNote:pe===`erd`?t.activeDiagram:pe===`flowchart`?t.activeFlowchart:t.activeDrawing,he=me?.project_id??me?.projectId,ge=pe&&me&&he!=null?{type:pe,uid:String(me.uid??me.id),title:me.title||me.name||`Untitled`,projectId:String(he)}:null,_e=ge??p[0]??null,ve=`${t.user?.id}:${t.teamScopeVersion}`;(0,W.useLayoutEffect)(()=>{if(s)return s.current=e=>p.some(t=>N(t)===e)?re.current.get(e)?.ai:void 0,()=>{s.current=null}},[s,p]);let V=(0,W.useCallback)((e,t)=>{re.current.set(e,t);let n=te(t.file,t.workspace.activeDocument);n&&w(t=>t[e]===n?t:{...t,[e]:n}),e===b.current&&a(t)},[a]);(0,W.useEffect)(()=>{a(re.current.get(_)??null)},[_,a]),(0,W.useEffect)(()=>()=>a(null),[a]),(0,W.useEffect)(()=>{h([]),S(null),y(``),w({}),re.current.clear(),ie.current.clear(),a(null)},[ve,a]),(0,W.useEffect)(()=>{t.isPublicView&&(h([]),S(null),y(``),a(null))},[t.isPublicView,a]),(0,W.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1024px)`),t=()=>f(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let H=(0,W.useCallback)(async e=>{let t=re.current.get(N(e));if(!t)throw Error(`Wait for the editor to finish loading.`);await t.flush()},[]);(0,W.useEffect)(()=>{let e=e=>{p.length&&e.detail.push(Promise.all(p.map(H)).then(()=>{}))};return window.addEventListener(k,e),()=>window.removeEventListener(k,e)},[p,H]);let ye=async e=>{if(!F.current){F.current=!0,P(!0);try{await e()}catch(e){l.error(e instanceof Error?e.message:`Could not switch files.`)}finally{F.current=!1,P(!1)}}},be=e=>{b.current=N(e),y(N(e)),a(re.current.get(N(e))??null)},xe=e=>{let n=p[0]??_e;(d||e.previewSchema)&&n&&T(p,n,e)!==`reject`&&(p.some(t=>N(t)===N(e))?(e.previewSchema&&h(t=>t.map(t=>N(t)===N(e)?e:t)),be(e)):(p.length||N(n)!==N(e))&&(p.length===2?(S(e),O(``)):ye(async()=>{p.length||await YC(t),h([...p.length?p:[n],e]),be(e)})))},Se=e=>{p.some(t=>N(t)===N(e))?be(e):p.length===2&&d?xe(e):ye(async()=>{p.length?await Promise.all(p.map(H)):await YC(t),h([]),y(``),a(null),u(z(e))})},Ce=e=>void ye(async()=>{await H(e);let t=p.filter(t=>N(t)!==N(e));re.current.delete(N(e)),ie.current.delete(N(e)),h(t),t[0]&&(be(t[0]),c.pathname!==z(t[0]).split(`?`)[0]&&u(z(t[0]),{replace:!0}))}),we=e=>{let n=e.match(/^\/(notes|diagrams|flowcharts|drawings)\/([^/?]+)/);if(n&&_e){let e=fe[n[1]],r=decodeURIComponent(n[2]),i=[...re.current.values()],a=j(e,r,[t,...i.map(e=>e.workspace)],i.map(e=>({file:e.file,document:e.workspace.activeDocument})));Se({type:e,uid:String(a?.uid??a?.id??r),title:ne(a)||`Untitled`,projectId:String(a?.project_id??a?.projectId??_e.projectId)})}else ye(async()=>{await Promise.all(p.map(H)),h([]),y(``),a(null),u(e)})},Te=(0,W.useRef)(xe),Ee=(0,W.useRef)(we);Ee.current=we;let De=(0,W.useCallback)(e=>Ee.current(e),[]);Te.current=xe,(0,W.useEffect)(()=>{let e=c.pathname+c.search;if(!p.length){L.current=e;return}if(M||L.current===e||B&&(!ge||ge.uid!==decodeURIComponent(B[2])&&String(me?.id)!==decodeURIComponent(B[2])))return;let t=L.current;L.current=e;let n=ge&&p.find(e=>N(e)===N(ge));B&&n?be(n):B&&ge&&p.length===2&&ge.projectId===p[0].projectId?(R.current=t,S(ge),O(``)):ye(async()=>{try{await Promise.all(p.map(H)),h([]),y(``),a(null)}catch(e){throw L.current=t,u(t,{replace:!0}),e}})},[c.pathname,c.search,ge?.uid,ge?.projectId,p,M,H,u,a]);let Oe=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=p.find(e=>N(e)===_),t=e?z(e):null,n=ee(t,Oe.current,window.location.pathname+window.location.search,c.pathname+c.search);n&&window.history.replaceState(window.history.state,``,n),Oe.current=t},[p,_]);let ke=()=>{M||(S(null),R.current&&=(L.current=R.current,u(R.current,{replace:!0}),null))};if((0,W.useEffect)(()=>{let e=e=>{let t=e.detail?.file;le(t)&&Te.current(t)};return window.addEventListener(I,e),()=>window.removeEventListener(I,e)},[]),(0,W.useEffect)(()=>{let e=e=>{if(!ce.current||!ae.current)return;let t=ae.current.getBoundingClientRect();se(Math.max(30,Math.min(70,(e.clientX-t.left)/t.width*100)))},t=()=>{ce.current=!1};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[]),!_e||!B&&!p.length||t.isPublicView)return(0,G.jsx)(G.Fragment,{children:e});let Ae=p.find(e=>N(e)===_)??_e,je=re.current.get(N(Ae))?.workspace.activeDocument??(ge&&N(Ae)===N(ge)?me:void 0),Me=M?{inert:``}:{};return(0,G.jsxs)(Ot.Provider,{value:{files:p,focused:_,desktop:d,canSplit:!!(p[0]??_e),open:xe,select:Se,close:Ce},children:[(0,G.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,G.jsx)(lT,{host:!0,currentView:Ae.type,currentFile:je}),p.length?(0,G.jsx)(`div`,{ref:ae,className:`flex min-h-0 flex-1 overflow-hidden`,"aria-label":`Open files`,children:p.map((e,r)=>{let a=N(e),o=ie.current.get(a);return o||(o={active:{current:_===a},host:{current:null}},ie.current.set(a,o)),(0,G.jsxs)(`div`,{className:g||_===a?`contents`:`hidden`,children:[g&&r===1&&(0,G.jsx)(`div`,{role:`separator`,"aria-label":`Resize editors`,"aria-orientation":`vertical`,"aria-valuemin":30,"aria-valuemax":70,"aria-valuenow":Math.round(oe),tabIndex:0,className:`w-2 shrink-0 cursor-col-resize touch-none border-x bg-muted/30 focus-visible:bg-accent`,onPointerDown:e=>{ce.current=!0,e.currentTarget.setPointerCapture(e.pointerId)},onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.preventDefault(),se(t=>Math.max(30,Math.min(70,t+(e.key===`ArrowLeft`?-2:2)))))}}),(0,G.jsxs)(`section`,{"data-file-session":a,"data-active":_===a,"aria-label":E(e),...Me,onPointerDownCapture:t=>{A(t.target)&&be(e)},onFocusCapture:t=>{_!==a&&A(t.target)&&be(e)},className:`relative flex min-h-0 min-w-0 flex-col overflow-hidden${g?` rounded-lg border-2 ${_===a?`border-foreground`:`border-transparent`}`:``}`,style:g?{width:r===0?`${oe}%`:void 0,flex:r===1?1:void 0}:{flex:1},children:[g&&(0,G.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center justify-between gap-2 border-b px-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`truncate`,children:E(e)}),(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close pane: ${E(e)}`,"data-pane-close":!0,disabled:M,onClick:()=>Ce(e),children:(0,G.jsx)(Pr,{})})]}),(0,G.jsx)(`div`,{ref:o.host,className:`relative isolate flex min-h-0 flex-1 flex-col overflow-hidden [transform:translateZ(0)]`,children:(0,G.jsx)(Yw,{file:e,active:_===a,scope:o,root:t,mainAI:n,teamState:de,discussionTarget:i,onUpdate:V,onNavigate:De})})]})]},a)})}):(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,...Me,children:[(0,G.jsx)(Uw,{}),e]})]}),(0,G.jsx)(pi,{open:!!x,onOpenChange:e=>{e||ke()},children:(0,G.jsxs)(ni,{children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(mi,{children:`Replace an open file`}),(0,G.jsxs)(li,{children:[`Choose the file to close before opening `,x&&E(x),`.`]})]}),(0,G.jsx)(di,{className:`p-4`,children:(0,G.jsx)(qC,{"aria-label":`File to replace`,value:D,onValueChange:e=>O(String(e)),className:`flex flex-col gap-2`,children:p.map(e=>(0,G.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 rounded-lg border p-3`,children:[(0,G.jsx)(zC,{value:N(e),className:`flex size-4 shrink-0 items-center justify-center rounded-full border border-input data-checked:border-primary focus-visible:ring-2 focus-visible:ring-ring`,children:(0,G.jsx)(BC,{className:`size-2 rounded-full bg-primary`})}),(0,G.jsxs)(`span`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`block truncate`,children:E(e)}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:{notes:`Notes`,erd:`ERD Builder`,flowchart:`Flowchart`,drawings:`Drawings`}[e.type]})]})]},N(e)))})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(U,{variant:`outline`,disabled:M,onClick:ke,children:`Cancel`}),(0,G.jsx)(U,{disabled:!D||M,onClick:()=>void ye(async()=>{let e=p.find(e=>N(e)===D);x&&e&&(await H(e),re.current.delete(D),ie.current.delete(D),h(p.map(e=>N(e)===D?x:e)),be(x),S(null),R.current=null,ge&&N(ge)===N(e)&&u(z(x),{replace:!0}))}),children:`Replace file`})]})]})})]})}var dT=W.createContext(void 0);function fT(){let e=W.useContext(dT);if(e===void 0)throw Error(De(13));return e}var pT={imageLoadingStatus:()=>null},mT=W.forwardRef(function(e,t){let{className:n,render:r,...i}=e,[a,o]=W.useState(`idle`),s={imageLoadingStatus:a},c=W.useMemo(()=>({imageLoadingStatus:a,setImageLoadingStatus:o}),[a,o]),l=je(`span`,e,{state:s,ref:t,props:i,stateAttributesMapping:pT});return(0,G.jsx)(dT.Provider,{value:c,children:l})});function hT(e,{referrerPolicy:t,crossOrigin:n}){let[r,i]=W.useState(`idle`);return Ae(()=>{if(!e)return i(`error`),Ee;let r=!0,a=new window.Image,o=e=>()=>{r&&i(e)};return i(`loading`),a.onload=o(`loaded`),a.onerror=o(`error`),t&&(a.referrerPolicy=t),a.crossOrigin=n??null,a.src=e,()=>{r=!1}},[e,n,t]),r}var gT={...pT,...Ge},_T=W.forwardRef(function(e,t){let{className:n,render:r,onLoadingStatusChange:i,referrerPolicy:a,crossOrigin:o,...s}=e,c=fT(),l=hT(e.src,{referrerPolicy:a,crossOrigin:o}),u=l===`loaded`,{mounted:d,transitionStatus:f,setMounted:p}=Ie(u),m=W.useRef(null),h=Me(e=>{i?.(e),c.setImageLoadingStatus(e)});Ae(()=>{l!==`idle`&&h(l)},[l,h]);let g={imageLoadingStatus:l,transitionStatus:f};Be({open:u,ref:m,onComplete(){u||p(!1)}});let _=je(`img`,e,{state:g,ref:[t,m],props:s,stateAttributesMapping:gT,enabled:d});return d?_:null}),vT=W.forwardRef(function(e,t){let{className:n,render:r,delay:i,...a}=e,{imageLoadingStatus:o}=fT(),[s,c]=W.useState(i===void 0),l=et();return W.useEffect(()=>(i!==void 0&&l.start(i,()=>c(!0)),l.clear),[l,i]),je(`span`,e,{state:{imageLoadingStatus:o},ref:t,props:a,stateAttributesMapping:pT,enabled:o!==`loaded`&&s})}),yT=W.forwardRef(({className:e,size:t=`default`,...n},r)=>(0,G.jsx)(mT,{ref:r,"data-slot":`avatar`,"data-size":t,className:d(`group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten`,e),...n}));yT.displayName=`Avatar`;var bT=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(_T,{ref:n,"data-slot":`avatar-image`,className:d(`aspect-square size-full rounded-full object-cover`,e),...t}));bT.displayName=`AvatarImage`;var xT=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(vT,{ref:n,"data-slot":`avatar-fallback`,className:d(`flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs`,e),...t}));xT.displayName=`AvatarFallback`;function ST({open:e,onOpenChange:t}){let[n,r]=(0,W.useState)(!1);return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-105 bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`Guest Data Backup`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Export your Guest Mode data as a JSON file for safe keeping or future import.`}),(0,G.jsxs)(`div`,{className:`p-2 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-amber-500/10 rounded-xl`,children:(0,G.jsx)(Qo,{className:`size-5 text-amber-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-semibold text-base`,children:`Guest Mode`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`You are browsing as a guest`})]})]}),(0,G.jsxs)(`div`,{className:`bg-muted/10 border border-border/40 rounded-xl p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Cr,{className:`size-4 text-muted-foreground shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:(0,G.jsxs)(`p`,{children:[`Your data (notes, diagrams, flowcharts, drawings, and AI chats) is stored locally in your browser. Export it as a `,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px]`,children:`.json`}),` `,`file so you can import it after signing in.`]})})]}),(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Ya,{className:`size-4 text-muted-foreground shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:(0,G.jsxs)(`p`,{children:[`The export file can be imported into any ERD Builder Pro account via`,(0,G.jsx)(`strong`,{children:` Settings → Guest Data Import`}),`.`]})})]})]}),(0,G.jsx)(U,{onClick:async()=>{r(!0);try{await pC(),l.success(`Data exported successfully!`)}catch(e){l.error(`Export failed: `+(e.message||`Unknown error`))}finally{r(!1)}},disabled:n,className:`w-full`,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`size-4 mr-2 animate-spin`}),`Exporting…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rn,{className:`size-4 mr-2`}),`Export My Data`]})}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`span`,{className:`w-full border-t border-border/30`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-xs`,children:(0,G.jsx)(`span`,{className:`bg-background px-2 text-muted-foreground`,children:`Need an account?`})})]}),(0,G.jsx)(`div`,{className:`text-center space-y-2`,children:(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sign up or log in from the main page to import your backup.`})})]})]})})}function CT({user:e,onLogout:t,onViewChange:n,isOnline:r,onOpenFeedback:i,compact:a=!1}){let{isMobile:o}=wh(),{isGuest:s,setIsSettingsOpen:c,setSettingsTab:l,hasUpdate:u,latestVersion:f,isCheckingUpdate:p,isDownloadingUpdate:m,isWebOutdated:h,showOutdatedBadge:g,checkForUpdates:_,downloadUpdate:v}=pa(),y=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__);if(!e)return null;let b=e.email||``,x=e.name||e.user_metadata?.full_name||e.user_metadata?.name||b.split(`@`)[0]||`User`,S=e.user_metadata?.avatar_url||``,C=x.substring(0,2).toUpperCase(),w=e=>{l(e),c(!0)},[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(Nh,{size:`lg`,"aria-label":a?`Account menu for ${x}`:void 0,title:a?x:void 0,className:d(`data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground`,a&&`!size-8 !justify-center !p-0`),children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(yT,{className:`h-8 w-8 rounded-lg`,children:[(0,G.jsx)(bT,{src:S,alt:x}),(0,G.jsx)(xT,{className:`rounded-lg`,children:C})]}),g&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 flex size-3 rounded-full bg-amber-500 ring-2 ring-sidebar`,title:u?`Update available: v${f}`:h?`New version available: v${f}. You're on v3.5.3. Pull latest Docker image or update your install.`:``})]}),!a&&(0,G.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:x}),(0,G.jsx)(`span`,{className:`truncate text-xs`,children:b})]}),!a&&(0,G.jsx)(Pa,{className:`ml-auto size-4`})]})}),(0,G.jsxs)(Gt,{className:`w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg`,side:o?`bottom`:`right`,align:`end`,sideOffset:4,children:[(0,G.jsx)(Vt,{children:(0,G.jsx)(Wt,{className:`p-0 font-normal`,children:(0,G.jsx)(Vt,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-1.5 text-left text-sm`,children:[(0,G.jsxs)(yT,{className:`h-8 w-8 rounded-lg`,children:[(0,G.jsx)(bT,{src:S,alt:x}),(0,G.jsx)(xT,{className:`rounded-lg`,children:C})]}),(0,G.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:x}),(0,G.jsx)(`span`,{className:`truncate text-xs`,children:b})]})]})})})}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(Vt,{children:[(0,G.jsxs)(It,{onClick:()=>w(s||e.isSso?`appearance`:`account`),className:`cursor-pointer`,disabled:!s&&!r,children:[(0,G.jsx)(zo,{className:`mr-2 size-4`}),`Settings`]}),s&&(0,G.jsxs)(It,{onClick:()=>E(!0),className:`cursor-pointer`,children:[(0,G.jsx)(rn,{className:`mr-2 size-4`}),`Backup Data`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>O(!0),className:`cursor-pointer`,children:[u?(0,G.jsx)(Fa,{className:`mr-2 size-4 text-emerald-400`}):h?(0,G.jsx)(Ta,{className:`mr-2 size-4 text-amber-500`}):(0,G.jsx)(vr,{className:`mr-2 size-4`}),`About`,g&&(0,G.jsx)(`span`,{className:`ml-auto flex size-2 rounded-full ${u?`bg-emerald-400`:`bg-amber-500`}`})]}),(0,G.jsxs)(It,{render:(0,G.jsx)(`a`,{href:`https://github.com/hadziqmtqn/erd-builder-pro`,target:`_blank`,rel:`noopener noreferrer`}),className:`cursor-pointer`,children:[(0,G.jsx)(oo,{className:`mr-2 size-4`}),`Github`]}),(0,G.jsxs)(It,{onClick:i,className:`cursor-pointer`,children:[(0,G.jsx)(To,{className:`mr-2 size-4`}),`Feedback`]})]}),(0,G.jsx)(Kt,{}),(0,G.jsx)(Vt,{children:(0,G.jsxs)(It,{onClick:()=>r&&n(`trash`),disabled:!r,className:`text-destructive focus:bg-accent focus:text-destructive cursor-pointer ${!r&&`opacity-50 cursor-not-allowed`}`,children:[(0,G.jsx)($r,{className:`mr-2 size-4`}),`Trash`]})}),(0,G.jsx)(Kt,{}),!y&&(0,G.jsxs)(It,{onClick:()=>r&&t(),disabled:!r,className:`cursor-pointer ${!r&&`opacity-50 cursor-not-allowed`}`,title:r?``:`Logging out while offline may cause data loss of unsynced changes`,children:[(0,G.jsx)(wo,{className:`mr-2 size-4`}),`Log out`]})]})]})})}),(0,G.jsx)(ST,{open:T,onOpenChange:E}),(0,G.jsx)(kC,{open:D,onOpenChange:O,hasUpdate:u,latestVersion:f,isChecking:p,isDownloading:m,onCheckUpdate:_,onDownload:v})]})}function wT(e){try{let t=new URL(e);return t.searchParams.set(`utm_source`,`erdbuilderpro.com`),t.searchParams.set(`utm_medium`,`referral`),t.searchParams.set(`utm_campaign`,`sponsor`),t.toString()}catch{return e}}var TT=[{logoOnLightSurfaceSrc:`https://s3.erdbuilderpro.com/sponsors/Sumopod-Light.png`,logoOnDarkSurfaceSrc:`https://s3.erdbuilderpro.com/sponsors/Sumopod-Dark.png`,logoAlt:`SumoPod`,title:`Deploy your App in 15 Seconds!`,description:`Seamless container deployment for businesses of all sizes.`,buttonText:`Get Started →`,buttonAction:`https://sumopod.com`}];function ET(){let e=TT[0];return(0,G.jsx)(`div`,{className:`px-2 pb-2`,children:(0,G.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-dashed border-zinc-700 bg-zinc-950 p-3 text-zinc-50 dark:border-zinc-300 dark:bg-zinc-100 dark:text-zinc-950`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5`,children:[e.icon?(0,G.jsx)(e.icon,{className:`w-5 h-5 text-rose-500 shrink-0`}):e.logoOnDarkSurfaceSrc||e.logoOnLightSurfaceSrc?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`img`,{src:e.logoOnDarkSurfaceSrc??e.logoOnLightSurfaceSrc,alt:e.logoAlt??``,className:`h-8 w-auto max-w-full shrink-0 object-contain dark:hidden`}),e.logoOnLightSurfaceSrc&&(0,G.jsx)(`img`,{src:e.logoOnLightSurfaceSrc,alt:e.logoAlt??``,className:`hidden h-8 w-auto max-w-full shrink-0 object-contain dark:block`})]}):null,(0,G.jsx)(`p`,{className:`max-w-full truncate text-center text-xs font-semibold text-zinc-50 dark:text-zinc-950`,children:e.title}),(0,G.jsx)(`p`,{className:`wrap-break-word text-center text-[11px] leading-relaxed text-zinc-300 dark:text-zinc-600`,children:e.description}),(0,G.jsx)(U,{type:`button`,className:`mt-1 w-full bg-[#1a5fd4] text-white hover:bg-[#174ea6]`,onClick:()=>ia(wT(e.buttonAction)),children:e.buttonText})]})})})}function DT({teams:e,activeTeamId:t,enabled:n,canManageTeams:r,onOpen:i,onSelect:a,onAdd:o,onManage:s}){let{isMobile:c}=wh(),l=(e.find(e=>e.id===t)||null)?.name||(t?`Loading workspace…`:`Personal`),u=(0,G.jsxs)(Nh,{size:`lg`,"aria-label":`Switch workspace. Current workspace: ${l}`,title:`Workspace: ${l}`,className:`cursor-pointer transition-colors hover:bg-accent/50 active:bg-accent/70`,onClick:n?void 0:()=>a(null),children:[(0,G.jsxs)(`span`,{className:`flex size-8 shrink-0 items-center justify-center`,"aria-hidden":`true`,children:[(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Light-1.svg`,alt:``,className:`size-full dark:hidden`}),(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Dark-1.svg`,alt:``,className:`hidden size-full dark:block`})]}),(0,G.jsxs)(`span`,{className:`grid min-w-0 flex-1 text-left leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:`ERD Builder Pro`}),(0,G.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:l})]}),n&&(0,G.jsx)(Pa,{className:`ml-auto size-4 shrink-0`})]});return n?(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{onOpenChange:e=>{e&&i()},children:[(0,G.jsx)(zt,{render:u}),(0,G.jsxs)(Gt,{className:`min-w-64 border border-border/70 p-1.5 shadow-xl`,side:c?`bottom`:`right`,align:`start`,sideOffset:6,children:[(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`px-2 py-1.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80`,children:`Workspace`}),(0,G.jsxs)(It,{onClick:()=>a(null),className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand ${t?``:`bg-brand/10 text-foreground [&>svg]:text-brand`}`,children:[(0,G.jsx)(Zo,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{children:`Personal`}),!t&&(0,G.jsx)(Yt,{className:`ml-auto size-4 text-brand`})]})]}),e.length>0&&(0,G.jsx)(Kt,{className:`my-1.5`}),e.length>0&&(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`px-2 py-1.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80`,children:`Teams`}),e.map(e=>(0,G.jsxs)(It,{onClick:()=>a(e.id),className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand ${t===e.id?`bg-brand/10 text-foreground [&>svg]:text-brand`:``}`,children:[(0,G.jsx)($o,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[t===e.id&&(0,G.jsx)(Yt,{className:`size-4 text-brand`}),e.canManage&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(`button`,{type:`button`,"aria-label":`Open Team Management for ${e.name}`,className:`flex size-7 shrink-0 items-center justify-center rounded-md border border-transparent bg-muted/50 text-muted-foreground transition-all hover:border-brand/40 hover:bg-brand hover:text-white hover:shadow-sm focus-visible:border-brand focus-visible:bg-brand focus-visible:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.preventDefault(),t.stopPropagation(),s(e)},children:(0,G.jsx)(Ro,{className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,className:`text-xs`,children:`Manage team`})]})]})]},e.id))]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{className:`my-1.5`}),(0,G.jsx)(Vt,{children:(0,G.jsxs)(It,{onClick:o,className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand`,children:[(0,G.jsx)(jt,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{children:`Add Team`})]})})]})]})]})})}):(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:u})})}function OT(){if(typeof navigator>`u`)return`Ctrl+K`;let e=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad/i.test(e)?`⌘K`:`Ctrl+K`}function kT({isLoading:e,isOnline:t,onQueryChange:n,onResultSelect:r,query:i,results:a,showDbClient:o}){let[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(`all`),d=(0,W.useRef)(null),f=OT(),p=[{value:`all`,label:`All`},{value:`workspace`,label:`Projects`},{value:`erd`,label:`ERD Builder`},...o?[{value:`db-client`,label:`DB Client`}]:[],{value:`notes`,label:`Notes`},{value:`flowchart`,label:`Flowcharts`},{value:`drawings`,label:`Drawings`}],m=l===`all`?a:a.filter(e=>e.type===l);return(0,W.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),c(!0),d.current?.focus(),d.current?.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,W.useEffect)(()=>{s&&window.setTimeout(()=>{d.current?.focus(),d.current?.select()},0)},[s]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{onClick:()=>c(!0),disabled:!t,"aria-label":`Search files (${f})`,tooltip:`Search (${f})`,className:`border border-sidebar-border bg-background text-muted-foreground shadow-xs`,children:[(0,G.jsx)(Zr,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`flex-1`,children:`Search`}),(0,G.jsx)(Di,{className:`group-data-[collapsible=icon]:hidden`,children:f})]})})}),(0,G.jsx)(Yr,{open:s,onOpenChange:e=>{c(e),e||(u(`all`),n(``))},children:(0,G.jsxs)(Vr,{size:`2xl`,showCloseButton:!1,className:`translate-y-0! max-h-[76vh] sm:max-w-2xl`,style:{top:`12vh`},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-border/60 px-4 py-3`,children:[(0,G.jsx)(Zr,{className:`size-5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(wi,{ref:d,value:i,onChange:e=>n(e.target.value),placeholder:`Search files and projects`,"aria-label":`Spotlight file search`,className:`min-w-0 flex-1`}),(0,G.jsx)(Di,{className:`h-7 rounded-lg px-2.5 text-xs`,children:`Esc`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 overflow-x-auto border-b border-border/60 px-4 py-2.5 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Filter:`}),(0,G.jsx)(`div`,{className:`flex min-w-max items-center gap-1`,children:p.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(e.value),className:`min-h-10 rounded-md px-2.5 py-1 font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${l===e.value?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60 hover:text-foreground`}`,children:e.label},e.value))})]}),(e||i.trim().length>=2)&&(0,G.jsx)(`div`,{className:`max-h-[min(26rem,60vh)] overflow-y-auto p-2`,children:e?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,G.jsx)(xo,{className:`size-4 animate-spin`,"aria-hidden":`true`}),` Searching...`]}):m.length===0?(0,G.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`No results found.`}):m.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{r(e),c(!1)},className:`group flex min-h-11 w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,G.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-muted`,children:e.type===`workspace`?(0,G.jsx)(eo,{className:`size-4 text-muted-foreground`}):e.type===`erd`?(0,G.jsx)(Cr,{className:`size-4 text-muted-foreground`}):e.type===`db-client`?(0,G.jsx)(xr,{className:`size-4 text-muted-foreground`}):e.type===`notes`?(0,G.jsx)(de,{className:`size-4 text-muted-foreground`}):e.type===`flowchart`?(0,G.jsx)(Sr,{className:`size-4 text-muted-foreground`}):(0,G.jsx)(wr,{className:`size-4 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name||`(Untitled)`}),(0,G.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e.type===`workspace`?`Project`:e.type===`erd`?`ERD Builder`:e.type===`db-client`?`DB Client`:e.type===`flowchart`?`Flowchart`:e.type===`notes`?`Note`:`Drawing`,e.workspace?.name&&` · ${e.workspace.name}`]})]}),(0,G.jsx)(Ca,{className:`size-4 shrink-0 text-muted-foreground/40 group-hover:text-primary`,"aria-hidden":`true`})]},`${e.type}-${e.uid??e.id}`))})]})})]})}var AT=({isOpen:e,onOpenChange:t,mode:n=`move-to-trash`,activeDocument:r,view:i,deleteDiagram:a,deleteNote:o,deleteDrawing:s,deleteFlowchart:c,deleteProject:l,fetchTrash:u,itemType:d,onConfirm:f,onAfterDelete:p})=>{let m=async()=>{if(n===`permanent-delete`){f?.(),p?.();return}if(f){f(),p?.();return}let e=i===`erd`||i===`notes`||i===`flowchart`||i===`drawings`?r?.uid??r?.id:r?.id;e&&(i===`erd`?await a?.(e):i===`notes`?await o?.(String(e)):i===`drawings`?await s?.(e):i===`flowchart`?await c?.(e):i===`project`&&await l?.(e),u?.(),t(!1),p?.())},h=d===`erd`?`diagram`:d===`notes`?`note`:d===`drawings`?`drawing`:d===`project`?`workspace`:`item`;if(n===`permanent-delete`)return(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(ei,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Are you absolutely sure?`})]}),(0,G.jsx)(di,{children:(0,G.jsx)(li,{children:d===`project`?(0,G.jsxs)(G.Fragment,{children:[`This action cannot be undone. Deleting this workspace will also permanently delete all`,(0,G.jsx)(`strong`,{children:` notes, diagrams, drawings, and flowcharts`}),` inside it.`]}):(0,G.jsxs)(G.Fragment,{children:[`This action cannot be undone. This will permanently delete the `,(0,G.jsx)(`strong`,{children:h}),` from our servers.`]})})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:m,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Permanently Delete`})]})]})});let g=i!==`project`;return(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)($r,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:g?`Move to Trash?`:`Delete Workspace?`})]}),(0,G.jsx)(di,{children:(0,G.jsx)(li,{children:g?(0,G.jsxs)(G.Fragment,{children:[`Are you sure you want to move `,(0,G.jsx)(`strong`,{children:r?.title||r?.name||`this item`}),` to trash?`,(0,G.jsx)(`br`,{}),`You can restore it later from the trash bin.`]}):(0,G.jsxs)(G.Fragment,{children:[`This will move the workspace and all its contents to trash.`,(0,G.jsx)(`br`,{}),`You can restore it later from the trash bin.`]})})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:m,children:g?`Move to Trash`:`Delete`})]})]})})},jT={data:[],total:0,counts:{notes:0,erd:0,flowchart:0,"db-client":0,drawings:0},locked:[]};async function MT({projectId:e,type:t,page:n,perPage:r,q:i}){let a={...jT.counts},o=[],s=i?.trim().toLowerCase();for(let{value:n}of Wi){if(n===`db-client`)continue;let r=(await ca.getAllResources(n)).filter(t=>!t.is_deleted&&String(t.project_id??`null`)===e&&(!s||String(t.title??t.name??``).toLowerCase().includes(s)));a[n]=r.length,(t===`all`||t===n)&&o.push(...r.map(e=>({...e,type:n})))}return o.sort((e,t)=>new Date(t.created_at??0).getTime()-new Date(e.created_at??0).getTime()),{data:o.slice((n-1)*r,n*r),total:t===`all`?Object.values(a).reduce((e,t)=>e+t,0):a[t],counts:a,locked:[]}}function NT(e,t){let{isGuest:n}=la(),[r,i]=(0,W.useState)(jT),[a,o]=(0,W.useState)(!1),{projectId:s,type:c,page:l,perPage:u,q:d=``}=e;return(0,W.useEffect)(()=>{if(!s){i(jT);return}let e=!1;return o(!0),(async()=>{if(n)return MT({projectId:s,type:c,page:l,perPage:u,q:d});let e=new URLSearchParams({project_id:s,type:c,limit:String(u),offset:String((l-1)*u),include_db_client:String(yi())});d.trim()&&e.set(`q`,d.trim());let t=await Si(`/api/projects/files?${e}`);if(!t.ok)throw Error(`Failed to load project files`);let r=await t.json();return{...jT,...r,counts:{...jT.counts,...r.counts},locked:r.locked??[]}})().then(t=>{e||i(t)}).catch(()=>{e||i(jT)}).finally(()=>{e||o(!1)}),()=>{e=!0}},[s,c,l,u,d,n,t]),{...r,isLoading:a}}var PT={owner:`Creator`,manager:`Manager`,editor:`Editor`,commenter:`Commenter`,viewer:`Viewer`},FT=[`editor`,`commenter`,`viewer`],IT={owner:`Full access as the Project creator.`,editor:`Can change the files.`,commenter:`Can read and comment.`,viewer:`Can read only.`};function LT(e){return{userId:String(e.user_id??e.userId),name:e.name??null,email:e.email??null,teamRole:String(e.team_role??e.teamRole??`staff`),role:e.role,isCreator:(e.is_creator??e.isCreator)===!0,canChange:(e.can_change??e.canChange)===!0}}function RT({project:e,onOpenChange:t}){let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),c=e?.id,u=(0,W.useCallback)(async()=>{if(c!==void 0){a(``);try{let e=await Si(`/api/projects/${encodeURIComponent(String(c))}/access`),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||`Could not load access.`);r((t.members??[]).map(LT))}catch(e){r(null),a(e instanceof Error?e.message:`Could not load access.`)}}},[c]);(0,W.useEffect)(()=>{r(null),c!==void 0&&u()},[c,u]);let d=async(e,t)=>{if(t!==e.role&&c!==void 0){s(e.userId);try{let n=`/api/projects/${encodeURIComponent(String(c))}/access/${encodeURIComponent(e.userId)}`,i=t===(e.isCreator?`owner`:`commenter`)?await Si(n,{method:`DELETE`}):await Si(n,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({role:t})}),a=await i.json().catch(()=>({}));if(!i.ok)throw Error(a.error||`Could not change access.`);r(n=>n?.map(n=>n.userId===e.userId?{...n,role:t}:n)??n),l.success(`${e.name||e.email||`Member`} is now ${PT[t]}.`)}catch(e){l.error(e instanceof Error?e.message:`Could not change access.`),await u()}finally{s(null)}}};return(0,G.jsx)(Yr,{open:e!==null,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-lg`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Project access`}),(0,G.jsxs)(Fr,{children:[`Choose what each Team member can do in `,e?.name,`. Team Managers always have full access; only a Manager can limit the Project creator.`]})]}),(0,G.jsxs)(Wr,{children:[i&&(0,G.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),!i&&n===null&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,children:[(0,G.jsx)(xo,{className:`size-4 animate-spin`,"aria-hidden":`true`}),` Loading members…`]}),n&&n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This Team has no other active members.`}),n&&n.length>0&&!n.some(e=>e.canChange)&&(0,G.jsx)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:`Everyone here already has full access as the Project creator or a Team Manager, so there is no role to change. Roles apply to other Staff members of the Team.`}),n&&n.length>0&&(0,G.jsx)(`ul`,{className:`divide-y rounded-lg border`,"aria-label":`Project members`,children:n.map(e=>(0,G.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name||e.email||`Member`}),e.name&&e.email&&(0,G.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),e.canChange?(0,G.jsxs)(_r,{value:e.role,onValueChange:t=>{t&&d(e,t)},disabled:o===e.userId,children:[(0,G.jsx)(mr,{className:`w-36`,"aria-label":`Access for ${e.name||e.email||`member`}`,children:(0,G.jsx)(gr,{children:PT[e.role]})}),(0,G.jsx)(pr,{className:`min-w-72`,children:(0,G.jsx)(hr,{children:(e.isCreator?[`owner`,...FT]:FT).map(t=>(0,G.jsx)(fr,{value:t,children:(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{children:PT[t]}),(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[IT[t],t===(e.isCreator?`owner`:`commenter`)?` Default.`:``]})]})},t))})})]}):(0,G.jsx)(`span`,{className:`w-36 px-3 text-sm text-muted-foreground`,children:PT[e.role]})]},e.userId))})]})]})})}function zT({activeTeamId:e,isProjectsLoading:t,onProjectCreate:n,onProjectDelete:r,onProjectUpdate:i,projects:a,user:o}){let s=m(),c=v(),[l,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(``),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),[y,b]=(0,W.useState)(!1),[x,S]=(0,W.useState)(``),C=a.filter(e=>!e.is_deleted),w=s.pathname.match(/^\/projects\/([^/]+)$/)?.[1],T=w?decodeURIComponent(w):null,{activeDocument:E}=pa(),D=/^\/(notes|diagrams|drawings|flowcharts|db-client)\/[^/]+$/.test(s.pathname)?E?.project_id??E?.projectId??null:null,{total:O}=NT({projectId:`null`,type:`all`,page:1,perPage:10},s.pathname),k=O>0,A=(e,t)=>{let n=e??(t==null?null:String(t));n&&c(`/projects/${encodeURIComponent(n)}`)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Oh,{children:[(0,G.jsx)(kh,{children:`Projects`}),(0,G.jsx)(sne,{title:`New Project`,"aria-label":`New Project`,onClick:()=>{S(``),b(!0)},children:(0,G.jsx)(jt,{})}),(0,G.jsx)(Ah,{children:(0,G.jsxs)(jh,{children:[t?(0,G.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground animate-pulse`,children:`Loading projects...`}):C.length===0?(0,G.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground group-data-[collapsible=icon]:hidden`,children:`No projects yet`}):C.map(t=>(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:t.name,isActive:T===t.uid||T===String(t.id??``)||D!=null&&String(D)===String(t.id),onClick:()=>A(t.uid,t.id),children:[(0,G.jsx)(eo,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:t.name}),(0,G.jsx)(`span`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(`button`,{type:`button`,"aria-label":`Project options for ${t.name}`,className:`flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring`,children:(0,G.jsx)(Tr,{className:`size-4`})})}),(0,G.jsxs)(Gt,{align:`end`,className:`min-w-44`,children:[e&&(t.access_role===`owner`||t.access_role===`manager`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(It,{onClick:()=>_({id:t.id,name:t.name}),children:[(0,G.jsx)(es,{className:`size-3.5`,"aria-hidden":`true`}),`Manage access`]}),(0,G.jsx)(Kt,{})]}),Ui(t,o?.id,o?.id===`guest`)?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(It,{onClick:()=>{f(t.name),u(t)},children:[(0,G.jsx)(ar,{className:`size-3.5`,"aria-hidden":`true`}),`Rename`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>h(t),children:[(0,G.jsx)($r,{className:`size-3.5 text-destructive`,"aria-hidden":`true`}),`Delete`]})]}):(0,G.jsx)(It,{disabled:!0,children:`Only the creator can rename or delete`})]})]})})]})},t.uid??t.id)),k&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Unassigned`,isActive:T===`unassigned`,onClick:()=>A(`unassigned`),children:[(0,G.jsx)(no,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Unassigned`})]})})]})})]}),(0,G.jsx)(RT,{project:g,onOpenChange:e=>{e||_(null)}}),(0,G.jsx)(Yr,{open:l!==null,onOpenChange:e=>{e||u(null)},children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Rename Project`})}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`rename-project-input`,children:`Name`}),(0,G.jsx)(wi,{id:`rename-project-input`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d.trim()&&l&&(i(l.id,d.trim()),u(null))},autoFocus:!0})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),(0,G.jsx)(U,{className:`h-9 px-6`,disabled:!d.trim(),onClick:()=>{l&&d.trim()&&(i(l.id,d.trim()),u(null))},children:`Save Changes`})]})]})}),(0,G.jsx)(Yr,{open:y,onOpenChange:b,children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Create Project`})}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`create-project-input`,children:`Project name`}),(0,G.jsx)(wi,{id:`create-project-input`,value:x,onChange:e=>S(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x.trim()&&(n(x.trim()),b(!1),S(``))},autoFocus:!0})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),(0,G.jsx)(U,{className:`h-9 px-6`,disabled:!x.trim(),onClick:()=>{x.trim()&&(n(x.trim()),b(!1),S(``))},children:`Create`})]})]})}),(0,G.jsx)(AT,{isOpen:p!==null,onOpenChange:e=>{e||h(null)},mode:`move-to-trash`,view:`project`,activeDocument:p?{id:p.id,name:p.name}:void 0,deleteProject:r,onAfterDelete:()=>h(null)})]})}var BT=[`INSTANCE_LICENSE_REQUIRED`,`LICENSE_SYNC_REQUIRED`,`TEAM_LIMIT_REACHED`];function VT({open:e,onOpenChange:t,onCreate:n,onCreated:r,onLicenseIssue:i}){let[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{e||(o(``),c(``),u(!1))},[e]),(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsx)(Vr,{size:`md`,children:(0,G.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),c(``),u(!0);try{let e=await n({name:a});t(!1),r?.(e)}catch(e){if(i&&BT.includes(e?.code)){t(!1),i(e.code);return}c(e?.message||`Team could not be created.`)}finally{u(!1)}},children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Add Team`}),(0,G.jsx)(Fr,{children:`Create a Team using this installation's active license.`})]}),(0,G.jsxs)(Wr,{className:`space-y-4`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`team-name`,children:`Team name`}),(0,G.jsx)(wi,{id:`team-name`,value:a,onChange:e=>o(e.target.value),placeholder:`Acme Engineering`,maxLength:100,required:!0,autoFocus:!0})]}),s&&(0,G.jsx)(`p`,{className:`text-sm text-destructive`,role:`alert`,children:s})]}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(U,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:l,children:`Cancel`}),(0,G.jsx)(U,{type:`submit`,disabled:l||!a.trim(),children:l?`Creating…`:`Add Team`})]})]})})})}var HT=`https://www.erdbuilderpro.com/pricing/self-host`;function UT(e){if(e.active===!0){let t=e.usage?.teamCount??e.usage?.team_count??0,n=e.maxTeams??e.max_teams;return typeof n==`number`&&t>=n?{kind:`limit`,used:t,max:n}:null}return e.code===`LICENSE_NOT_ACTIVATED`?{kind:`inactive`}:e.code===`LICENSE_EXPIRED`?{kind:`expired`}:{kind:`invalid`}}function WT({issue:e,onOpenChange:t,onOpenLicenseSettings:n,onManageTeams:r,onRetry:i}){let a=()=>t(!1),o=()=>window.open(HT,`_blank`,`noopener,noreferrer`),s=()=>{a(),n()},c=e?(e=>{switch(e.kind){case`inactive`:return{title:`Unlock Teams`,body:`Teams need a Self-host license key. Personal Workspace stays free.`,primary:[`Buy license`,o],secondary:[`Activate key`,s]};case`expired`:return{title:`License expired`,body:`Renew to access your Teams again. Your data is safe.`,primary:[`Renew`,o],secondary:[`Check again`,s]};case`invalid`:return{title:`License can't be verified`,body:`Reactivate your key on this server. Your data is safe.`,primary:[`Reactivate`,s],secondary:[`Close`,a]};case`sync`:return{title:`Can't reach license server`,body:`Existing Teams still work. Try again later.`,primary:[`Try again`,()=>{a(),i()}],secondary:[`Close`,a]};case`limit`:return{title:`Team limit reached`,body:`You're using ${e.used} of ${e.max} Teams. Upgrade to add more.`,primary:[`Upgrade`,o],secondary:[`Manage Teams`,()=>{a(),r()}]}}})(e):null;return(0,G.jsx)(Yr,{open:e!==null,onOpenChange:t,children:(0,G.jsx)(Vr,{size:`sm`,children:c&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:c.title}),(0,G.jsx)(Fr,{children:c.body})]}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(U,{type:`button`,variant:`outline`,onClick:c.secondary[1],children:c.secondary[0]}),(0,G.jsx)(U,{type:`button`,onClick:c.primary[1],children:c.primary[0]})]})]})})})}var GT=W.memo(({projects:e,globalSearchResults:t,isGlobalSearchLoading:n,onGlobalSearchResultSelect:r,onViewChange:i,onProjectCreate:a,onProjectUpdate:o,onProjectDelete:s,onLogout:c,globalSearchQuery:l,onGlobalSearchChange:u,isProjectsLoading:d,user:f,isOnline:p,onOpenFeedback:h,teams:g,teamsAvailable:_,licenseRequired:y,activeTeamId:b,onTeamsRefresh:x,onTeamSelect:S,onTeamManage:C,onTeamCreate:w,onTeamCreated:T,onOpenLicenseSettings:E,ssoPortalUrl:D,...O})=>{let k=m(),A=v(),{isMobile:j}=wh(),[M,N]=(0,W.useState)(!1),[P,F]=(0,W.useState)(null),I=async e=>{try{let t=await Si(`/api/license/status`),n=t.ok?UT(await t.json()):null;if(n||e){F(n||e||null);return}}catch{}N(!0)},L=e=>{e===`LICENSE_SYNC_REQUIRED`?F({kind:`sync`}):I({kind:`invalid`})},R=yi(),ee=!R&&!f?.isSso&&(f?.isSuperAdmin!==void 0||f?.is_super_admin!==void 0),te=!!(f?.isSuperAdmin||f?.is_super_admin),ne=f?.isSso===!0||R||ee&&y,re=()=>{if(D)try{window.location.assign(new URL(`/dashboard`,D).toString())}catch{}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Eh,{collapsible:`icon`,...O,children:[(0,G.jsxs)(ane,{className:`gap-2 border-b border-sidebar-border`,children:[(0,G.jsx)(DT,{teams:g,activeTeamId:b,enabled:_||g.length>0||te&&y,canManageTeams:te,onOpen:x,onSelect:S,onAdd:()=>{I()},onManage:C}),(0,G.jsx)(kT,{query:l,results:t,isLoading:n,isOnline:p,showDbClient:R,onQueryChange:u,onResultSelect:r})]}),(0,G.jsxs)(Dh,{children:[(0,G.jsx)(Oh,{children:(0,G.jsx)(Ah,{children:(0,G.jsxs)(jh,{children:[(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Dashboard`,isActive:k.pathname===`/`,onClick:()=>A(`/`),children:[(0,G.jsx)(ho,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Dashboard`})]})}),ee&&te&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(Nh,{title:`Instance Administration`,"aria-label":`Instance Administration`,isActive:k.pathname===`/team-workspaces`||k.pathname===`/users`,children:[(0,G.jsx)(Uo,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Instance Administration`}),(0,G.jsx)(Tr,{"aria-hidden":`true`,className:`ml-auto text-muted-foreground group-data-[collapsible=icon]:hidden`})]})}),(0,G.jsxs)(Gt,{side:j?`bottom`:`right`,align:`start`,sideOffset:8,children:[(0,G.jsxs)(It,{onClick:()=>A(`/team-workspaces`),children:[(0,G.jsx)(ro,{"aria-hidden":`true`}),`Team`]}),(0,G.jsxs)(It,{onClick:()=>A(`/users`),children:[(0,G.jsx)($o,{"aria-hidden":`true`}),`Users`]})]})]})}),f?.isSso&&D&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Manage account & billing`,onClick:re,children:[(0,G.jsx)(Ga,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Manage account & billing`})]})}),f?.isSso&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Library`,isActive:k.pathname===`/library`,disabled:!p,onClick:()=>A(`/library`),children:[(0,G.jsx)(_o,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Library`})]})})]})})}),(0,G.jsx)(zT,{activeTeamId:b,isProjectsLoading:d,onProjectCreate:a,onProjectDelete:s,onProjectUpdate:o,projects:e,user:f})]}),(0,G.jsxs)(one,{className:`border-t border-sidebar-border`,children:[ne&&(0,G.jsx)(`div`,{className:`group-data-[collapsible=icon]:hidden`,children:(0,G.jsx)(ET,{})}),(0,G.jsx)(CT,{user:f,onLogout:c,onViewChange:i,isOnline:p,onOpenFeedback:h})]})]}),(0,G.jsx)(VT,{open:M,onOpenChange:N,onCreate:w,onCreated:T,onLicenseIssue:L}),(0,G.jsx)(WT,{issue:P,onOpenChange:e=>{e||F(null)},onOpenLicenseSettings:E,onManageTeams:()=>A(`/team-workspaces`),onRetry:()=>{I()}})]})});function KT({isOpen:e,onOpenChange:t,documentType:n,documentUid:r,documentId:i,documentTitle:a,isPublicView:o=!1,initialSettings:s,onSettingsSaved:c}){let[u,d]=W.useState(s?.share_token||``),[f,p]=W.useState(!1),[m,h]=W.useState(s?.is_public||!1),[g,_]=W.useState(``),[v,y]=W.useState(!1);W.useEffect(()=>{if(s?.expiry_date){let e=new Date(s.expiry_date),t=new Date,n=e.getTime()-t.getTime(),r=Math.ceil(n/864e5);r>0&&_(r.toString())}d(s?.share_token||``),h(s?.is_public||!1)},[s]);let b={erd:`diagram`,notes:`note`,drawings:`drawing`,flowchart:`flowchart`}[n]||n,x=`${window.location.origin}/view/${b}/${r}`;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-md`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:o?`Share Document`:`Share "${a}"`}),(0,G.jsx)(Fr,{children:o?`Share this link with others to view this document.`:m?`Anyone with this link can view this document. No account required.`:`This document is currently private. Only you can access it.`})]}),(0,G.jsxs)(Wr,{className:`space-y-4`,children:[!o&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/30 transition-colors hover:bg-muted/50`,children:[(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m?(0,G.jsx)(so,{className:`w-4 h-4 text-primary`}):(0,G.jsx)(So,{className:`w-4 h-4 text-muted-foreground`}),(0,G.jsx)(ha,{htmlFor:`public-status`,className:`text-sm font-bold`,children:`Public Access`})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Enable sharing via public link`})]}),(0,G.jsx)(Kh,{id:`public-status`,checked:m,onCheckedChange:e=>h(e)})]}),(0,G.jsxs)(`div`,{className:`space-y-4 transition-all duration-300 ${m||o?`opacity-100`:`opacity-40 pointer-events-none grayscale-[0.5]`}`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(ha,{htmlFor:`share-link`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Public Link`}),(0,G.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,G.jsx)(wi,{id:`share-link`,readOnly:!0,value:x,className:`flex-1 bg-muted/20 font-mono text-xs`}),(0,G.jsx)(U,{onClick:()=>{navigator.clipboard.writeText(x),p(!0),l.success(`Link copied to clipboard!`),setTimeout(()=>p(!1),2e3)},size:`icon`,variant:`outline`,className:`shrink-0 cursor-pointer hover:bg-primary/10 hover:text-primary transition-colors`,disabled:!m&&!o,children:f?(0,G.jsx)(Yt,{className:`w-4 h-4 text-green-500`}):(0,G.jsx)(Ua,{className:`w-4 h-4`})})]})]}),!o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(ha,{htmlFor:`access-token`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Access Token (Optional)`}),(0,G.jsxs)(U,{variant:`link`,size:`sm`,onClick:()=>{let e=Math.random().toString(36).substring(2,10).toUpperCase();d(e),l.info(`Secure token generated`)},className:`h-auto p-0 text-[10px] uppercase font-bold tracking-tighter cursor-pointer text-primary hover:no-underline`,disabled:!m,children:[(0,G.jsx)(cr,{className:`w-3 h-3 mr-1`}),`Generate`]})]}),(0,G.jsx)(wi,{id:`access-token`,placeholder:`Enter or generate a token...`,value:u,onChange:e=>d(e.target.value),disabled:!m,className:`font-mono text-xs`})]}),(0,G.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,G.jsx)(ha,{htmlFor:`valid-until`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Duration (Days)`}),(0,G.jsx)(wi,{id:`valid-until`,type:`number`,placeholder:`Forever`,value:g,onChange:e=>_(e.target.value),disabled:!m,className:`text-xs`})]})]})]})]}),(0,G.jsx)(Gr,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:o?(0,G.jsx)(U,{type:`button`,onClick:()=>t(!1),className:`cursor-pointer w-full sm:w-auto font-bold`,children:`Close`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(U,{variant:`ghost`,onClick:()=>t(!1),className:`cursor-pointer order-2 sm:order-1 font-semibold`,disabled:v,children:`Cancel`}),(0,G.jsx)(U,{type:`button`,onClick:async()=>{y(!0);try{let e=n===`erd`?`diagrams`:n===`flowchart`?`flowcharts`:n,r=null;if(g&&!isNaN(parseInt(g))){let e=new Date;e.setDate(e.getDate()+parseInt(g)),r=e.toISOString()}if(!(await Si(`/api/${e}/${i}/share`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({is_public:m,share_token:u,expiry_date:r})})).ok)throw Error(`Failed to save settings`);l.success(`Sharing settings updated!`),c&&c(),t(!1)}catch(e){l.error(e.message||`Something went wrong`)}finally{y(!1)}},className:`cursor-pointer order-1 sm:order-2 font-bold min-w-[120px]`,disabled:v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 mr-2 animate-spin`}),`Saving...`]}):`Save Changes`})]})})]})})}function qT({open:e,onOpenChange:t}){return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{size:`2xl`,className:`max-h-[82vh]`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Table Calculation Guide`})}),(0,G.jsxs)(Wr,{className:`space-y-5 overflow-y-auto pr-1 text-sm leading-6`,children:[(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`How it works`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Type a formula command in a table cell, then leave the cell. The editor replaces the command with the calculated result. Hover the result cell to see the Excel-style source range used for that value.`})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Vertical formulas`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Vertical formulas calculate numeric values in the same column. They are intended for header or footer rows.`}),(0,G.jsxs)(`div`,{className:`grid gap-2 rounded-md border bg-muted/30 p-3`,children:[(0,G.jsx)(`code`,{children:`=SUM`}),(0,G.jsx)(`code`,{children:`=SUMV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sum values vertically, for example: SUMV(B2:B5).`}),(0,G.jsx)(`code`,{children:`=AVG`}),(0,G.jsx)(`code`,{children:`=AVGV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Average values vertically, for example: AVGV(C2:C5).`}),(0,G.jsx)(`code`,{children:`=MUL`}),(0,G.jsx)(`code`,{children:`=PRODUCT`}),(0,G.jsx)(`code`,{children:`=MULV`}),(0,G.jsx)(`code`,{children:`=PRODUCTV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Multiply values vertically, for example: PRODUCTV(D2:D5).`})]})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Horizontal formulas`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Horizontal formulas calculate numeric values to the left of the formula cell in the same row.`}),(0,G.jsxs)(`div`,{className:`grid gap-2 rounded-md border bg-muted/30 p-3`,children:[(0,G.jsx)(`code`,{children:`=SUMH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sum values horizontally, for example: SUMH(B2:C2).`}),(0,G.jsx)(`code`,{children:`=AVGH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Average values horizontally, for example: AVGH(B2:D2).`}),(0,G.jsx)(`code`,{children:`=MULH`}),(0,G.jsx)(`code`,{children:`=PRODUCTH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Multiply values horizontally, for example: PRODUCTH(B2:C2).`})]})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Examples`}),(0,G.jsx)(`div`,{className:`rounded-md border overflow-hidden`,children:(0,G.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,G.jsx)(`thead`,{className:`bg-muted/50`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Item`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Qty`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Price`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Total`})]})}),(0,G.jsxs)(`tbody`,{children:[(0,G.jsxs)(`tr`,{className:`border-t`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`Hosting`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`12`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`90.000`}),(0,G.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,G.jsx)(`code`,{children:`=MULH`}),` becomes 1.080.000`]})]}),(0,G.jsxs)(`tr`,{className:`border-t`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`Setup`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`100.000`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`50.000`}),(0,G.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,G.jsx)(`code`,{children:`=SUMH`}),` becomes 150.000`]})]})]})]})}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Text cells are skipped. Indonesian number formatting such as 1.080.000 and decimal commas is accepted. Currency symbols are ignored when possible.`})]})]})]})})}var JT=({onShare:e,onCopyPath:t,onRename:n,onDelete:r,onDuplicate:i,onExportAll:a,onExportMarkdown:o,onCopyMarkdown:s,onImportMarkdown:c,onExportImage:u,isOnline:d,isPublicView:f=!1,isPublic:p=!1,activeFileUid:m,documentType:h,noteContent:g,historyEnabled:_=!1,onOpenHistory:v,onRefresh:y,isRefreshing:b=!1})=>{let[x,S]=(0,W.useState)(!1),C=e=>e.replace(/<[^>]+>/g,``).replace(/&[^;]+;/g,` `).trim(),w=(e=>{let t=e?C(e):``;return t?{words:t.split(/\s+/).filter(Boolean).length,sentences:t.split(/[.!?]+(?:\s|$)/).filter(e=>e.trim().length>0).length,paragraphs:e&&(e.match(/<p[^>]*>[\s\S]*?<\/p>/g)||[]).length||t.split(/\n\s*\n/).filter(Boolean).length,characters:t.replace(/\s/g,``).length}:{words:0,sentences:0,paragraphs:0,characters:0}})(g),T=()=>{if(!m){l.error(`Document link not available`);return}let e={erd:`diagram`,notes:`note`,drawings:`drawing`,flowchart:`flowchart`}[h]||h,t=`${window.location.origin}/view/${e}/${m}`;navigator.clipboard.writeText(t),l.success(`Public share link copied to clipboard`)};return(0,G.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2`,children:[(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(U,{"aria-label":`Actions`,variant:`ghost`,size:`sm`,className:`h-8 text-muted-foreground hover:bg-muted/80 hover:text-foreground hover:shadow-sm active:scale-95 transition-all duration-200`,children:[(0,G.jsx)(`span`,{className:`hidden sm:inline mr-1.5 text-xs font-medium`,children:`Actions`}),(0,G.jsx)(Tr,{className:`h-4 w-4`})]})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-56`,children:[f?(0,G.jsxs)(It,{onClick:T,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Public Link`})]}):(0,G.jsxs)(G.Fragment,{children:[t&&(0,G.jsxs)(It,{onClick:t,children:[(0,G.jsx)(Ua,{className:`text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Path`})]}),e&&(0,G.jsxs)(It,{disabled:!d,onClick:e,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Bo,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Share`})]}),p&&(0,G.jsxs)(It,{disabled:!d,onClick:T,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Public Link`})]}),(0,G.jsx)(Kt,{}),n&&(0,G.jsxs)(It,{disabled:!d,onClick:n,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(No,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Edit`})]}),y&&(0,G.jsxs)(It,{disabled:!d||b,onClick:()=>y(),className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(cr,{className:`h-4 w-4 text-muted-foreground ${b?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:`Refresh`})]}),v&&(0,G.jsxs)(It,{disabled:!_,onClick:()=>v(),className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(uo,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Version History`})]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{disabled:!d,onClick:r,className:`gap-2 text-destructive focus:text-destructive focus:bg-destructive/10 cursor-pointer`,children:[(0,G.jsx)($r,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{children:`Move to Trash`})]})]})]}),(h===`notes`||h===`drawings`)&&!f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{disabled:!d,onClick:i,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Ua,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Duplicate`})]})]}),h===`erd`&&!f&&a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(Ht,{children:[(0,G.jsxs)(Rt,{className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(rn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Export All`})]}),(0,G.jsxs)(Jt,{className:`w-48`,children:[(0,G.jsx)(It,{onClick:a,className:`gap-2 cursor-pointer`,children:(0,G.jsx)(`span`,{children:`Export Schemas`})}),(0,G.jsx)(It,{onClick:u,className:`gap-2 cursor-pointer`,children:(0,G.jsx)(`span`,{children:`Download SVG`})})]})]})]}),h===`notes`&&!f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>S(!0),children:[(0,G.jsx)(Aa,{className:`text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Calculation Guide`})]}),(0,G.jsx)(It,{disabled:!d,onClick:s,className:`gap-2 cursor-pointer flex items-center`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Ua,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Markdown`})]})}),c&&(0,G.jsxs)(It,{disabled:!d,onClick:c,className:`gap-2 cursor-pointer flex items-center`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Yn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Import`})]}),(0,G.jsx)(Lt,{children:`⇧⌘I`})]}),(0,G.jsxs)(It,{disabled:!d,onClick:o,className:`gap-2 cursor-pointer flex items-center`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(rn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Export`})]}),(0,G.jsx)(Lt,{children:`⇧⌘E`})]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(Ht,{children:[(0,G.jsxs)(Rt,{className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(ja,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Text Stats`})]}),(0,G.jsx)(Jt,{className:`w-52 p-1`,children:(0,G.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Words`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.words.toLocaleString()})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sentences`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.sentences.toLocaleString()})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Paragraphs`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.paragraphs.toLocaleString()})]}),(0,G.jsx)(Kt,{className:`my-1.5`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Characters`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.characters.toLocaleString()})]})]})})]})]})]})]}),h===`notes`&&(0,G.jsx)(qT,{open:x,onOpenChange:S})]})},YT=W.memo(({featureLabel:e,documentPath:t,sidebarDisabled:n=!1,activeProjectName:r,activeFileName:i,view:a,hasActiveItem:o,syncError:s,isSyncing:c,isRefreshing:u,isLocalSaving:f=!1,hasPendingSyncs:p,activeFileUid:h,activeFileId:g,initialShareSettings:_,onSettingsSaved:v,isPublicView:y=!1,isOnline:b,updatedAt:x,onDelete:S,onRename:C,onSave:w,onExportAll:T,onExportSQL:E,onExportImage:D,onExportMarkdown:O,onCopyMarkdown:k,onImportMarkdown:A,onDuplicate:j,isGuest:M=!1,breadcrumbLabel:N,noteContent:P,historyAvailable:F=!0,canManage:I=!0,onRefresh:L,discussionPanel:R,tabsRef:ee,aiAssistant:te})=>{let ne=m(),[re,ie]=W.useState(!1),{setRightPanelMode:z}=bn(),ae=!(!F||a!==`erd`&&a!==`flowchart`&&(a!==`notes`&&a!==`drawings`||!a)||!h||M||y||!b||f||c||p),oe=W.useCallback(()=>z(`history`),[z]),se=W.useCallback(e=>{navigator.clipboard.writeText(`${e} > ${r||`No Workspace`} > ${i}`).then(()=>l.success(`File path copied`)).catch(()=>l.error(`Failed to copy file path`))},[i,r]),ce=t??ne.pathname,le=!y&&/^\/(notes|diagrams|drawings|flowcharts|db-client)\/[^/]+$/.test(ce);return(0,G.jsxs)(`header`,{className:`flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 w-full overflow-hidden border-b bg-background/50 backdrop-blur-sm`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 px-2 sm:px-4`,children:[!y&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nne,{className:`-ml-1 shrink-0`,disabled:n}),(0,G.jsx)(Ti,{orientation:`vertical`,className:`h-4 shrink-0 bg-border/50`})]}),(0,G.jsx)(`div`,{ref:ee,className:le?`flex min-w-0 flex-1 items-center`:`hidden`}),!le&&(0,G.jsx)(Ph,{className:`min-w-0 flex items-center`,children:(0,G.jsx)(Fh,{className:`min-w-0 flex-nowrap items-center`,children:!y&&(()=>{let n=t??ne.pathname;if(n===`/`)return(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:`Dashboard`})});if(n.startsWith(`/projects/`))return null;if(n.startsWith(`/table/`)){let e={notes:`Notes`,erd:`ERD Builder`,"db-client":`DB Client`,drawings:`Drawings`,flowchart:`Flowcharts`},t=n.match(/^\/table\/([^/]+)$/)?.[1],r=t?e[t]||t:`Unknown`;return(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:r})})}return n.startsWith(`/trash`)?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:`Trash`})}):n.startsWith(`/library`)?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:`Library`})}):n.startsWith(`/teams/`)?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ih,{className:`shrink-0 text-muted-foreground`,children:`Teams`}),(0,G.jsx)(Rh,{}),(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:N||`Team management`})})]}):N?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:N})}):(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-muted-foreground`,children:e})})})()})})]}),!b&&!y&&(0,G.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 px-3 py-1 rounded-full bg-destructive/10 border border-destructive/20 text-destructive animate-in fade-in slide-in-from-top-1 duration-500`,children:[(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-destructive animate-pulse`}),(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider`,children:`Offline Mode: Navigation Disabled`})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 pr-2 sm:pr-4`,children:[!!ne.pathname.match(/^\/(notes|diagrams|drawings|flowcharts)\/[^/]+$/)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2`,children:[!y&&s&&(0,G.jsxs)(`span`,{role:`status`,title:`Changes saved locally, but cloud sync failed. We'll retry automatically.`,className:`flex shrink-0 items-center gap-1 text-destructive`,children:[(0,G.jsx)(za,{className:`size-4`}),(0,G.jsx)(`span`,{className:`hidden lg:inline text-xs`,children:`Sync Failed`})]}),!y&&_?.is_public&&(0,G.jsxs)(Vh,{variant:`outline`,title:`This document is shared publicly via a secret link.`,className:`shrink-0 gap-1`,children:[(0,G.jsx)(so,{className:`size-3`}),(0,G.jsx)(`span`,{className:`hidden lg:inline`,children:`Public`})]}),R,(0,G.jsx)(JT,{onCopyPath:y?void 0:()=>se(new URLSearchParams(ne.search).get(`feature`)===`db-client`?`DB Client`:{notes:`Notes`,erd:`ERD Builder`,flowchart:`Flowcharts`,drawings:`Drawings`}[a]||e),onShare:I?()=>b&&ie(!0):void 0,onDelete:S,onRename:C,onDuplicate:j,onExportAll:T,onExportSQL:E,onExportImage:D,onExportMarkdown:O,onCopyMarkdown:k,onImportMarkdown:A,isOnline:b,isPublicView:y,isPublic:_?.is_public,activeFileUid:h,documentType:a,noteContent:P,historyEnabled:ae,onOpenHistory:M||y?void 0:oe,onRefresh:M||y?void 0:L,isRefreshing:u}),h&&g&&b&&(0,G.jsx)(KT,{isOpen:re,onOpenChange:ie,documentType:a,documentUid:h,documentId:g,documentTitle:i||`Untitled`,isPublicView:y,initialSettings:_,onSettingsSaved:v})]}),te&&(0,G.jsxs)(U,{type:`button`,variant:`outline`,onClick:te.onToggle,"aria-pressed":te.open,"aria-keyshortcuts":te.shortcut.ariaKeyShortcuts,title:`AI Assistant (${te.shortcut.label})`,className:d(`ml-1 h-8 gap-2 px-2.5 text-[13px] font-medium`,te.open&&`border-ring bg-muted`),children:[(0,G.jsx)(Qr,{className:`size-4 text-primary`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:`AI Assistant`}),te.answering&&!te.open&&(0,G.jsxs)(`span`,{title:`AI is still answering`,className:`text-primary`,children:[(0,G.jsx)(xo,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`AI is still answering`})]}),(0,G.jsx)(Di,{className:`hidden lg:inline-flex`,children:te.shortcut.label})]})]})]})}),XT=`(max-width: 1023px)`;function ZT(){let[e,t]=(0,W.useState)(()=>typeof window>`u`||!window.matchMedia(XT).matches);return(0,W.useEffect)(()=>{let e=window.matchMedia(XT),n=e=>t(!e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),{open:e,onOpenChange:t}}var QT=`https://api.erdbuilderpro.com/api/feedback`;function $T(){return QT}function eE({open:e,onOpenChange:t,isCloud:n=!1}){let[r,i]=W.useState(!1),[a,o]=W.useState(``),[s,c]=W.useState(`suggestion`),[u,d]=W.useState(``);return(0,G.jsx)(Yr,{open:e,onOpenChange:e=>{t(e),e||o(``)},children:(0,G.jsx)(Vr,{className:`sm:max-w-106.25 border-border bg-popover/95 backdrop-blur-xl shadow-2xl`,children:(0,G.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),a.trim()){i(!0);try{if((n?await Si(`/api/feedback`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:a,category:s,page_path:window.location.pathname})}):await fetch($T(),{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`omit`,body:JSON.stringify({content:a,category:s,email:u,url:window.location.href,browser:navigator.userAgent})})).ok)l.success(`Feedback terkirim! Terima kasih masukannya.`),t(!1),o(``);else throw Error()}catch{l.error(`Gagal mengirim feedback. Coba lagi nanti.`)}finally{i(!1)}}},className:`flex flex-col max-h-[inherit]`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{className:`text-xl font-bold`,children:`Kirim Masukan`}),(0,G.jsx)(Fr,{className:`text-sm text-muted-foreground`,children:`Bantu kami membuat ERD Builder Pro jadi lebih baik. Saran Anda sangat berharga!`})]}),(0,G.jsxs)(Wr,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`category`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Tipe Masukan`}),(0,G.jsxs)(_r,{value:s,onValueChange:e=>e&&c(e),children:[(0,G.jsx)(mr,{id:`category`,className:`bg-white/5 border-white/10 focus:ring-primary/50`,children:(0,G.jsx)(gr,{placeholder:`Pilih tipe`,children:s===`suggestion`?`Saran Fitur`:s===`bug`?`Lapor Bug`:s===`other`?`Kritik / Lainnya`:s})}),(0,G.jsxs)(pr,{className:`bg-popover border-border text-popover-foreground`,children:[(0,G.jsx)(fr,{value:`suggestion`,className:`focus:bg-muted`,children:`Saran Fitur`}),(0,G.jsx)(fr,{value:`bug`,className:`focus:bg-muted text-destructive`,children:`Lapor Bug`}),(0,G.jsx)(fr,{value:`other`,className:`focus:bg-muted`,children:`Kritik / Lainnya`})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`content`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Pesan`}),(0,G.jsx)(`textarea`,{id:`content`,autoComplete:`off`,className:`flex min-h-35 w-full rounded-lg border border-border bg-muted/50 px-4 py-3 text-sm ring-offset-background placeholder:text-muted-foreground/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-all resize-none`,placeholder:`Tuliskan masukan Anda di sini...`,value:a,onChange:e=>o(e.target.value),maxLength:n?2e3:3e3,required:!0})]}),!n&&(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`email`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Email (Opsional)`}),(0,G.jsx)(wi,{id:`email`,type:`email`,autoComplete:`off`,placeholder:`email@contoh.com`,className:`bg-muted/50 border-border focus:ring-primary/50 h-10 px-4`,value:u,onChange:e=>d(e.target.value)})]})]}),(0,G.jsxs)(Gr,{className:`gap-3`,children:[(0,G.jsx)(U,{variant:`ghost`,type:`button`,onClick:()=>t(!1),className:`hover:bg-muted`,children:`Batal`}),(0,G.jsx)(U,{type:`submit`,disabled:r,className:`bg-primary text-primary-foreground hover:bg-primary/90 shadow-lg shadow-primary/20`,children:r?`Mengirim...`:`Kirim Masukan`})]})]})})})}var tE=[{key:`disappointment`,label:`Seberapa kecewa Anda kalau tidak bisa memakai ERD Builder Pro lagi?`,options:[{value:`very_disappointed`,label:`Sangat kecewa`},{value:`somewhat_disappointed`,label:`Agak kecewa`},{value:`not_disappointed`,label:`Tidak kecewa`}]},{key:`primary_use`,label:`Untuk apa Anda paling banyak memakainya?`,options:[{value:`design_new_schema`,label:`Merancang skema baru`},{value:`document_existing_database`,label:`Mendokumentasikan database yang ada`},{value:`team_collaboration`,label:`Kolaborasi dengan tim`},{value:`ai_features`,label:`Fitur AI`},{value:`other`,label:`Lainnya`}]},{key:`main_blocker`,label:`Apa yang paling menghambat Anda?`,options:[{value:`hard_to_learn`,label:`Sulit dipahami di awal`},{value:`missing_feature`,label:`Fitur yang dibutuhkan belum ada`},{value:`slow_or_error`,label:`Lambat atau error`},{value:`team_reluctant`,label:`Tim sulit diajak pindah`},{value:`none`,label:`Tidak ada hambatan`}]}],nE={beta_trial:`Satu hal yang paling ingin Anda ubah?`,cloud_trial:`Apa yang membuat Anda ragu berlangganan?`},rE=1e3;function iE({teamId:e}){let[t,n]=W.useState(null),[r,i]=W.useState(!1),[a,o]=W.useState({}),[s,c]=W.useState(``),[u,d]=W.useState(!1),[f,p]=W.useState(null);if(W.useEffect(()=>{let e=!1;return n(null),i(!1),o({}),c(``),p(null),Si(`/api/cloud/trial-survey`).then(e=>e.ok?e.json():null).then(t=>{!e&&t?.show&&(t.survey_key===`beta_trial`||t.survey_key===`cloud_trial`)&&n(t.survey_key)}).catch(()=>{}),()=>{e=!0}},[e]),!t)return null;let m=()=>{n(null),Si(`/api/cloud/trial-survey/dismiss`,{method:`POST`}).catch(()=>{})};return(0,G.jsxs)(`section`,{"aria-labelledby":`trial-survey-title`,className:`fixed bottom-20 right-4 z-40 flex max-h-[calc(100dvh-6rem)] w-[min(22rem,calc(100vw-2rem))] flex-col rounded-xl bg-popover text-popover-foreground shadow-xl ring-1 ring-foreground/10 sm:right-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2 px-4 py-3 ${r?`border-b`:`pb-0`}`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`h2`,{id:`trial-survey-title`,className:`text-sm font-semibold`,children:`Bagaimana Trial Anda sejauh ini?`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`4 pertanyaan singkat, kurang dari 1 menit.`})]}),(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:m,"aria-label":`Tutup, tampilkan lagi besok`,children:(0,G.jsx)(Pr,{"aria-hidden":`true`})})]}),r?(0,G.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),d(!0),p(null);try{let e=await Si(`/api/cloud/trial-survey`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({answers:{...a,open_answer:s}})});if(!e.ok){p(e.status===429?`Terlalu banyak kiriman. Coba lagi nanti.`:`Jawaban belum terkirim. Coba lagi.`);return}n(null),l.success(`Terima kasih! Jawaban Anda sudah kami terima.`)}catch{p(`Jawaban belum terkirim. Periksa koneksi lalu coba lagi.`)}finally{d(!1)}},className:`flex min-h-0 flex-col`,children:[(0,G.jsxs)(`div`,{className:`space-y-4 overflow-y-auto px-4 py-3`,children:[tE.map((e,t)=>(0,G.jsxs)(`fieldset`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`legend`,{className:`mb-1.5 text-sm font-medium`,children:[t+1,`. `,e.label]}),e.options.map(n=>(0,G.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-sm hover:bg-muted has-checked:bg-primary/10`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`trial-survey-${e.key}`,value:n.value,checked:a[e.key]===n.value,onChange:()=>o(t=>({...t,[e.key]:n.value})),className:`size-4 accent-primary`,required:!0,autoFocus:t===0&&n===e.options[0]}),n.label]},n.value))]},e.key)),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`label`,{htmlFor:`trial-survey-open-answer`,className:`block text-sm font-medium`,children:[`4. `,nE[t],` `,(0,G.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(opsional)`})]}),(0,G.jsx)(`textarea`,{id:`trial-survey-open-answer`,value:s,onChange:e=>c(e.target.value),maxLength:rE,rows:3,className:`w-full resize-none rounded-lg border border-border bg-muted/50 px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`})]})]}),(0,G.jsxs)(`div`,{className:`border-t px-4 py-3`,children:[f&&(0,G.jsx)(`p`,{role:`alert`,className:`mb-2 text-sm text-destructive`,children:f}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:m,children:`Nanti saja`}),(0,G.jsx)(U,{type:`submit`,size:`sm`,disabled:u,children:u?`Mengirim...`:`Kirim`})]})]})]}):(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:m,children:`Nanti saja`}),(0,G.jsx)(U,{type:`button`,size:`sm`,onClick:()=>i(!0),children:`Isi sekarang`})]})]})}var aE=({isOpen:e,onOpenChange:t,selectedEntity:n,deleteEntity:r,setSelectedNodeId:i})=>(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(ei,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Delete Table`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Are you sure you want to delete the table `,(0,G.jsx)(`strong`,{children:n?.name}),`? This action cannot be undone.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:()=>{n&&(r(n.id),i(null),t(!1))},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})}),oE=e=>e===`erd`?`diagram`:e===`notes`?`note`:e===`drawings`?`drawing`:e===`db-client`?`DB Client`:`flowchart`,sE=({isOpen:e,onOpenChange:t,mode:n=`edit`,view:r,activeDocument:i,newName:a,setNewName:o,projects:s,requireProject:c=!1,canMoveProject:u=!1,selectedProjectId:f,setSelectedProjectId:p,onCreate:m,onProjectCreate:h,updateDiagram:g,updateNote:_,updateDrawing:v,updateFlowchart:y,updateDbClient:b,onMoveDiagramToProject:x,onMoveNoteToProject:S,onMoveDrawingToProject:C,onMoveFlowchartToProject:w,onRenameSuccess:T,fileTypes:E,onViewChange:D,onViewPlans:O,onOpenDbConnections:k})=>{let A=n===`create`,j=E?.find(e=>e.value===r),M=A&&!!j?.locked,N=A&&r===`db-client`,P=i?.project_id??i?.projectId,F=c&&f===`none`&&(A||P!=null),[I,L]=(0,W.useState)(!1),[R,ee]=(0,W.useState)(``),[te,ne]=(0,W.useState)(!1),[re,ie]=(0,W.useState)(!1),z=e=>{e||(L(!1),ee(``)),t(e)},ae=async()=>{let e=R.trim();if(e&&h&&!te){ne(!0);try{let t=await h(e);if(!t){l.error(`Failed to create project`);return}p(String(t.id)),L(!1),ee(``)}catch{l.error(`Failed to create project`)}finally{ne(!1)}}};(0,W.useEffect)(()=>{if(e&&!A&&i){let e=i?.project_id??i?.projectId;p(e==null?`none`:String(e))}},[e]);let oe=async()=>{if(I||te||re||!a.trim()||F||M||N)return;if(A){ie(!0);try{await m?.(a.trim(),f===`none`?null:f)&&z(!1)}finally{ie(!1)}return}let e=(r===`db-client`||r===`notes`||r===`flowchart`||r===`drawings`)&&i?.uid||i?.id;if(e&&a.trim()){let t=f===`none`?null:f,n=a.trim()!==(i?.title||i?.name),o=r!==`db-client`&&String(t)!==String(P);if(o&&!u){l.error(`Only the file creator can move this file.`);return}try{if(n&&(r===`erd`?await g?.(e,a,{silent:!0}):r===`notes`?await _?.(String(e),a,{silent:!0}):r===`drawings`?await v?.(e,a,{silent:!0}):r===`flowchart`?await y?.(e,a,{silent:!0}):r===`db-client`&&await b?.(String(e),a.trim())),o){let n;if(r===`erd`?n=await x?.(e,t,{silent:!0}):r===`notes`?n=await S?.(e,t,{silent:!0}):r===`drawings`?n=await C?.(e,t,{silent:!0}):r===`flowchart`&&(n=await w?.(e,t,{silent:!0})),n===!1)throw Error(`Failed to move document`)}(n||o)&&T&&await T(),l.success(r===`db-client`?`DB Client renamed successfully`:`Document updated successfully`),z(!1)}catch{l.error(r===`db-client`?`Failed to rename DB Client`:`Failed to update document`)}}};return(0,G.jsx)(Yr,{open:e,onOpenChange:z,children:(0,G.jsxs)(Vr,{className:E&&A?`sm:max-w-md`:`sm:max-w-sm`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:A?E?`New file`:`Create ${oE(r)}`:`Edit`}),(0,G.jsx)(Fr,{children:A?`Choose a project for your new ${oE(r)}.`:r===`db-client`?`Change the name of this DB Client.`:u?`Update the name and project for your ${oE(r)}.`:`Update the name of this ${oE(r)}.`})]}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[A&&E&&(0,G.jsxs)(`fieldset`,{children:[(0,G.jsx)(`legend`,{className:`sr-only`,children:`File type`}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:E.map(e=>{let t=e.icon;return(0,G.jsxs)(`label`,{className:d(`relative flex cursor-pointer flex-col items-center gap-1.5 rounded-lg border border-border px-2 py-3 text-center text-xs font-medium transition-colors hover:bg-accent/50`,`has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring`,r===e.value&&`border-primary bg-primary/5 text-foreground`,e.locked&&`text-muted-foreground`),children:[(0,G.jsx)(`input`,{type:`radio`,name:`create-file-type`,value:e.value,checked:r===e.value,onChange:()=>D?.(e.value),className:`sr-only`}),(0,G.jsx)(t,{className:`size-5`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:e.label}),e.locked&&(0,G.jsx)(`span`,{className:`absolute right-1.5 top-1.5 rounded border border-primary/30 px-1 text-[9px] font-semibold uppercase text-primary`,children:`Pro`})]},e.value)})})]}),M?(0,G.jsxs)(`div`,{className:`rounded-lg border border-primary/20 bg-primary/5 px-3.5 py-3 text-sm`,children:[(0,G.jsxs)(`p`,{className:`font-medium`,children:[j?.label,` needs a paid Cloud plan`]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Plans, limits, and checkout are managed in ERDBPro SaaS.`}),O&&(0,G.jsxs)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:O,children:[`View Cloud plans`,(0,G.jsx)(Ca,{className:`size-4`})]})]}):N?(0,G.jsxs)(`div`,{className:`rounded-lg border border-border px-3.5 py-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`DB Client files start from a database connection`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Pick a connection and a database, then choose the project for the new DB Client.`}),k&&(0,G.jsx)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:()=>{z(!1),k()},children:`Open database connections`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`rename-input`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:A||r===`db-client`?`Name`:`New Name`}),(0,G.jsx)(wi,{id:`rename-input`,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a.trim()&&oe()},autoFocus:!0})]}),r!==`db-client`&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`document-project-select`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(_r,{value:f,onValueChange:e=>e!==null&&p(e),disabled:!A&&!u||I||te,children:[(0,G.jsx)(mr,{id:`document-project-select`,className:`min-w-0 flex-1`,"aria-required":c,"aria-describedby":A&&F?`document-project-hint`:void 0,children:(0,G.jsx)(gr,{children:f===`none`?c?`Select Project`:`No project`:s.find(e=>e.id.toString()===f)?.name||`Select Project`})}),(0,G.jsxs)(pr,{children:[!c&&(0,G.jsx)(fr,{value:`none`,children:`No project`}),s.map(e=>(0,G.jsx)(fr,{value:e.id.toString(),children:e.name},e.id))]})]}),A&&h&&(0,G.jsx)(U,{type:`button`,variant:`outline`,size:`icon-lg`,className:`shrink-0`,"aria-label":I?`Cancel adding project`:`Add a project`,"aria-expanded":I,"aria-controls":`new-project-field`,disabled:te,onClick:()=>{L(!I),ee(``)},children:I?(0,G.jsx)(Pr,{className:`size-4`}):(0,G.jsx)(jt,{className:`size-4`})})]}),A&&F&&!I&&(0,G.jsx)(`p`,{id:`document-project-hint`,className:`mt-1.5 px-1 text-xs text-muted-foreground`,children:`Every file needs a project. Choose one, or add one with +.`}),A&&I&&(0,G.jsxs)(`div`,{id:`new-project-field`,className:`mt-3 space-y-2`,children:[(0,G.jsx)(Dr,{htmlFor:`new-project-name`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New project name`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{id:`new-project-name`,value:R,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ae())},placeholder:`Enter project name`,className:`min-w-0 flex-1`,autoFocus:!0,disabled:te}),(0,G.jsx)(U,{type:`button`,size:`lg`,className:`shrink-0`,disabled:!R.trim()||te,onClick:()=>void ae(),children:te?`Adding…`:`Add project`})]})]})]})]})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),!M&&!N&&(0,G.jsx)(U,{disabled:I||te||re||!a.trim()||F,onClick:oe,className:`h-9 px-6`,children:A?re?`Creating…`:`Create`:`Save Changes`})]})]})})},cE=({isOpen:e,onOpenChange:t,view:n,duplicateName:r,setDuplicateName:i,executeDuplicate:a,isRefreshing:o})=>(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Duplicate Document`}),(0,G.jsxs)(Fr,{children:[`Create a copy of this `,n===`erd`?`diagram`:n===`notes`?`note`:n===`drawings`?`drawing`:`flowchart`,`.`]})]}),(0,G.jsx)(Wr,{children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`duplicate-input`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New Name`}),(0,G.jsx)(wi,{id:`duplicate-input`,type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&r.trim()&&a()},autoFocus:!0})]})})}),(0,G.jsxs)(Gr,{className:`gap-2 sm:gap-0`,children:[(0,G.jsx)(U,{variant:`ghost`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(U,{onClick:a,disabled:!r.trim()||o,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`mr-2 h-4 w-4 animate-spin`}),`Duplicating...`]}):`Duplicate`})]})]})}),lE=r(ce(),1),uE=[{id:`sql`,label:`SQL`,formats:[{id:`mysql`,label:`MySQL`},{id:`postgresql`,label:`PostgreSQL`}]},{id:`laravel`,label:`Laravel`,formats:[{id:`laravel_migration`,label:`Migration`},{id:`laravel_model`,label:`Model`}]},{id:`goravel`,label:`Goravel`,formats:[{id:`goravel`,label:`Model`},{id:`goravel_migration`,label:`Migration`}]},{id:`typescript`,label:`TypeScript`,formats:[{id:`typescript`,label:`Interface`},{id:`zod`,label:`Zod`}]},{id:`prisma`,label:`Prisma`,formats:[{id:`prisma`,label:`Schema`}]}],dE=new Set([`mysql`,`postgresql`,`prisma`]),fE=({open:e,onOpenChange:t,nodes:n,edges:r,fileName:i})=>{let[a,o]=W.useState(uE[0].id),[s,c]=W.useState(uE[0].formats[0].id),[u,d]=W.useState(!1),[f,p]=W.useState(!1),[m,h]=W.useState(!1),{resolvedTheme:g}=pa(),_=uE.find(e=>e.id===a)?.formats??[],v=s,y=dE.has(s),b=W.useMemo(()=>e?ea(v,n,r,i)+`
|
|
48
|
+
`);c=r.pop()||``;for(let e of r)if(e.trim())try{let t=JSON.parse(e);if(t.type===`progress`)y({current:Number(t.current)||0,total:Number(t.total)||5,phase:String(t.phase||``)});else if(t.type===`complete`){await ca.clearAllPendingSyncs(),o(`done`),l.success(t.message||`Database restored successfully!`),n.current=null;return}else if(t.type===`error`)throw Error(t.error||`Restore failed on server.`)}catch(e){if(e instanceof SyntaxError)continue;throw e}}throw Error(`Stream ended unexpectedly. Restore may be incomplete.`)}catch(e){if(e.name===`AbortError`)return;o(`error`),_(e.message||`Restore failed`),l.error(`Restore failed: `+(e.message||`Unknown error`))}n.current=null}},[]),w=(0,W.useCallback)(()=>{t.current&&=(clearTimeout(t.current),null),r.current=null,i.current=null,o(`idle`),c(null),h(null),d(null),p(null),_(``),y({current:0,total:1,phase:``})},[]),T=(0,W.useCallback)(()=>{r.current=null,i.current=null,d(null),p(null),o(`idle`),c(null)},[]),E=(0,W.useCallback)(()=>{t.current&&=(clearTimeout(t.current),null),window.location.reload()},[]),D=(0,W.useCallback)(()=>{n.current&&=(n.current.abort(),null),r.current=null,i.current=null,o(`idle`),c(null),y({current:0,total:1,phase:``})},[]),O=(0,W.useCallback)(()=>{s===`db`?C():S()},[s,C,S]),k=Math.min(Math.round(v.current/v.total*100),100),{accept:A,acceptLabel:j}=b===`desktop`?{accept:`.json,.db,.sqlite,.sqlite3`,acceptLabel:`.json (data) or .db / .sqlite (database restore)`}:{accept:`.json`,acceptLabel:`.json format from Guest Mode export`};if(a===`done`)return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-emerald-500/10 border border-emerald-500/20 rounded-xl`,children:[(0,G.jsx)(yr,{className:`size-6 text-emerald-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:s===`db`?`Database Restored`:`Import Completed`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:s===`db`?`The database file has been restored. The app will reload to apply the changes.`:`Data has been added to your workspace.`})]})]}),m&&(0,G.jsx)(iC,{summary:m}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:E,children:[(0,G.jsx)(cr,{className:`size-3.5 mr-1.5`}),`Reload App Now`]}),(0,G.jsx)(U,{variant:`outline`,size:`sm`,onClick:w,children:`Import Another File`})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`App will reload automatically in a few seconds…`})]});if(a===`preview`){if(s===`db`&&f)return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Za,{className:`size-5 text-blue-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:`Restore Database File`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`This will `,(0,G.jsx)(`strong`,{className:`text-amber-500`,children:`replace`}),` your current local database with the selected file. A safety backup will be created automatically before the restore.`]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[`Use this if you reinstalled the app and want to restore from a previous`,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px] mx-0.5`,children:`.db`}),` file that you saved manually.`]})]})]}),(0,G.jsxs)(`div`,{className:`bg-muted/20 border border-border/40 rounded-lg p-4 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`File`}),(0,G.jsx)(`span`,{className:`font-medium`,children:f.fileName})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Size`}),(0,G.jsx)(`span`,{className:`font-medium`,children:f.fileSize})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:O,children:[(0,G.jsx)(Hn,{className:`size-3.5 mr-1.5`}),`Restore Database`]}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:T,children:[(0,G.jsx)(Pr,{className:`size-3.5 mr-1.5`}),`Cancel`]})]})]});if(s===`json`&&u){let e=Object.values(u).reduce((e,t)=>e+(t||0),0);return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Ya,{className:`size-5 text-blue-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-semibold text-sm`,children:`Import Preview`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e,` items found in the export file. Click `,(0,G.jsx)(`strong`,{children:`Submit`}),` to import the data.`]})]})]}),(0,G.jsx)(iC,{summary:u}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(U,{variant:`default`,size:`sm`,onClick:O,children:[(0,G.jsx)(Hn,{className:`size-3.5 mr-1.5`}),`Submit`]}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:T,children:[(0,G.jsx)(Pr,{className:`size-3.5 mr-1.5`}),`Cancel`]})]})]})}}return a===`error`?(0,G.jsx)(`div`,{className:`space-y-5`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-3 bg-red-500/10 border border-red-500/20 rounded-lg`,children:[(0,G.jsx)(Kn,{className:`size-4 text-red-500 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-red-600`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:s===`db`?`Database restore failed`:`Import failed`}),(0,G.jsx)(`p`,{className:`mt-0.5`,children:g}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,className:`mt-2 h-auto py-1 text-xs`,onClick:w,children:`Try again`})]})]})}):(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-blue-500/10 border border-blue-500/20 rounded-xl`,children:[(0,G.jsx)(Mr,{className:`size-5 text-blue-500 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm space-y-1`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`Import Data`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Upload a `,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px]`,children:`.json`}),` file exported from Guest Mode. All data will be `,(0,G.jsx)(`strong`,{children:`added`}),` to your workspace — existing items with the same ID will be skipped. New projects will be created for any project‑scoped items.`]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Supports: Notes, ERD Diagrams (entities, columns, relationships), Flowcharts, Drawings, AI Chat sessions & messages, and Projects.`}),b===`desktop`&&(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-2 pt-2 border-t border-border/40`,children:[(0,G.jsx)(`strong`,{className:`text-amber-500`,children:`Desktop only:`}),` You can also restore a`,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px] mx-0.5`,children:`.db`}),` database file — useful after reinstalling the app to recover data from a manually saved copy. A safety backup is created automatically.`]})]})]}),(0,G.jsxs)(`div`,{onClick:()=>{a!==`importing`&&e.current?.click()},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&a!==`importing`&&e.current?.click()},role:`button`,tabIndex:0,className:`border-2 border-dashed border-border/50 hover:border-primary/40 rounded-xl p-8 text-center cursor-pointer transition-colors`,children:[(0,G.jsx)(`input`,{ref:e,type:`file`,accept:A,className:`hidden`,onChange:x}),a===`importing`?(0,G.jsxs)(`div`,{className:`w-full max-w-sm mx-auto space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground truncate mr-2`,children:v.phase||`Importing…`}),(0,G.jsxs)(`span`,{className:`text-muted-foreground shrink-0 tabular-nums`,children:[k,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full h-2 bg-muted/50 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full bg-primary rounded-full transition-all duration-300 ease-out`,style:{width:`${k}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground tabular-nums`,children:[v.current.toLocaleString(),` / `,v.total.toLocaleString(),` items`]})]}),(0,G.jsx)(U,{variant:`ghost`,size:`sm`,onClick:e=>{e.stopPropagation(),D()},className:`text-xs`,children:`Cancel`})]}):(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-muted/30 rounded-full`,children:(0,G.jsx)(Yn,{className:`size-6 text-muted-foreground`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`Click to select a file`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:j})]})]})]})]})}function iC({summary:e}){return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-3`,children:[(0,G.jsx)(aC,{label:`Projects`,value:e.projects}),(0,G.jsx)(aC,{label:`Notes`,value:e.notes}),(0,G.jsx)(aC,{label:`ERD Diagrams`,value:e.diagrams}),(0,G.jsx)(aC,{label:`Tables (Entities)`,value:e.entities}),(0,G.jsx)(aC,{label:`Columns`,value:e.columns}),(0,G.jsx)(aC,{label:`Relationships`,value:e.relationships}),(0,G.jsx)(aC,{label:`Flowcharts`,value:e.flowcharts}),(0,G.jsx)(aC,{label:`Drawings`,value:e.drawings}),(0,G.jsx)(aC,{label:`AI Sessions`,value:e.ai_chat_sessions})]}),e.ai_chat_messages>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground px-0.5`,children:[`Includes `,e.ai_chat_messages.toLocaleString(),` AI chat messages.`]}),e.skipped_existing>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-amber-500 px-0.5`,children:[e.skipped_existing.toLocaleString(),` item(s) already existed and were skipped.`]})]})}function aC({label:e,value:t}){return(0,G.jsxs)(`div`,{className:`bg-muted/20 border border-border/40 rounded-lg p-3 text-center`,children:[(0,G.jsx)(`p`,{className:`text-lg font-bold`,children:t.toLocaleString()}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:e})]})}function oC(){return sessionStorage.getItem(`auth_mode`)===`guest`}function sC(e){if(!e||typeof e!=`string`)return null;try{let t=JSON.parse(e);return t?.dbml_source??t?.dbmlSource??null}catch{return null}}function cC(e){let t=e.dbml_source??e.dbmlSource??sC(e.data);return{...e,dbml_source:t??null,dbmlSource:t??null}}async function lC(e){try{return(await ca.getAllResources(e)||[]).filter(e=>!e.is_deleted)}catch{return[]}}function uC(e){return!e.messages||!Array.isArray(e.messages)?[]:e.messages.map(e=>({id:e.id||e.uid,role:e.role,content:e.content,selection_text:e.selection_text||null,created_at:e.created_at||null}))}async function dC(){if(!oC()){let e=await Si(`/api/guest/export`);if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Failed to export data`)}return e.json()}let[e,t,n,r,i,a]=await Promise.all([lC(`project`),lC(`notes`),lC(`erd`),lC(`flowchart`),lC(`drawings`),lC(`ai_chat_session`)]),o=a.map(e=>({uid:e.uid||e.id,title:e.title||`Untitled`,entity_type:e.entity_type||null,entity_uid:e.entity_uid||null,project_id:e.project_id??null,created_at:e.created_at||null,updated_at:e.updated_at||null,messages:uC(e)})),s={projects:e.length,notes:t.length,diagrams:n.length,flowcharts:r.length,drawings:i.length,ai_chat_sessions:o.length};return{version:`1.0`,exported_at:new Date().toISOString(),application:`ERD Builder Pro`,total_items:s,data:{projects:e,notes:t,diagrams:n.map(cC),flowcharts:r,drawings:i,ai_chat_sessions:o}}}function fC(e){let t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`erd-data-export-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}async function pC(){fC(await dC())}function mC(){let[e,t]=(0,W.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Export Data`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Download projects, notes, ERDs, DBML, flowcharts, drawings, and AI chats as JSON.`})]}),(0,G.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-muted/10 p-5 max-w-xl`,children:(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold`,children:`JSON Backup`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Use this file with Import Data to restore or migrate your workspace data.`})]}),(0,G.jsxs)(U,{onClick:async()=>{t(!0);try{await pC(),l.success(`Data exported successfully`)}catch(e){l.error(`Export failed: `+(e.message||`Unknown error`))}finally{t(!1)}},disabled:e,className:`shrink-0`,children:[e?(0,G.jsx)(xo,{className:`size-3.5 mr-2 animate-spin`}):(0,G.jsx)(rn,{className:`size-3.5 mr-2`}),e?`Exporting...`:`Export JSON`]})]})})]})}function hC(){if(typeof window>`u`||!window.__TAURI__&&!window.__TAURI_INTERNALS__&&window.ERD_INSTALL_MODE!==`cli`)return(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(Lr,{className:`border-border/50 bg-background/50 backdrop-blur-sm`,children:(0,G.jsxs)(Rr,{className:`py-12 text-center`,children:[(0,G.jsx)(Mr,{className:`w-8 h-8 mx-auto text-muted-foreground/40`}),(0,G.jsx)(`p`,{className:`text-muted-foreground mt-4 text-sm`,children:`Storage configuration is only available in the desktop app or CLI mode.`})]})})});let[e,t]=(0,W.useState)({type:`r2`,accountId:``,endpoint:``,region:`auto`,accessKeyId:``,secretAccessKey:``,bucketName:``,publicUrl:``}),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(`none`),[o,s]=(0,W.useState)(!0),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)({type:``,message:``}),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(!1),v=(0,W.useCallback)(async()=>{s(!0);try{let e=await Si(`/api/storage/config`,{credentials:`include`});if(e.ok){let n=await e.json();a(n.source),n.config&&(r(n.config),t({type:n.config.type||`r2`,accountId:n.config.accountId||``,endpoint:n.config.endpoint||``,region:n.config.region||`auto`,accessKeyId:n.config.accessKeyId||``,secretAccessKey:n.config.secretAccessKey||``,bucketName:n.config.bucketName||``,publicUrl:n.config.publicUrl||``}))}}catch(e){console.error(`Failed to load storage config:`,e)}finally{s(!1)}},[]);(0,W.useEffect)(()=>{v()},[v]);let y=async()=>{l(!0),p({type:``,message:``});try{let t=await Si(`/api/storage/config`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),credentials:`include`});if(t.ok)p({type:`success`,message:`Storage configuration saved successfully.`}),r({...e}),await v();else{let e=await t.json();p({type:`error`,message:e.error||`Failed to save configuration`})}}catch(e){p({type:`error`,message:e.message||`Network error`})}finally{l(!1)}},b=async()=>{d(!0),p({type:``,message:``});try{let t=await Si(`/api/storage/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),credentials:`include`});if(t.ok)p({type:`success`,message:`Successfully connected to storage.`});else{let e=await t.json();p({type:`error`,message:e.error||`Connection failed`})}}catch(e){p({type:`error`,message:e.message||`Network error`})}finally{d(!1)}},x=(e,n)=>{t(t=>({...t,[e]:n})),p({type:``,message:``})};return o?(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(Lr,{className:`border-border/50 bg-background/50 backdrop-blur-sm`,children:(0,G.jsxs)(Rr,{className:`py-12 text-center`,children:[(0,G.jsx)(cr,{className:`w-6 h-6 animate-spin mx-auto text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-muted-foreground mt-4 text-sm`,children:`Loading storage configuration...`})]})})}):(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsxs)(Lr,{className:`border border-border/50 bg-background/50 backdrop-blur-sm shadow-lg`,children:[(0,G.jsxs)(Br,{className:`border-b border-border/30 pb-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Ba,{className:`w-6 h-6 text-blue-500`}),(0,G.jsx)(zr,{className:`text-xl md:text-2xl font-bold`,children:`Storage Configuration`})]}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Configure Cloudflare R2 or S3-compatible storage for image uploads in Notes and Drawings.`})]}),(0,G.jsxs)(Rr,{className:`space-y-6 p-4 md:p-6`,children:[i===`env`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-blue-500/10 border border-blue-500/20`,children:[(0,G.jsx)(vr,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,G.jsx)(`p`,{className:`text-xs text-blue-600 dark:text-blue-400`,children:`Pre-filled from environment variables. Save to override with custom settings.`})]}),f.type&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-4 rounded-lg border ${f.type===`success`?`bg-green-500/10 border-green-500/20 text-green-600 dark:text-green-400`:`bg-red-500/10 border-red-500/20 text-red-600 dark:text-red-400`}`,children:[f.type===`success`?(0,G.jsx)(Rn,{className:`w-5 h-5 shrink-0`}):(0,G.jsx)(La,{className:`w-5 h-5 shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm`,children:f.message})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(Mr,{className:`size-3`}),`Storage Provider`]}),(0,G.jsxs)(_r,{value:e.type,onValueChange:(e,t)=>e&&x(`type`,e),children:[(0,G.jsx)(mr,{className:`h-9 text-sm`,children:(0,G.jsx)(gr,{children:e.type===`r2`?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ba,{className:`w-4 h-4`}),`Cloudflare R2`]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mr,{className:`w-4 h-4`}),`S3-Compatible`]})})}),(0,G.jsxs)(pr,{children:[(0,G.jsx)(fr,{value:`r2`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ba,{className:`w-4 h-4`}),`Cloudflare R2`]})}),(0,G.jsx)(fr,{value:`s3-compatible`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mr,{className:`w-4 h-4`}),`S3-Compatible`]})})]})]})]}),e.type===`r2`&&(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Account ID`]}),(0,G.jsx)(wi,{placeholder:`Your Cloudflare R2 Account ID`,value:e.accountId||``,onChange:e=>x(`accountId`,e.target.value),className:`h-9 text-sm font-mono`}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-1 px-1`,children:`Found in your Cloudflare dashboard under R2 → Account ID.`})]}),e.type===`s3-compatible`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Endpoint URL`]}),(0,G.jsx)(wi,{placeholder:`https://s3.us-east-1.amazonaws.com`,value:e.endpoint||``,onChange:e=>x(`endpoint`,e.target.value),className:`h-9 text-sm font-mono`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(so,{className:`size-3`}),`Region`]}),(0,G.jsx)(wi,{placeholder:`us-east-1`,value:e.region||``,onChange:e=>x(`region`,e.target.value),className:`h-9 text-sm font-mono`})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(po,{className:`size-3`}),`Access Key ID`]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{type:g?`text`:`password`,placeholder:`Your access key ID`,value:e.accessKeyId,onChange:e=>x(`accessKeyId`,e.target.value),className:`h-9 text-sm font-mono pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors`,children:g?(0,G.jsx)(kr,{className:`w-4 h-4`}):(0,G.jsx)(Ka,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(po,{className:`size-3`}),`Secret Access Key`]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{type:m?`text`:`password`,placeholder:`Your secret access key`,value:e.secretAccessKey,onChange:e=>x(`secretAccessKey`,e.target.value),className:`h-9 text-sm font-mono pr-10`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(!m),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors`,children:m?(0,G.jsx)(kr,{className:`w-4 h-4`}):(0,G.jsx)(Ka,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(no,{className:`size-3`}),`Bucket Name`]}),(0,G.jsx)(wi,{placeholder:`your-bucket-name`,value:e.bucketName,onChange:e=>x(`bucketName`,e.target.value),className:`h-9 text-sm font-mono`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsxs)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 flex items-center gap-2 px-1`,children:[(0,G.jsx)(yo,{className:`size-3`}),`Public URL (optional)`]}),(0,G.jsx)(wi,{placeholder:`https://cdn.yourdomain.com`,value:e.publicUrl||``,onChange:e=>x(`publicUrl`,e.target.value),className:`h-9 text-sm font-mono`}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-1 px-1`,children:e.type===`s3-compatible`?`Optional. If set, overrides the auto-constructed endpoint URL. Useful for custom CDN/domain. If empty, URL is built from Endpoint + Bucket.`:`Optional public URL prefix for direct image access (e.g., custom domain or CDN). If empty, R2 public URL is auto-constructed.`})]})]}),(0,G.jsxs)(Ur,{className:`bg-muted/5 border-t border-border/30 p-4 md:px-6 md:py-4 flex flex-col sm:flex-row gap-3 sm:justify-end`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:b,disabled:u||!e.bucketName||!e.accessKeyId||!e.secretAccessKey,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border text-sm font-medium whitespace-nowrap transition-colors h-10 px-4 bg-background hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50 cursor-pointer select-none`,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 shrink-0 animate-spin pointer-events-none`}),(0,G.jsx)(`span`,{className:`pointer-events-none`,children:`Testing...`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 shrink-0 pointer-events-none`}),(0,G.jsx)(`span`,{className:`pointer-events-none`,children:`Test Connection`})]})}),(0,G.jsxs)(U,{onClick:y,className:`gap-2 px-6`,disabled:c,children:[c?(0,G.jsx)(cr,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xn,{className:`w-4 h-4`}),c?`Saving...`:`Save Configuration`]})]})]})})}var gC=[{title:`General`,rows:[[`Sync pending changes`,`⌘S`,`Ctrl+S`],[`Focus file search`,`⌘K`,`Ctrl+K`],[`Open or close AI Assistant`,`⌘J`,`Ctrl+J`],[`Open Settings (desktop)`,`⌘,`,`Ctrl+,`]]},{title:`Notes`,rows:[[`Bold`,`⌘B`,`Ctrl+B`],[`Italic`,`⌘I`,`Ctrl+I`],[`Underline`,`⌘U`,`Ctrl+U`],[`Strikethrough`,`⇧⌘S`,`Ctrl+Shift+S`],[`Inline code`,`⌘E`,`Ctrl+E`],[`Heading 1–4`,`⌥⌘1–4`,`Ctrl+Alt+1–4`],[`Bulleted list`,`⇧⌘8`,`Ctrl+Shift+8`],[`Numbered list`,`⇧⌘7`,`Ctrl+Shift+7`],[`Task list`,`⇧⌘9`,`Ctrl+Shift+9`],[`Blockquote`,`⇧⌘B`,`Ctrl+Shift+B`],[`Code block`,`⌥⌘C`,`Ctrl+Alt+C`],[`Insert table`,`⌥⌘T`,`Ctrl+Alt+T`],[`Toggle badge`,`⌥⌘B`,`Ctrl+Alt+B`],[`Align left / center / right`,`⇧⌘L / C / R`,`Ctrl+Shift+L / C / R`],[`Undo / redo`,`⌘Z / ⌘Y`,`Ctrl+Z / Ctrl+Y`],[`Export note`,`⇧⌘E`,`Ctrl+Shift+E`],[`Import note`,`⇧⌘I`,`Ctrl+Shift+I`]]},{title:`ERD Builder`,rows:[[`Open Explorer (tables and relationships)`,`⇧⌘F`,`Ctrl+Shift+F`],[`Close the table editor`,`Esc`,`Esc`],[`Undo / redo`,`⌘Z / ⇧⌘Z`,`Ctrl+Z / Ctrl+Y`],[`Add or remove from selection`,`⌘-click`,`Ctrl+click`]]},{title:`Flowchart`,rows:[[`Undo / redo`,`⌘Z / ⇧⌘Z`,`Ctrl+Z / Ctrl+Shift+Z`],[`Delete selected node or edge`,`Delete / Backspace`,`Delete / Backspace`]]}],_C=[[`Focus table search`,`⌘P`,`Ctrl+P`],[`Toggle filters`,`⌘F`,`Ctrl+F`],[`Refresh records`,`⌘R`,`Ctrl+R`],[`Select all records`,`⌘A`,`Ctrl+A`],[`Add or remove a record from selection`,`⌘-click`,`Ctrl+click`],[`Save record or structure`,`⌘S`,`Ctrl+S`],[`Run SQL query`,`⌘Enter`,`Ctrl+Enter`],[`Format SQL query`,`⌘I`,`Ctrl+I`],[`Cancel inline changes`,`Esc`,`Esc`]];function vC(){let e=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform),t=typeof window<`u`&&(window.__TAURI__||window.__TAURI_INTERNALS__||window.ERD_INSTALL_MODE===`cli`)?[...gC,{title:`DB Client`,rows:_C}]:gC;return(0,G.jsxs)(`div`,{className:`p-4 md:p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Keymap`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Keyboard shortcuts available in ERD Builder Pro.`})]}),t.map(({title:t,rows:n})=>(0,G.jsxs)(`section`,{className:`overflow-hidden rounded-lg border border-border`,children:[(0,G.jsx)(`h3`,{className:`border-b border-border bg-muted/40 px-4 py-2.5 text-sm font-medium`,children:t}),(0,G.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(([t,n,r])=>(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3 px-4 py-2.5 text-sm`,children:[(0,G.jsx)(`span`,{children:t}),(0,G.jsx)(Di,{className:`h-6 px-2 text-xs`,children:e?n:r})]},t))})]},t)),(0,G.jsxs)(`section`,{className:`rounded-lg border border-border p-4 text-sm`,children:[(0,G.jsx)(`h3`,{className:`font-medium`,children:`Drawings`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Drawings use Excalidraw’s built-in keymap. Open Help from its menu to view the shortcuts available for the current editor version.`})]})]})}var yC=e=>JSON.stringify(e,null,2);function bC(e,t){return/[\s"']/.test(e)?t?`"${e.replace(/"/g,`\\"`)}"`:`'${e.replace(/'/g,`'\\''`)}'`:e}function xC(e){let t={command:e.command,...e.args.length?{args:e.args}:{}},n=e.args.map(t=>bC(t,e.platform===`win32`)).join(` `),r=[`codex`,`mcp`,`add`,`erdbpro`,`--`,e.command,...e.args].map(t=>bC(t,e.platform===`win32`)).join(` `);return[{id:`jetbrains`,label:`JetBrains AI`,description:`Paste into the MCP server JSON configuration.`,language:`json`,content:yC({mcpServers:{erdbpro:t}})},{id:`vscode`,label:`VS Code`,description:`Save as .vscode/mcp.json or paste into the MCP configuration.`,language:`json`,content:yC({servers:{erdbpro:{type:`stdio`,...t}}})},{id:`codex`,label:`Codex`,description:`Run once in a terminal to register the local MCP server.`,language:`bash`,content:r},{id:`hermes`,label:`Hermes Agent`,description:`Enter these values in Add MCP Server. Leave Environment empty.`,language:`text`,content:`Name: erdbpro\nTransport: stdio\nCommand: ${e.command}\nArgs: ${n||`(leave empty)`}\nEnvironment: (leave empty)`},{id:`generic`,label:`Generic MCP (STDIO)`,description:`Use for clients that accept a standard STDIO command definition.`,language:`json`,content:yC({transport:`stdio`,...t})}]}function SC(){let[e,t]=W.useState(null),[n,r]=W.useState(``),[i,a]=W.useState(``),[o,s]=W.useState(`jetbrains`);W.useEffect(()=>{let e=!1;return Si(`/api/mcp/client-config`).then(async n=>{let r=await n.json();if(!n.ok)throw Error(r.error||`Failed to load MCP configuration.`);e||t(r)}).catch(t=>{e||r(t instanceof Error?t.message:`Failed to load MCP configuration.`)}),()=>{e=!0}},[]);let c=async(e,t)=>{await navigator.clipboard.writeText(t),a(e),l.success(`MCP configuration copied`),window.setTimeout(()=>a(``),1500)};if(n)return(0,G.jsxs)(`div`,{className:`p-6`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`MCP Integration`}),(0,G.jsx)(`p`,{className:`mt-4 rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive`,children:n})]});if(!e)return(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,G.jsx)(xo,{className:`size-5 animate-spin text-muted-foreground`})});if(e.mode===`web`)return(0,G.jsxs)(`div`,{className:`space-y-5 p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-semibold`,children:[(0,G.jsx)(Wa,{className:`size-5`}),`Public MCP Integration`]}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Detected mode: Web App. This page automatically shows the matching MCP connection for the current installation mode.`})]}),e.configured&&e.url?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`Public MCP URL (Streamable HTTP)`}),(0,G.jsxs)(U,{variant:`ghost`,size:`xs`,onClick:()=>void c(`public-url`,e.url),children:[i===`public-url`?(0,G.jsx)(Yt,{}):(0,G.jsx)(Ua,{}),i===`public-url`?`Copied`:`Copy`]})]}),(0,G.jsx)(`code`,{className:`mt-1 block break-all text-xs`,children:e.url})]}),(0,G.jsx)(`div`,{className:`rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground`,children:`Add this URL as a custom connector in Claude Web or Claude Desktop. Authentication uses OAuth and grants user-scoped, read-only access.`})]}):(0,G.jsx)(`p`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm text-amber-700 dark:text-amber-300`,children:`Public MCP is not configured. Set MCP_PUBLIC_URL on the Web App server and restart it to publish the connection URL.`})]});let u=xC(e),d=u.find(e=>e.id===o)||u[0];return(0,G.jsxs)(`div`,{className:`space-y-5 p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-semibold`,children:[(0,G.jsx)(or,{className:`size-5`}),`Connect AI Clients`]}),(0,G.jsxs)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:[`Detected mode: `,e.mode===`cli`?`CLI`:`Desktop App`,`. Use ERD Builder Pro as a local MCP Server (STDIO) with an external AI client. The launcher runs headlessly without opening another app window.`]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-4 py-3`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`MCP Server (STDIO) launcher`}),(0,G.jsx)(`code`,{className:`mt-1 block break-all text-xs`,children:e.command})]}),(0,G.jsx)(`div`,{role:`tablist`,"aria-label":`MCP client`,className:`flex w-full flex-wrap gap-1 rounded-lg border bg-muted p-1`,children:u.map(e=>{let t=e.id===d.id;return(0,G.jsx)(U,{type:`button`,size:`sm`,variant:t?`default`:`ghost`,role:`tab`,"aria-selected":t,onClick:()=>s(e.id),className:`flex-1 text-xs`,children:e.label},e.id)})}),(0,G.jsxs)(`div`,{role:`tabpanel`,"aria-label":d.label,className:`space-y-3 pt-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d.description}),(0,G.jsxs)(`div`,{className:`overflow-hidden rounded-lg border bg-muted/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground`,children:d.language}),(0,G.jsxs)(U,{variant:`ghost`,size:`xs`,onClick:()=>void c(d.id,d.content),children:[i===d.id?(0,G.jsx)(Yt,{}):(0,G.jsx)(Ua,{}),i===d.id?`Copied`:`Copy`]})]}),(0,G.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre p-4 text-xs leading-relaxed`,children:(0,G.jsx)(`code`,{children:d.content})})]})]})]})}function CC(e){return{active:e.active===!0,planCode:e.planCode??e.plan_code,expiresAt:e.expiresAt??e.expires_at,lastCheckedAt:e.lastCheckedAt??e.last_checked_at,maxTeams:e.maxTeams??e.max_teams,maxMembers:e.maxMembers??e.max_members,usage:{teamCount:e.usage?.teamCount??e.usage?.team_count??0,memberCount:e.usage?.memberCount??e.usage?.member_count??0}}}function wC(e,t){return{message:e.error||t,...e.code?{code:e.code}:{}}}async function TC(e){return e.json().catch(()=>({}))}function EC(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),[c,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),h=(0,W.useCallback)(async()=>{try{let e=await Si(`/api/license/status`),n=await TC(e);if(!e.ok){s(wC(n,`Failed to load license status.`));return}t(CC(n))}catch(e){s({message:e instanceof Error?e.message:`Failed to load license status.`})}},[]);(0,W.useEffect)(()=>{h()},[h]);let g=async()=>{s(null),f(!0);try{let e={license_key:n.trim()},o=i.trim();o&&(e.activation_grant=o);let c=await Si(`/api/license/activate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),u=await TC(c);if(!c.ok){s(wC(u,`License activation failed.`));return}r(``),a(``),t(CC(u)),l.success(`License activated`)}catch(e){s({message:e instanceof Error?e.message:`License activation failed.`})}finally{f(!1)}},_=async()=>{s(null),u(!0);try{let e=await Si(`/api/license/check`,{method:`POST`}),n=await TC(e);if(!e.ok){s(wC(n,`License check failed.`));return}t(CC(n)),l.success(`License checked successfully`)}catch(e){s({message:e instanceof Error?e.message:`License check failed.`})}finally{u(!1)}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-6 p-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Application License`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`This instance license controls commercial Team capacity. Personal use does not require activation.`})]}),e&&(0,G.jsxs)(`div`,{className:`rounded-lg border p-4 text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:e.active?`Active: ${e.planCode}`:`No commercial license is active`}),(0,G.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Active Teams: `,e.usage.teamCount,` /`,` `,e.maxTeams??(e.active?`No limit`:`N/A`),` · Active members: `,e.usage.memberCount,` /`,` `,e.maxMembers??(e.active?`No limit`:`N/A`)]}),e.active&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(U,{variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>void _(),disabled:c||d,children:[c?(0,G.jsx)(cr,{className:`animate-spin`}):(0,G.jsx)(cr,{}),`Check license`]}),e.lastCheckedAt&&(0,G.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Last checked: `,new Date(e.lastCheckedAt).toLocaleString()]})]})]}),(0,G.jsxs)(Ar,{className:`gap-4`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`instance-license-key`,children:`Instance license key`}),(0,G.jsx)(wi,{id:`instance-license-key`,type:`password`,autoComplete:`off`,disabled:d,value:n,onChange:e=>{r(e.target.value),s(null)}})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`instance-activation-grant`,children:`Activation grant`}),(0,G.jsx)(wi,{id:`instance-activation-grant`,type:`password`,autoComplete:`off`,disabled:d,"aria-describedby":`activation-grant-description`,value:i,onChange:e=>{a(e.target.value),s(null)}}),(0,G.jsx)(Or,{id:`activation-grant-description`,children:`Only needed after resetting a deployment binding. Enter the one-time grant from SaaS with the same license key.`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(U,{onClick:()=>m(!0),disabled:!n.trim()||c||d,children:[(0,G.jsx)(po,{}),d?`Activating...`:`Activate license`]}),o&&(0,G.jsxs)(`div`,{id:`license-activation-error`,role:`alert`,children:[(0,G.jsx)(`p`,{className:`text-sm text-destructive`,children:o.message}),o.code&&(0,G.jsxs)(`p`,{className:`font-mono text-xs text-muted-foreground`,children:[`Code: `,o.code]}),o.code===`LICENSE_ALREADY_BOUND`&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Reset the old deployment binding in SaaS, then enter its activation grant above.`})]})]})]}),(0,G.jsx)(br,{isOpen:p,title:`Activate license?`,message:`This will activate the license for this Self-host instance and update its Team and member capacity.`,confirmText:`Activate license`,cancelText:`Cancel`,variant:`info`,onCancel:()=>m(!1),onConfirm:()=>{m(!1),g()}})]})}function DC(){let{isSettingsOpen:e,setIsSettingsOpen:t,settingsTab:n,setSettingsTab:r}=pa(),i=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),a=i||typeof window<`u`&&window.ERD_INSTALL_MODE===`cli`,[o,s]=W.useState(`configuration`);W.useEffect(()=>{if(!i)return;let e,n=!1;return(async()=>{let{listen:i}=await _i(async()=>{let{listen:e}=await import(`./event-C6gFlqUR.js`);return{listen:e}},__vite__mapDeps([0,1]));n||(e=await i(`menu-settings`,()=>{r(`account`),t(!0)}))})(),()=>{n=!0,e?.()}},[i,t,r]);let{isGuest:c,user:l}=la(),u=!!l?.isSso,d=!u&&(a||!!(l?.isSuperAdmin||l?.is_super_admin)),f=d&&!a,{providers:p,configs:m,isTesting:h,isSaving:g,handleSaveConfig:_,handleTestConnection:v,handleInitializeProviders:y,updateProviderLocal:b,updateConfigLocal:x}=fne(d),{models:S,newModel:C,editingModelId:w,isSaving:T,setNewModel:E,handleAddModel:D,handleDeleteModel:O,ensureModel:k,startEditingModel:A,cancelEdit:j,refresh:M}=pne(d),{prompts:N,isSaving:P,handleSavePrompt:F,handleDeletePrompt:I,togglePromptDefault:L}=mne(),R=W.useMemo(()=>c?[{label:`General`,items:[{id:`appearance`,label:`Appearance`,icon:(0,G.jsx)(Ao,{className:`size-4`})}]},{label:`More`,items:[{id:`keymap`,label:`Keymap`,icon:(0,G.jsx)(mo,{className:`size-4`})},{id:`changelog`,label:`What's New`,icon:(0,G.jsx)(uo,{className:`size-4`})}]}]:[{label:`General`,items:[...u?[]:[{id:`account`,label:`Account`,icon:(0,G.jsx)(Qo,{className:`size-4`})}],{id:`appearance`,label:`Appearance`,icon:(0,G.jsx)(Ao,{className:`size-4`})},...a&&!u?[{id:`storage`,label:`Storage`,icon:(0,G.jsx)(Mr,{className:`size-4`})}]:[],...u?[{id:`usage`,label:`Usage`,icon:(0,G.jsx)(io,{className:`size-4`})}]:[]]},{label:`Feature`,items:[...d?[{id:`ai-config`,label:`AI Configuration`,icon:(0,G.jsx)(Qr,{className:`size-4`})}]:[],...f?[{id:`license`,label:`Application License`,icon:(0,G.jsx)(po,{className:`size-4`})}]:[],{id:`mcp-server`,label:`MCP Integration`,icon:(0,G.jsx)(Lo,{className:`size-4`})},{id:`ai-rules`,label:`AI Rules`,icon:(0,G.jsx)(bo,{className:`size-4`})},{id:`ai-prompts`,label:`System Prompts`,icon:(0,G.jsx)(Oa,{className:`size-4`})}]},{label:`More`,items:[{id:`keymap`,label:`Keymap`,icon:(0,G.jsx)(mo,{className:`size-4`})},...d?[{id:`export-data`,label:`Export Data`,icon:(0,G.jsx)(rn,{className:`size-4`})},{id:`import-data`,label:`Import Data`,icon:(0,G.jsx)(Yn,{className:`size-4`})},{id:`backups`,label:`Database Backup`,icon:(0,G.jsx)(Cr,{className:`size-4`})}]:[],{id:`changelog`,label:`What's New`,icon:(0,G.jsx)(uo,{className:`size-4`})}]}],[f,c,a,u,d]);W.useEffect(()=>{(!d&&[`ai-config`,`license`,`export-data`,`import-data`,`backups`].includes(n)||u&&n===`account`||n===`license`&&!f)&&r(c||u?`appearance`:`account`)},[f,c,u,d,n,r]);let ee=R.flatMap(e=>e.items),te=e=>ee.find(t=>t.id===e)?.label||``;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`overflow-hidden p-0 md:max-h-150 md:max-w-175 lg:max-w-237.5 bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`Settings`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Manage your application settings and AI configuration.`}),(0,G.jsxs)(Th,{className:`items-start min-h-0! h-full`,children:[(0,G.jsx)(Eh,{collapsible:`none`,className:`w-55 border-r border-border/40 bg-muted/5 hidden md:flex h-full`,children:(0,G.jsxs)(Dh,{className:`pt-4 px-2 pb-0`,children:[(0,G.jsx)(`div`,{className:`px-4 py-2 mb-2`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-bold flex items-center gap-2`,children:[(0,G.jsx)(zo,{className:`size-4`}),`Settings`]})}),R.map(e=>(0,G.jsxs)(Oh,{className:`py-1`,children:[(0,G.jsx)(kh,{className:`text-[10px] uppercase tracking-widest text-muted-foreground/60 px-4 mb-0.5`,children:e.label}),(0,G.jsx)(Ah,{children:(0,G.jsx)(jh,{children:e.items.map(e=>(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{isActive:n===e.id,onClick:()=>r(e.id),className:`transition-all duration-200 px-4 py-2 rounded-md ${n===e.id?`bg-sidebar-accent text-sidebar-accent-foreground font-medium`:`text-muted-foreground hover:bg-sidebar-accent/50`}`,children:[e.icon,(0,G.jsx)(`span`,{className:`text-xs`,children:e.label})]})},e.id))})})]},e.label))]})}),(0,G.jsxs)(`main`,{className:`flex-1 flex flex-col h-150 overflow-hidden`,children:[(0,G.jsx)(`header`,{className:`flex h-14 shrink-0 items-center gap-2 border-b border-border/40 px-6 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Ph,{className:`hidden md:flex`,children:(0,G.jsxs)(Fh,{children:[(0,G.jsx)(Ih,{children:(0,G.jsx)(dne,{href:`#`,className:`text-[11px] text-muted-foreground`,children:`Settings`})}),(0,G.jsx)(Rh,{}),(0,G.jsx)(Ih,{children:(0,G.jsx)(Lh,{className:`text-[11px] font-semibold`,children:te(n)})})]})}),(0,G.jsx)(`div`,{className:`md:hidden`,children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`-ml-2 h-8 gap-2 text-xs font-semibold`,children:[(0,G.jsx)(zo,{className:`size-3.5`}),te(n),(0,G.jsx)(Xt,{className:`size-3 opacity-50`})]})}),(0,G.jsx)(Gt,{align:`start`,className:`w-56`,children:R.map(e=>(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`text-[10px] uppercase tracking-widest text-muted-foreground/60 px-2 py-1.5`,children:e.label}),e.items.map(e=>(0,G.jsxs)(It,{onClick:()=>r(e.id),className:n===e.id?`bg-accent`:``,children:[e.icon,(0,G.jsx)(`span`,{className:`ml-2`,children:e.label})]},e.id)),(0,G.jsx)(Kt,{})]},e.label))})]})})]})}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar`,children:[d&&n===`ai-config`&&(0,G.jsxs)(`div`,{className:`p-4 md:p-6`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 bg-muted border border-border rounded-lg p-1 w-full mb-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(`configuration`),className:`flex-1 flex items-center justify-center gap-1.5 px-3.5 py-2 rounded-md text-xs font-semibold transition-all ${o===`configuration`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,G.jsx)(zo,{className:`w-3.5 h-3.5`}),`Configuration`]}),(0,G.jsxs)(`button`,{onClick:()=>s(`models`),className:`flex-1 flex items-center justify-center gap-1.5 px-3.5 py-2 rounded-md text-xs font-semibold transition-all ${o===`models`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,G.jsx)(Oa,{className:`w-3.5 h-3.5`}),`AI Models`]})]}),o===`configuration`&&(0,G.jsx)(hne,{providers:p,configs:m,models:S,isSaving:g,isTesting:h,onSave:_,onTest:e=>v(e,Object.values(S).flat()),onUpdateProvider:b,onUpdateConfig:x,onEnsureModel:k,onRefreshModels:M,onInitialize:y}),o===`models`&&(0,G.jsx)(vne,{providers:p,models:Object.values(S).flat(),newModel:C,editingModelId:w,isSaving:T,onSetNewModel:E,onAddModel:D,onEditModel:A,onDeleteModel:O,onCancelEdit:j})]}),n===`ai-prompts`&&(0,G.jsx)(Tne,{prompts:N,isSaving:P,onSave:F,onDelete:I,onToggleDefault:L}),n===`ai-rules`&&(0,G.jsx)(One,{}),n===`mcp-server`&&(0,G.jsx)(SC,{}),f&&n===`license`&&(0,G.jsx)(EC,{}),d&&n===`backups`&&(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsx)(Wne,{})}),!u&&n===`account`&&(0,G.jsx)(kne,{}),n===`changelog`&&(0,G.jsx)(`div`,{className:`p-6 space-y-6`,children:(0,G.jsx)(QS,{})}),n===`keymap`&&(0,G.jsx)(vC,{}),d&&n===`export-data`&&(0,G.jsx)(`div`,{className:`p-4 md:p-6 overflow-y-auto h-full`,children:(0,G.jsx)(mC,{})}),d&&n===`import-data`&&(0,G.jsxs)(`div`,{className:`p-4 md:p-6 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Import Data`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restore data from a JSON backup or replace the local database from a .db file.`})]}),(0,G.jsx)(rC,{})]}),n===`appearance`&&(0,G.jsx)(Mne,{}),n===`storage`&&(0,G.jsx)(hC,{}),u&&n===`usage`&&(0,G.jsx)(gne,{onClose:()=>t(!1)})]})]})]})]})})}async function OC(){try{let{getVersion:e}=await _i(async()=>{let{getVersion:e}=await import(`./app-Aufmny-7.js`);return{getVersion:e}},__vite__mapDeps([2,1,3]));return await e()}catch{return`0.0.0`}}function kC({open:e,onOpenChange:t,hasUpdate:n=!1,latestVersion:r=null,isChecking:i=!1,isDownloading:a=!1,onCheckUpdate:o,onDownload:s}){let c=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),[u,d]=(0,W.useState)(`...`),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(null),S=n||f,C=r||m,w=i||g,T=a||v;(0,W.useEffect)(()=>{c?OC().then(d):d(`3.5.5`)},[c]),(0,W.useEffect)(()=>{if(!e||!c||n||i||a)return;if(o){o();return}if(s)return;_(!0);let t=!1;return(async()=>{try{let{check:e}=await _i(async()=>{let{check:e}=await import(`./dist-js-CGfv5pu7.js`).then(e=>e.n);return{check:e}},__vite__mapDeps([4,5,1])),n=await e();if(t)return;n?(p(!0),h(n.version),x(n)):(p(!1),h(null),x(null))}catch{}finally{t||_(!1)}})(),()=>{t=!0}},[e,c]);let E=(0,W.useCallback)(()=>{if(s)s();else if(b){if(v)return;y(!0),b.downloadAndInstall(()=>{}).catch(e=>{let t=typeof e==`string`?e:e?.message?e.message:JSON.stringify(e);l.error(`Update failed`,{description:t||`An error occurred while downloading the update.`,duration:12e3,action:{label:`Copy Error`,onClick:()=>navigator.clipboard.writeText(t).catch(()=>{})}})}).finally(()=>y(!1))}},[s,b,v]),D=(0,W.useCallback)(()=>{T||(o?o():(_(!0),p(!1),h(null),(async()=>{try{let{check:e}=await _i(async()=>{let{check:e}=await import(`./dist-js-CGfv5pu7.js`).then(e=>e.n);return{check:e}},__vite__mapDeps([4,5,1])),t=await e();t?(p(!0),h(t.version),x(t)):(p(!1),h(null),x(null))}catch{}finally{_(!1)}})()))},[o,T]);return(0,W.useEffect)(()=>{e||(p(!1),h(null),_(!1),x(null))},[e]),(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`max-w-sm bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`About ERD Builder Pro`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Application information and credits.`}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-6 gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex size-14 items-center justify-center`,children:[(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Light-1.svg`,alt:``,"aria-hidden":`true`,className:`size-full dark:hidden`}),(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Dark-1.svg`,alt:``,"aria-hidden":`true`,className:`hidden size-full dark:block`})]}),(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:`ERD Builder Pro`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`Version `,u]})]}),(0,G.jsx)(`p`,{className:`text-xs text-center text-muted-foreground max-w-60 leading-relaxed`,children:`Entity-Relationship Diagram builder, flowcharts, notes, and AI-powered assistance — all in one desktop app.`}),c&&(0,G.jsxs)(`div`,{className:`w-full`,children:[(0,G.jsx)(`div`,{className:`w-full border-t border-border/40 mb-3`}),w?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-xs text-muted-foreground py-1`,children:[(0,G.jsx)(xo,{className:`size-3.5 animate-spin`}),`Checking for updates...`]}):S&&C?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-amber-500`,children:[(0,G.jsx)(rn,{className:`size-3.5`}),(0,G.jsxs)(`span`,{children:[`Update `,(0,G.jsxs)(`strong`,{children:[`v`,C]}),` available`]})]}),(0,G.jsxs)(U,{variant:`default`,size:`sm`,className:`h-8 text-xs gap-1.5`,onClick:E,disabled:T,children:[T?(0,G.jsx)(xo,{className:`size-3.5 animate-spin`}):(0,G.jsx)(rn,{className:`size-3.5`}),T?`Downloading...`:`Download Update`]})]}):(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-emerald-500`,children:[(0,G.jsx)(Rn,{className:`size-3.5`}),(0,G.jsx)(`span`,{children:`You're up to date`})]}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-muted-foreground hover:text-foreground`,onClick:D,children:[(0,G.jsx)(cr,{className:`size-3`}),`Check Again`]})]})]}),(0,G.jsx)(`div`,{className:`w-full border-t border-border/40`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-center text-muted-foreground/60 leading-relaxed`,children:[(0,G.jsx)(`p`,{children:`Built with React, Tauri, Express & Prisma.`}),(0,G.jsxs)(`p`,{className:`mt-0.5`,children:[`© `,new Date().getFullYear(),` Bekenweb.`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-muted-foreground hover:text-foreground`,onClick:()=>{ia(`https://github.com/hadziqmtqn/erd-builder-pro`)},children:[(0,G.jsx)(Ga,{className:`size-3`}),`GitHub`]}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`h-7 text-[11px] gap-1 text-rose-500 hover:text-rose-600`,onClick:()=>{ia(`https://trakteer.id/khadziq_muttaqin/tip`)},children:[(0,G.jsx)(lo,{className:`size-3`}),`Support`]})]})]})]})})}function AC(e){let[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null),{setViewport:u,fitView:d}=ve();return{isPublicView:t,setIsPublicView:n,publicData:r,isPublicLoading:a,forbiddenDoc:s,fetchPublicDocument:async(t,n,r,a,s)=>{o(!0),c(null);try{let o=t===`erd`?`files`:t===`flowchart`?`flowcharts`:t,l={"Content-Type":`application/json`};s&&(l[`x-share-token`]=s);let f=await Si(`/api/${o}/public/${n}`,{headers:l,credentials:`include`});if(!f.ok){let e=`Document not found or access denied`,t=`Access Denied`;try{e=(await f.json()).error||e,f.status===404?t=`Not Found`:(f.status===401||f.status===403)&&(t=`Access Denied`)}catch{}if(f.status===401||f.status===403||f.status===404)return c({title:t,message:e,status:f.status}),!1;throw Error(e)}let p=f.headers.get(`content-type`);if(!p||!p.includes(`application/json`))throw Error(`Received invalid response from server`);let m=await f.json();if(i(m),e(t),t===`erd`){let e=m.entities.map(e=>({id:e.id,type:`entity`,position:{x:e.x,y:e.y},data:e})),t=m.relationships.map(e=>{let t=m.entities.find(t=>String(t.id)===String(e.source_entity_id)),n=m.entities.find(t=>String(t.id)===String(e.target_entity_id)),r=e.source_handle,i=e.target_handle;if(t&&n){let a=Number(t.x)||0,o=Number(n.x)||0,s=(e.source_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),c=(e.target_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);s&&(r=a<o?`col-${s}-source`:`col-${s}-source-l`),c&&(i=a<o?`col-${c}-target`:`col-${c}-target-r`)}let a=(e.source_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),o=(e.target_column_id||``).replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);return{id:e.id,source:e.source_entity_id,target:e.target_entity_id,sourceHandle:r||(a?`col-${a}-source`:void 0),targetHandle:i||(o?`col-${o}-target`:void 0),label:e.label,type:`smoothstep`,animated:!0}});r(e),a(t);let n=(t=0)=>{let n=qi(m);n?u(n,{duration:t}):e.length>0&&d({padding:.2,duration:t})};setTimeout(()=>n(0),100)}else if(t===`flowchart`)try{let e=typeof m.data==`string`?JSON.parse(m.data):m.data;r(e.nodes||[]),a(e.edges||[]);let t=(t=0)=>{let n=qi(m);n?u(n,{duration:t}):e.nodes?.length>0&&d({padding:.2,duration:t})};setTimeout(()=>t(0),100)}catch(e){console.error(`Failed to parse flowchart data:`,e)}else r([]),a([]);return!0}catch(e){return l.error(e.message||`Failed to load shared document`),setTimeout(()=>window.location.href=`/`,3e3),!1}finally{o(!1)}}}}var jC=(0,W.createContext)(null),MC=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),NC={checked(e){return e?{[MC.checked]:``}:{[MC.unchecked]:``}},...Ge,...bt},PC=`data-composite-item-active`,FC=W.createContext(void 0);function IC(){return W.useContext(FC)}var LC=W.createContext(void 0);function RC(){let e=W.useContext(LC);if(e===void 0)throw Error(De(52));return e}var zC=W.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,readOnly:a=!1,required:o=!1,"aria-labelledby":s,value:c,inputRef:l,nativeButton:u=!1,id:d,...f}=e,p=IC(),{disabled:m,readOnly:h,required:g,checkedValue:_,touched:v=!1,validation:y,name:b}=p??{},x=p?.setCheckedValue??Ee,S=p?.setTouched??Ee,C=p?.registerControlRef??Ee,w=p?.registerInputRef??Ee,{setDirty:T,validityData:E,setTouched:D,setFilled:O,state:k,disabled:A}=_t(),j=os(),{labelId:M,getDescriptionProps:N}=xt(),P=A||j.disabled||m||i,F=h||a,I=g||o,L=p?_===c:c===``,R=W.useMemo(()=>dr(c),[c]),ee=W.useRef(null),te=W.useRef(null),ne=Me(e=>{e&&C(e,P)}),re=Se(l,te,w);Ae(()=>{te.current?.checked&&O(!0)},[O]),Ae(()=>{te.current&&(P&&L?w(null):(ee.current&&C(ee.current,P),w(te.current)))},[L,P,C,w]);let ie=He(),z=yt({id:d,implicit:!1,controlRef:ee}),ae=u?void 0:z,oe=Wh(s,M,te,!u,ae),se={role:`radio`,"aria-checked":L,"aria-required":I||void 0,"aria-readonly":F||void 0,"aria-labelledby":oe,[PC]:L?``:void 0,id:u?z:ie,onKeyDown(e){e.key===`Enter`&&e.preventDefault()},onClick(e){e.defaultPrevented||P||F||(e.preventDefault(),te.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))},onFocus(e){e.defaultPrevented||P||F||!v||(te.current?.click(),S(!1))}},{getButtonProps:ce,buttonRef:le}=we({disabled:P,native:u}),ue={type:`radio`,ref:re,id:ae,name:b,tabIndex:-1,style:b?ft:rt,"aria-hidden":!0,...c===void 0?Oe:{value:R},disabled:P,checked:L,required:I,readOnly:F,onChange(e){if(e.nativeEvent.defaultPrevented||P||F||c===void 0)return;let t=ct(Ue,e.nativeEvent);t.isCanceled||(D(!0),T(c!==E.initialValue),O(!0),x(c,t))},onFocus(){ee.current?.focus()}},de=W.useMemo(()=>({...k,required:I,disabled:P,readOnly:F,checked:L}),[k,P,F,L,I]),B=de,fe=p!==void 0,pe=[t,ee,le,ne],me=[se,N,y?.getValidationProps??Oe,f,ce],he=je(`span`,e,{enabled:!fe,state:de,ref:pe,props:me,stateAttributesMapping:NC});return(0,G.jsxs)(LC.Provider,{value:B,children:[fe?(0,G.jsx)(Bt,{tag:`span`,render:n,className:r,state:de,refs:pe,props:me,stateAttributesMapping:NC}):he,(0,G.jsx)(`input`,{...ue})]})}),BC=W.forwardRef(function(e,t){let{render:n,className:r,keepMounted:i=!1,...a}=e,o=RC(),s=o.checked,{mounted:c,transitionStatus:l,setMounted:u}=Ie(s),d={...o,transitionStatus:l},f=W.useRef(null),p=i||c,m=je(`span`,e,{ref:[t,f],state:d,props:a,stateAttributesMapping:NC});return Be({open:s,ref:f,onComplete(){s||u(!1)}}),p?m:null});function VC(e){return e==null||e.hasAttribute(`disabled`)||e.getAttribute(`aria-disabled`)===`true`}var HC=[];function UC(e){let{itemSizes:t,cols:n=1,loopFocus:r=!0,dense:i=!1,orientation:a=`both`,direction:o,highlightedIndex:s,onHighlightedIndexChange:c,rootRef:l,enableHomeAndEndKeys:u=!1,stopEventPropagation:d=!1,disabledIndices:f,modifierKeys:p=HC}=e,[m,h]=W.useState(0),g=n>1,_=W.useRef(null),v=Se(_,l),y=W.useRef([]),b=W.useRef(!1),x=s??m,S=Me((e,t=!1)=>{if((c??h)(e),t){let t=y.current[e];Xe(_.current,t,o,a)}}),C=Me(e=>{if(e.size===0||b.current)return;b.current=!0;let t=Array.from(e.keys()),n=t.find(e=>e?.hasAttribute(`data-composite-item-active`))??null,r=n?t.indexOf(n):-1;r!==-1&&S(r),Xe(_.current,n,o,a)}),w=W.useMemo(()=>({"aria-orientation":a===`both`?void 0:a,ref:v,onFocus(e){_.current&&ht(e.target)&&e.target.setSelectionRange(0,e.target.value.length??0)},onKeyDown(e){let s=u?Ye:ut;if(!s.has(e.key)||WC(e,p)||!_.current)return;let c=o===`rtl`,l=c?Ze:nt,m={horizontal:l,vertical:ot,both:l}[a],h=c?nt:Ze,v={horizontal:h,vertical:dt,both:h}[a];if(ht(e.target)&&!VC(e.target)){let t=e.target.selectionStart,n=e.target.selectionEnd,r=e.target.value??``;if(t==null||e.shiftKey||t!==n||e.key!==v&&t<r.length||e.key!==m&&t>0)return}let b=x,C=qe(y,f),w=We(y,f);if(g){let o=t||Array.from({length:y.current.length},()=>({width:1,height:1})),s=Ve(o,n,i),l=s.findIndex(e=>e!=null&&!lt(y,e,f)),u=s.reduce((e,t,n)=>t!=null&&!lt(y,t,f)?n:e,-1);b=s[Le({current:s.map(e=>e?y.current[e]:null)},{event:e,orientation:a,loopFocus:r,cols:n,disabledIndices:Ke([...f||y.current.map((e,t)=>lt(y,t)?t:void 0),void 0],s),minIndex:l,maxIndex:u,prevIndex:Fe(x>w?C:x,o,s,n,e.key===`ArrowDown`?`bl`:e.key===`ArrowRight`?`tr`:`tl`),rtl:c})]}let T={horizontal:[l],vertical:[ot],both:[l,ot]}[a],E={horizontal:[h],vertical:[dt],both:[h,dt]}[a],D=g?s:{horizontal:u?it:st,vertical:u?pt:Je,both:s}[a];u&&(e.key===`Home`?b=C:e.key===`End`&&(b=w)),b===x&&(T.includes(e.key)||E.includes(e.key))&&(b=r&&b===w&&T.includes(e.key)?C:r&&b===C&&E.includes(e.key)?w:gt(y,{startingIndex:b,decrement:E.includes(e.key),disabledIndices:f})),b!==x&&!Re(y,b)&&(d&&e.stopPropagation(),D.has(e.key)&&e.preventDefault(),S(b,!0),queueMicrotask(()=>{y.current[b]?.focus()}))}}),[n,i,o,f,y,u,x,g,t,r,v,p,S,a,d]);return W.useMemo(()=>({props:w,highlightedIndex:x,onHighlightedIndexChange:S,elementsRef:y,disabledIndices:f,onMapChange:C,relayKeyboardEvent:w.onKeyDown}),[w,x,S,y,f,C])}function WC(e,t){for(let n of tt.values())if(!t.includes(n)&&e.getModifierState(n))return!0;return!1}function GC(e){let{render:t,className:n,refs:r=Ce,props:i=Ce,state:a=Oe,stateAttributesMapping:o,highlightedIndex:s,onHighlightedIndexChange:c,orientation:l,dense:u,itemSizes:d,loopFocus:f,cols:p,enableHomeAndEndKeys:m,onMapChange:h,stopEventPropagation:g=!0,rootRef:_,disabledIndices:v,modifierKeys:y,highlightItemOnHover:b=!1,tag:x=`div`,...S}=e,{props:C,highlightedIndex:w,onHighlightedIndexChange:T,elementsRef:E,onMapChange:D,relayKeyboardEvent:O}=UC({itemSizes:d,cols:p,loopFocus:f,dense:u,orientation:l,highlightedIndex:s,onHighlightedIndexChange:c,rootRef:_,stopEventPropagation:g,enableHomeAndEndKeys:m,direction:Zt(),disabledIndices:v,modifierKeys:y}),k=je(x,e,{state:a,ref:r,props:[C,...i,S],stateAttributesMapping:o}),A=W.useMemo(()=>({highlightedIndex:w,onHighlightedIndexChange:T,highlightItemOnHover:b,relayKeyboardEvent:O}),[w,T,b,O]);return(0,G.jsx)(be.Provider,{value:A,children:(0,G.jsx)(en,{elementsRef:E,onMapChange:e=>{h?.(e),D(e)},children:k})})}var KC=[$e],qC=W.forwardRef(function(e,t){let{render:n,className:r,disabled:i,readOnly:a,required:o,onValueChange:s,value:c,defaultValue:l,name:u,inputRef:d,id:f,...p}=e,{setTouched:m,setFocused:h,shouldValidateOnChange:g,validationMode:_,name:v,disabled:y,state:b,validation:x,setDirty:S,setFilled:C,validityData:w}=_t(),{labelId:T}=xt(),{clearErrors:E}=vt(),D=is(!0),O=y||i,k=v??u,A=He(f),[j,M]=Qt({controlled:c,default:l,name:`RadioGroup`,state:`value`}),N=Me(s),P=Me((e,t)=>{N(e,t),!t.isCanceled&&M(e)}),F=W.useRef(null),I=W.useRef(null),L=W.useRef(null);function R(e){let t;return d&&(typeof d==`function`?t=d(e):d.current=e),I.current=e,x.inputRef.current=e,t}let ee=Me((e,t=!1)=>{e&&(t?F.current===e&&(F.current=null):F.current??=e)}),te=Me(e=>{if(!e||e.disabled)return;L.current||=e;let t=I.current;if(e.checked||t==null||t.disabled)return R(e)});Ct({id:A,commit:x.commit,value:j,controlRef:F,name:k,getValue:()=>j??null}),at(j,()=>{E(k),S(j!==w.initialValue),C(j!=null),g()?x.commit(j):x.commit(j,!0);let e=L.current;j==null&&e&&!e.disabled&&R(e)});let[ne,re]=W.useState(!1),ie=p[`aria-labelledby`]??T??D?.legendId,z={...b,disabled:O??!1,required:o??!1,readOnly:a??!1},ae=W.useMemo(()=>({...b,checkedValue:j,disabled:O,validation:x,name:k,onValueChange:N,readOnly:a,registerControlRef:ee,registerInputRef:te,required:o,setCheckedValue:P,setTouched:re,touched:ne}),[j,O,x,b,k,N,a,ee,te,o,P,re,ne]),oe={role:`radiogroup`,"aria-required":o||void 0,"aria-disabled":O||void 0,"aria-readonly":a||void 0,"aria-labelledby":ie,onFocus(){h(!0)},onBlur(e){Qe(e.currentTarget,e.relatedTarget)||(m(!0),h(!1),_===`onBlur`&&x.commit(j))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(m(!0),re(!0),h(!0))}};return(0,G.jsx)(FC.Provider,{value:ae,children:(0,G.jsx)(GC,{render:n,className:r,state:z,props:[oe,x.getValidationProps,p],refs:[t],stateAttributesMapping:bt,enableHomeAndEndKeys:!1,modifierKeys:KC})})});async function JC(e,t,n){if(await e(),await t(),(await ca.getAllPendingSyncs()).some(e=>e.type===n.type&&[n.id,n.uid].some(t=>t!=null&&String(t)===String(e.id))))throw Error(`Save your pending changes before switching workspaces.`)}async function YC(e,t=document){R(t),O(t);let{view:n,activeNote:r,activeDiagram:i,activeFlowchart:a,activeDrawing:o}=e,s=n===`notes`?r:n===`erd`?i:n===`flowchart`?a:o,c=!1;if(n===`notes`&&r&&!e.isReadOnlyFile(r)){let t={uid:String(r.uid??r.id),content:null};if(window.dispatchEvent(new CustomEvent(L,{detail:t})),t.content!==null){if(c=!0,e.cancelPendingNoteSaves(),t.content!==r.content&&!await e.saveNote({...r,content:t.content}))throw Error(`Could not save the note. Keep this panel open and try again.`);e.setIsLocalSaving(!1)}}await JC(c?async()=>{}:e.flushPendingSaves,e.syncDrafts,{type:n,id:s?.id,uid:s?.uid})}var XC={erd_builder:`ERD Builder`,notes:`Notes`,drawings:`Drawings`,flowcharts:`Flowcharts`,desktop_only:`DB Client`};function ZC({capability:e,teamName:t,ssoPortalUrl:n}){let r=v(),i=XC[e];return(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 py-10`,children:(0,G.jsxs)(`section`,{className:`w-full max-w-md rounded-lg border border-border bg-card p-6 shadow-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground`,children:(0,G.jsx)(Kn,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`h1`,{className:`text-base font-semibold text-foreground`,children:[`Unlock `,i]}),(0,G.jsxs)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:[i,` is not included in `,t||`this Team`,`'s current Cloud plan. Upgrade to continue using it.`]})]})]}),(0,G.jsx)(`div`,{className:`mt-5 flex justify-end border-t border-border pt-4`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(U,{variant:`outline`,onClick:()=>r(`/`),children:`Return to dashboard`}),n&&(0,G.jsx)(U,{onClick:()=>{if(n)try{window.location.assign(new URL(`/pricing#cloud-saas`,n).toString())}catch{}},children:`View Cloud plans`})]})})]})})}function QC({capability:e,children:t}){let{user:n}=la(),{activeTeamId:r,activeTeam:i,isLoading:a}=w();return!n?.isSso||!r?(0,G.jsx)(G.Fragment,{children:t}):a?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Checking Team plan…`}):e!==`desktop_only`&&i?.capabilities?.[e]===!0?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(ZC,{capability:e,teamName:i?.name,ssoPortalUrl:n?.ssoPortalUrl??n?.sso_portal_url})}var $C=W.createContext(void 0);function ew(){let e=W.useContext($C);if(e===void 0)throw Error(De(64));return e}var tw=function(e){return e.activationDirection=`data-activation-direction`,e.orientation=`data-orientation`,e}({}),nw={tabActivationDirection:e=>({[tw.activationDirection]:e})},rw=W.forwardRef(function(e,t){let{className:n,defaultValue:r=0,onValueChange:i,orientation:a=`horizontal`,render:o,value:s,...c}=e,l=Zt(),u=Object.hasOwn(e,`defaultValue`),d=W.useRef([]),[f,p]=W.useState(()=>new Map),[m,h]=Qt({controlled:s,default:r,name:`Tabs`,state:`value`}),g=s!==void 0,[_,v]=W.useState(()=>new Map),[y,b]=W.useState(`none`),x=Me((e,t)=>{i?.(e,t),!t.isCanceled&&(h(e),b(t.activationDirection))}),S=Me((e,t)=>{p(n=>{if(n.get(e)===t)return n;let r=new Map(n);return r.set(e,t),r})}),C=Me((e,t)=>{p(n=>{if(!n.has(e)||n.get(e)!==t)return n;let r=new Map(n);return r.delete(e),r})}),w=W.useCallback(e=>f.get(e),[f]),T=W.useCallback(e=>{for(let t of _.values())if(e===t?.value)return t?.id},[_]),E=W.useCallback(e=>{if(e===void 0)return null;for(let[t,n]of _.entries())if(n!=null&&e===(n.value??n.index))return t;return null},[_]),D=W.useMemo(()=>({direction:l,getTabElementBySelectedValue:E,getTabIdByPanelValue:T,getTabPanelIdByValue:w,onValueChange:x,orientation:a,registerMountedTabPanel:S,setTabMap:v,unregisterMountedTabPanel:C,tabActivationDirection:y,value:m}),[l,E,T,w,x,a,S,v,C,y,m]),O=W.useMemo(()=>{for(let e of _.values())if(e!=null&&e.value===m)return e},[_,m]),k=W.useMemo(()=>{for(let e of _.values())if(e!=null&&!e.disabled)return e.value},[_]);Ae(()=>{if(g||_.size===0)return;let e=O?.disabled;if(u&&e&&m===r||!e&&(O!=null||m===null))return;let t=k??null;m!==t&&(h(t),b(`none`))},[r,k,u,g,O,b,h,_,m]);let A=je(`div`,e,{state:{orientation:a,tabActivationDirection:y},ref:t,props:c,stateAttributesMapping:nw});return(0,G.jsx)($C.Provider,{value:D,children:(0,G.jsx)(en,{elementsRef:d,children:A})})}),iw=W.createContext(void 0);function aw(){let e=W.useContext(iw);if(e===void 0)throw Error(De(65));return e}var ow=W.forwardRef(function(e,t){let{className:n,disabled:r=!1,render:i,value:a,id:o,nativeButton:s=!0,...c}=e,{value:l,getTabPanelIdByValue:u,orientation:d}=ew(),{activateOnFocus:f,highlightedTabIndex:p,onTabActivation:m,registerTabResizeObserverElement:h,setHighlightedTabIndex:g,tabsListElement:_}=aw(),v=He(o),y=W.useMemo(()=>({disabled:r,id:v,value:a}),[r,v,a]),{compositeProps:b,compositeRef:x,index:S}=Vi({metadata:y}),C=a===l,w=W.useRef(!1),T=W.useRef(null);W.useEffect(()=>{let e=T.current;if(e)return h(e)},[h]),Ae(()=>{if(w.current){w.current=!1;return}if(!(C&&S>-1&&p!==S))return;let e=_;if(e!=null){let t=Ne(ze(e));if(t&&Qe(e,t))return}r||g(S)},[C,S,p,g,r,_]);let{getButtonProps:E,buttonRef:D}=we({disabled:r,native:s,focusableWhenDisabled:!0}),O=u(a),k=W.useRef(!1),A=W.useRef(!1);function j(e){C||r||m(a,ct(Ue,e.nativeEvent,void 0,{activationDirection:`none`}))}function M(e){C||(S>-1&&!r&&g(S),!r&&f&&(!k.current||k.current&&A.current)&&m(a,ct(Ue,e.nativeEvent,void 0,{activationDirection:`none`})))}function N(e){if(C||r)return;k.current=!0;function t(){k.current=!1,A.current=!1}e.button&&e.button!==0||(A.current=!0,ze(e.currentTarget).addEventListener(`pointerup`,t,{once:!0}))}return je(`button`,e,{state:{disabled:r,active:C,orientation:d},ref:[t,D,x,T],props:[b,{role:`tab`,"aria-controls":O,"aria-selected":C,id:v,onClick:j,onFocus:M,onPointerDown:N,[PC]:C?``:void 0,onKeyDownCapture(){w.current=!0}},c,E]})}),sw=function(e){return e.index=`data-index`,e.activationDirection=`data-activation-direction`,e.orientation=`data-orientation`,e.hidden=`data-hidden`,e[e.startingStyle=Pe.startingStyle]=`startingStyle`,e[e.endingStyle=Pe.endingStyle]=`endingStyle`,e}({}),cw={...nw,...Ge},lw=W.forwardRef(function(e,t){let{className:n,value:r,render:i,keepMounted:a=!1,...o}=e,{value:s,getTabIdByPanelValue:c,orientation:l,tabActivationDirection:u,registerMountedTabPanel:d,unregisterMountedTabPanel:f}=ew(),p=He(),m=W.useMemo(()=>({id:p,value:r}),[p,r]),{ref:h,index:g}=$t({metadata:m}),_=r===s,{mounted:v,transitionStatus:y,setMounted:b}=Ie(_),x=!v,S=c(r),C={hidden:x,orientation:l,tabActivationDirection:u,transitionStatus:y},w=W.useRef(null),T=je(`div`,e,{state:C,ref:[t,h,w],props:[{"aria-labelledby":S,hidden:x,id:p,role:`tabpanel`,tabIndex:_?0:-1,inert:mt(!_),[sw.index]:g},o],stateAttributesMapping:cw});return Be({open:_,ref:w,onComplete(){_||b(!1)}}),Ae(()=>{if((!x||a)&&p!=null)return d(r,p),()=>{f(r,p)}},[x,a,r,p,d,f]),a||v?T:null}),uw=W.forwardRef(function(e,t){let{activateOnFocus:n=!1,className:r,loopFocus:i=!0,render:a,...o}=e,{getTabElementBySelectedValue:s,onValueChange:c,orientation:l,value:u,setTabMap:d,tabActivationDirection:f}=ew(),[p,m]=W.useState(0),[h,g]=W.useState(null),_=W.useRef(new Set),v=W.useRef(new Set),y=W.useRef(null),b=Me(()=>{_.current.forEach(e=>{e()})});W.useEffect(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>{_.current.size&&b()});return y.current=e,h&&e.observe(h),v.current.forEach(t=>{e.observe(t)}),()=>{e.disconnect(),y.current=null}},[h,b]);let x=Me(e=>(_.current.add(e),()=>{_.current.delete(e)})),S=Me(e=>(v.current.add(e),y.current?.observe(e),()=>{v.current.delete(e),y.current?.unobserve(e)})),C=fw(u,l,h,s),w=Me((e,t)=>{e!==u&&(t.activationDirection=C(e),c(e,t))}),T={orientation:l,tabActivationDirection:f},E={"aria-orientation":l===`vertical`?`vertical`:void 0,role:`tablist`},D=W.useMemo(()=>({activateOnFocus:n,highlightedTabIndex:p,registerIndicatorUpdateListener:x,registerTabResizeObserverElement:S,onTabActivation:w,setHighlightedTabIndex:m,tabsListElement:h}),[n,p,x,S,w,m,h]);return(0,G.jsx)(iw.Provider,{value:D,children:(0,G.jsx)(GC,{render:a,className:r,state:T,refs:[t,g],props:[E,o],stateAttributesMapping:nw,highlightedIndex:p,enableHomeAndEndKeys:!0,loopFocus:i,orientation:l,onHighlightedIndexChange:m,onMapChange:d,disabledIndices:Ce})})});function dw(e,t){let{left:n,top:r}=e.getBoundingClientRect(),{left:i,top:a}=t.getBoundingClientRect();return{left:n-i,top:r-a}}function fw(e,t,n,r){let[i,a]=W.useState(null);return Ae(()=>{if(e==null||n==null){a(null);return}let i=r(e);if(i==null){a(null);return}let{left:o,top:s}=dw(i,n);a(t===`horizontal`?o:s)},[t,r,n,e]),W.useCallback(o=>{if(o===e)return`none`;if(o==null)return a(null),`none`;if(o!=null&&n!=null){let e=r(o);if(e!=null){let{left:r,top:o}=dw(e,n);if(i==null)return a(t===`horizontal`?r:o),`none`;if(t===`horizontal`){if(r<i)return a(r),`left`;if(r>i)return a(r),`right`}else if(o<i)return a(o),`up`;else if(o>i)return a(o),`down`}}return`none`},[r,t,i,n,e])}var pw=r(c(),1);function mw({className:e,orientation:t=`horizontal`,...n}){return(0,G.jsx)(rw,{"data-slot":`tabs`,"data-orientation":t,className:d(`group/tabs flex gap-2 data-horizontal:flex-col`,e),...n})}var hw=ke(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function gw({className:e,variant:t=`default`,...n}){return(0,G.jsx)(uw,{"data-slot":`tabs-list`,"data-variant":t,className:d(hw({variant:t}),e),...n})}function _w({className:e,...t}){return(0,G.jsx)(ow,{"data-slot":`tabs-trigger`,className:d(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent`,`data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100`,e),...t})}function vw({className:e,...t}){return(0,G.jsx)(lw,{"data-slot":`tabs-content`,className:d(`flex-1 text-sm outline-none`,e),...t})}function yw({userName:e,value:t,onChange:n,onSubmit:r,disabled:i=!1,placeholder:a=`Reply…`,submitLabel:o=`Send reply`}){let[s,c]=(0,W.useState)(!1),l=(0,W.useRef)(null),u=s||t.length>0;(0,W.useEffect)(()=>{s&&l.current?.focus()},[s]),(0,W.useEffect)(()=>{let e=l.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,128)}px`)},[t,u]);let d=()=>{n(``),c(!1)},f=()=>{t.trim()&&!i&&(r(),c(!1))};return u?(0,G.jsx)(`form`,{onSubmit:e=>{e.preventDefault(),f()},className:`shrink-0 border-t border-border p-3`,children:(0,G.jsxs)(`div`,{className:`flex items-end gap-1.5 rounded-lg border border-primary/60 bg-background px-2.5 py-1.5 ring-2 ring-primary/20`,children:[(0,G.jsx)(`textarea`,{"data-comment-draft":!0,ref:l,rows:1,maxLength:4e3,value:t,disabled:i,"aria-label":o,placeholder:a,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),f())},className:`min-h-6 max-h-32 flex-1 resize-none bg-transparent py-0.5 text-sm outline-none placeholder:text-muted-foreground`}),(0,G.jsx)(U,{type:`button`,variant:`secondary`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Cancel reply`,onClick:d,disabled:i,children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-3.5`})}),(0,G.jsx)(U,{type:`submit`,size:`icon-xs`,className:`rounded-full`,"aria-label":o,disabled:!t.trim()||i,children:(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-3.5`})})]})}):(0,G.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`flex w-full shrink-0 items-center gap-2.5 border-t border-border px-4 py-2.5 text-left text-sm text-muted-foreground transition-colors hover:bg-muted/50`,children:[(0,G.jsx)(_n,{name:e,className:`size-7`}),a]})}function bw(e,t=144){e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,t)}px`}function xw({value:e,onChange:t,className:n,...r}){let i=(0,W.useRef)(null);return(0,W.useEffect)(()=>{i.current&&bw(i.current)},[e]),(0,G.jsx)(Bi,{"data-comment-draft":!0,...r,ref:i,rows:1,value:e,onChange:e=>{t(e.target.value),bw(e.currentTarget)},maxLength:4e3,className:n})}function Sw({id:e,value:t,onChange:n,onSubmit:r,placeholder:i,disabled:a,submitLabel:o}){return(0,G.jsx)(`div`,{className:`shrink-0 border-t border-border p-3`,children:(0,G.jsxs)(`form`,{onSubmit:r,className:`relative`,children:[(0,G.jsx)(`label`,{htmlFor:e,className:`sr-only`,children:o}),(0,G.jsx)(xw,{id:e,value:t,onChange:n,placeholder:i,className:`min-h-11! max-h-36 resize-none overflow-y-auto rounded-2xl bg-muted/40 px-3 py-2 pr-12 shadow-none`,required:!0}),(0,G.jsx)(U,{type:`submit`,size:`icon`,className:`absolute right-1 bottom-1 size-9 rounded-full`,"aria-label":o,disabled:!t.trim()||a,children:(0,G.jsx)(Io,{"aria-hidden":`true`})})]})})}function Cw(e,t){let n=new URLSearchParams;for(let[e,r]of Object.entries(t))r&&n.set(e,r);let r=n.toString();return r?`${e}?${r}`:e}async function ww(e,t){let n=await Si(e,t),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error||`The request could not be completed.`);return r}function Tw({message:e,canEdit:t,canDelete:n=t,editing:r,editDraft:i,editOriginalBody:a,disabled:o,onEdit:s,onDelete:c,onEditDraftChange:l,onCancelEdit:u,onSaveEdit:d}){let f=e.body!==a;return(0,G.jsxs)(`div`,{className:`group/message relative flex gap-2.5 rounded-md px-1.5 py-1.5 hover:bg-muted/40 focus-within:bg-muted/40`,children:[(0,G.jsx)(_n,{name:e.authorName,className:`mt-0.5 size-7`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:e.authorName}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,title:Fw(e.createdAt),children:ln(e.createdAt)})]}),r&&t?(0,G.jsxs)(`form`,{onSubmit:d,className:`mt-1 flex flex-col gap-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-end gap-1.5 rounded-lg border border-primary/60 bg-background px-2.5 py-1.5 ring-2 ring-primary/20`,children:[(0,G.jsx)(xw,{autoFocus:!0,onFocus:e=>{let t=e.currentTarget.value.length;e.currentTarget.setSelectionRange(t,t)},"aria-label":`Edit your message`,value:i,onChange:l,className:`min-h-6! max-h-32 flex-1 resize-none overflow-y-auto border-0 bg-transparent p-0 py-0.5 text-sm shadow-none focus-visible:ring-0`,disabled:o}),(0,G.jsx)(U,{type:`button`,variant:`secondary`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Cancel edit`,onClick:u,disabled:o,children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-3.5`})}),(0,G.jsx)(U,{type:`submit`,size:`icon-xs`,className:`rounded-full`,"aria-label":`Save message`,disabled:o||!i.trim()||f,children:(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-3.5`})})]}),f&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:`This message changed. Cancel and edit the latest version.`})]}):(0,G.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-sm`,children:e.body})]}),t&&!r&&(0,G.jsxs)(`div`,{className:`absolute -top-3 right-1 z-10 hidden rounded-md border bg-popover shadow-sm group-hover/message:flex group-focus-within/message:flex [@media(hover:none)]:flex`,children:[(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Edit message`,onClick:s,children:(0,G.jsx)(ar,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,children:`Edit`})]}),n&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`text-destructive hover:text-destructive`,"aria-label":`Delete message`,onClick:c,children:(0,G.jsx)($r,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,children:`Delete`})]})]})]})}function Ew(e,t){let n=e.featureType??e.feature_type??t?.featureType,r=e.anchorType??e.anchor_type??t?.anchorType;if(![`diagram`,`note`,`drawing`,`flowchart`].includes(String(n))||r!=null&&![`general`,`table`,`relationship`,`block`,`shape`,`point`].includes(String(r)))return null;let i=e.fileId??e.file_id??t?.fileId;return i==null?null:{featureType:n,fileId:String(i),fileName:e.fileName==null&&e.file_name==null?t?.fileName??null:String(e.fileName??e.file_name),anchorType:r??`general`,anchorId:e.anchorId==null&&e.anchor_id==null&&t?.anchorId==null?null:String(e.anchorId??e.anchor_id??t?.anchorId),anchorLabel:String(e.anchorLabel??e.anchor_label??t?.anchorLabel??`General`)}}function Dw(e){let t=Array.isArray(e.contexts)?e.contexts.map(e=>Ew(e)).filter(Boolean):[],n=Ew(e,t[0])||t[0]||null,r=e.anchorType??e.anchor_type,i=[`general`,`table`,`relationship`,`block`,`shape`,`point`].includes(String(r))?r:`general`,a=e.status,o=e.previewMessages??e.preview_messages,s=Array.isArray(o)?o.map(e=>Ow(e)):typeof o==`string`?(()=>{try{let e=JSON.parse(o);return Array.isArray(e)?e.map(e=>Ow(e)):[]}catch{return[]}})():[],c=e.latestMessage==null&&e.latest_message==null?null:{id:String(e.latestMessageId??e.latest_message_id??`latest`),authorId:String(e.latestAuthorId??e.latest_author_id??``),authorName:`Team member`,body:String(e.latestMessage??e.latest_message??``),createdAt:String(e.lastMessageAt??e.last_message_at??``)};return{id:String(e.id??``),featureType:n?.featureType??null,fileId:n?.fileId??(e.fileId==null&&e.file_id==null?null:String(e.fileId??e.file_id)),anchorType:n?.anchorType??i,anchorId:n?.anchorId??(e.anchorId==null&&e.anchor_id==null?null:String(e.anchorId??e.anchor_id)),anchorLabel:n?.anchorLabel??String(e.anchorLabel??e.anchor_label??`General`),contexts:t.length>0?t:n?[n]:[],status:a===`resolved`?`resolved`:`open`,canDelete:!!(e.canDelete??e.can_delete),unread:!!e.unread,latestMessageId:e.latestMessageId==null&&e.latest_message_id==null?null:String(e.latestMessageId??e.latest_message_id),latestMessage:e.latestMessage==null&&e.latest_message==null?null:String(e.latestMessage??e.latest_message),latestAuthorId:e.latestAuthorId==null&&e.latest_author_id==null?null:String(e.latestAuthorId??e.latest_author_id),lastMessageAt:e.lastMessageAt==null&&e.last_message_at==null?null:String(e.lastMessageAt??e.last_message_at),previewMessages:s.length>0?s:c?[c]:[]}}function Ow(e){return{id:String(e.id??``),threadId:e.threadId==null&&e.thread_id==null?void 0:String(e.threadId??e.thread_id),authorId:String(e.authorId??e.author_id??``),authorName:String(e.authorName??e.author_name??`Team member`),body:String(e.body??``),createdAt:String(e.createdAt??e.created_at??``)}}function kw(e){let t=e.nextCursor;return{hasMore:e.hasMore===!0,nextCursor:t?.createdAt&&t.id?{createdAt:String(t.createdAt),id:String(t.id)}:null}}function Aw(e,t){let n=new Map(e.map(e=>[e.id,e]));for(let e of t)n.set(e.id,e);return[...n.values()].sort((e,t)=>Date.parse(e.createdAt)-Date.parse(t.createdAt)||e.id.localeCompare(t.id))}function jw(e,t,n){let r=Aw(e.messages,t).slice(-Math.max(50,e.messages.length)),i=r[0],a=e.hasMore||n.hasMore;return{messages:r,hasMore:a,nextCursor:a&&i?{createdAt:i.createdAt,id:i.id}:null}}function Mw(e,t,n,r){return e===`thread`?t===`comments`&&n?{kind:`anchor`,anchor:n,threadId:r}:r?{kind:`thread`,threadId:r}:null:null}function Nw(e){return[e.featureType||`diagram`,e.fileId||``,e.anchorType,e.anchorId||``].join(`:`)}function Pw(e){let t=new Map;for(let n of e){let e=Nw(n),r=t.get(e);r?(r.threads.push(n),r.previewMessages.push(...n.previewMessages)):t.set(e,{key:e,representative:n,threads:[n],previewMessages:[...n.previewMessages]})}return[...t.values()].map(e=>({...e,previewMessages:e.previewMessages.sort((e,t)=>new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime()).slice(-3)}))}function Fw(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}function Iw(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:Pn(t,{addSuffix:!0})}function Lw(e){return e===`diagram`?`ERD`:e===`note`?`Notes`:e===`drawing`?`Drawing`:e===`flowchart`?`Flowchart`:`File`}var Rw={diagram:{Icon:Cr,className:`bg-feature-erd/10 text-feature-erd`},note:{Icon:de,className:`bg-feature-notes/10 text-feature-notes`},drawing:{Icon:wr,className:`bg-feature-drawing/10 text-feature-drawing`},flowchart:{Icon:Sr,className:`bg-feature-flowchart/10 text-feature-flowchart`}},zw={diagram:new Set([`table`,`relationship`]),note:new Set([`block`]),drawing:new Set([`point`]),flowchart:new Set([`shape`])};function Bw(e,t){return typeof t==`string`&&zw[e].has(t)}function Vw({projectId:e,teamId:t,userId:n,userName:r,fileContext:i,anchorContext:a,onContextSelected:o,anchorPreview:s,readOnly:c=!1}){let u=ie(),f=(0,W.useId)(),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(`discussions`),_=h===`comments`,[v,y]=(0,W.useState)(`file`),[b,x]=(0,W.useState)(`list`),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)([]),[E,D]=(0,W.useState)(0),[O,k]=(0,W.useState)({messages:[],hasMore:!1,nextCursor:null}),[A,j]=(0,W.useState)(!1),[M,N]=(0,W.useState)(``),[P,F]=(0,W.useState)(!0),[I,L]=(0,W.useState)(!1),[R,ee]=(0,W.useState)(``),[te,ne]=(0,W.useState)(``),[re,z]=(0,W.useState)(null),[ae,oe]=(0,W.useState)(``),[se,ce]=(0,W.useState)(``),[le,ue]=(0,W.useState)(null),[de,B]=(0,W.useState)(!1),[fe,pe]=(0,W.useState)(``),[me,he]=(0,W.useState)(null),[ge,_e]=(0,W.useState)(null),[ve,V]=(0,W.useState)(null),H=O.messages,ye=(0,W.useRef)(0),be=(0,W.useRef)(0),xe=(0,W.useRef)(0),Se=(0,W.useRef)(new Map),Ce=(0,W.useRef)(!1),we=(0,W.useRef)({screen:b,selectedThreadId:S});we.current={screen:b,selectedThreadId:S};let Te=(0,W.useCallback)(()=>{we.current={screen:`list`,selectedThreadId:null},be.current++,xe.current++,x(`list`),C(null),k({messages:[],hasMore:!1,nextCursor:null}),j(!1),N(``),ne(``),z(null),oe(``),ce(``),ue(null),V(null)},[]),Ee=(0,W.useCallback)(e=>{let t=e;t!==h&&(Te(),he(null),pe(``),g(t))},[h,Te]),De=`/api/projects/${encodeURIComponent(e)}/${h===`comments`?`comments`:`discussions`}`,Oe=(0,W.useMemo)(()=>Cw(De,{scope:h===`discussions`?v:void 0,feature_type:i.featureType,file_id:i.fileId,anchor_type:h===`comments`&&!_&&a?a.type:void 0,anchor_id:h===`comments`&&!_&&a?a.id:void 0}),[h,a,v,De,i.featureType,i.fileId,_]),ke=(0,W.useCallback)(e=>Cw(`${De}/${encodeURIComponent(e)}`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),[h,De,i.featureType,i.fileId]),Ae=(0,W.useCallback)(async(e=!1)=>{let t=++ye.current;ee(``),Ce.current||F(!0);try{let r=await ww(Oe);if(t!==ye.current)return[];let i=Array.isArray(r.threads)?r.threads.map(e=>Dw(e)):[];if(e&&Ce.current)for(let e of i){let t=Se.current.get(e.id);e.latestMessageId&&e.latestAuthorId!==n&&(t&&e.latestMessageId!==t||!t&&e.unread)&&l.info(`New activity in ${e.contexts[0]?.fileName||`Project discussion`}`)}Se.current=new Map(i.filter(e=>e.latestMessageId).map(e=>[e.id,e.latestMessageId])),Ce.current=!0,T(i);let a=we.current;return a.screen===`thread`&&a.selectedThreadId&&!i.some(e=>e.id===a.selectedThreadId)&&Te(),D(Number(r.unreadCount??r.unread_count)||0),i}catch{return t===ye.current&&ee(`Couldn't load ${h}. Try again.`),[]}finally{t===ye.current&&F(!1)}},[h,Te,Oe,n]),je=(0,W.useCallback)(e=>{o?.({featureType:i.featureType,fileId:i.fileId,anchorType:e.type,anchorId:e.id,anchorLabel:e.type===`table`?`Table`:e.type===`relationship`?`Relationship`:e.type[0].toUpperCase()+e.type.slice(1)})},[i.featureType,i.fileId,o]),Me=(0,W.useCallback)(async(e,t,n=!1)=>{let r=++be.current;n||ne(``);try{let a=await ww(ke(e));if(r!==be.current)return!1;let s=Array.isArray(a.messages)?a.messages.map(e=>Ow(e)):[],c=kw(a);k(e=>n?jw(e,s,c):{...c,messages:s}),n||N(``),t&&ww(Cw(`${ke(e)}/read`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`POST`}).then(()=>Ae()).catch(()=>{});let l=Array.isArray(a.contexts)?a.contexts.map(e=>Ew(e)).filter(Boolean):[];return l[0]&&o?.(l[0]),!0}catch{return!n&&r===be.current&&ne(`Couldn't load this ${h===`comments`?`comment`:`discussion`}. Try again.`),!1}},[h,i.fileId,i.featureType,Ae,o,ke]),Ne=(0,W.useCallback)(async(e,t,n=!1,r)=>{let a=++be.current;n||ne(``);try{let s=await ww(Cw(`${De}/anchor`,{feature_type:i.featureType,file_id:i.fileId,anchor_type:e.type,anchor_id:e.id}));if(a!==be.current)return!1;let c=Array.isArray(s.threads)?s.threads.map(e=>Dw(e)):[];if(!c.length)return Te(),!0;let l=Array.isArray(s.messages)?s.messages.map(e=>Ow(e)):[];T(e=>{let t=new Map(c.map(e=>[e.id,e]));return e.map(e=>{let n=t.get(e.id);return n?{...e,...n}:e})});let u=kw(s);k(e=>n?jw(e,l,u):{...u,messages:l}),n||N(``);let d=c.some(e=>e.id===r)?r:c[0].id;C(d);let f=Array.isArray(s.contexts)?s.contexts.map(e=>Ew(e)).filter(Boolean):[];return f[0]?o?.(f[0]):je(e),t&&Promise.all(c.map(e=>ww(Cw(`${De}/${encodeURIComponent(e.id)}/read`,{feature_type:i.featureType,file_id:i.fileId}),{method:`POST`}).catch(()=>null))).then(()=>Ae()),!0}catch{return!n&&a===be.current&&ne(`Couldn't load the full comment history. Try again.`),!1}},[Te,De,i.fileId,i.featureType,je,Ae,o]),Pe=(0,W.useCallback)(e=>{if(!p)return;let t=Mw(b,h,ve,S);t&&(t.kind===`anchor`?Ne(t.anchor,e,!0,t.threadId||void 0):Me(t.threadId,e,!0))},[ve,h,Ne,Me,p,b,S]),Fe=(0,W.useCallback)(async()=>{let e=O.nextCursor,t=S;if(!O.hasMore||!e||!t||A)return;let n=++xe.current,r=be.current;j(!0),N(``);try{let a={before_created_at:e.createdAt,before_id:e.id},o=await ww(_&&ve?Cw(`${De}/anchor`,{feature_type:i.featureType,file_id:i.fileId,anchor_type:ve.type,anchor_id:ve.id,...a}):Cw(ke(t),a));if(n!==xe.current||r!==be.current)return;let s=Array.isArray(o.messages)?o.messages.map(e=>Ow(e)):[],c=kw(o);k(e=>({...c,messages:Aw(e.messages,s)}))}catch{n===xe.current&&N(`Could not load earlier messages.`)}finally{n===xe.current&&j(!1)}},[ve,De,i.featureType,i.fileId,_,A,O,S,ke]);(0,W.useEffect)(()=>{Ce.current=!1,x(`list`),C(null),k({messages:[],hasMore:!1,nextCursor:null}),T([]),Ae()},[Ae]),(0,W.useEffect)(()=>{let n=e=>{let n=e.detail;n?.teamId!==t||n.eventType&&n.eventType!==`cloud.workspace.sync`||(Ae(!0),Pe(document.visibilityState===`visible`))},r=e=>{e.detail?.teamId===t&&(Ae(),Pe(document.visibilityState===`visible`))},i=n=>{let r=n.detail;r?.teamId===t&&String(r.projectId)===String(e)&&Ae(!0)};return window.addEventListener(`cloud-workspace-sync`,n),window.addEventListener(`cloud-live-sync-reconnected`,r),window.addEventListener(`collaboration-updated`,i),()=>{window.removeEventListener(`cloud-workspace-sync`,n),window.removeEventListener(`cloud-live-sync-reconnected`,r),window.removeEventListener(`collaboration-updated`,i)}},[Ae,e,Pe,t]),(0,W.useEffect)(()=>{if(!p)return;let e=window.setInterval(()=>{Ae(!0),document.hidden||Pe(!0)},15e3);return()=>window.clearInterval(e)},[Ae,p,Pe]),(0,W.useEffect)(()=>{let e=e=>{let t=e.detail;!t?.id||t.featureType!==i.featureType||t.fileId&&String(t.fileId)!==i.fileId||!Bw(i.featureType,t.type)||(he({type:t.type,id:t.id}),pe(``),ne(``),g(`comments`),m(!0))};return window.addEventListener(`project-comment-open-request`,e),()=>window.removeEventListener(`project-comment-open-request`,e)},[i.fileId,i.featureType]),(0,W.useEffect)(()=>{if(h!==`comments`||!me)return;let e=!1,t=me;return V(t),_e(t),(async()=>{let n=await Ae();if(e)return;let r=Pw(n).find(e=>e.representative.anchorType===t.type&&e.representative.anchorId===t.id);r?(x(`thread`),C(r.representative.id),await Ne(t,!0,!1,r.representative.id)):x(c?`list`:`compose`),e||he(null)})(),()=>{e=!0}},[h,Ne,Ae,me]);let Ie=(b===`thread`||b===`compose`)&&fe.trim()!==``||re!==null&&ae!==se,Le=(e,t)=>{if(!e&&(le||de))return;let n=t?.event?.target;!e&&u&&t?.reason===`outside-press`&&n instanceof Element&&!u.host.current?.contains(n)||!e&&t?.reason===`outside-press`&&n instanceof Element&&n.closest(`[data-slot="dropdown-menu-content"]`)||(!e&&Ie?B(!0):(m(e),e?(Ae(),b===`thread`&&_&&ve?Ne(ve,!0,!1,S||void 0):b===`thread`&&S&&Me(S,!0)):(qe(),ue(null))))},Re=async e=>{pe(``),qe(),ue(null);let t=e.contexts[0]||Ew(e),n=t?.anchorType??e.anchorType,r=t?.anchorId??e.anchorId,a=t?.featureType??e.featureType??i.featureType,s=r&&Bw(a,n)?{type:n,id:r}:null;_&&s?(V(s),x(`thread`),C(e.id),k({messages:[],hasMore:!1,nextCursor:null}),je(s),await Ne(s,!0,!1,e.id)):(x(`thread`),C(e.id),k({messages:[],hasMore:!1,nextCursor:null}),await Me(e.id,!0)&&t&&o?.(t))},ze=async e=>{let t=e.representative.featureType??i.featureType;e.representative.anchorType&&e.representative.anchorId&&Bw(t,e.representative.anchorType)&&{type:e.representative.anchorType,id:e.representative.anchorId}&&await Re(e.representative)},Be=()=>{let e=h===`comments`?(_?ve:a)??null:null;h===`comments`&&!e?l.info(`Select an item on this file before adding a comment.`):(_e(e),pe(``),ne(``),qe(),x(`compose`))},Ve=()=>window.dispatchEvent(new CustomEvent(`collaboration-updated`,{detail:{teamId:t,projectId:e}})),He=async e=>{e.preventDefault();let t=fe.trim();if(t&&!I){L(!0),ne(``);try{let e=await ww(De,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:t,context:{type:h===`comments`?ge?.type:`general`,...h===`comments`?{id:ge?.id}:{},featureType:i.featureType,fileId:i.fileId}})});pe(``),_e(null),C(e.id),x(`thread`),Ve(),await Ae(),_&&ge?await Ne(ge,!0,!1,e.id):await Me(e.id,!0)}catch{ne(`Couldn't start the ${h===`comments`?`comment`:`discussion`}. Try again.`)}finally{L(!1)}}},Ue=async()=>{let e=fe.trim();if(e&&S&&!I){L(!0),ne(``);try{await ww(Cw(`${De}/${encodeURIComponent(S)}/messages`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:e})}),pe(``),Ve(),_&&ve?await Ne(ve,!0,!0,S):await Me(S,!0,!0),await Ae()}catch{ne(`Couldn't send the reply. Reopen the ${h===`comments`?`comment`:`discussion`} if it was resolved.`)}finally{L(!1)}}},We=_?{feature_type:i.featureType,file_id:i.fileId}:{},Ge=e=>_&&ve?Ne(ve,!0,!0,e):Me(e,!0,!0),Ke=e=>{e.authorId===n&&(z(e.id),oe(e.body),ce(e.body))},qe=()=>{z(null),oe(``),ce(``)},Je=async(e,t)=>{t.preventDefault();let r=ae.trim(),i=S;if(e.authorId===n&&i&&r&&e.body===se&&!I){L(!0);try{await ww(Cw(`${De}/${encodeURIComponent(i)}/messages/${encodeURIComponent(e.id)}`,We),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:r,expectedBody:se})}),k(t=>({...t,messages:t.messages.map(t=>t.id===e.id?{...t,body:r}:t)})),qe(),Ve()}catch(e){await Ge(i),l.error(e instanceof Error?e.message:`Couldn't update this message. Try again.`)}finally{L(!1)}}},Ye=async e=>{let t=w.find(t=>t.id===e);if(t?.canDelete&&!I){L(!0);try{await ww(Cw(`${De}/${encodeURIComponent(t.id)}`,We),{method:`DELETE`}),ue(null),S===e&&Te(),Ve(),_&&await Ae()}catch(e){l.error(e instanceof Error?e.message:`Couldn't delete this ${_?`comment`:`discussion`}. Try again.`)}finally{L(!1)}}},Xe=async(e,t)=>{if(!(h!==`discussions`||S!==e||t.authorId!==n||I)){L(!0);try{await ww(`${De}/${encodeURIComponent(e)}/messages/${encodeURIComponent(t.id)}`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({expectedBody:t.body})}),k(e=>({...e,messages:e.messages.filter(e=>e.id!==t.id)})),re===t.id&&qe(),ue(null),await Ae(),Ve()}catch(t){await Me(e,!0,!0),l.error(t instanceof Error?t.message:`Couldn't delete this message. Try again.`)}finally{L(!1)}}},Ze=async()=>{let e=w.find(e=>e.id===S);if(!e||I)return;L(!0);let t=e.status;try{await ww(Cw(`${De}/${encodeURIComponent(e.id)}`,h===`comments`?{feature_type:i.featureType,file_id:i.fileId}:{}),{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({status:t===`open`?`resolved`:`open`,expectedStatus:t})}),Ve(),await Ae()}catch(e){ne(e instanceof Error?e.message:`Couldn't update this ${h===`comments`?`comment`:`discussion`}. Try again.`),await Ae()}finally{L(!1)}},Qe=w.find(e=>e.id===S),$e=(0,W.useMemo)(()=>Pw(w),[w]),et=h===`discussions`?`Discussions`:b===`compose`?`New comment`:b===`thread`?Qe?.anchorLabel||`Comment`:`Comments`,tt=b===`list`?v===`file`?i.label:null:b===`compose`?i.label:Qe?.contexts[0]?.fileName||(Qe?.fileId===i.fileId?i.label:null),nt=h===`comments`?_?`Latest activity on ${i.label}`:`Comments on ${i.label}`:tt?`Related to ${tt}`:b===`list`?`All project discussions`:`Project discussion`,rt=`${f}-description`;return(0,G.jsxs)(Pt,{open:p,onOpenChange:Le,children:[(0,G.jsx)(Mt,{render:(0,G.jsxs)(U,{type:`button`,variant:`ghost`,size:`icon`,className:`relative shrink-0 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`${_?`Open comments`:`Open discussions`}${E?`, ${E} unread`:``}`,title:_?`Comments`:`Discussions`,children:[_?(0,G.jsx)(qn,{"aria-hidden":`true`}):(0,G.jsx)(Eo,{"aria-hidden":`true`}),E>0&&(0,G.jsx)(Vh,{variant:`default`,className:`absolute -right-1 -top-1 h-4 min-w-4 px-1 text-[10px] leading-none`,children:E})]})}),(0,G.jsxs)(At,{anchor:u?()=>{let e=u.host.current;return e?{contextElement:e,getBoundingClientRect:()=>{let t=e.getBoundingClientRect();return new DOMRect(t.right-8,t.top+8,0,0)}}:null}:void 0,side:u?`bottom`:`left`,align:u?`end`:`start`,sideOffset:8,"data-discussions-panel":``,className:d(`flex h-[min(42rem,calc(100svh-5rem))] w-[min(24rem,calc(100vw-1rem))] max-w-[calc(100vw-1rem)] flex-col gap-0 overflow-hidden p-0`,u&&`max-h-(--available-height)`),"aria-describedby":rt,children:[(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b!==`list`&&(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Back to list`,onClick:()=>x(`list`),children:(0,G.jsx)(sr,{"aria-hidden":`true`,className:`size-4`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`h2`,{className:`truncate text-sm font-semibold`,children:et}),(0,G.jsx)(`p`,{id:rt,className:`truncate text-xs text-muted-foreground`,children:nt})]}),h===`discussions`&&b===`thread`&&Qe&&!c&&(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Discussion actions`,children:(0,G.jsx)(Tr,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(Gt,{align:`end`,className:`w-44`,positionerClassName:`z-[210]`,children:(0,G.jsxs)(Vt,{children:[(0,G.jsxs)(It,{onClick:()=>void Ze(),disabled:I,children:[Qe.status===`open`?(0,G.jsx)(Yt,{"aria-hidden":`true`}):(0,G.jsx)(zn,{"aria-hidden":`true`}),Qe.status===`open`?`Resolve`:`Reopen`]}),Qe.canDelete&&(0,G.jsxs)(It,{variant:`destructive`,onClick:()=>ue({type:`thread`,threadId:Qe.id}),children:[(0,G.jsx)($r,{"aria-hidden":`true`}),`Delete Thread`]})]})})]}),(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${h}`,onClick:()=>Le(!1),children:(0,G.jsx)(Pr,{"aria-hidden":`true`,className:`size-4`})})]})}),(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-2`,children:(0,G.jsx)(mw,{value:h,onValueChange:Ee,className:`w-full`,children:(0,G.jsxs)(gw,{className:`mx-auto`,children:[(0,G.jsx)(_w,{value:`discussions`,children:`Discussions`}),(0,G.jsx)(_w,{value:`comments`,children:`Comments`})]})})}),b===`list`&&(0,G.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden`,children:[h===`discussions`?(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-2`,children:(0,G.jsx)(mw,{value:v,onValueChange:e=>y(e),className:`w-full`,children:(0,G.jsxs)(gw,{className:`mx-auto`,children:[(0,G.jsx)(_w,{value:`file`,children:`This File`}),(0,G.jsx)(_w,{value:`project`,children:`All Project`})]})})}):_?(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-3 py-1.5 text-[11px] text-muted-foreground`,children:`Latest messages. Open a card for the full history.`}):(0,G.jsx)(`div`,{className:`shrink-0 border-b border-border/70 px-4 py-2 text-xs text-muted-foreground`,children:a?`Selected ${a.type}`:`Select a table or relationship to add a comment.`}),(0,G.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-24`,children:[P&&(0,G.jsxs)(`p`,{role:`status`,className:`px-4 py-5 text-center text-sm text-muted-foreground`,children:[`Loading `,h,`…`]}),!P&&R&&(0,G.jsxs)(`div`,{className:`m-4 rounded-lg border border-destructive/40 p-4 text-sm`,children:[(0,G.jsx)(`p`,{children:R}),(0,G.jsx)(U,{variant:`outline`,className:`mt-3 min-h-11`,onClick:()=>void Ae(),children:`Retry`})]}),!P&&!R&&(_?$e.length:w.length)===0&&(0,G.jsxs)(`div`,{className:`mx-4 mt-4 rounded-lg border border-dashed border-border px-4 py-8 text-center`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:h===`comments`?`No comments on this file yet.`:`No discussions in this view yet.`}),(0,G.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:c?`You can read threads here, but only members with comment access can start one.`:h===`comments`?`Use the node context menu to start one.`:`Start a thread to capture a question or design decision.`})]}),!R&&_&&$e.map(e=>{let t=e.representative,n=e.previewMessages[e.previewMessages.length-1],r=t.anchorId?s?.(t.anchorId):void 0,i=n?.authorName||`Team member`;return(0,G.jsxs)(`button`,{type:`button`,className:d(`w-full border-b border-border/70 px-3 py-2 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,t.unread&&`bg-primary/5`),onClick:()=>void ze(e),children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`relative shrink-0`,children:[(0,G.jsx)(_n,{name:i}),t.unread&&(0,G.jsx)(`span`,{role:`img`,"aria-label":`New activity`,className:`absolute -right-0.5 -top-0.5 size-2 rounded-full bg-primary ring-2 ring-popover`})]}),(0,G.jsx)(`span`,{className:`min-w-0 truncate text-xs font-semibold`,children:i}),t.status===`resolved`&&(0,G.jsx)(Rn,{role:`img`,"aria-label":`Resolved`,className:`size-3.5 shrink-0 text-emerald-500`}),(0,G.jsx)(`span`,{className:`ml-auto shrink-0 text-[11px] text-muted-foreground`,children:ln(t.lastMessageAt??``)})]}),(0,G.jsxs)(`span`,{className:`mt-1 block space-y-0.5 pl-8`,children:[r?(0,G.jsx)(`span`,{className:`line-clamp-2 border-l-2 border-yellow-500/70 pl-2 text-xs leading-snug text-muted-foreground`,children:r.length>50?`${r.slice(0,50).trimEnd()}…`:r}):(0,G.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:r===null?`Deleted block`:t.anchorLabel||`Comment`}),n&&(0,G.jsx)(`span`,{className:`block truncate text-xs`,children:n.body})]})]},e.key)}),!R&&!_&&w.map(e=>{let t=e.featureType?Rw[e.featureType]:null,n=t?.Icon??Eo,r=e.contexts[0]?.fileName||(e.fileId===i.fileId?i.label:`Project discussion`);return(0,G.jsxs)(`button`,{type:`button`,className:d(`flex min-h-18 w-full items-center gap-3 border-b border-border/70 px-4 py-3 text-left transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,e.unread&&`bg-primary/5`),onClick:()=>void Re(e),children:[(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:d(`relative flex size-10 shrink-0 items-center justify-center rounded-full`,t?.className??`bg-muted text-muted-foreground`),children:[(0,G.jsx)(n,{}),e.unread&&(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`absolute right-0.5 top-0.5 size-2 rounded-full bg-primary ring-2 ring-popover`})]}),(0,G.jsxs)(`span`,{className:`sr-only`,children:[Lw(e.featureType),` file`]}),(0,G.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-sm`,e.unread?`font-semibold text-foreground`:`font-medium`),children:r}),(0,G.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:Iw(e.lastMessageAt)})]}),(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate text-sm`,e.unread?`text-foreground`:`text-muted-foreground`),children:e.latestMessage||``}),e.status===`resolved`&&(0,G.jsxs)(Vh,{variant:`outline`,className:`shrink-0 gap-1 font-normal text-muted-foreground`,children:[(0,G.jsx)(Rn,{"aria-hidden":`true`}),`Resolved`]})]}),e.unread&&(0,G.jsx)(`span`,{className:`sr-only`,children:`New activity`})]})]},e.id)})]}),!c&&(0,G.jsx)(Ft,{delay:250,children:(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,size:`icon-lg`,className:`absolute bottom-4 right-4 z-10 min-h-11 min-w-11 rounded-full shadow-lg`,"aria-label":h===`comments`?`Add a comment`:`Start a discussion`,onClick:Be,children:(0,G.jsx)(jt,{"aria-hidden":`true`})})}),(0,G.jsx)(kt,{side:`left`,children:h===`comments`?`Add a comment`:`Start a discussion`})]})})]}),b===`compose`&&(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4`,children:[h===`comments`&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/30 p-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:`Context`}),(0,G.jsx)(`p`,{className:`mt-1 font-medium`,children:`${ge?.type||`node`} · ${i.label}`})]}),te&&(0,G.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:te})]}),(0,G.jsx)(Sw,{id:`${f}-composer`,value:fe,onChange:pe,onSubmit:He,placeholder:h===`comments`?`Write a comment...`:`Write a question or design decision...`,disabled:I,submitLabel:I?`Sending…`:h===`comments`?`Add comment`:`Start discussion`})]}),b===`thread`&&Qe&&(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[h===`comments`&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-border px-3 py-1.5`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:(()=>{let e=Qe.anchorId&&(_||Qe.fileId===i.fileId)?s?.(Qe.anchorId):void 0;return e===null?(0,G.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[`Deleted block · `,Lw(Qe.featureType??`note`)]}):e?(0,G.jsx)(`p`,{className:`line-clamp-2 border-l-2 border-yellow-500/70 pl-2 text-xs leading-snug text-muted-foreground`,children:e}):(0,G.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[Qe.anchorType===`general`?`General`:Qe.anchorType,Qe.featureType&&` · ${Lw(Qe.featureType)}`]})})()}),!c&&(0,G.jsxs)(Ft,{delay:250,children:[(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`shrink-0`,"aria-label":Qe.status===`open`?`Resolve`:`Reopen`,onClick:()=>void Ze(),disabled:I,children:Qe.status===`open`?(0,G.jsx)(Yt,{"aria-hidden":`true`,className:`size-4`}):(0,G.jsx)(zn,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(kt,{side:`left`,children:Qe.status===`open`?`Resolve`:`Reopen`})]}),Qe.canDelete&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`shrink-0 text-destructive hover:text-destructive`,"aria-label":`Delete thread`,onClick:()=>ue({type:`thread`,threadId:Qe.id}),disabled:I,children:(0,G.jsx)($r,{"aria-hidden":`true`,className:`size-4`})})}),(0,G.jsx)(kt,{side:`left`,children:`Delete thread`})]})]})]}),te&&(0,G.jsxs)(`div`,{className:`m-4 rounded-lg border border-destructive/40 p-4 text-sm`,role:`alert`,children:[(0,G.jsx)(`p`,{children:te}),(0,G.jsx)(U,{variant:`outline`,className:`mt-3 min-h-11`,onClick:()=>void(_&&ve?Ne(ve,!0):Me(Qe.id,!0)),children:`Retry`})]}),!te&&(0,G.jsx)(Ft,{delay:250,children:(0,G.jsx)(wn,{defaultScrollPosition:`end`,children:(0,G.jsxs)(vn,{className:`flex-1`,children:[(0,G.jsx)(In,{"aria-label":`${h===`comments`?`Comment`:`Discussion`} messages`,children:(0,G.jsxs)(pn,{className:`gap-1 p-3`,children:[O.hasMore&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void Fe(),disabled:A,children:A?`Loading…`:`Load earlier messages`}),M&&(0,G.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:M})]}),H.map(e=>(0,G.jsx)(tn,{messageId:e.id,scrollAnchor:!0,children:(0,G.jsx)(Tw,{message:e,canEdit:e.authorId===n&&!c,canDelete:!_,editing:re===e.id,editDraft:ae,editOriginalBody:se,disabled:I,onEdit:()=>Ke(e),onDelete:()=>ue({type:`message`,threadId:Qe.id,message:e}),onEditDraftChange:oe,onCancelEdit:qe,onSaveEdit:t=>{Je(e,t)}})},e.id))]})}),(0,G.jsx)(yn,{})]})},Qe.id)}),Qe.status===`open`&&!te&&!c&&(0,G.jsx)(yw,{userName:r||`You`,value:fe,onChange:pe,onSubmit:()=>void Ue(),disabled:I,submitLabel:I?`Sending…`:`Send reply`}),Qe.status===`resolved`&&!c&&(0,G.jsx)(`p`,{className:`border-t border-border px-4 py-3 text-sm text-muted-foreground`,children:`Reopen this thread to reply.`}),c&&(0,G.jsx)(`p`,{className:`border-t border-border px-4 py-3 text-sm text-muted-foreground`,children:`You can read this thread but not reply to it.`})]})]}),(0,G.jsx)(br,{isOpen:de,title:`Discard unsent changes?`,message:`You have text that hasn't been sent or saved. If you close this panel now, it will be lost.`,confirmText:`Discard`,cancelText:`Cancel`,variant:`warning`,onCancel:()=>{B(!1),window.setTimeout(()=>document.querySelector(`[data-discussions-panel] textarea`)?.focus(),150)},onConfirm:()=>{B(!1),pe(``),qe(),m(!1)}}),(0,G.jsx)(br,{isOpen:le!==null,title:le?.type===`message`?`Delete message?`:_?`Delete thread?`:`Delete discussion?`,message:le?.type===`message`?`This message will be permanently deleted.`:`This permanently deletes the ${_?`thread and all of its comments`:`discussion and all its messages`}. This action cannot be undone.`,confirmText:le?.type===`message`?`Delete message`:`Delete Thread`,cancelText:`Cancel`,variant:`danger`,onCancel:()=>ue(null),onConfirm:()=>{le?.type===`message`?Xe(le.threadId,le.message):le&&Ye(le.threadId)}})]})}function Hw({file:e,active:t,target:n,teamId:r}){let i=pa(),a=v(),o=i.activeDocument,s=o?.project_id??o?.projectId,c=i.projects.find(e=>String(e.id)===String(s)),l=c?.team_id??c?.teamId;if(!n||!o||i.isGuest||!l||String(l)!==String(r))return null;let u=e.type===`erd`?`diagram`:e.type===`notes`?`note`:e.type===`drawings`?`drawing`:`flowchart`,d=t=>{t.featureType===u&&String(t.fileId)===e.uid?u===`diagram`&&t.anchorId&&window.dispatchEvent(new CustomEvent(`erd-discussion-anchor-selected`,{detail:{fileId:e.uid,type:t.anchorType,id:t.anchorId}})):a(`/${{diagram:`diagrams`,note:`notes`,drawing:`drawings`,flowchart:`flowcharts`}[t.featureType]}/${encodeURIComponent(t.fileId)}`)},f=i.selectedEdgeId?{type:`relationship`,id:i.selectedEdgeId}:i.selectedNodeId?{type:`table`,id:i.selectedNodeId}:null;return(0,pw.createPortal)((0,G.jsx)(`span`,{hidden:!t,children:(0,G.jsx)(Vw,{projectId:String(s),teamId:String(r),fileContext:{featureType:u,fileId:e.uid,label:o.title||o.name||e.title},userId:i.user?.id?String(i.user.id):void 0,userName:i.user?.name||i.user?.email,readOnly:i.getFileAccessRole(o)===`viewer`,anchorContext:f,onContextSelected:d,anchorPreview:u===`note`?e=>Ki(o.content,e):void 0})}),n)}function Uw(){let{activeDocument:e,isReadOnlyFile:t,getFileAccessRole:n,handleDuplicate:r,isGuest:i,isPublicView:a,view:o,user:s}=pa();if(a||!e||!t(e))return null;let c=Hi(n(e),e.user?.name||e.user?.email||`another member`,Ui(e,s?.id));if(!c)return null;let l=c.indexOf(` · `),u=c.slice(0,l),d=c.slice(l+3);return(0,G.jsxs)(`div`,{role:`status`,className:`flex shrink-0 items-center gap-2 border-b bg-muted/40 px-3 py-1 text-xs text-muted-foreground`,children:[(0,G.jsx)(Ka,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,G.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:u}),` · `,d]}),!i&&(o===`notes`||o===`drawings`)&&(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`xs`,onClick:r,children:`Duplicate to edit`})]})}var Ww=(0,W.lazy)(()=>_i(()=>import(`./NoteEditorRoute-OhCVPcxP.js`).then(e=>({default:e.NoteEditorRoute})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,4,1,22]))),Gw=(0,W.lazy)(()=>_i(()=>import(`./DiagramEditorRoute-D5Hde5-D.js`).then(e=>({default:e.DiagramEditorRoute})),__vite__mapDeps([23,5,7,9,12,8,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54]))),Kw=(0,W.lazy)(()=>_i(()=>import(`./FlowchartEditorRoute-DFGhMS9_.js`).then(e=>({default:e.FlowchartEditorRoute})),__vite__mapDeps([55,5,7,8,9,12,13,14,15,10,16,25,28,27,26,29,30,31,32,33,34,35,36,37,38,39,40,20,56,47,50,42,11,17,18,19,21,4,1,22,52,54]))),qw=(0,W.lazy)(()=>_i(()=>import(`./DrawingEditorRoute-D-2RJREu.js`).then(e=>({default:e.DrawingEditorRoute})),__vite__mapDeps([57,5,7,9,30,8,25,58,48,10,16,11,12,13,14,15,17,18,19,20,21,4,1,22])));function Jw({file:e,scope:t,root:n,discussionTarget:r,onUpdate:i,teamState:a}){let o=pa(),s=(0,W.useMemo)(()=>({...o,theme:n.theme,resolvedTheme:n.resolvedTheme,setTheme:n.setTheme,setIsSettingsOpen:n.setIsSettingsOpen,setSettingsTab:n.setSettingsTab}),[o,n.theme,n.resolvedTheme,n.setTheme,n.setIsSettingsOpen,n.setSettingsTab]),c=bn(),l=ta(),u=(0,W.useRef)(s),d=(0,W.useRef)(null);u.current=s;let f=(0,W.useMemo)(()=>()=>YC(u.current,t.host.current??document),[t]);return(0,W.useEffect)(()=>{i(N(e),{file:e,scope:t,workspace:s,ai:c,canvas:l,flush:f})},[e,t,s,c,l,f,i]),(0,W.useEffect)(()=>{e.previewSchema&&d.current!==e&&!s.isERDItemLoading&&s.activeDiagram&&!s.isReadOnlyFile(s.activeDiagram)&&c.applyContent(e.previewSchema,`append`,`erd-generate-sql`)&&(d.current=e)},[e.previewSchema,s.isERDItemLoading,!!s.activeDiagram,c.applyContent]),(0,G.jsxs)(ma.Provider,{value:s,children:[(0,G.jsx)(Hw,{file:e,active:t.active.current,target:r,teamId:a?.activeTeamId}),(0,G.jsx)(Uw,{}),(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{role:`status`,className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Loading editor…`}),children:(0,G.jsx)(p,{context:a})})]})}var Yw=(0,W.memo)(function({file:e,active:t,scope:n,root:r,mainAI:i,teamState:a,discussionTarget:o,onUpdate:s,onNavigate:c}){n.active.current=t;let l=(0,W.useContext)(_),u=(0,W.useRef)(c);u.current=c;let d=(0,W.useMemo)(()=>({...l,navigator:{...l.navigator,push:e=>u.current(typeof e==`string`?e:`${e.pathname??``}${e.search??``}`),replace:t=>{let n=typeof t==`string`?t:`${t.pathname??``}${t.search??``}`;n.split(`?`)[0]!==z(e).split(`?`)[0]&&u.current(n)}}}),[l,e.type,e.uid]);return(0,G.jsx)(pe.Provider,{value:n,children:(0,G.jsx)(_.Provider,{value:d,children:(0,G.jsx)(S,{location:z(e),children:(0,G.jsxs)(b,{element:(e=>(0,G.jsx)(se,{children:(0,G.jsx)(aa,{isPublicView:!1,publicData:null,isPublicLoading:!1,forbiddenDoc:null,fetchPublicDocument:void 0,setIsPublicView:r.setIsPublicView,handleLogout:async()=>{await r.handleLogout()},children:(0,G.jsx)(Nn,{panelMode:i.rightPanelMode,onPanelModeChange:i.setRightPanelMode,children:e})})}))((0,G.jsx)(Jw,{file:e,scope:n,root:r,discussionTarget:o,onUpdate:s,teamState:a})),children:[(0,G.jsx)(b,{path:`notes/:id`,element:(0,G.jsx)(QC,{capability:`notes`,children:(0,G.jsx)(Ww,{})})}),(0,G.jsx)(b,{path:`diagrams/:id`,element:(0,G.jsx)(QC,{capability:`erd_builder`,children:(0,G.jsx)(Gw,{})})}),(0,G.jsx)(b,{path:`flowcharts/:id`,element:(0,G.jsx)(QC,{capability:`flowcharts`,children:(0,G.jsx)(Kw,{})})}),(0,G.jsx)(b,{path:`drawings/:id`,element:(0,G.jsx)(QC,{capability:`drawings`,children:(0,G.jsx)(qw,{})})})]})})})})});function Xw({className:e,...t}){return(0,G.jsx)(`div`,{role:`group`,"data-slot":`button-group`,className:d(`inline-flex items-center rounded-lg shadow-xs [&>button:not(:first-child)]:rounded-l-none [&>button:not(:first-child)]:border-l-0 [&>button:not(:last-child)]:rounded-r-none`,e),...t})}function Zw({file:e,title:t,feature:n,icon:r,active:i,onSelect:a}){let o=wt(),s=e&&o?.files.some(t=>N(t)===N(e)),c=o?.files.length?!!s:i;return(0,G.jsxs)(Xw,{"aria-label":t,children:[(0,G.jsxs)(U,{variant:c?`default`:`outline`,size:`sm`,"aria-current":c?`page`:void 0,"data-state":c?`active`:`inactive`,onClick:a,className:`max-w-44 border-input`,title:`${n}: ${t}`,children:[(0,G.jsx)(r,{"data-icon":`inline-start`}),(0,G.jsx)(`span`,{className:`truncate`,children:t})]}),o?.desktop&&o.canSplit&&e&&(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:c?`default`:`outline`,size:`icon-sm`,className:`rounded-r-lg! border border-input data-open:rounded-r-lg!`,"aria-label":`File options: ${t}`,children:(0,G.jsx)(Xt,{})})}),(0,G.jsx)(Gt,{align:`start`,className:`w-60`,children:(0,G.jsx)(Vt,{children:(0,G.jsx)(It,{className:`whitespace-nowrap`,disabled:o.files.length<2&&c,onClick:()=>s&&o.files.length===2?o.close(e):o.open(e),children:s&&o.files.length===2?`Close pane`:`Open side by side`})})})]})]})}var Qw=[{id:`notes`,label:`Notes`,icon:de,route:`/notes`},{id:`erd`,label:`ERD Builder`,icon:Cr,route:`/diagrams`},{id:`db-client`,label:`DB Client`,icon:xr,route:`/db-client`},{id:`flowchart`,label:`Flowchart`,icon:Nt,route:`/flowcharts`},{id:`drawings`,label:`Drawings`,icon:wr,route:`/drawings`}],$w=e=>e.title||e.name||`Untitled`,eT=e=>e.uid||e.id,tT=e=>new Date(e.created_at||e.createdAt||0).getTime(),nT=3e4,rT=new Map,iT=new Map,aT=(e,t)=>{let n=e?.uid??e?.id;return n==null?null:{type:t,uid:String(n),title:$w(e),createdAt:e.created_at??e.createdAt}};function oT(e,t){let n=t=>!t.is_deleted&&!t.isDeleted&&String(t.project_id??t.projectId)===String(e),r=(e,t)=>e.filter(n).map(e=>aT(e,t)).filter(e=>e!==null);return[...r(t.notes,`notes`),...r(t.diagrams.filter(e=>(e.source_type??e.sourceType)!==`production_db`),`erd`),...r(t.flowcharts,`flowchart`),...r(t.drawings,`drawings`)]}function sT(...e){return[...new Map(e.flatMap(e=>e.map(e=>[`${e.type}-${e.uid}`,e]))).values()].sort((e,t)=>tT(e)-tT(t))}async function cT(e,t){let n=String(e),r=`${t}:${n}`,i=rT.get(r);if(i&&i.expiresAt>Date.now())return i;let a=iT.get(r);if(a)return a;let o=Si(`/api/projects/${encodeURIComponent(n)}/files`).then(async e=>{if(!e.ok)throw Error(`Failed to load project files`);let t=await e.json(),n={files:Array.isArray(t.data)?t.data:[]};return rT.set(r,{...n,expiresAt:Date.now()+nT}),n}).finally(()=>iT.delete(r));return iT.set(r,o),o}function lT({currentView:e,currentFile:t,host:n=!1}){let r=(0,W.useContext)(jC),i=wt(),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(`notes`),[l,u]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)({projectKey:``,files:[]}),_=(0,W.useRef)(null),y=v(),[b]=g(),{user:x,isGuest:S,activeProjectId:C,notes:w,diagrams:T,drawings:E,flowcharts:D,activeDiagram:O,activeNote:k,activeDrawing:A,activeFlowchart:j,activeDiagramId:M,activeNoteUid:N,activeDrawingId:P,activeFlowchartId:F,handleDiagramSelect:I,handleSidebarDiagramCreate:L,handleSidebarNoteCreate:R,handleSidebarDrawingCreate:ee,handleSidebarFlowchartCreate:te}=pa();(0,W.useEffect)(()=>{a&&setTimeout(()=>_.current?.focus(),0)},[a,s]);let ne=(0,W.useMemo)(()=>{let n=t??(e===`notes`?k:e===`erd`?O:e===`flowchart`?j:A);return n?.project_id??n?.projectId??(C&&C!==`all`?C:b.get(`pid`))},[C,k,O,j,A,t,e,b]),re=ne==null?``:String(ne),ie=m.projectKey===re?m.files:[],z=(0,W.useMemo)(()=>ne?oT(ne,{notes:w,diagrams:T,drawings:E,flowcharts:D}):[],[ne,w,T,E,D]);(0,W.useEffect)(()=>{if(!ne){h({projectKey:``,files:[]});return}if(!S&&x?.id==null)return;let e=!1,t=String(ne);return(async()=>{try{let n;if(S){let[e,t,r,i]=await Promise.all([ca.getAllResources(`notes`),ca.getAllResources(`erd`),ca.getAllResources(`flowchart`),ca.getAllResources(`drawings`)]);n=oT(ne,{notes:e,diagrams:t,flowcharts:r,drawings:i})}else n=(await cT(ne,x.id)).files;e||h({projectKey:t,files:n})}catch{e||h({projectKey:t,files:[]})}})(),()=>{e=!0}},[ne,S,x?.id]);let ae=(0,W.useMemo)(()=>{if(!ne)return[];let n=t??(e===`notes`?k:e===`erd`?O:e===`flowchart`?j:A),r=n?aT(n,e):null;return sT(ie,z,r?[r]:[]).map(e=>({file:e,type:e.type}))},[ne,ie,z,e,t,k,O,j,A]),oe=t?eT(t):e===`notes`?N:e===`erd`?O?.uid||M:e===`flowchart`?j?.uid||F:A?.uid||P,se=(e,t)=>{if(i&&e!==`db-client`){i.select({type:e,uid:String(eT(t)),title:$w(t),projectId:String(ne)});return}if(e===`erd`){I(String(eT(t)));return}let n=Qw.find(t=>t.id===e);if(!n)return;let r=new URLSearchParams({pid:String(ne)});y(`${n.route}/${eT(t)}?${r}`)},ce=async()=>{let e=l.trim();if(e&&!f&&ne){p(!0);try{let t=String(ne);s===`notes`?await R(e,t):s===`erd`?await L(e,t):s===`flowchart`?await te(e,t):await ee(e,t),o(!1),u(``)}finally{p(!1)}}},le=(0,W.useRef)(null),[ue,de]=(0,W.useState)({before:!1,after:!1}),B=(0,W.useCallback)(()=>{let e=le.current;if(!e)return;let t=e.scrollLeft>1,n=e.scrollLeft+e.clientWidth<e.scrollWidth-1;de(e=>e.before===t&&e.after===n?e:{before:t,after:n})},[]);(0,W.useEffect)(()=>{let e=le.current;if(!e)return;let t=()=>{let t=e.querySelector(`[aria-current="page"]`);if(t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();n.left<r.left?e.scrollLeft-=r.left-n.left+8:n.right>r.right&&(e.scrollLeft+=Math.min(n.right-r.right+8,n.left-r.left))}B()};if(t(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t);let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[oe,ae.length,B,r]);let fe=e=>{let t=le.current;t&&t.scrollBy({left:e*Math.max(t.clientWidth*.6,160),behavior:`smooth`})};return!ne||i&&!n||!r?null:(0,pw.createPortal)((0,G.jsxs)(`nav`,{"aria-label":`Project files`,className:`flex w-full min-w-0 items-center gap-1 py-1`,children:[(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[ue.before&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(-1),className:`absolute inset-y-0 left-0 z-10 flex items-center bg-gradient-to-r from-background from-60% to-transparent pl-0.5 pr-3 text-muted-foreground hover:text-foreground`,"aria-label":`Scroll files left`,children:(0,G.jsx)(lr,{className:`size-4`})}),ue.after&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(1),className:`absolute inset-y-0 right-0 z-10 flex items-center bg-gradient-to-l from-background from-60% to-transparent pl-3 pr-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Scroll files right`,children:(0,G.jsx)(St,{className:`size-4`})}),(0,G.jsx)(`div`,{ref:le,onScroll:B,onWheel:e=>{Math.abs(e.deltaY)>Math.abs(e.deltaX)&&(e.currentTarget.scrollLeft+=e.deltaY)},className:`overflow-x-auto scrollbar-hide`,children:(0,G.jsx)(`div`,{className:`flex w-max items-center justify-start gap-1 py-1`,children:ae.map(({file:t,type:n})=>{let r=Qw.find(e=>e.id===n),i=r.icon,a=eT(t),o=n===`db-client`?null:{type:n,uid:String(a),title:$w(t),projectId:String(ne)};return(0,G.jsx)(Zw,{file:o,title:$w(t),feature:r.label,icon:i,active:e===n&&String(oe)===String(a),onSelect:()=>se(n,t)},`${n}-${a}`)})})})]}),(0,G.jsxs)(Pt,{open:a,onOpenChange:e=>{o(e),e||u(``)},children:[(0,G.jsx)(Ft,{children:(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(`span`,{className:`inline-flex shrink-0`}),children:(0,G.jsx)(Mt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,"aria-label":`Create file`,children:(0,G.jsx)(jt,{})})})}),(0,G.jsx)(kt,{side:`bottom`,children:`Create file`})]})}),(0,G.jsxs)(At,{align:`end`,className:`w-72 max-w-[calc(100vw-1rem)] overflow-hidden p-0`,children:[(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto p-1`,children:Qw.filter(e=>e.id!==`db-client`).map(e=>{let t=e.icon;return(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:d(`flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm hover:bg-accent`,s===e.id&&`bg-accent text-accent-foreground`),children:[(0,G.jsx)(t,{className:`size-4`}),(0,G.jsx)(`span`,{className:`flex-1`,children:e.label}),s===e.id&&(0,G.jsx)(Yt,{className:`size-4`})]},e.id)})}),(0,G.jsxs)(`div`,{className:`sticky bottom-0 flex gap-2 border-t bg-popover p-2`,children:[(0,G.jsx)(wi,{ref:_,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&(o(!1),u(``))},placeholder:`New file name`,className:`h-8 text-xs`,disabled:f}),(0,G.jsx)(`button`,{onClick:ce,disabled:!l.trim()||f,className:`h-8 shrink-0 rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-40`,children:`Create`})]})]})]})]}),r)}function uT({children:e,root:t,mainAI:n,teamState:r,discussionTarget:i,onFocusedSession:a,onPairChange:o,paneAIRef:s}){let c=m(),u=v(),[d,f]=(0,W.useState)(()=>window.matchMedia(`(min-width: 1024px)`).matches),[p,h]=(0,W.useState)([]),g=d&&p.length===2;(0,W.useLayoutEffect)(()=>(o(g),()=>o(!1)),[g,o]);let[_,y]=(0,W.useState)(``),b=(0,W.useRef)(_);b.current=_;let[x,S]=(0,W.useState)(null),[C,w]=(0,W.useState)({}),E=e=>C[N(e)]||e.title,[D,O]=(0,W.useState)(``),[M,P]=(0,W.useState)(!1),F=(0,W.useRef)(!1),L=(0,W.useRef)(c.pathname+c.search),R=(0,W.useRef)(null),re=(0,W.useRef)(new Map),ie=(0,W.useRef)(new Map),ae=(0,W.useRef)(null),[oe,se]=(0,W.useState)(50),ce=(0,W.useRef)(!1),ue=r,de=(0,W.useMemo)(()=>({activeTeamId:ue.activeTeamId,activeTeam:ue.activeTeam,isLoading:ue.isLoading}),[ue.activeTeamId,ue.activeTeam,ue.isLoading]),B=c.pathname.match(/^\/(notes|diagrams|flowcharts|drawings)\/([^/]+)$/),fe={notes:`notes`,diagrams:`erd`,flowcharts:`flowchart`,drawings:`drawings`},pe=B?fe[B[1]]:null,me=pe===`notes`?t.activeNote:pe===`erd`?t.activeDiagram:pe===`flowchart`?t.activeFlowchart:t.activeDrawing,he=me?.project_id??me?.projectId,ge=pe&&me&&he!=null?{type:pe,uid:String(me.uid??me.id),title:me.title||me.name||`Untitled`,projectId:String(he)}:null,_e=ge??p[0]??null,ve=`${t.user?.id}:${t.teamScopeVersion}`;(0,W.useLayoutEffect)(()=>{if(s)return s.current=e=>p.some(t=>N(t)===e)?re.current.get(e)?.ai:void 0,()=>{s.current=null}},[s,p]);let V=(0,W.useCallback)((e,t)=>{re.current.set(e,t);let n=te(t.file,t.workspace.activeDocument);n&&w(t=>t[e]===n?t:{...t,[e]:n}),e===b.current&&a(t)},[a]);(0,W.useEffect)(()=>{a(re.current.get(_)??null)},[_,a]),(0,W.useEffect)(()=>()=>a(null),[a]),(0,W.useEffect)(()=>{h([]),S(null),y(``),w({}),re.current.clear(),ie.current.clear(),a(null)},[ve,a]),(0,W.useEffect)(()=>{t.isPublicView&&(h([]),S(null),y(``),a(null))},[t.isPublicView,a]),(0,W.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1024px)`),t=()=>f(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let H=(0,W.useCallback)(async e=>{let t=re.current.get(N(e));if(!t)throw Error(`Wait for the editor to finish loading.`);await t.flush()},[]);(0,W.useEffect)(()=>{let e=e=>{p.length&&e.detail.push(Promise.all(p.map(H)).then(()=>{}))};return window.addEventListener(k,e),()=>window.removeEventListener(k,e)},[p,H]);let ye=async e=>{if(!F.current){F.current=!0,P(!0);try{await e()}catch(e){l.error(e instanceof Error?e.message:`Could not switch files.`)}finally{F.current=!1,P(!1)}}},be=e=>{b.current=N(e),y(N(e)),a(re.current.get(N(e))??null)},xe=e=>{let n=p[0]??_e;(d||e.previewSchema)&&n&&T(p,n,e)!==`reject`&&(p.some(t=>N(t)===N(e))?(e.previewSchema&&h(t=>t.map(t=>N(t)===N(e)?e:t)),be(e)):(p.length||N(n)!==N(e))&&(p.length===2?(S(e),O(``)):ye(async()=>{p.length||await YC(t),h([...p.length?p:[n],e]),be(e)})))},Se=e=>{p.some(t=>N(t)===N(e))?be(e):p.length===2&&d?xe(e):ye(async()=>{p.length?await Promise.all(p.map(H)):await YC(t),h([]),y(``),a(null),u(z(e))})},Ce=e=>void ye(async()=>{await H(e);let t=p.filter(t=>N(t)!==N(e));re.current.delete(N(e)),ie.current.delete(N(e)),h(t),t[0]&&(be(t[0]),c.pathname!==z(t[0]).split(`?`)[0]&&u(z(t[0]),{replace:!0}))}),we=e=>{let n=e.match(/^\/(notes|diagrams|flowcharts|drawings)\/([^/?]+)/);if(n&&_e){let e=fe[n[1]],r=decodeURIComponent(n[2]),i=[...re.current.values()],a=j(e,r,[t,...i.map(e=>e.workspace)],i.map(e=>({file:e.file,document:e.workspace.activeDocument})));Se({type:e,uid:String(a?.uid??a?.id??r),title:ne(a)||`Untitled`,projectId:String(a?.project_id??a?.projectId??_e.projectId)})}else ye(async()=>{await Promise.all(p.map(H)),h([]),y(``),a(null),u(e)})},Te=(0,W.useRef)(xe),Ee=(0,W.useRef)(we);Ee.current=we;let De=(0,W.useCallback)(e=>Ee.current(e),[]);Te.current=xe,(0,W.useEffect)(()=>{let e=c.pathname+c.search;if(!p.length){L.current=e;return}if(M||L.current===e||B&&(!ge||ge.uid!==decodeURIComponent(B[2])&&String(me?.id)!==decodeURIComponent(B[2])))return;let t=L.current;L.current=e;let n=ge&&p.find(e=>N(e)===N(ge));B&&n?be(n):B&&ge&&p.length===2&&ge.projectId===p[0].projectId?(R.current=t,S(ge),O(``)):ye(async()=>{try{await Promise.all(p.map(H)),h([]),y(``),a(null)}catch(e){throw L.current=t,u(t,{replace:!0}),e}})},[c.pathname,c.search,ge?.uid,ge?.projectId,p,M,H,u,a]);let Oe=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=p.find(e=>N(e)===_),t=e?z(e):null,n=ee(t,Oe.current,window.location.pathname+window.location.search,c.pathname+c.search);n&&window.history.replaceState(window.history.state,``,n),Oe.current=t},[p,_]);let ke=()=>{M||(S(null),R.current&&=(L.current=R.current,u(R.current,{replace:!0}),null))};if((0,W.useEffect)(()=>{let e=e=>{let t=e.detail?.file;le(t)&&Te.current(t)};return window.addEventListener(I,e),()=>window.removeEventListener(I,e)},[]),(0,W.useEffect)(()=>{let e=e=>{if(!ce.current||!ae.current)return;let t=ae.current.getBoundingClientRect();se(Math.max(30,Math.min(70,(e.clientX-t.left)/t.width*100)))},t=()=>{ce.current=!1};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[]),!_e||!B&&!p.length||t.isPublicView)return(0,G.jsx)(G.Fragment,{children:e});let Ae=p.find(e=>N(e)===_)??_e,je=re.current.get(N(Ae))?.workspace.activeDocument??(ge&&N(Ae)===N(ge)?me:void 0),Me=M?{inert:``}:{};return(0,G.jsxs)(Ot.Provider,{value:{files:p,focused:_,desktop:d,canSplit:!!(p[0]??_e),open:xe,select:Se,close:Ce},children:[(0,G.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,G.jsx)(lT,{host:!0,currentView:Ae.type,currentFile:je}),p.length?(0,G.jsx)(`div`,{ref:ae,className:`flex min-h-0 flex-1 overflow-hidden`,"aria-label":`Open files`,children:p.map((e,r)=>{let a=N(e),o=ie.current.get(a);return o||(o={active:{current:_===a},host:{current:null}},ie.current.set(a,o)),(0,G.jsxs)(`div`,{className:g||_===a?`contents`:`hidden`,children:[g&&r===1&&(0,G.jsx)(`div`,{role:`separator`,"aria-label":`Resize editors`,"aria-orientation":`vertical`,"aria-valuemin":30,"aria-valuemax":70,"aria-valuenow":Math.round(oe),tabIndex:0,className:`w-2 shrink-0 cursor-col-resize touch-none border-x bg-muted/30 focus-visible:bg-accent`,onPointerDown:e=>{ce.current=!0,e.currentTarget.setPointerCapture(e.pointerId)},onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.preventDefault(),se(t=>Math.max(30,Math.min(70,t+(e.key===`ArrowLeft`?-2:2)))))}}),(0,G.jsxs)(`section`,{"data-file-session":a,"data-active":_===a,"aria-label":E(e),...Me,onPointerDownCapture:t=>{A(t.target)&&be(e)},onFocusCapture:t=>{_!==a&&A(t.target)&&be(e)},className:`relative flex min-h-0 min-w-0 flex-col overflow-hidden${g?` rounded-lg border-2 ${_===a?`border-foreground`:`border-transparent`}`:``}`,style:g?{width:r===0?`${oe}%`:void 0,flex:r===1?1:void 0}:{flex:1},children:[g&&(0,G.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center justify-between gap-2 border-b px-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`truncate`,children:E(e)}),(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close pane: ${E(e)}`,"data-pane-close":!0,disabled:M,onClick:()=>Ce(e),children:(0,G.jsx)(Pr,{})})]}),(0,G.jsx)(`div`,{ref:o.host,className:`relative isolate flex min-h-0 flex-1 flex-col overflow-hidden [transform:translateZ(0)]`,children:(0,G.jsx)(Yw,{file:e,active:_===a,scope:o,root:t,mainAI:n,teamState:de,discussionTarget:i,onUpdate:V,onNavigate:De})})]})]},a)})}):(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,...Me,children:[(0,G.jsx)(Uw,{}),e]})]}),(0,G.jsx)(pi,{open:!!x,onOpenChange:e=>{e||ke()},children:(0,G.jsxs)(ni,{children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(mi,{children:`Replace an open file`}),(0,G.jsxs)(li,{children:[`Choose the file to close before opening `,x&&E(x),`.`]})]}),(0,G.jsx)(di,{className:`p-4`,children:(0,G.jsx)(qC,{"aria-label":`File to replace`,value:D,onValueChange:e=>O(String(e)),className:`flex flex-col gap-2`,children:p.map(e=>(0,G.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 rounded-lg border p-3`,children:[(0,G.jsx)(zC,{value:N(e),className:`flex size-4 shrink-0 items-center justify-center rounded-full border border-input data-checked:border-primary focus-visible:ring-2 focus-visible:ring-ring`,children:(0,G.jsx)(BC,{className:`size-2 rounded-full bg-primary`})}),(0,G.jsxs)(`span`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`block truncate`,children:E(e)}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:{notes:`Notes`,erd:`ERD Builder`,flowchart:`Flowchart`,drawings:`Drawings`}[e.type]})]})]},N(e)))})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(U,{variant:`outline`,disabled:M,onClick:ke,children:`Cancel`}),(0,G.jsx)(U,{disabled:!D||M,onClick:()=>void ye(async()=>{let e=p.find(e=>N(e)===D);x&&e&&(await H(e),re.current.delete(D),ie.current.delete(D),h(p.map(e=>N(e)===D?x:e)),be(x),S(null),R.current=null,ge&&N(ge)===N(e)&&u(z(x),{replace:!0}))}),children:`Replace file`})]})]})})]})}var dT=W.createContext(void 0);function fT(){let e=W.useContext(dT);if(e===void 0)throw Error(De(13));return e}var pT={imageLoadingStatus:()=>null},mT=W.forwardRef(function(e,t){let{className:n,render:r,...i}=e,[a,o]=W.useState(`idle`),s={imageLoadingStatus:a},c=W.useMemo(()=>({imageLoadingStatus:a,setImageLoadingStatus:o}),[a,o]),l=je(`span`,e,{state:s,ref:t,props:i,stateAttributesMapping:pT});return(0,G.jsx)(dT.Provider,{value:c,children:l})});function hT(e,{referrerPolicy:t,crossOrigin:n}){let[r,i]=W.useState(`idle`);return Ae(()=>{if(!e)return i(`error`),Ee;let r=!0,a=new window.Image,o=e=>()=>{r&&i(e)};return i(`loading`),a.onload=o(`loaded`),a.onerror=o(`error`),t&&(a.referrerPolicy=t),a.crossOrigin=n??null,a.src=e,()=>{r=!1}},[e,n,t]),r}var gT={...pT,...Ge},_T=W.forwardRef(function(e,t){let{className:n,render:r,onLoadingStatusChange:i,referrerPolicy:a,crossOrigin:o,...s}=e,c=fT(),l=hT(e.src,{referrerPolicy:a,crossOrigin:o}),u=l===`loaded`,{mounted:d,transitionStatus:f,setMounted:p}=Ie(u),m=W.useRef(null),h=Me(e=>{i?.(e),c.setImageLoadingStatus(e)});Ae(()=>{l!==`idle`&&h(l)},[l,h]);let g={imageLoadingStatus:l,transitionStatus:f};Be({open:u,ref:m,onComplete(){u||p(!1)}});let _=je(`img`,e,{state:g,ref:[t,m],props:s,stateAttributesMapping:gT,enabled:d});return d?_:null}),vT=W.forwardRef(function(e,t){let{className:n,render:r,delay:i,...a}=e,{imageLoadingStatus:o}=fT(),[s,c]=W.useState(i===void 0),l=et();return W.useEffect(()=>(i!==void 0&&l.start(i,()=>c(!0)),l.clear),[l,i]),je(`span`,e,{state:{imageLoadingStatus:o},ref:t,props:a,stateAttributesMapping:pT,enabled:o!==`loaded`&&s})}),yT=W.forwardRef(({className:e,size:t=`default`,...n},r)=>(0,G.jsx)(mT,{ref:r,"data-slot":`avatar`,"data-size":t,className:d(`group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten`,e),...n}));yT.displayName=`Avatar`;var bT=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(_T,{ref:n,"data-slot":`avatar-image`,className:d(`aspect-square size-full rounded-full object-cover`,e),...t}));bT.displayName=`AvatarImage`;var xT=W.forwardRef(({className:e,...t},n)=>(0,G.jsx)(vT,{ref:n,"data-slot":`avatar-fallback`,className:d(`flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs`,e),...t}));xT.displayName=`AvatarFallback`;function ST({open:e,onOpenChange:t}){let[n,r]=(0,W.useState)(!1);return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-105 bg-background border-border/40 shadow-2xl`,children:[(0,G.jsx)(Hr,{className:`sr-only`,children:`Guest Data Backup`}),(0,G.jsx)(Fr,{className:`sr-only`,children:`Export your Guest Mode data as a JSON file for safe keeping or future import.`}),(0,G.jsxs)(`div`,{className:`p-2 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-amber-500/10 rounded-xl`,children:(0,G.jsx)(Qo,{className:`size-5 text-amber-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-semibold text-base`,children:`Guest Mode`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`You are browsing as a guest`})]})]}),(0,G.jsxs)(`div`,{className:`bg-muted/10 border border-border/40 rounded-xl p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Cr,{className:`size-4 text-muted-foreground shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:(0,G.jsxs)(`p`,{children:[`Your data (notes, diagrams, flowcharts, drawings, and AI chats) is stored locally in your browser. Export it as a `,(0,G.jsx)(`code`,{className:`bg-muted px-1 rounded text-[11px]`,children:`.json`}),` `,`file so you can import it after signing in.`]})})]}),(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Ya,{className:`size-4 text-muted-foreground shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:(0,G.jsxs)(`p`,{children:[`The export file can be imported into any ERD Builder Pro account via`,(0,G.jsx)(`strong`,{children:` Settings → Guest Data Import`}),`.`]})})]})]}),(0,G.jsx)(U,{onClick:async()=>{r(!0);try{await pC(),l.success(`Data exported successfully!`)}catch(e){l.error(`Export failed: `+(e.message||`Unknown error`))}finally{r(!1)}},disabled:n,className:`w-full`,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`size-4 mr-2 animate-spin`}),`Exporting…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rn,{className:`size-4 mr-2`}),`Export My Data`]})}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`span`,{className:`w-full border-t border-border/30`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-xs`,children:(0,G.jsx)(`span`,{className:`bg-background px-2 text-muted-foreground`,children:`Need an account?`})})]}),(0,G.jsx)(`div`,{className:`text-center space-y-2`,children:(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sign up or log in from the main page to import your backup.`})})]})]})})}function CT({user:e,onLogout:t,onViewChange:n,isOnline:r,onOpenFeedback:i,compact:a=!1}){let{isMobile:o}=wh(),{isGuest:s,setIsSettingsOpen:c,setSettingsTab:l,hasUpdate:u,latestVersion:f,isCheckingUpdate:p,isDownloadingUpdate:m,isWebOutdated:h,showOutdatedBadge:g,checkForUpdates:_,downloadUpdate:v}=pa(),y=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__);if(!e)return null;let b=e.email||``,x=e.name||e.user_metadata?.full_name||e.user_metadata?.name||b.split(`@`)[0]||`User`,S=e.user_metadata?.avatar_url||``,C=x.substring(0,2).toUpperCase(),w=e=>{l(e),c(!0)},[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(Nh,{size:`lg`,"aria-label":a?`Account menu for ${x}`:void 0,title:a?x:void 0,className:d(`data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground`,a&&`!size-8 !justify-center !p-0`),children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(yT,{className:`h-8 w-8 rounded-lg`,children:[(0,G.jsx)(bT,{src:S,alt:x}),(0,G.jsx)(xT,{className:`rounded-lg`,children:C})]}),g&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 flex size-3 rounded-full bg-amber-500 ring-2 ring-sidebar`,title:u?`Update available: v${f}`:h?`New version available: v${f}. You're on v3.5.5. Pull latest Docker image or update your install.`:``})]}),!a&&(0,G.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:x}),(0,G.jsx)(`span`,{className:`truncate text-xs`,children:b})]}),!a&&(0,G.jsx)(Pa,{className:`ml-auto size-4`})]})}),(0,G.jsxs)(Gt,{className:`w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg`,side:o?`bottom`:`right`,align:`end`,sideOffset:4,children:[(0,G.jsx)(Vt,{children:(0,G.jsx)(Wt,{className:`p-0 font-normal`,children:(0,G.jsx)(Vt,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-1.5 text-left text-sm`,children:[(0,G.jsxs)(yT,{className:`h-8 w-8 rounded-lg`,children:[(0,G.jsx)(bT,{src:S,alt:x}),(0,G.jsx)(xT,{className:`rounded-lg`,children:C})]}),(0,G.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:x}),(0,G.jsx)(`span`,{className:`truncate text-xs`,children:b})]})]})})})}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(Vt,{children:[(0,G.jsxs)(It,{onClick:()=>w(s||e.isSso?`appearance`:`account`),className:`cursor-pointer`,disabled:!s&&!r,children:[(0,G.jsx)(zo,{className:`mr-2 size-4`}),`Settings`]}),s&&(0,G.jsxs)(It,{onClick:()=>E(!0),className:`cursor-pointer`,children:[(0,G.jsx)(rn,{className:`mr-2 size-4`}),`Backup Data`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>O(!0),className:`cursor-pointer`,children:[u?(0,G.jsx)(Fa,{className:`mr-2 size-4 text-emerald-400`}):h?(0,G.jsx)(Ta,{className:`mr-2 size-4 text-amber-500`}):(0,G.jsx)(vr,{className:`mr-2 size-4`}),`About`,g&&(0,G.jsx)(`span`,{className:`ml-auto flex size-2 rounded-full ${u?`bg-emerald-400`:`bg-amber-500`}`})]}),(0,G.jsxs)(It,{render:(0,G.jsx)(`a`,{href:`https://github.com/hadziqmtqn/erd-builder-pro`,target:`_blank`,rel:`noopener noreferrer`}),className:`cursor-pointer`,children:[(0,G.jsx)(oo,{className:`mr-2 size-4`}),`Github`]}),(0,G.jsxs)(It,{onClick:i,className:`cursor-pointer`,children:[(0,G.jsx)(To,{className:`mr-2 size-4`}),`Feedback`]})]}),(0,G.jsx)(Kt,{}),(0,G.jsx)(Vt,{children:(0,G.jsxs)(It,{onClick:()=>r&&n(`trash`),disabled:!r,className:`text-destructive focus:bg-accent focus:text-destructive cursor-pointer ${!r&&`opacity-50 cursor-not-allowed`}`,children:[(0,G.jsx)($r,{className:`mr-2 size-4`}),`Trash`]})}),(0,G.jsx)(Kt,{}),!y&&(0,G.jsxs)(It,{onClick:()=>r&&t(),disabled:!r,className:`cursor-pointer ${!r&&`opacity-50 cursor-not-allowed`}`,title:r?``:`Logging out while offline may cause data loss of unsynced changes`,children:[(0,G.jsx)(wo,{className:`mr-2 size-4`}),`Log out`]})]})]})})}),(0,G.jsx)(ST,{open:T,onOpenChange:E}),(0,G.jsx)(kC,{open:D,onOpenChange:O,hasUpdate:u,latestVersion:f,isChecking:p,isDownloading:m,onCheckUpdate:_,onDownload:v})]})}function wT(e){try{let t=new URL(e);return t.searchParams.set(`utm_source`,`erdbuilderpro.com`),t.searchParams.set(`utm_medium`,`referral`),t.searchParams.set(`utm_campaign`,`sponsor`),t.toString()}catch{return e}}var TT=[{logoOnLightSurfaceSrc:`https://s3.erdbuilderpro.com/sponsors/Sumopod-Light.png`,logoOnDarkSurfaceSrc:`https://s3.erdbuilderpro.com/sponsors/Sumopod-Dark.png`,logoAlt:`SumoPod`,title:`Deploy your App in 15 Seconds!`,description:`Seamless container deployment for businesses of all sizes.`,buttonText:`Get Started →`,buttonAction:`https://sumopod.com`}];function ET(){let e=TT[0];return(0,G.jsx)(`div`,{className:`px-2 pb-2`,children:(0,G.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-dashed border-zinc-700 bg-zinc-950 p-3 text-zinc-50 dark:border-zinc-300 dark:bg-zinc-100 dark:text-zinc-950`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5`,children:[e.icon?(0,G.jsx)(e.icon,{className:`w-5 h-5 text-rose-500 shrink-0`}):e.logoOnDarkSurfaceSrc||e.logoOnLightSurfaceSrc?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`img`,{src:e.logoOnDarkSurfaceSrc??e.logoOnLightSurfaceSrc,alt:e.logoAlt??``,className:`h-8 w-auto max-w-full shrink-0 object-contain dark:hidden`}),e.logoOnLightSurfaceSrc&&(0,G.jsx)(`img`,{src:e.logoOnLightSurfaceSrc,alt:e.logoAlt??``,className:`hidden h-8 w-auto max-w-full shrink-0 object-contain dark:block`})]}):null,(0,G.jsx)(`p`,{className:`max-w-full truncate text-center text-xs font-semibold text-zinc-50 dark:text-zinc-950`,children:e.title}),(0,G.jsx)(`p`,{className:`wrap-break-word text-center text-[11px] leading-relaxed text-zinc-300 dark:text-zinc-600`,children:e.description}),(0,G.jsx)(U,{type:`button`,className:`mt-1 w-full bg-[#1a5fd4] text-white hover:bg-[#174ea6]`,onClick:()=>ia(wT(e.buttonAction)),children:e.buttonText})]})})})}function DT({teams:e,activeTeamId:t,enabled:n,canManageTeams:r,onOpen:i,onSelect:a,onAdd:o,onManage:s}){let{isMobile:c}=wh(),l=(e.find(e=>e.id===t)||null)?.name||(t?`Loading workspace…`:`Personal`),u=(0,G.jsxs)(Nh,{size:`lg`,"aria-label":`Switch workspace. Current workspace: ${l}`,title:`Workspace: ${l}`,className:`cursor-pointer transition-colors hover:bg-accent/50 active:bg-accent/70`,onClick:n?void 0:()=>a(null),children:[(0,G.jsxs)(`span`,{className:`flex size-8 shrink-0 items-center justify-center`,"aria-hidden":`true`,children:[(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Light-1.svg`,alt:``,className:`size-full dark:hidden`}),(0,G.jsx)(`img`,{src:`/img/ERD-Builder-Pro-Dark-1.svg`,alt:``,className:`hidden size-full dark:block`})]}),(0,G.jsxs)(`span`,{className:`grid min-w-0 flex-1 text-left leading-tight`,children:[(0,G.jsx)(`span`,{className:`truncate font-semibold`,children:`ERD Builder Pro`}),(0,G.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:l})]}),n&&(0,G.jsx)(Pa,{className:`ml-auto size-4 shrink-0`})]});return n?(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{onOpenChange:e=>{e&&i()},children:[(0,G.jsx)(zt,{render:u}),(0,G.jsxs)(Gt,{className:`min-w-64 border border-border/70 p-1.5 shadow-xl`,side:c?`bottom`:`right`,align:`start`,sideOffset:6,children:[(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`px-2 py-1.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80`,children:`Workspace`}),(0,G.jsxs)(It,{onClick:()=>a(null),className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand ${t?``:`bg-brand/10 text-foreground [&>svg]:text-brand`}`,children:[(0,G.jsx)(Zo,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{children:`Personal`}),!t&&(0,G.jsx)(Yt,{className:`ml-auto size-4 text-brand`})]})]}),e.length>0&&(0,G.jsx)(Kt,{className:`my-1.5`}),e.length>0&&(0,G.jsxs)(Vt,{children:[(0,G.jsx)(Wt,{className:`px-2 py-1.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80`,children:`Teams`}),e.map(e=>(0,G.jsxs)(It,{onClick:()=>a(e.id),className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand ${t===e.id?`bg-brand/10 text-foreground [&>svg]:text-brand`:``}`,children:[(0,G.jsx)($o,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[t===e.id&&(0,G.jsx)(Yt,{className:`size-4 text-brand`}),e.canManage&&(0,G.jsxs)(Tt,{children:[(0,G.jsx)(Et,{render:(0,G.jsx)(`button`,{type:`button`,"aria-label":`Open Team Management for ${e.name}`,className:`flex size-7 shrink-0 items-center justify-center rounded-md border border-transparent bg-muted/50 text-muted-foreground transition-all hover:border-brand/40 hover:bg-brand hover:text-white hover:shadow-sm focus-visible:border-brand focus-visible:bg-brand focus-visible:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.preventDefault(),t.stopPropagation(),s(e)},children:(0,G.jsx)(Ro,{className:`size-3.5`})})}),(0,G.jsx)(kt,{side:`top`,className:`text-xs`,children:`Manage team`})]})]})]},e.id))]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{className:`my-1.5`}),(0,G.jsx)(Vt,{children:(0,G.jsxs)(It,{onClick:o,className:`cursor-pointer gap-2 px-2.5 py-2 transition-colors hover:bg-brand/10 hover:text-foreground focus:bg-brand/10 focus:text-foreground focus:[&>svg]:text-brand`,children:[(0,G.jsx)(jt,{className:`size-4 text-muted-foreground transition-colors`}),(0,G.jsx)(`span`,{children:`Add Team`})]})})]})]})]})})}):(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:u})})}function OT(){if(typeof navigator>`u`)return`Ctrl+K`;let e=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad/i.test(e)?`⌘K`:`Ctrl+K`}function kT({isLoading:e,isOnline:t,onQueryChange:n,onResultSelect:r,query:i,results:a,showDbClient:o}){let[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(`all`),d=(0,W.useRef)(null),f=OT(),p=[{value:`all`,label:`All`},{value:`workspace`,label:`Projects`},{value:`erd`,label:`ERD Builder`},...o?[{value:`db-client`,label:`DB Client`}]:[],{value:`notes`,label:`Notes`},{value:`flowchart`,label:`Flowcharts`},{value:`drawings`,label:`Drawings`}],m=l===`all`?a:a.filter(e=>e.type===l);return(0,W.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),c(!0),d.current?.focus(),d.current?.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,W.useEffect)(()=>{s&&window.setTimeout(()=>{d.current?.focus(),d.current?.select()},0)},[s]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jh,{children:(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{onClick:()=>c(!0),disabled:!t,"aria-label":`Search files (${f})`,tooltip:`Search (${f})`,className:`border border-sidebar-border bg-background text-muted-foreground shadow-xs`,children:[(0,G.jsx)(Zr,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`flex-1`,children:`Search`}),(0,G.jsx)(Di,{className:`group-data-[collapsible=icon]:hidden`,children:f})]})})}),(0,G.jsx)(Yr,{open:s,onOpenChange:e=>{c(e),e||(u(`all`),n(``))},children:(0,G.jsxs)(Vr,{size:`2xl`,showCloseButton:!1,className:`translate-y-0! max-h-[76vh] sm:max-w-2xl`,style:{top:`12vh`},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-border/60 px-4 py-3`,children:[(0,G.jsx)(Zr,{className:`size-5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(wi,{ref:d,value:i,onChange:e=>n(e.target.value),placeholder:`Search files and projects`,"aria-label":`Spotlight file search`,className:`min-w-0 flex-1`}),(0,G.jsx)(Di,{className:`h-7 rounded-lg px-2.5 text-xs`,children:`Esc`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 overflow-x-auto border-b border-border/60 px-4 py-2.5 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Filter:`}),(0,G.jsx)(`div`,{className:`flex min-w-max items-center gap-1`,children:p.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(e.value),className:`min-h-10 rounded-md px-2.5 py-1 font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${l===e.value?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60 hover:text-foreground`}`,children:e.label},e.value))})]}),(e||i.trim().length>=2)&&(0,G.jsx)(`div`,{className:`max-h-[min(26rem,60vh)] overflow-y-auto p-2`,children:e?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,G.jsx)(xo,{className:`size-4 animate-spin`,"aria-hidden":`true`}),` Searching...`]}):m.length===0?(0,G.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`No results found.`}):m.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{r(e),c(!1)},className:`group flex min-h-11 w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,G.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-muted`,children:e.type===`workspace`?(0,G.jsx)(eo,{className:`size-4 text-muted-foreground`}):e.type===`erd`?(0,G.jsx)(Cr,{className:`size-4 text-muted-foreground`}):e.type===`db-client`?(0,G.jsx)(xr,{className:`size-4 text-muted-foreground`}):e.type===`notes`?(0,G.jsx)(de,{className:`size-4 text-muted-foreground`}):e.type===`flowchart`?(0,G.jsx)(Sr,{className:`size-4 text-muted-foreground`}):(0,G.jsx)(wr,{className:`size-4 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name||`(Untitled)`}),(0,G.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e.type===`workspace`?`Project`:e.type===`erd`?`ERD Builder`:e.type===`db-client`?`DB Client`:e.type===`flowchart`?`Flowchart`:e.type===`notes`?`Note`:`Drawing`,e.workspace?.name&&` · ${e.workspace.name}`]})]}),(0,G.jsx)(Ca,{className:`size-4 shrink-0 text-muted-foreground/40 group-hover:text-primary`,"aria-hidden":`true`})]},`${e.type}-${e.uid??e.id}`))})]})})]})}var AT=({isOpen:e,onOpenChange:t,mode:n=`move-to-trash`,activeDocument:r,view:i,deleteDiagram:a,deleteNote:o,deleteDrawing:s,deleteFlowchart:c,deleteProject:l,fetchTrash:u,itemType:d,onConfirm:f,onAfterDelete:p})=>{let m=async()=>{if(n===`permanent-delete`){f?.(),p?.();return}if(f){f(),p?.();return}let e=i===`erd`||i===`notes`||i===`flowchart`||i===`drawings`?r?.uid??r?.id:r?.id;e&&(i===`erd`?await a?.(e):i===`notes`?await o?.(String(e)):i===`drawings`?await s?.(e):i===`flowchart`?await c?.(e):i===`project`&&await l?.(e),u?.(),t(!1),p?.())},h=d===`erd`?`diagram`:d===`notes`?`note`:d===`drawings`?`drawing`:d===`project`?`workspace`:`item`;if(n===`permanent-delete`)return(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(ei,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Are you absolutely sure?`})]}),(0,G.jsx)(di,{children:(0,G.jsx)(li,{children:d===`project`?(0,G.jsxs)(G.Fragment,{children:[`This action cannot be undone. Deleting this workspace will also permanently delete all`,(0,G.jsx)(`strong`,{children:` notes, diagrams, drawings, and flowcharts`}),` inside it.`]}):(0,G.jsxs)(G.Fragment,{children:[`This action cannot be undone. This will permanently delete the `,(0,G.jsx)(`strong`,{children:h}),` from our servers.`]})})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:m,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Permanently Delete`})]})]})});let g=i!==`project`;return(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)($r,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:g?`Move to Trash?`:`Delete Workspace?`})]}),(0,G.jsx)(di,{children:(0,G.jsx)(li,{children:g?(0,G.jsxs)(G.Fragment,{children:[`Are you sure you want to move `,(0,G.jsx)(`strong`,{children:r?.title||r?.name||`this item`}),` to trash?`,(0,G.jsx)(`br`,{}),`You can restore it later from the trash bin.`]}):(0,G.jsxs)(G.Fragment,{children:[`This will move the workspace and all its contents to trash.`,(0,G.jsx)(`br`,{}),`You can restore it later from the trash bin.`]})})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:m,children:g?`Move to Trash`:`Delete`})]})]})})},jT={data:[],total:0,counts:{notes:0,erd:0,flowchart:0,"db-client":0,drawings:0},locked:[]};async function MT({projectId:e,type:t,page:n,perPage:r,q:i}){let a={...jT.counts},o=[],s=i?.trim().toLowerCase();for(let{value:n}of Wi){if(n===`db-client`)continue;let r=(await ca.getAllResources(n)).filter(t=>!t.is_deleted&&String(t.project_id??`null`)===e&&(!s||String(t.title??t.name??``).toLowerCase().includes(s)));a[n]=r.length,(t===`all`||t===n)&&o.push(...r.map(e=>({...e,type:n})))}return o.sort((e,t)=>new Date(t.created_at??0).getTime()-new Date(e.created_at??0).getTime()),{data:o.slice((n-1)*r,n*r),total:t===`all`?Object.values(a).reduce((e,t)=>e+t,0):a[t],counts:a,locked:[]}}function NT(e,t){let{isGuest:n}=la(),[r,i]=(0,W.useState)(jT),[a,o]=(0,W.useState)(!1),{projectId:s,type:c,page:l,perPage:u,q:d=``}=e;return(0,W.useEffect)(()=>{if(!s){i(jT);return}let e=!1;return o(!0),(async()=>{if(n)return MT({projectId:s,type:c,page:l,perPage:u,q:d});let e=new URLSearchParams({project_id:s,type:c,limit:String(u),offset:String((l-1)*u),include_db_client:String(yi())});d.trim()&&e.set(`q`,d.trim());let t=await Si(`/api/projects/files?${e}`);if(!t.ok)throw Error(`Failed to load project files`);let r=await t.json();return{...jT,...r,counts:{...jT.counts,...r.counts},locked:r.locked??[]}})().then(t=>{e||i(t)}).catch(()=>{e||i(jT)}).finally(()=>{e||o(!1)}),()=>{e=!0}},[s,c,l,u,d,n,t]),{...r,isLoading:a}}var PT={owner:`Creator`,manager:`Manager`,editor:`Editor`,commenter:`Commenter`,viewer:`Viewer`},FT=[`editor`,`commenter`,`viewer`],IT={owner:`Full access as the Project creator.`,editor:`Can change the files.`,commenter:`Can read and comment.`,viewer:`Can read only.`};function LT(e){return{userId:String(e.user_id??e.userId),name:e.name??null,email:e.email??null,teamRole:String(e.team_role??e.teamRole??`staff`),role:e.role,isCreator:(e.is_creator??e.isCreator)===!0,canChange:(e.can_change??e.canChange)===!0}}function RT({project:e,onOpenChange:t}){let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),c=e?.id,u=(0,W.useCallback)(async()=>{if(c!==void 0){a(``);try{let e=await Si(`/api/projects/${encodeURIComponent(String(c))}/access`),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||`Could not load access.`);r((t.members??[]).map(LT))}catch(e){r(null),a(e instanceof Error?e.message:`Could not load access.`)}}},[c]);(0,W.useEffect)(()=>{r(null),c!==void 0&&u()},[c,u]);let d=async(e,t)=>{if(t!==e.role&&c!==void 0){s(e.userId);try{let n=`/api/projects/${encodeURIComponent(String(c))}/access/${encodeURIComponent(e.userId)}`,i=t===(e.isCreator?`owner`:`commenter`)?await Si(n,{method:`DELETE`}):await Si(n,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({role:t})}),a=await i.json().catch(()=>({}));if(!i.ok)throw Error(a.error||`Could not change access.`);r(n=>n?.map(n=>n.userId===e.userId?{...n,role:t}:n)??n),l.success(`${e.name||e.email||`Member`} is now ${PT[t]}.`)}catch(e){l.error(e instanceof Error?e.message:`Could not change access.`),await u()}finally{s(null)}}};return(0,G.jsx)(Yr,{open:e!==null,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-lg`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Project access`}),(0,G.jsxs)(Fr,{children:[`Choose what each Team member can do in `,e?.name,`. Team Managers always have full access; only a Manager can limit the Project creator.`]})]}),(0,G.jsxs)(Wr,{children:[i&&(0,G.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i}),!i&&n===null&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,children:[(0,G.jsx)(xo,{className:`size-4 animate-spin`,"aria-hidden":`true`}),` Loading members…`]}),n&&n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This Team has no other active members.`}),n&&n.length>0&&!n.some(e=>e.canChange)&&(0,G.jsx)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:`Everyone here already has full access as the Project creator or a Team Manager, so there is no role to change. Roles apply to other Staff members of the Team.`}),n&&n.length>0&&(0,G.jsx)(`ul`,{className:`divide-y rounded-lg border`,"aria-label":`Project members`,children:n.map(e=>(0,G.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name||e.email||`Member`}),e.name&&e.email&&(0,G.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e.email})]}),e.canChange?(0,G.jsxs)(_r,{value:e.role,onValueChange:t=>{t&&d(e,t)},disabled:o===e.userId,children:[(0,G.jsx)(mr,{className:`w-36`,"aria-label":`Access for ${e.name||e.email||`member`}`,children:(0,G.jsx)(gr,{children:PT[e.role]})}),(0,G.jsx)(pr,{className:`min-w-72`,children:(0,G.jsx)(hr,{children:(e.isCreator?[`owner`,...FT]:FT).map(t=>(0,G.jsx)(fr,{value:t,children:(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{children:PT[t]}),(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[IT[t],t===(e.isCreator?`owner`:`commenter`)?` Default.`:``]})]})},t))})})]}):(0,G.jsx)(`span`,{className:`w-36 px-3 text-sm text-muted-foreground`,children:PT[e.role]})]},e.userId))})]})]})})}function zT({activeTeamId:e,isProjectsLoading:t,onProjectCreate:n,onProjectDelete:r,onProjectUpdate:i,projects:a,user:o}){let s=m(),c=v(),[l,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(``),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),[y,b]=(0,W.useState)(!1),[x,S]=(0,W.useState)(``),C=a.filter(e=>!e.is_deleted),w=s.pathname.match(/^\/projects\/([^/]+)$/)?.[1],T=w?decodeURIComponent(w):null,{activeDocument:E}=pa(),D=/^\/(notes|diagrams|drawings|flowcharts|db-client)\/[^/]+$/.test(s.pathname)?E?.project_id??E?.projectId??null:null,{total:O}=NT({projectId:`null`,type:`all`,page:1,perPage:10},s.pathname),k=O>0,A=(e,t)=>{let n=e??(t==null?null:String(t));n&&c(`/projects/${encodeURIComponent(n)}`)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Oh,{children:[(0,G.jsx)(kh,{children:`Projects`}),(0,G.jsx)(sne,{title:`New Project`,"aria-label":`New Project`,onClick:()=>{S(``),b(!0)},children:(0,G.jsx)(jt,{})}),(0,G.jsx)(Ah,{children:(0,G.jsxs)(jh,{children:[t?(0,G.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground animate-pulse`,children:`Loading projects...`}):C.length===0?(0,G.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground group-data-[collapsible=icon]:hidden`,children:`No projects yet`}):C.map(t=>(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:t.name,isActive:T===t.uid||T===String(t.id??``)||D!=null&&String(D)===String(t.id),onClick:()=>A(t.uid,t.id),children:[(0,G.jsx)(eo,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:t.name}),(0,G.jsx)(`span`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(`button`,{type:`button`,"aria-label":`Project options for ${t.name}`,className:`flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring`,children:(0,G.jsx)(Tr,{className:`size-4`})})}),(0,G.jsxs)(Gt,{align:`end`,className:`min-w-44`,children:[e&&(t.access_role===`owner`||t.access_role===`manager`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(It,{onClick:()=>_({id:t.id,name:t.name}),children:[(0,G.jsx)(es,{className:`size-3.5`,"aria-hidden":`true`}),`Manage access`]}),(0,G.jsx)(Kt,{})]}),Ui(t,o?.id,o?.id===`guest`)?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(It,{onClick:()=>{f(t.name),u(t)},children:[(0,G.jsx)(ar,{className:`size-3.5`,"aria-hidden":`true`}),`Rename`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>h(t),children:[(0,G.jsx)($r,{className:`size-3.5 text-destructive`,"aria-hidden":`true`}),`Delete`]})]}):(0,G.jsx)(It,{disabled:!0,children:`Only the creator can rename or delete`})]})]})})]})},t.uid??t.id)),k&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Unassigned`,isActive:T===`unassigned`,onClick:()=>A(`unassigned`),children:[(0,G.jsx)(no,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Unassigned`})]})})]})})]}),(0,G.jsx)(RT,{project:g,onOpenChange:e=>{e||_(null)}}),(0,G.jsx)(Yr,{open:l!==null,onOpenChange:e=>{e||u(null)},children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Rename Project`})}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`rename-project-input`,children:`Name`}),(0,G.jsx)(wi,{id:`rename-project-input`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d.trim()&&l&&(i(l.id,d.trim()),u(null))},autoFocus:!0})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),(0,G.jsx)(U,{className:`h-9 px-6`,disabled:!d.trim(),onClick:()=>{l&&d.trim()&&(i(l.id,d.trim()),u(null))},children:`Save Changes`})]})]})}),(0,G.jsx)(Yr,{open:y,onOpenChange:b,children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Create Project`})}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`create-project-input`,children:`Project name`}),(0,G.jsx)(wi,{id:`create-project-input`,value:x,onChange:e=>S(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x.trim()&&(n(x.trim()),b(!1),S(``))},autoFocus:!0})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),(0,G.jsx)(U,{className:`h-9 px-6`,disabled:!x.trim(),onClick:()=>{x.trim()&&(n(x.trim()),b(!1),S(``))},children:`Create`})]})]})}),(0,G.jsx)(AT,{isOpen:p!==null,onOpenChange:e=>{e||h(null)},mode:`move-to-trash`,view:`project`,activeDocument:p?{id:p.id,name:p.name}:void 0,deleteProject:r,onAfterDelete:()=>h(null)})]})}var BT=[`INSTANCE_LICENSE_REQUIRED`,`LICENSE_SYNC_REQUIRED`,`TEAM_LIMIT_REACHED`];function VT({open:e,onOpenChange:t,onCreate:n,onCreated:r,onLicenseIssue:i}){let[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{e||(o(``),c(``),u(!1))},[e]),(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsx)(Vr,{size:`md`,children:(0,G.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),c(``),u(!0);try{let e=await n({name:a});t(!1),r?.(e)}catch(e){if(i&&BT.includes(e?.code)){t(!1),i(e.code);return}c(e?.message||`Team could not be created.`)}finally{u(!1)}},children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Add Team`}),(0,G.jsx)(Fr,{children:`Create a Team using this installation's active license.`})]}),(0,G.jsxs)(Wr,{className:`space-y-4`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`team-name`,children:`Team name`}),(0,G.jsx)(wi,{id:`team-name`,value:a,onChange:e=>o(e.target.value),placeholder:`Acme Engineering`,maxLength:100,required:!0,autoFocus:!0})]}),s&&(0,G.jsx)(`p`,{className:`text-sm text-destructive`,role:`alert`,children:s})]}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(U,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:l,children:`Cancel`}),(0,G.jsx)(U,{type:`submit`,disabled:l||!a.trim(),children:l?`Creating…`:`Add Team`})]})]})})})}var HT=`https://www.erdbuilderpro.com/pricing/self-host`;function UT(e){if(e.active===!0){let t=e.usage?.teamCount??e.usage?.team_count??0,n=e.maxTeams??e.max_teams;return typeof n==`number`&&t>=n?{kind:`limit`,used:t,max:n}:null}return e.code===`LICENSE_NOT_ACTIVATED`?{kind:`inactive`}:e.code===`LICENSE_EXPIRED`?{kind:`expired`}:{kind:`invalid`}}function WT({issue:e,onOpenChange:t,onOpenLicenseSettings:n,onManageTeams:r,onRetry:i}){let a=()=>t(!1),o=()=>window.open(HT,`_blank`,`noopener,noreferrer`),s=()=>{a(),n()},c=e?(e=>{switch(e.kind){case`inactive`:return{title:`Unlock Teams`,body:`Teams need a Self-host license key. Personal Workspace stays free.`,primary:[`Buy license`,o],secondary:[`Activate key`,s]};case`expired`:return{title:`License expired`,body:`Renew to access your Teams again. Your data is safe.`,primary:[`Renew`,o],secondary:[`Check again`,s]};case`invalid`:return{title:`License can't be verified`,body:`Reactivate your key on this server. Your data is safe.`,primary:[`Reactivate`,s],secondary:[`Close`,a]};case`sync`:return{title:`Can't reach license server`,body:`Existing Teams still work. Try again later.`,primary:[`Try again`,()=>{a(),i()}],secondary:[`Close`,a]};case`limit`:return{title:`Team limit reached`,body:`You're using ${e.used} of ${e.max} Teams. Upgrade to add more.`,primary:[`Upgrade`,o],secondary:[`Manage Teams`,()=>{a(),r()}]}}})(e):null;return(0,G.jsx)(Yr,{open:e!==null,onOpenChange:t,children:(0,G.jsx)(Vr,{size:`sm`,children:c&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:c.title}),(0,G.jsx)(Fr,{children:c.body})]}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(U,{type:`button`,variant:`outline`,onClick:c.secondary[1],children:c.secondary[0]}),(0,G.jsx)(U,{type:`button`,onClick:c.primary[1],children:c.primary[0]})]})]})})})}var GT=W.memo(({projects:e,globalSearchResults:t,isGlobalSearchLoading:n,onGlobalSearchResultSelect:r,onViewChange:i,onProjectCreate:a,onProjectUpdate:o,onProjectDelete:s,onLogout:c,globalSearchQuery:l,onGlobalSearchChange:u,isProjectsLoading:d,user:f,isOnline:p,onOpenFeedback:h,teams:g,teamsAvailable:_,licenseRequired:y,activeTeamId:b,onTeamsRefresh:x,onTeamSelect:S,onTeamManage:C,onTeamCreate:w,onTeamCreated:T,onOpenLicenseSettings:E,ssoPortalUrl:D,...O})=>{let k=m(),A=v(),{isMobile:j}=wh(),[M,N]=(0,W.useState)(!1),[P,F]=(0,W.useState)(null),I=async e=>{try{let t=await Si(`/api/license/status`),n=t.ok?UT(await t.json()):null;if(n||e){F(n||e||null);return}}catch{}N(!0)},L=e=>{e===`LICENSE_SYNC_REQUIRED`?F({kind:`sync`}):I({kind:`invalid`})},R=yi(),ee=!R&&!f?.isSso&&(f?.isSuperAdmin!==void 0||f?.is_super_admin!==void 0),te=!!(f?.isSuperAdmin||f?.is_super_admin),ne=f?.isSso===!0||R||ee&&y,re=()=>{if(D)try{window.location.assign(new URL(`/dashboard`,D).toString())}catch{}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Eh,{collapsible:`icon`,...O,children:[(0,G.jsxs)(ane,{className:`gap-2 border-b border-sidebar-border`,children:[(0,G.jsx)(DT,{teams:g,activeTeamId:b,enabled:_||g.length>0||te&&y,canManageTeams:te,onOpen:x,onSelect:S,onAdd:()=>{I()},onManage:C}),(0,G.jsx)(kT,{query:l,results:t,isLoading:n,isOnline:p,showDbClient:R,onQueryChange:u,onResultSelect:r})]}),(0,G.jsxs)(Dh,{children:[(0,G.jsx)(Oh,{children:(0,G.jsx)(Ah,{children:(0,G.jsxs)(jh,{children:[(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Dashboard`,isActive:k.pathname===`/`,onClick:()=>A(`/`),children:[(0,G.jsx)(ho,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Dashboard`})]})}),ee&&te&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(Nh,{title:`Instance Administration`,"aria-label":`Instance Administration`,isActive:k.pathname===`/team-workspaces`||k.pathname===`/users`,children:[(0,G.jsx)(Uo,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Instance Administration`}),(0,G.jsx)(Tr,{"aria-hidden":`true`,className:`ml-auto text-muted-foreground group-data-[collapsible=icon]:hidden`})]})}),(0,G.jsxs)(Gt,{side:j?`bottom`:`right`,align:`start`,sideOffset:8,children:[(0,G.jsxs)(It,{onClick:()=>A(`/team-workspaces`),children:[(0,G.jsx)(ro,{"aria-hidden":`true`}),`Team`]}),(0,G.jsxs)(It,{onClick:()=>A(`/users`),children:[(0,G.jsx)($o,{"aria-hidden":`true`}),`Users`]})]})]})}),f?.isSso&&D&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Manage account & billing`,onClick:re,children:[(0,G.jsx)(Ga,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Manage account & billing`})]})}),f?.isSso&&(0,G.jsx)(Mh,{children:(0,G.jsxs)(Nh,{tooltip:`Library`,isActive:k.pathname===`/library`,disabled:!p,onClick:()=>A(`/library`),children:[(0,G.jsx)(_o,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:`Library`})]})})]})})}),(0,G.jsx)(zT,{activeTeamId:b,isProjectsLoading:d,onProjectCreate:a,onProjectDelete:s,onProjectUpdate:o,projects:e,user:f})]}),(0,G.jsxs)(one,{className:`border-t border-sidebar-border`,children:[ne&&(0,G.jsx)(`div`,{className:`group-data-[collapsible=icon]:hidden`,children:(0,G.jsx)(ET,{})}),(0,G.jsx)(CT,{user:f,onLogout:c,onViewChange:i,isOnline:p,onOpenFeedback:h})]})]}),(0,G.jsx)(VT,{open:M,onOpenChange:N,onCreate:w,onCreated:T,onLicenseIssue:L}),(0,G.jsx)(WT,{issue:P,onOpenChange:e=>{e||F(null)},onOpenLicenseSettings:E,onManageTeams:()=>A(`/team-workspaces`),onRetry:()=>{I()}})]})});function KT({isOpen:e,onOpenChange:t,documentType:n,documentUid:r,documentId:i,documentTitle:a,isPublicView:o=!1,initialSettings:s,onSettingsSaved:c}){let[u,d]=W.useState(s?.share_token||``),[f,p]=W.useState(!1),[m,h]=W.useState(s?.is_public||!1),[g,_]=W.useState(``),[v,y]=W.useState(!1);W.useEffect(()=>{if(s?.expiry_date){let e=new Date(s.expiry_date),t=new Date,n=e.getTime()-t.getTime(),r=Math.ceil(n/864e5);r>0&&_(r.toString())}d(s?.share_token||``),h(s?.is_public||!1)},[s]);let b={erd:`diagram`,notes:`note`,drawings:`drawing`,flowchart:`flowchart`}[n]||n,x=`${window.location.origin}/view/${b}/${r}`;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-md`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:o?`Share Document`:`Share "${a}"`}),(0,G.jsx)(Fr,{children:o?`Share this link with others to view this document.`:m?`Anyone with this link can view this document. No account required.`:`This document is currently private. Only you can access it.`})]}),(0,G.jsxs)(Wr,{className:`space-y-4`,children:[!o&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/30 transition-colors hover:bg-muted/50`,children:[(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m?(0,G.jsx)(so,{className:`w-4 h-4 text-primary`}):(0,G.jsx)(So,{className:`w-4 h-4 text-muted-foreground`}),(0,G.jsx)(ha,{htmlFor:`public-status`,className:`text-sm font-bold`,children:`Public Access`})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Enable sharing via public link`})]}),(0,G.jsx)(Kh,{id:`public-status`,checked:m,onCheckedChange:e=>h(e)})]}),(0,G.jsxs)(`div`,{className:`space-y-4 transition-all duration-300 ${m||o?`opacity-100`:`opacity-40 pointer-events-none grayscale-[0.5]`}`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(ha,{htmlFor:`share-link`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Public Link`}),(0,G.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,G.jsx)(wi,{id:`share-link`,readOnly:!0,value:x,className:`flex-1 bg-muted/20 font-mono text-xs`}),(0,G.jsx)(U,{onClick:()=>{navigator.clipboard.writeText(x),p(!0),l.success(`Link copied to clipboard!`),setTimeout(()=>p(!1),2e3)},size:`icon`,variant:`outline`,className:`shrink-0 cursor-pointer hover:bg-primary/10 hover:text-primary transition-colors`,disabled:!m&&!o,children:f?(0,G.jsx)(Yt,{className:`w-4 h-4 text-green-500`}):(0,G.jsx)(Ua,{className:`w-4 h-4`})})]})]}),!o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(ha,{htmlFor:`access-token`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Access Token (Optional)`}),(0,G.jsxs)(U,{variant:`link`,size:`sm`,onClick:()=>{let e=Math.random().toString(36).substring(2,10).toUpperCase();d(e),l.info(`Secure token generated`)},className:`h-auto p-0 text-[10px] uppercase font-bold tracking-tighter cursor-pointer text-primary hover:no-underline`,disabled:!m,children:[(0,G.jsx)(cr,{className:`w-3 h-3 mr-1`}),`Generate`]})]}),(0,G.jsx)(wi,{id:`access-token`,placeholder:`Enter or generate a token...`,value:u,onChange:e=>d(e.target.value),disabled:!m,className:`font-mono text-xs`})]}),(0,G.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,G.jsx)(ha,{htmlFor:`valid-until`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Duration (Days)`}),(0,G.jsx)(wi,{id:`valid-until`,type:`number`,placeholder:`Forever`,value:g,onChange:e=>_(e.target.value),disabled:!m,className:`text-xs`})]})]})]})]}),(0,G.jsx)(Gr,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:o?(0,G.jsx)(U,{type:`button`,onClick:()=>t(!1),className:`cursor-pointer w-full sm:w-auto font-bold`,children:`Close`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(U,{variant:`ghost`,onClick:()=>t(!1),className:`cursor-pointer order-2 sm:order-1 font-semibold`,disabled:v,children:`Cancel`}),(0,G.jsx)(U,{type:`button`,onClick:async()=>{y(!0);try{let e=n===`erd`?`diagrams`:n===`flowchart`?`flowcharts`:n,r=null;if(g&&!isNaN(parseInt(g))){let e=new Date;e.setDate(e.getDate()+parseInt(g)),r=e.toISOString()}if(!(await Si(`/api/${e}/${i}/share`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({is_public:m,share_token:u,expiry_date:r})})).ok)throw Error(`Failed to save settings`);l.success(`Sharing settings updated!`),c&&c(),t(!1)}catch(e){l.error(e.message||`Something went wrong`)}finally{y(!1)}},className:`cursor-pointer order-1 sm:order-2 font-bold min-w-[120px]`,disabled:v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(cr,{className:`w-4 h-4 mr-2 animate-spin`}),`Saving...`]}):`Save Changes`})]})})]})})}function qT({open:e,onOpenChange:t}){return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{size:`2xl`,className:`max-h-[82vh]`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:`Table Calculation Guide`})}),(0,G.jsxs)(Wr,{className:`space-y-5 overflow-y-auto pr-1 text-sm leading-6`,children:[(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`How it works`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Type a formula command in a table cell, then leave the cell. The editor replaces the command with the calculated result. Hover the result cell to see the Excel-style source range used for that value.`})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Vertical formulas`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Vertical formulas calculate numeric values in the same column. They are intended for header or footer rows.`}),(0,G.jsxs)(`div`,{className:`grid gap-2 rounded-md border bg-muted/30 p-3`,children:[(0,G.jsx)(`code`,{children:`=SUM`}),(0,G.jsx)(`code`,{children:`=SUMV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sum values vertically, for example: SUMV(B2:B5).`}),(0,G.jsx)(`code`,{children:`=AVG`}),(0,G.jsx)(`code`,{children:`=AVGV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Average values vertically, for example: AVGV(C2:C5).`}),(0,G.jsx)(`code`,{children:`=MUL`}),(0,G.jsx)(`code`,{children:`=PRODUCT`}),(0,G.jsx)(`code`,{children:`=MULV`}),(0,G.jsx)(`code`,{children:`=PRODUCTV`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Multiply values vertically, for example: PRODUCTV(D2:D5).`})]})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Horizontal formulas`}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Horizontal formulas calculate numeric values to the left of the formula cell in the same row.`}),(0,G.jsxs)(`div`,{className:`grid gap-2 rounded-md border bg-muted/30 p-3`,children:[(0,G.jsx)(`code`,{children:`=SUMH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sum values horizontally, for example: SUMH(B2:C2).`}),(0,G.jsx)(`code`,{children:`=AVGH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Average values horizontally, for example: AVGH(B2:D2).`}),(0,G.jsx)(`code`,{children:`=MULH`}),(0,G.jsx)(`code`,{children:`=PRODUCTH`}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Multiply values horizontally, for example: PRODUCTH(B2:C2).`})]})]}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Examples`}),(0,G.jsx)(`div`,{className:`rounded-md border overflow-hidden`,children:(0,G.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,G.jsx)(`thead`,{className:`bg-muted/50`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Item`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Qty`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Price`}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Total`})]})}),(0,G.jsxs)(`tbody`,{children:[(0,G.jsxs)(`tr`,{className:`border-t`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`Hosting`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`12`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`90.000`}),(0,G.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,G.jsx)(`code`,{children:`=MULH`}),` becomes 1.080.000`]})]}),(0,G.jsxs)(`tr`,{className:`border-t`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`Setup`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`100.000`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:`50.000`}),(0,G.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,G.jsx)(`code`,{children:`=SUMH`}),` becomes 150.000`]})]})]})]})}),(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Text cells are skipped. Indonesian number formatting such as 1.080.000 and decimal commas is accepted. Currency symbols are ignored when possible.`})]})]})]})})}var JT=({onShare:e,onCopyPath:t,onRename:n,onDelete:r,onDuplicate:i,onExportAll:a,onExportMarkdown:o,onCopyMarkdown:s,onImportMarkdown:c,onExportImage:u,isOnline:d,isPublicView:f=!1,isPublic:p=!1,activeFileUid:m,documentType:h,noteContent:g,historyEnabled:_=!1,onOpenHistory:v,onRefresh:y,isRefreshing:b=!1})=>{let[x,S]=(0,W.useState)(!1),C=e=>e.replace(/<[^>]+>/g,``).replace(/&[^;]+;/g,` `).trim(),w=(e=>{let t=e?C(e):``;return t?{words:t.split(/\s+/).filter(Boolean).length,sentences:t.split(/[.!?]+(?:\s|$)/).filter(e=>e.trim().length>0).length,paragraphs:e&&(e.match(/<p[^>]*>[\s\S]*?<\/p>/g)||[]).length||t.split(/\n\s*\n/).filter(Boolean).length,characters:t.replace(/\s/g,``).length}:{words:0,sentences:0,paragraphs:0,characters:0}})(g),T=()=>{if(!m){l.error(`Document link not available`);return}let e={erd:`diagram`,notes:`note`,drawings:`drawing`,flowchart:`flowchart`}[h]||h,t=`${window.location.origin}/view/${e}/${m}`;navigator.clipboard.writeText(t),l.success(`Public share link copied to clipboard`)};return(0,G.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2`,children:[(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsxs)(U,{"aria-label":`Actions`,variant:`ghost`,size:`sm`,className:`h-8 text-muted-foreground hover:bg-muted/80 hover:text-foreground hover:shadow-sm active:scale-95 transition-all duration-200`,children:[(0,G.jsx)(`span`,{className:`hidden sm:inline mr-1.5 text-xs font-medium`,children:`Actions`}),(0,G.jsx)(Tr,{className:`h-4 w-4`})]})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-56`,children:[f?(0,G.jsxs)(It,{onClick:T,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Public Link`})]}):(0,G.jsxs)(G.Fragment,{children:[t&&(0,G.jsxs)(It,{onClick:t,children:[(0,G.jsx)(Ua,{className:`text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Path`})]}),e&&(0,G.jsxs)(It,{disabled:!d,onClick:e,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Bo,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Share`})]}),p&&(0,G.jsxs)(It,{disabled:!d,onClick:T,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Public Link`})]}),(0,G.jsx)(Kt,{}),n&&(0,G.jsxs)(It,{disabled:!d,onClick:n,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(No,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Edit`})]}),y&&(0,G.jsxs)(It,{disabled:!d||b,onClick:()=>y(),className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(cr,{className:`h-4 w-4 text-muted-foreground ${b?`animate-spin`:``}`}),(0,G.jsx)(`span`,{children:`Refresh`})]}),v&&(0,G.jsxs)(It,{disabled:!_,onClick:()=>v(),className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(uo,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Version History`})]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{disabled:!d,onClick:r,className:`gap-2 text-destructive focus:text-destructive focus:bg-destructive/10 cursor-pointer`,children:[(0,G.jsx)($r,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{children:`Move to Trash`})]})]})]}),(h===`notes`||h===`drawings`)&&!f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{disabled:!d,onClick:i,className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(Ua,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Duplicate`})]})]}),h===`erd`&&!f&&a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(Ht,{children:[(0,G.jsxs)(Rt,{className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(rn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Export All`})]}),(0,G.jsxs)(Jt,{className:`w-48`,children:[(0,G.jsx)(It,{onClick:a,className:`gap-2 cursor-pointer`,children:(0,G.jsx)(`span`,{children:`Export Schemas`})}),(0,G.jsx)(It,{onClick:u,className:`gap-2 cursor-pointer`,children:(0,G.jsx)(`span`,{children:`Download SVG`})})]})]})]}),h===`notes`&&!f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>S(!0),children:[(0,G.jsx)(Aa,{className:`text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Calculation Guide`})]}),(0,G.jsx)(It,{disabled:!d,onClick:s,className:`gap-2 cursor-pointer flex items-center`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Ua,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Copy Markdown`})]})}),c&&(0,G.jsxs)(It,{disabled:!d,onClick:c,className:`gap-2 cursor-pointer flex items-center`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(Yn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Import`})]}),(0,G.jsx)(Lt,{children:`⇧⌘I`})]}),(0,G.jsxs)(It,{disabled:!d,onClick:o,className:`gap-2 cursor-pointer flex items-center`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,G.jsx)(rn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Export`})]}),(0,G.jsx)(Lt,{children:`⇧⌘E`})]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(Ht,{children:[(0,G.jsxs)(Rt,{className:`gap-2 cursor-pointer`,children:[(0,G.jsx)(ja,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{children:`Text Stats`})]}),(0,G.jsx)(Jt,{className:`w-52 p-1`,children:(0,G.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Words`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.words.toLocaleString()})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sentences`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.sentences.toLocaleString()})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Paragraphs`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.paragraphs.toLocaleString()})]}),(0,G.jsx)(Kt,{className:`my-1.5`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Characters`}),(0,G.jsx)(`span`,{className:`font-medium tabular-nums`,children:w.characters.toLocaleString()})]})]})})]})]})]})]}),h===`notes`&&(0,G.jsx)(qT,{open:x,onOpenChange:S})]})},YT=W.memo(({featureLabel:e,documentPath:t,sidebarDisabled:n=!1,activeProjectName:r,activeFileName:i,view:a,hasActiveItem:o,syncError:s,isSyncing:c,isRefreshing:u,isLocalSaving:f=!1,hasPendingSyncs:p,activeFileUid:h,activeFileId:g,initialShareSettings:_,onSettingsSaved:v,isPublicView:y=!1,isOnline:b,updatedAt:x,onDelete:S,onRename:C,onSave:w,onExportAll:T,onExportSQL:E,onExportImage:D,onExportMarkdown:O,onCopyMarkdown:k,onImportMarkdown:A,onDuplicate:j,isGuest:M=!1,breadcrumbLabel:N,noteContent:P,historyAvailable:F=!0,canManage:I=!0,onRefresh:L,discussionPanel:R,tabsRef:ee,aiAssistant:te})=>{let ne=m(),[re,ie]=W.useState(!1),{setRightPanelMode:z}=bn(),ae=!(!F||a!==`erd`&&a!==`flowchart`&&(a!==`notes`&&a!==`drawings`||!a)||!h||M||y||!b||f||c||p),oe=W.useCallback(()=>z(`history`),[z]),se=W.useCallback(e=>{navigator.clipboard.writeText(`${e} > ${r||`No Workspace`} > ${i}`).then(()=>l.success(`File path copied`)).catch(()=>l.error(`Failed to copy file path`))},[i,r]),ce=t??ne.pathname,le=!y&&/^\/(notes|diagrams|drawings|flowcharts|db-client)\/[^/]+$/.test(ce);return(0,G.jsxs)(`header`,{className:`flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 w-full overflow-hidden border-b bg-background/50 backdrop-blur-sm`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 px-2 sm:px-4`,children:[!y&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nne,{className:`-ml-1 shrink-0`,disabled:n}),(0,G.jsx)(Ti,{orientation:`vertical`,className:`h-4 shrink-0 bg-border/50`})]}),(0,G.jsx)(`div`,{ref:ee,className:le?`flex min-w-0 flex-1 items-center`:`hidden`}),!le&&(0,G.jsx)(Ph,{className:`min-w-0 flex items-center`,children:(0,G.jsx)(Fh,{className:`min-w-0 flex-nowrap items-center`,children:!y&&(()=>{let n=t??ne.pathname;if(n===`/`)return(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:`Dashboard`})});if(n.startsWith(`/projects/`))return null;if(n.startsWith(`/table/`)){let e={notes:`Notes`,erd:`ERD Builder`,"db-client":`DB Client`,drawings:`Drawings`,flowchart:`Flowcharts`},t=n.match(/^\/table\/([^/]+)$/)?.[1],r=t?e[t]||t:`Unknown`;return(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:r})})}return n.startsWith(`/trash`)?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:`Trash`})}):n.startsWith(`/library`)?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-foreground`,children:`Library`})}):n.startsWith(`/teams/`)?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ih,{className:`shrink-0 text-muted-foreground`,children:`Teams`}),(0,G.jsx)(Rh,{}),(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:N||`Team management`})})]}):N?(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-semibold text-foreground`,children:N})}):(0,G.jsx)(Ih,{className:`shrink-0`,children:(0,G.jsx)(Lh,{className:`font-medium text-muted-foreground`,children:e})})})()})})]}),!b&&!y&&(0,G.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 px-3 py-1 rounded-full bg-destructive/10 border border-destructive/20 text-destructive animate-in fade-in slide-in-from-top-1 duration-500`,children:[(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-destructive animate-pulse`}),(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider`,children:`Offline Mode: Navigation Disabled`})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 pr-2 sm:pr-4`,children:[!!ne.pathname.match(/^\/(notes|diagrams|drawings|flowcharts)\/[^/]+$/)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2`,children:[!y&&s&&(0,G.jsxs)(`span`,{role:`status`,title:`Changes saved locally, but cloud sync failed. We'll retry automatically.`,className:`flex shrink-0 items-center gap-1 text-destructive`,children:[(0,G.jsx)(za,{className:`size-4`}),(0,G.jsx)(`span`,{className:`hidden lg:inline text-xs`,children:`Sync Failed`})]}),!y&&_?.is_public&&(0,G.jsxs)(Vh,{variant:`outline`,title:`This document is shared publicly via a secret link.`,className:`shrink-0 gap-1`,children:[(0,G.jsx)(so,{className:`size-3`}),(0,G.jsx)(`span`,{className:`hidden lg:inline`,children:`Public`})]}),R,(0,G.jsx)(JT,{onCopyPath:y?void 0:()=>se(new URLSearchParams(ne.search).get(`feature`)===`db-client`?`DB Client`:{notes:`Notes`,erd:`ERD Builder`,flowchart:`Flowcharts`,drawings:`Drawings`}[a]||e),onShare:I?()=>b&&ie(!0):void 0,onDelete:S,onRename:C,onDuplicate:j,onExportAll:T,onExportSQL:E,onExportImage:D,onExportMarkdown:O,onCopyMarkdown:k,onImportMarkdown:A,isOnline:b,isPublicView:y,isPublic:_?.is_public,activeFileUid:h,documentType:a,noteContent:P,historyEnabled:ae,onOpenHistory:M||y?void 0:oe,onRefresh:M||y?void 0:L,isRefreshing:u}),h&&g&&b&&(0,G.jsx)(KT,{isOpen:re,onOpenChange:ie,documentType:a,documentUid:h,documentId:g,documentTitle:i||`Untitled`,isPublicView:y,initialSettings:_,onSettingsSaved:v})]}),te&&(0,G.jsxs)(U,{type:`button`,variant:`outline`,onClick:te.onToggle,"aria-pressed":te.open,"aria-keyshortcuts":te.shortcut.ariaKeyShortcuts,title:`AI Assistant (${te.shortcut.label})`,className:d(`ml-1 h-8 gap-2 px-2.5 text-[13px] font-medium`,te.open&&`border-ring bg-muted`),children:[(0,G.jsx)(Qr,{className:`size-4 text-primary`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:`AI Assistant`}),te.answering&&!te.open&&(0,G.jsxs)(`span`,{title:`AI is still answering`,className:`text-primary`,children:[(0,G.jsx)(xo,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`AI is still answering`})]}),(0,G.jsx)(Di,{className:`hidden lg:inline-flex`,children:te.shortcut.label})]})]})]})}),XT=`(max-width: 1023px)`;function ZT(){let[e,t]=(0,W.useState)(()=>typeof window>`u`||!window.matchMedia(XT).matches);return(0,W.useEffect)(()=>{let e=window.matchMedia(XT),n=e=>t(!e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),{open:e,onOpenChange:t}}var QT=`https://api.erdbuilderpro.com/api/feedback`;function $T(){return QT}function eE({open:e,onOpenChange:t,isCloud:n=!1}){let[r,i]=W.useState(!1),[a,o]=W.useState(``),[s,c]=W.useState(`suggestion`),[u,d]=W.useState(``);return(0,G.jsx)(Yr,{open:e,onOpenChange:e=>{t(e),e||o(``)},children:(0,G.jsx)(Vr,{className:`sm:max-w-106.25 border-border bg-popover/95 backdrop-blur-xl shadow-2xl`,children:(0,G.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),a.trim()){i(!0);try{if((n?await Si(`/api/feedback`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:a,category:s,page_path:window.location.pathname})}):await fetch($T(),{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`omit`,body:JSON.stringify({content:a,category:s,email:u,url:window.location.href,browser:navigator.userAgent})})).ok)l.success(`Feedback terkirim! Terima kasih masukannya.`),t(!1),o(``);else throw Error()}catch{l.error(`Gagal mengirim feedback. Coba lagi nanti.`)}finally{i(!1)}}},className:`flex flex-col max-h-[inherit]`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{className:`text-xl font-bold`,children:`Kirim Masukan`}),(0,G.jsx)(Fr,{className:`text-sm text-muted-foreground`,children:`Bantu kami membuat ERD Builder Pro jadi lebih baik. Saran Anda sangat berharga!`})]}),(0,G.jsxs)(Wr,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`category`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Tipe Masukan`}),(0,G.jsxs)(_r,{value:s,onValueChange:e=>e&&c(e),children:[(0,G.jsx)(mr,{id:`category`,className:`bg-white/5 border-white/10 focus:ring-primary/50`,children:(0,G.jsx)(gr,{placeholder:`Pilih tipe`,children:s===`suggestion`?`Saran Fitur`:s===`bug`?`Lapor Bug`:s===`other`?`Kritik / Lainnya`:s})}),(0,G.jsxs)(pr,{className:`bg-popover border-border text-popover-foreground`,children:[(0,G.jsx)(fr,{value:`suggestion`,className:`focus:bg-muted`,children:`Saran Fitur`}),(0,G.jsx)(fr,{value:`bug`,className:`focus:bg-muted text-destructive`,children:`Lapor Bug`}),(0,G.jsx)(fr,{value:`other`,className:`focus:bg-muted`,children:`Kritik / Lainnya`})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`content`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Pesan`}),(0,G.jsx)(`textarea`,{id:`content`,autoComplete:`off`,className:`flex min-h-35 w-full rounded-lg border border-border bg-muted/50 px-4 py-3 text-sm ring-offset-background placeholder:text-muted-foreground/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-all resize-none`,placeholder:`Tuliskan masukan Anda di sini...`,value:a,onChange:e=>o(e.target.value),maxLength:n?2e3:3e3,required:!0})]}),!n&&(0,G.jsxs)(`div`,{className:`grid gap-2`,children:[(0,G.jsx)(ha,{htmlFor:`email`,className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Email (Opsional)`}),(0,G.jsx)(wi,{id:`email`,type:`email`,autoComplete:`off`,placeholder:`email@contoh.com`,className:`bg-muted/50 border-border focus:ring-primary/50 h-10 px-4`,value:u,onChange:e=>d(e.target.value)})]})]}),(0,G.jsxs)(Gr,{className:`gap-3`,children:[(0,G.jsx)(U,{variant:`ghost`,type:`button`,onClick:()=>t(!1),className:`hover:bg-muted`,children:`Batal`}),(0,G.jsx)(U,{type:`submit`,disabled:r,className:`bg-primary text-primary-foreground hover:bg-primary/90 shadow-lg shadow-primary/20`,children:r?`Mengirim...`:`Kirim Masukan`})]})]})})})}var tE=[{key:`disappointment`,label:`Seberapa kecewa Anda kalau tidak bisa memakai ERD Builder Pro lagi?`,options:[{value:`very_disappointed`,label:`Sangat kecewa`},{value:`somewhat_disappointed`,label:`Agak kecewa`},{value:`not_disappointed`,label:`Tidak kecewa`}]},{key:`primary_use`,label:`Untuk apa Anda paling banyak memakainya?`,options:[{value:`design_new_schema`,label:`Merancang skema baru`},{value:`document_existing_database`,label:`Mendokumentasikan database yang ada`},{value:`team_collaboration`,label:`Kolaborasi dengan tim`},{value:`ai_features`,label:`Fitur AI`},{value:`other`,label:`Lainnya`}]},{key:`main_blocker`,label:`Apa yang paling menghambat Anda?`,options:[{value:`hard_to_learn`,label:`Sulit dipahami di awal`},{value:`missing_feature`,label:`Fitur yang dibutuhkan belum ada`},{value:`slow_or_error`,label:`Lambat atau error`},{value:`team_reluctant`,label:`Tim sulit diajak pindah`},{value:`none`,label:`Tidak ada hambatan`}]}],nE={beta_trial:`Satu hal yang paling ingin Anda ubah?`,cloud_trial:`Apa yang membuat Anda ragu berlangganan?`},rE=1e3;function iE({teamId:e}){let[t,n]=W.useState(null),[r,i]=W.useState(!1),[a,o]=W.useState({}),[s,c]=W.useState(``),[u,d]=W.useState(!1),[f,p]=W.useState(null);if(W.useEffect(()=>{let e=!1;return n(null),i(!1),o({}),c(``),p(null),Si(`/api/cloud/trial-survey`).then(e=>e.ok?e.json():null).then(t=>{!e&&t?.show&&(t.survey_key===`beta_trial`||t.survey_key===`cloud_trial`)&&n(t.survey_key)}).catch(()=>{}),()=>{e=!0}},[e]),!t)return null;let m=()=>{n(null),Si(`/api/cloud/trial-survey/dismiss`,{method:`POST`}).catch(()=>{})};return(0,G.jsxs)(`section`,{"aria-labelledby":`trial-survey-title`,className:`fixed bottom-20 right-4 z-40 flex max-h-[calc(100dvh-6rem)] w-[min(22rem,calc(100vw-2rem))] flex-col rounded-xl bg-popover text-popover-foreground shadow-xl ring-1 ring-foreground/10 sm:right-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2 px-4 py-3 ${r?`border-b`:`pb-0`}`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`h2`,{id:`trial-survey-title`,className:`text-sm font-semibold`,children:`Bagaimana Trial Anda sejauh ini?`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`4 pertanyaan singkat, kurang dari 1 menit.`})]}),(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:m,"aria-label":`Tutup, tampilkan lagi besok`,children:(0,G.jsx)(Pr,{"aria-hidden":`true`})})]}),r?(0,G.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),d(!0),p(null);try{let e=await Si(`/api/cloud/trial-survey`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({answers:{...a,open_answer:s}})});if(!e.ok){p(e.status===429?`Terlalu banyak kiriman. Coba lagi nanti.`:`Jawaban belum terkirim. Coba lagi.`);return}n(null),l.success(`Terima kasih! Jawaban Anda sudah kami terima.`)}catch{p(`Jawaban belum terkirim. Periksa koneksi lalu coba lagi.`)}finally{d(!1)}},className:`flex min-h-0 flex-col`,children:[(0,G.jsxs)(`div`,{className:`space-y-4 overflow-y-auto px-4 py-3`,children:[tE.map((e,t)=>(0,G.jsxs)(`fieldset`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`legend`,{className:`mb-1.5 text-sm font-medium`,children:[t+1,`. `,e.label]}),e.options.map(n=>(0,G.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-sm hover:bg-muted has-checked:bg-primary/10`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`trial-survey-${e.key}`,value:n.value,checked:a[e.key]===n.value,onChange:()=>o(t=>({...t,[e.key]:n.value})),className:`size-4 accent-primary`,required:!0,autoFocus:t===0&&n===e.options[0]}),n.label]},n.value))]},e.key)),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`label`,{htmlFor:`trial-survey-open-answer`,className:`block text-sm font-medium`,children:[`4. `,nE[t],` `,(0,G.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(opsional)`})]}),(0,G.jsx)(`textarea`,{id:`trial-survey-open-answer`,value:s,onChange:e=>c(e.target.value),maxLength:rE,rows:3,className:`w-full resize-none rounded-lg border border-border bg-muted/50 px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`})]})]}),(0,G.jsxs)(`div`,{className:`border-t px-4 py-3`,children:[f&&(0,G.jsx)(`p`,{role:`alert`,className:`mb-2 text-sm text-destructive`,children:f}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:m,children:`Nanti saja`}),(0,G.jsx)(U,{type:`submit`,size:`sm`,disabled:u,children:u?`Mengirim...`:`Kirim`})]})]})]}):(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,G.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:m,children:`Nanti saja`}),(0,G.jsx)(U,{type:`button`,size:`sm`,onClick:()=>i(!0),children:`Isi sekarang`})]})]})}var aE=({isOpen:e,onOpenChange:t,selectedEntity:n,deleteEntity:r,setSelectedNodeId:i})=>(0,G.jsx)(pi,{open:e,onOpenChange:t,children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(ei,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Delete Table`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Are you sure you want to delete the table `,(0,G.jsx)(`strong`,{children:n?.name}),`? This action cannot be undone.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(ci,{onClick:()=>{n&&(r(n.id),i(null),t(!1))},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})}),oE=e=>e===`erd`?`diagram`:e===`notes`?`note`:e===`drawings`?`drawing`:e===`db-client`?`DB Client`:`flowchart`,sE=({isOpen:e,onOpenChange:t,mode:n=`edit`,view:r,activeDocument:i,newName:a,setNewName:o,projects:s,requireProject:c=!1,canMoveProject:u=!1,selectedProjectId:f,setSelectedProjectId:p,onCreate:m,onProjectCreate:h,updateDiagram:g,updateNote:_,updateDrawing:v,updateFlowchart:y,updateDbClient:b,onMoveDiagramToProject:x,onMoveNoteToProject:S,onMoveDrawingToProject:C,onMoveFlowchartToProject:w,onRenameSuccess:T,fileTypes:E,onViewChange:D,onViewPlans:O,onOpenDbConnections:k})=>{let A=n===`create`,j=E?.find(e=>e.value===r),M=A&&!!j?.locked,N=A&&r===`db-client`,P=i?.project_id??i?.projectId,F=c&&f===`none`&&(A||P!=null),[I,L]=(0,W.useState)(!1),[R,ee]=(0,W.useState)(``),[te,ne]=(0,W.useState)(!1),[re,ie]=(0,W.useState)(!1),z=e=>{e||(L(!1),ee(``)),t(e)},ae=async()=>{let e=R.trim();if(e&&h&&!te){ne(!0);try{let t=await h(e);if(!t){l.error(`Failed to create project`);return}p(String(t.id)),L(!1),ee(``)}catch{l.error(`Failed to create project`)}finally{ne(!1)}}};(0,W.useEffect)(()=>{if(e&&!A&&i){let e=i?.project_id??i?.projectId;p(e==null?`none`:String(e))}},[e]);let oe=async()=>{if(I||te||re||!a.trim()||F||M||N)return;if(A){ie(!0);try{await m?.(a.trim(),f===`none`?null:f)&&z(!1)}finally{ie(!1)}return}let e=(r===`db-client`||r===`notes`||r===`flowchart`||r===`drawings`)&&i?.uid||i?.id;if(e&&a.trim()){let t=f===`none`?null:f,n=a.trim()!==(i?.title||i?.name),o=r!==`db-client`&&String(t)!==String(P);if(o&&!u){l.error(`Only the file creator can move this file.`);return}try{if(n&&(r===`erd`?await g?.(e,a,{silent:!0}):r===`notes`?await _?.(String(e),a,{silent:!0}):r===`drawings`?await v?.(e,a,{silent:!0}):r===`flowchart`?await y?.(e,a,{silent:!0}):r===`db-client`&&await b?.(String(e),a.trim())),o){let n;if(r===`erd`?n=await x?.(e,t,{silent:!0}):r===`notes`?n=await S?.(e,t,{silent:!0}):r===`drawings`?n=await C?.(e,t,{silent:!0}):r===`flowchart`&&(n=await w?.(e,t,{silent:!0})),n===!1)throw Error(`Failed to move document`)}(n||o)&&T&&await T(),l.success(r===`db-client`?`DB Client renamed successfully`:`Document updated successfully`),z(!1)}catch{l.error(r===`db-client`?`Failed to rename DB Client`:`Failed to update document`)}}};return(0,G.jsx)(Yr,{open:e,onOpenChange:z,children:(0,G.jsxs)(Vr,{className:E&&A?`sm:max-w-md`:`sm:max-w-sm`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:A?E?`New file`:`Create ${oE(r)}`:`Edit`}),(0,G.jsx)(Fr,{children:A?`Choose a project for your new ${oE(r)}.`:r===`db-client`?`Change the name of this DB Client.`:u?`Update the name and project for your ${oE(r)}.`:`Update the name of this ${oE(r)}.`})]}),(0,G.jsx)(Wr,{children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[A&&E&&(0,G.jsxs)(`fieldset`,{children:[(0,G.jsx)(`legend`,{className:`sr-only`,children:`File type`}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:E.map(e=>{let t=e.icon;return(0,G.jsxs)(`label`,{className:d(`relative flex cursor-pointer flex-col items-center gap-1.5 rounded-lg border border-border px-2 py-3 text-center text-xs font-medium transition-colors hover:bg-accent/50`,`has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring`,r===e.value&&`border-primary bg-primary/5 text-foreground`,e.locked&&`text-muted-foreground`),children:[(0,G.jsx)(`input`,{type:`radio`,name:`create-file-type`,value:e.value,checked:r===e.value,onChange:()=>D?.(e.value),className:`sr-only`}),(0,G.jsx)(t,{className:`size-5`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{children:e.label}),e.locked&&(0,G.jsx)(`span`,{className:`absolute right-1.5 top-1.5 rounded border border-primary/30 px-1 text-[9px] font-semibold uppercase text-primary`,children:`Pro`})]},e.value)})})]}),M?(0,G.jsxs)(`div`,{className:`rounded-lg border border-primary/20 bg-primary/5 px-3.5 py-3 text-sm`,children:[(0,G.jsxs)(`p`,{className:`font-medium`,children:[j?.label,` needs a paid Cloud plan`]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Plans, limits, and checkout are managed in ERDBPro SaaS.`}),O&&(0,G.jsxs)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:O,children:[`View Cloud plans`,(0,G.jsx)(Ca,{className:`size-4`})]})]}):N?(0,G.jsxs)(`div`,{className:`rounded-lg border border-border px-3.5 py-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`DB Client files start from a database connection`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Pick a connection and a database, then choose the project for the new DB Client.`}),k&&(0,G.jsx)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:()=>{z(!1),k()},children:`Open database connections`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`rename-input`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:A||r===`db-client`?`Name`:`New Name`}),(0,G.jsx)(wi,{id:`rename-input`,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a.trim()&&oe()},autoFocus:!0})]}),r!==`db-client`&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`document-project-select`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(_r,{value:f,onValueChange:e=>e!==null&&p(e),disabled:!A&&!u||I||te,children:[(0,G.jsx)(mr,{id:`document-project-select`,className:`min-w-0 flex-1`,"aria-required":c,"aria-describedby":A&&F?`document-project-hint`:void 0,children:(0,G.jsx)(gr,{children:f===`none`?c?`Select Project`:`No project`:s.find(e=>e.id.toString()===f)?.name||`Select Project`})}),(0,G.jsxs)(pr,{children:[!c&&(0,G.jsx)(fr,{value:`none`,children:`No project`}),s.map(e=>(0,G.jsx)(fr,{value:e.id.toString(),children:e.name},e.id))]})]}),A&&h&&(0,G.jsx)(U,{type:`button`,variant:`outline`,size:`icon-lg`,className:`shrink-0`,"aria-label":I?`Cancel adding project`:`Add a project`,"aria-expanded":I,"aria-controls":`new-project-field`,disabled:te,onClick:()=>{L(!I),ee(``)},children:I?(0,G.jsx)(Pr,{className:`size-4`}):(0,G.jsx)(jt,{className:`size-4`})})]}),A&&F&&!I&&(0,G.jsx)(`p`,{id:`document-project-hint`,className:`mt-1.5 px-1 text-xs text-muted-foreground`,children:`Every file needs a project. Choose one, or add one with +.`}),A&&I&&(0,G.jsxs)(`div`,{id:`new-project-field`,className:`mt-3 space-y-2`,children:[(0,G.jsx)(Dr,{htmlFor:`new-project-name`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New project name`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{id:`new-project-name`,value:R,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ae())},placeholder:`Enter project name`,className:`min-w-0 flex-1`,autoFocus:!0,disabled:te}),(0,G.jsx)(U,{type:`button`,size:`lg`,className:`shrink-0`,disabled:!R.trim()||te,onClick:()=>void ae(),children:te?`Adding…`:`Add project`})]})]})]})]})]})}),(0,G.jsxs)(Gr,{children:[(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`outline`,className:`h-9`}),children:`Cancel`}),!M&&!N&&(0,G.jsx)(U,{disabled:I||te||re||!a.trim()||F,onClick:oe,className:`h-9 px-6`,children:A?re?`Creating…`:`Create`:`Save Changes`})]})]})})},cE=({isOpen:e,onOpenChange:t,view:n,duplicateName:r,setDuplicateName:i,executeDuplicate:a,isRefreshing:o})=>(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-sm`,children:[(0,G.jsxs)(Jr,{children:[(0,G.jsx)(Hr,{children:`Duplicate Document`}),(0,G.jsxs)(Fr,{children:[`Create a copy of this `,n===`erd`?`diagram`:n===`notes`?`note`:n===`drawings`?`drawing`:`flowchart`,`.`]})]}),(0,G.jsx)(Wr,{children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`duplicate-input`,className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New Name`}),(0,G.jsx)(wi,{id:`duplicate-input`,type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&r.trim()&&a()},autoFocus:!0})]})})}),(0,G.jsxs)(Gr,{className:`gap-2 sm:gap-0`,children:[(0,G.jsx)(U,{variant:`ghost`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(U,{onClick:a,disabled:!r.trim()||o,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`mr-2 h-4 w-4 animate-spin`}),`Duplicating...`]}):`Duplicate`})]})]})}),lE=r(ce(),1),uE=[{id:`sql`,label:`SQL`,formats:[{id:`mysql`,label:`MySQL`},{id:`postgresql`,label:`PostgreSQL`}]},{id:`laravel`,label:`Laravel`,formats:[{id:`laravel_migration`,label:`Migration`},{id:`laravel_model`,label:`Model`}]},{id:`goravel`,label:`Goravel`,formats:[{id:`goravel`,label:`Model`},{id:`goravel_migration`,label:`Migration`}]},{id:`typescript`,label:`TypeScript`,formats:[{id:`typescript`,label:`Interface`},{id:`zod`,label:`Zod`}]},{id:`prisma`,label:`Prisma`,formats:[{id:`prisma`,label:`Schema`}]}],dE=new Set([`mysql`,`postgresql`,`prisma`]),fE=({open:e,onOpenChange:t,nodes:n,edges:r,fileName:i})=>{let[a,o]=W.useState(uE[0].id),[s,c]=W.useState(uE[0].formats[0].id),[u,d]=W.useState(!1),[f,p]=W.useState(!1),[m,h]=W.useState(!1),{resolvedTheme:g}=pa(),_=uE.find(e=>e.id===a)?.formats??[],v=s,y=dE.has(s),b=W.useMemo(()=>e?ea(v,n,r,i)+`
|
|
49
49
|
|
|
50
50
|
`:``,[e,v,n,r,i]),x=W.useMemo(()=>{switch((e=>e===`mysql`||e===`postgresql`?`sql`:e===`laravel_migration`||e===`laravel_model`?`php`:e===`goravel`||e===`goravel_migration`?`go`:e===`typescript`||e===`zod`?`typescript`:e===`prisma`?`prisma`:``)(s)){case`sql`:return[Li()];case`php`:return[Ai()];case`go`:return[zi(),...Pi(g)];case`prisma`:case`typescript`:return[ji({typescript:!0})];default:return[]}},[s,g]),S=()=>{navigator.clipboard.writeText(b),d(!0),setTimeout(()=>d(!1),2e3)},C=async()=>{p(!0);let e=l.loading(y?`Downloading...`:`Creating archive...`);try{if(y){let e=oa(v),t=new Blob([b],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${i.toLowerCase().replace(/\s+/g,`_`)}_schema.${e}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}else{let e=Qi(v,n,r,i),t=new lE.default;e.forEach(e=>t.file(e.filename,e.content));let a=await t.generateAsync({type:`blob`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${i.toLowerCase().replace(/\s+/g,`_`)}_schema.zip`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}h(!0),l.success(y?`File downloaded successfully`:`Archive downloaded successfully`,{id:e}),setTimeout(()=>h(!1),2e3)}catch{l.error(`Failed to download file`,{id:e})}finally{p(!1)}},w=e=>{o(e);let t=uE.find(t=>t.id===e);t&&t.formats.length>0&&c(t.formats[0].id)};return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{size:`2xl`,className:`bg-popover border-border text-popover-foreground shadow-2xl`,onDoubleClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(Jr,{className:`px-6 pt-6 pb-0 border-b border-border space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(Hr,{className:`text-xl font-bold tracking-tight`,children:`Export All`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/40 font-bold uppercase tracking-widest mt-1`,children:[n.length,` tables · `,r.length,` relationships`]})]}),(0,G.jsx)(`div`,{className:`overflow-x-auto scrollbar-hide w-full`,children:(0,G.jsx)(`div`,{className:`flex gap-1 bg-muted/40 border border-border rounded-lg p-0.5 w-fit`,children:uE.map(e=>(0,G.jsx)(`button`,{onClick:()=>w(e.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded text-[11px] font-semibold transition-all text-nowrap ${a===e.id?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:e.label},e.id))})}),(0,G.jsx)(`div`,{className:`overflow-x-auto scrollbar-hide w-full -mt-1 mb-2`,children:(0,G.jsx)(`div`,{className:`flex gap-1 bg-muted border border-border rounded-lg p-1 w-fit`,children:_.map(e=>(0,G.jsx)(`button`,{onClick:()=>c(e.id),className:`flex items-center gap-1.5 px-3.5 py-2 rounded-md text-xs font-semibold transition-all text-nowrap ${s===e.id?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:e.label},e.id))})})]}),(0,G.jsx)(Wr,{className:`p-0 bg-muted relative flex-1 min-h-0 overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-[min(52vh,520px)] min-h-0`,children:(0,G.jsx)(Fi,{value:b,extensions:x,theme:g===`dark`?Mi:void 0,readOnly:!0,height:`100%`,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!1,highlightActiveLineGutter:!1,bracketMatching:!1,closeBrackets:!1,indentOnInput:!1},className:`text-[13px] text-foreground/90 h-full`,style:{minHeight:`300px`}})})}),(0,G.jsxs)(Gr,{className:`border-t border-border p-4 bg-muted/20 gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mr-auto`,children:[(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:C,disabled:f||m,className:`h-9 px-4 border-border hover:bg-muted bg-muted/50 text-xs font-semibold`,children:[m?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Yt,{className:`w-3.5 h-3.5 mr-2 text-green-400`}),`Downloaded`]}):f?(0,G.jsx)(xo,{className:`w-3.5 h-3.5 mr-2 animate-spin`}):(0,G.jsx)(rn,{className:`w-3.5 h-3.5 mr-2`}),!m&&(y?`Download`:`Download .zip`)]}),(0,G.jsx)(U,{variant:`outline`,size:`sm`,onClick:S,disabled:!y,className:`h-9 px-4 border-border hover:bg-muted bg-muted/50 text-xs font-semibold min-w-22.5 disabled:opacity-30 disabled:cursor-not-allowed`,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Yt,{className:`w-3.5 h-3.5 mr-2 text-green-400`}),`Copied`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ua,{className:`w-3.5 h-3.5 mr-2`}),`Copy`]})})]}),(0,G.jsx)(U,{onClick:()=>t(!1),className:`h-9 px-6 bg-secondary text-secondary-foreground hover:bg-secondary/80 font-bold`,children:`Close`})]})]})})};function pE({nodes:e,edges:t,setNodes:n,setEdges:r,activeDiagramId:i,takeSnapshot:a,saveDiagram:o,triggerDebouncedSync:s,broadcastMessage:c,setIsLocalSaving:u,viewportRef:d,lastLoadedDiagramIdRef:f,onComplete:p}){let[m,h]=(0,W.useState)(``),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(!1),b=(0,W.useRef)(null),{resolvedTheme:x}=pa(),[S,C]=(0,W.useState)(`input`),[w,T]=(0,W.useState)([]),[E,D]=(0,W.useState)(null),O=e=>{let t=e.target.files?.[0];if(!t)return;if(!t.name.toLowerCase().endsWith(`.sql`)){_(`Invalid file format. Please upload a .sql file.`);return}_(null);let n=new FileReader;n.onload=e=>{let n=e.target?.result;h(n),l.success(`Successfully loaded ${t.name}`)},n.readAsText(t),b.current&&(b.current.value=``)};function k(e,t){let n=[];for(let r of t){let t=e.find(e=>e.name.toLowerCase()===r.name.toLowerCase());t?(t.type!==r.type||t.is_pk!==r.is_pk||t.is_nullable!==r.is_nullable||(t.comment||``)!==(r.comment||``)||(t.max_length??null)!==(r.max_length??null)||(t.numeric_precision??null)!==(r.numeric_precision??null)||(t.numeric_scale??null)!==(r.numeric_scale??null))&&n.push({type:`modify`,column:{...r},existing:{...t}}):n.push({type:`add`,column:{...r}})}return n}function A(t){return e?.find(e=>e.data.name.toLowerCase()===t.toLowerCase())}let j=()=>{m.trim()&&(y(!0),_(null),setTimeout(()=>{try{let t=_e(m);if(t.nodes.length===0){/ALTER\s+TABLE\s+/i.test(m)?l.error(`ALTER TABLE requires an existing table in the diagram. Only CREATE TABLE can create new tables.`):l.error(`No valid CREATE TABLE statements found.`),y(!1);return}if(e&&e.length>0){let e=t.nodes,n=[],r=[];for(let t of e){let e=A(t.data.name);if(e){let r=k(e.data.columns,t.data.columns);r.length>0&&n.push({tableName:t.data.name,existingNode:e,columnChanges:r})}else r.push(t)}if(n.length>0){T(n),D({nodes:r,edges:t.edges,allParsedNodes:e}),C(`review`),y(!1);return}}M(t.nodes,t.edges,void 0,t.nodes),y(!1)}catch(e){console.error(e),_(`Failed to parse SQL. Check your syntax.`),y(!1)}},100))};function M(m,g,v,y){if(e&&t&&n&&r&&a){a(e,t);let p=[...e],h=[...t],_={};if(v)for(let e of v){_[e.existingNode.id]=e.existingNode.id;let t=p.findIndex(t=>t.id===e.existingNode.id);if(t===-1)continue;let n={...p[t]},r=[...n.data.columns];for(let t of e.columnChanges)if(t.type===`add`)r.push({...t.column,id:`col-${Math.random().toString(36).substring(2,11)}`,sort_order:r.length});else if(t.type===`modify`){let e=r.findIndex(e=>e.name.toLowerCase()===t.column.name.toLowerCase());e!==-1&&(r[e]={...r[e],type:t.column.type,is_pk:t.column.is_pk,is_nullable:t.column.is_nullable,comment:t.column.comment,max_length:t.column.max_length,numeric_precision:t.column.numeric_precision,numeric_scale:t.column.numeric_scale})}p[t]={...n,data:{...n.data,columns:r}}}let b=p.map(e=>e.data.name.toLowerCase());if(y)for(let e of y){let t=p.find(t=>t.data.name.toLowerCase()===e.data.name.toLowerCase());t&&(_[e.id]=t.id)}for(let e of m){let t=e.data.name,n=1;for(;b.includes(t.toLowerCase());)t=`${e.data.name}_imported_${n}`,n++;t!==e.data.name&&(e.data.name=t);let r=`node-${Math.random().toString(36).substring(2,11)}`;_[e.id]=r,e.id=r,e.data.id=r,p.push(e)}for(let e of g){let t=_[e.source]||e.source,n=_[e.target]||e.target;h.push({...e,id:`e-${Math.random().toString(36).substring(2,11)}`,source:t,target:n})}p=V(p);let x=new Set((t||[]).map(e=>e.id)),S=ye(p,h.filter(e=>!x.has(e.id)));h.splice(0,h.length,...h.filter(e=>x.has(e.id)),...S),n(p),r(h),i&&o&&s&&c&&u&&d&&f&&(f.current=i,u(!0),o(p,h,d.current).then(()=>{u(!1),s(),c($i.DRAFT_UPDATED,P.ERD,i)}));let C=v?.length||0,w=m.length,T=[];C>0&&T.push(`${C} table(s) updated`),w>0&&T.push(`${w} table(s) added`),l.success(`Success! ${T.join(`, `)}.`)}h(``),_(null),C(`input`),T([]),D(null),p?.()}return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`input`,{type:`file`,ref:b,className:`hidden`,accept:`.sql`,onChange:O}),S===`input`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`SQL Schema Editor`}),(0,G.jsxs)(U,{variant:`outline`,size:`sm`,className:`h-8 text-xs font-bold border-dashed border-primary/50 hover:border-primary hover:bg-primary/5`,onClick:()=>b.current?.click(),children:[(0,G.jsx)(Yn,{className:`w-3 h-3 mr-2`}),`Upload .sql File`]})]}),(0,G.jsx)(Fi,{value:m,height:`280px`,theme:x===`dark`?Mi:void 0,extensions:[Li()],placeholder:`CREATE TABLE users (
|
|
51
51
|
id SERIAL PRIMARY KEY,
|
|
@@ -782,4 +782,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
782
782
|
|
|
783
783
|
`);return{...re(e),dbml:e,warnings:[]}}let n=t.map(e=>e.content).join(`
|
|
784
784
|
|
|
785
|
-
`),r=_e(n);return{...r,dbml:ue(r.nodes,r.edges),warnings:[]}}var D9=e=>e.trim().toLowerCase(),O9=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``)||``;function k9(e,t,n,r){let i=new Map(e.map(e=>[D9(e.data.name),e])),a=new Map,o=new Map,s=n.map((e,t)=>{let n=i.get(D9(e.data.name));if(!n)return{...e,position:e.position||{x:t%4*320+50,y:Math.floor(t/4)*320+50}};a.set(e.id,n.id);let r=e.data.columns.map(t=>{let r=n.data.columns.find(e=>D9(e.name)===D9(t.name));return r&&o.set(`${e.id}:${t.id}`,r.id),r?{...t,id:r.id}:t}),s=(t=[])=>t.map(t=>o.get(`${e.id}:${t}`)||t);return{...e,id:n.id,position:n.position,data:{...e.data,id:n.data.id,x:n.data.x,y:n.data.y,color:n.data.color,collapsed:n.data.collapsed,hidden_columns:n.data.hidden_columns,columns:r,constraints:(e.data.constraints||[]).map(e=>({...e,entity_id:n.data.id,column_ids:s(e.column_ids)})),indexes:(e.data.indexes||[]).map(e=>({...e,entity_id:n.data.id,column_ids:s(e.column_ids)}))}}});return{nodes:s,edges:r.map(e=>{let r=n.find(t=>t.id===e.source),i=n.find(t=>t.id===e.target),o=a.get(e.source)||e.source,c=a.get(e.target)||e.target,l=r?.data.columns.find(t=>t.id===O9(e.sourceHandle)),u=i?.data.columns.find(t=>t.id===O9(e.targetHandle)),d=s.find(e=>e.id===o),f=s.find(e=>e.id===c),p=d?.data.columns.find(e=>D9(e.name)===D9(l?.name||``)),m=f?.data.columns.find(e=>D9(e.name)===D9(u?.name||``)),h=p?`col-${p.id}-${(d?.position.x||0)<(f?.position.x||0)?`source`:`source-l`}`:void 0,g=m?`col-${m.id}-${(d?.position.x||0)<(f?.position.x||0)?`target`:`target-r`}`:void 0,_=me(t,o,c,h,g);return{...e,id:_?.id||e.id,source:o,target:c,sourceHandle:_?.sourceHandle||h,targetHandle:_?.targetHandle||g}})}}var A9=`WORKTREE`;async function j9(e,t){let n=await Si(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error||`Repository request failed`);return r}async function M9(e,t,n){let r=await Si(e,{method:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify({repository_path:n.repositoryPath,ref:n.ref,source_id:n.sourceId})}:{}}),i=r.status===204?null:await r.json().catch(()=>({}));if(!r.ok)throw Error(i?.error||`Repository link request failed`);return i}function yke({diagramUid:e,nodes:t,edges:n,onClose:r}){let i=`erdbpro:repository-link:${e}`,a=`/api/repositories/link/${encodeURIComponent(e)}`,[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(A9),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(``),[_,v]=(0,W.useState)([]),[y,b]=(0,W.useState)(null),x=(0,W.useRef)(null),S=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),C=(0,W.useCallback)(e=>{let t=JSON.stringify(e);x.current!==t&&(localStorage.setItem(i,JSON.stringify(e)),M9(a,`PUT`,e).then(()=>{x.current=t,localStorage.removeItem(i)}).catch(()=>{}))},[a,i]),w=(0,W.useCallback)(async(e,t,n=``)=>{let r=await j9(`/api/repositories/inspect`,{repository_path:e,ref:t}),i=r.sources.find(e=>e.id===n)?.id||r.sources[0]?.id||``;return s(r.root),u(r),f(t),g(i),m(e=>e||r.current_ref||r.refs.find(e=>e.current)?.value||``),i&&C({repositoryPath:r.root,ref:t,sourceId:i}),r},[C]);(0,W.useEffect)(()=>{b(`connect`),M9(a,`GET`).then(e=>{if(e?.repositoryPath)return x.current=JSON.stringify(e),e;try{return JSON.parse(localStorage.getItem(i)||`null`)}catch{return null}}).then(e=>e?.repositoryPath?w(e.repositoryPath,e.ref||A9,e.sourceId):void 0).catch(e=>l.error(e.message)).finally(()=>b(null))},[w,a,i]),(0,W.useEffect)(()=>()=>Ni(),[]);let T=(0,W.useMemo)(()=>c?[{value:A9,label:`Working tree`},...c.refs.map(e=>({value:e.value,label:`${e.name}${e.current?` (current)`:``}`})),...c.commits.map(e=>({value:e.value,label:`${e.short} · ${e.subject}`}))]:[],[c]),E=c?.sources.find(e=>e.id===h),D=async()=>{if(o.trim()){b(`connect`),v([]);try{(await w(o.trim(),A9)).sources.length?l.success(`Repository connected`):l.info(`Repository connected, but no supported schema source was found`)}catch(e){l.error(e.message)}finally{b(null)}}},O=async e=>{if(c){b(`connect`),v([]);try{await w(c.root,e,h)}catch(e){l.error(e.message)}finally{b(null)}}},k=async e=>{if(!c||!h)throw Error(`Select a schema source first`);let[t]=await Promise.all([j9(`/api/repositories/read`,{repository_path:c.root,ref:e,source_id:h}),M()]),n=vke(t.source.kind,t.files);if(!n.nodes.length)throw Error(`No tables could be parsed from this schema source`);return{...t,...n}},A=async()=>{b(`preview`),v([]);try{let e=await k(d),r=k9(t,n,e.nodes,e.edges);v(e.warnings),Oi({proposedNodes:r.nodes,proposedEdges:r.edges,sourceLabel:P9(d,T),commit:e.commit,dbmlSource:e.dbml,canApply:!0}),C({repositoryPath:c.root,ref:d,sourceId:h}),l.info(`Repository schema preview opened on the canvas`)}catch(e){l.error(e.message)}finally{b(null)}},j=async()=>{if(p&&p!==d){b(`compare`),v([]);try{let[e,t]=await Promise.all([k(p),k(d)]),n=k9(e.nodes,e.edges,t.nodes,t.edges);v([...e.warnings,...t.warnings]),Oi({originalNodes:e.nodes,originalEdges:e.edges,proposedNodes:n.nodes,proposedEdges:n.edges,sourceLabel:`${P9(p,T)} → ${P9(d,T)}`,commit:t.commit,canApply:!1}),l.info(`Git ref comparison opened on the canvas`)}catch(e){l.error(e.message)}finally{b(null)}}},N=async()=>{let{open:e}=await _i(async()=>{let{open:e}=await Promise.resolve().then(()=>Yh);return{open:e}},void 0),t=await e({directory:!0,multiple:!1,title:`Select Git repository`});typeof t==`string`&&s(t)};return(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b p-4`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h2`,{className:`font-semibold`,children:`Repository Schema`}),(0,G.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:c?.root||`Link this ERD to a local Git repository`})]}),(0,G.jsx)(U,{variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>{Ni(),r()},"aria-label":`Close repository panel`,children:(0,G.jsx)(Pr,{className:`size-4`})})]}),(0,G.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto p-4`,children:[c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Schema source`}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,onClick:async()=>{try{await M9(a,`DELETE`),x.current=null,localStorage.removeItem(i),Ni(),u(null),g(``),v([])}catch(e){l.error(e.message)}},children:[(0,G.jsx)(Xo,{className:`size-3.5`}),`Disconnect`]})]}),(0,G.jsx)(N9,{label:`Git ref`,children:(0,G.jsx)($n,{value:d,onChange:e=>void O(e),items:T,disabled:y!==null,placeholder:`Select Git ref`,searchPlaceholder:`Search branch or commit...`,emptyMessage:`No Git ref found`,className:`h-9 text-sm`,getItemValue:e=>e.value,getItemLabel:e=>e.label,filterItem:(e,t)=>e.label.toLowerCase().includes(t.toLowerCase())})}),(0,G.jsx)(N9,{label:`Schema`,children:(0,G.jsxs)(_r,{value:h,disabled:y!==null||!c.sources.length,onValueChange:e=>{e&&(g(e),C({repositoryPath:c.root,ref:d,sourceId:e}))},children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{placeholder:`Select schema`,children:E?.label})}),(0,G.jsx)(pr,{children:c.sources.map(e=>(0,G.jsx)(fr,{value:e.id,children:e.label},e.id))})]})}),!c.sources.length&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Supported sources: Laravel migrations, DBML, and SQL schema/migration files.`}),(0,G.jsxs)(U,{className:`w-full`,disabled:!h||y!==null,onClick:()=>void A(),children:[y===`preview`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(cr,{className:`size-4`}),`Preview against current ERD`]})]}),(0,G.jsxs)(`section`,{className:`space-y-3 border-t pt-5`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Compare Git refs`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`Compare branches or commits without checking them out. This preview cannot modify the current ERD.`})]}),(0,G.jsx)(N9,{label:`Base ref`,children:(0,G.jsx)($n,{value:p,onChange:m,items:T.filter(e=>e.value!==A9),disabled:y!==null,placeholder:`Select base ref`,searchPlaceholder:`Search branch or commit...`,emptyMessage:`No Git ref found`,className:`h-9 text-sm`,getItemValue:e=>e.value,getItemLabel:e=>e.label,filterItem:(e,t)=>e.label.toLowerCase().includes(t.toLowerCase())})}),(0,G.jsxs)(U,{variant:`outline`,className:`w-full`,disabled:!h||!p||p===d||y!==null,onClick:()=>void j(),children:[y===`compare`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(ao,{className:`size-4`}),`Compare with selected ref`]})]})]}):(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-lg bg-muted`,children:(0,G.jsx)(ir,{className:`size-5 text-muted-foreground`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Connect a repository`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`Only supported schema files are read. The repository and active branch are never modified.`})]}),(0,G.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:`Repository path`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{value:o,onChange:e=>s(e.target.value),placeholder:`/path/to/project`,onKeyDown:e=>{e.key===`Enter`&&D()}}),S&&(0,G.jsx)(U,{variant:`outline`,size:`icon`,onClick:()=>void N(),"aria-label":`Browse repository`,children:(0,G.jsx)(no,{className:`size-4`})})]})]}),(0,G.jsxs)(U,{className:`w-full`,disabled:!o.trim()||y!==null,onClick:()=>void D(),children:[y===`connect`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(ir,{className:`size-4`}),`Connect repository`]})]}),_.length>0&&(0,G.jsxs)(`section`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(ei,{className:`size-4`}),_.length,` migration statement`,_.length===1?``:`s`,` need review`]}),(0,G.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted-foreground`,children:_.slice(0,8).map(e=>(0,G.jsx)(`li`,{className:`break-words`,children:e},e))})]})]})]})}function N9({label:e,children:t}){return(0,G.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:e}),t]})}function P9(e,t){return t.find(t=>t.value===e)?.label||e.slice(0,12)}function bke(e,t){switch(e){case`chat`:return t.aiChat;case`history`:return t.history;case`repository`:return t.repository;default:return!1}}var F9=`ERD Builder Pro`;function xke({pathname:e,activeFileName:t,breadcrumbLabel:n,featureLabel:r,searchFeature:i}){let a=e.replace(/\/+$/,``)||`/`;return/^\/(?:notes|diagrams|db-client|flowcharts|drawings)\/[^/]+$/.test(a)&&t?`${t} | ${F9}`:a===`/`?`Dashboard | ${F9}`:a===`/trash`?`Trash | ${F9}`:a===`/library`?`Library | ${F9}`:a===`/team-workspaces`?`Team Workspaces | ${F9}`:a===`/users`?`User Management | ${F9}`:a.startsWith(`/teams/`)?`${n||`Team management`} | ${F9}`:a.startsWith(`/projects/`)?`${n||`Project`} | ${F9}`:a.startsWith(`/notes/`)?`Notes | ${F9}`:a.startsWith(`/diagrams/`)?`${i===`db-client`?`DB Client`:`Diagram`} | ${F9}`:a.startsWith(`/db-client/`)?`${n||`DB Client`} | ${F9}`:a.startsWith(`/flowcharts/`)?`Flowchart | ${F9}`:a.startsWith(`/drawings/`)?`Drawing | ${F9}`:F9}var Ske={postgresql:`PostgreSQL`,mysql:`MySQL`,sqlite:`SQLite`},Cke={postgresql:`bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20`,mysql:`bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20`,sqlite:`bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/20`};function wke({account:e,catalogs:t,onEdit:n,onDelete:r,onTest:i,onAddCatalog:a,onImportCatalog:o,onDeleteCatalog:s,isTesting:c}){let[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),{id:p,name:m,type:h,host:g,port:_}=e,v=h===`sqlite`?g||`Local file`:g?`${g}:${_||``}`:`-`,y=e=>{e.stopPropagation(),u(!l)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rounded-lg border transition-colors hover:bg-accent/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 cursor-pointer`,onClick:y,children:[(0,G.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-full border bg-muted/50`,children:(0,G.jsx)(Mr,{className:`h-4 w-4 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`truncate pr-2 text-sm font-medium`,title:m,children:m}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] px-1.5 py-0 h-4 ${Cke[h]}`,children:Ske[h]}),(0,G.jsx)(Vh,{variant:`outline`,className:e.environment===`production`?`h-4 border-red-500/30 bg-red-500/10 px-1.5 py-0 text-[10px] uppercase text-red-600`:`h-4 px-1.5 py-0 text-[10px] uppercase`,children:e.environment||`development`}),e.safeMode===`read-only`&&(0,G.jsx)(Vh,{variant:`outline`,className:`h-4 border-emerald-500/30 bg-emerald-500/10 px-1.5 py-0 text-[10px] text-emerald-600`,children:`READ ONLY`}),e.sslMode&&e.sslMode!==`disable`&&(0,G.jsx)(Vh,{variant:`outline`,className:`h-4 px-1.5 py-0 text-[10px]`,children:`TLS`}),t.length>0&&(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] px-1.5 py-0 h-4 bg-muted`,children:h===`sqlite`?`1 DB`:`${t.length} DB`})]})]}),(0,G.jsx)(`div`,{className:`mt-2 truncate text-xs text-muted-foreground`,title:v,children:v})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-7 w-7`,onClick:y,children:l?(0,G.jsx)(Xt,{className:`h-3.5 w-3.5`}):(0,G.jsx)(St,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-7 w-7`}),onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Tr,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-36`,children:[(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),i(e)},disabled:c,className:`cursor-pointer`,children:[c?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,G.jsx)(ka,{className:`h-3.5 w-3.5 mr-2`}),`Test`]}),(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),n(e)},className:`cursor-pointer`,children:[(0,G.jsx)(ar,{className:`h-3.5 w-3.5 mr-2`}),`Edit`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),r(e)},className:`cursor-pointer text-destructive focus:text-destructive`,children:[(0,G.jsx)($r,{className:`h-3.5 w-3.5 mr-2`}),`Delete`]})]})]})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t px-3 py-2 space-y-1.5`,children:[t.length===0?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground py-1`,children:`No databases connected yet`}):(0,G.jsx)(jn,{className:`max-h-48`,children:t.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between rounded-md px-2 py-1.5 hover:bg-accent/50 group/cat`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(Cr,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs truncate`,children:e.label||e.databaseName}),e.label&&e.label!==e.databaseName&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.databaseName,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover/cat:opacity-100 transition-opacity`,children:[(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-6 w-6`,title:`Import as ERD`,onClick:t=>{t.stopPropagation(),o(e)},children:(0,G.jsx)(Cr,{className:`h-3 w-3`})}),(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-6 w-6 text-destructive hover:text-destructive`,title:`Disconnect database`,onClick:t=>{t.stopPropagation(),f(e)},children:(0,G.jsx)(Xo,{className:`h-3 w-3`})})]})]},e.id))}),h!==`sqlite`&&(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full h-7 text-xs justify-start text-muted-foreground hover:text-foreground`,onClick:t=>{t.stopPropagation(),a(e)},children:[(0,G.jsx)(jt,{className:`h-3 w-3 mr-1.5`}),`Add Database`]})]})]}),(0,G.jsx)(pi,{open:d!==null,onOpenChange:e=>!e&&f(null),children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(Xo,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Disconnect Database`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Disconnect `,(0,G.jsx)(`strong`,{children:d?.label||d?.databaseName}),`? ERD Builder files created from this database will also be deleted.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:()=>{d&&s(d),f(null)},children:`Disconnect`})]})]})})]})}var I9=`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,L9={local:`Local`,development:`Development`,staging:`Staging`,production:`Production`},R9={normal:`Normal`,protected:`Protected`,"read-only":`Read-only`},z9={disable:`Disable`,require:`Require`,"verify-ca":`Verify CA`,"verify-full":`Verify Full`};function Tke(e){return(0,G.jsxs)(`div`,{className:`space-y-3 rounded-lg border bg-muted/20 p-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Environment`}),(0,G.jsxs)(_r,{value:e.environment,onValueChange:t=>e.onEnvironmentChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:L9[e.environment]})}),(0,G.jsx)(pr,{children:Object.entries(L9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Safe Mode`}),(0,G.jsxs)(_r,{value:e.safeMode,onValueChange:t=>e.onSafeModeChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:R9[e.safeMode]})}),(0,G.jsx)(pr,{children:Object.entries(R9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`TLS / SSL`}),(0,G.jsxs)(_r,{value:e.sslMode,onValueChange:t=>e.onSslModeChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:z9[e.sslMode]})}),(0,G.jsx)(pr,{children:Object.entries(z9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Query timeout (ms)`}),(0,G.jsx)(wi,{type:`number`,min:1e3,max:6e5,value:e.queryTimeoutMs,onChange:t=>e.onQueryTimeoutChange(t.target.value)})]})]}),e.sslMode!==`disable`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(wi,{placeholder:`CA certificate path (optional)`,value:e.sslCa,onChange:t=>e.onSslCaChange(t.target.value)}),(0,G.jsx)(wi,{placeholder:`Client certificate path (optional)`,value:e.sslCert,onChange:t=>e.onSslCertChange(t.target.value)}),(0,G.jsx)(wi,{placeholder:`Client private key path (optional)`,value:e.sslKey,onChange:t=>e.onSslKeyChange(t.target.value)})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Protected and Production connections require the table name for destructive actions.`})]})}var B9=[{value:`postgresql`,label:`PostgreSQL`,defaultPort:5432},{value:`mysql`,label:`MySQL`,defaultPort:3306},{value:`sqlite`,label:`SQLite`,defaultPort:0}];function Eke({open:e,onOpenChange:t,editing:n,onSave:r,onTest:i,getDefaultPort:a,projects:o=[]}){let[s,c]=(0,W.useState)(n?.type||`postgresql`),[l,u]=(0,W.useState)(n?.name||``),[d,f]=(0,W.useState)(n?.host||``),[p,m]=(0,W.useState)(String(n?.port??a(s))),[h,g]=(0,W.useState)(n?.user||``),[_,v]=(0,W.useState)(``),[y,b]=(0,W.useState)(n?.environment||`development`),[x,S]=(0,W.useState)(n?.safeMode||`protected`),[C,w]=(0,W.useState)(n?.sslMode||`disable`),[T,E]=(0,W.useState)(n?.sslCa||``),[D,O]=(0,W.useState)(n?.sslCert||``),[k,A]=(0,W.useState)(n?.sslKey||``),[j,M]=(0,W.useState)(String(n?.queryTimeoutMs||3e4)),[N,P]=(0,W.useState)(``),[F,I]=(0,W.useState)(`none`),[L,R]=(0,W.useState)(!1),[ee,te]=(0,W.useState)(null),[ne,re]=(0,W.useState)(!1),ie=!!n;(0,W.useEffect)(()=>{e&&(n?(c(n.type),u(n.name),f(n.host||``),m(String(n.port??a(n.type))),g(n.user||``),v(``),b(n.environment||`development`),S(n.safeMode||`protected`),w(n.sslMode||`disable`),E(n.sslCa||``),O(n.sslCert||``),A(n.sslKey||``),M(String(n.queryTimeoutMs||3e4)),P(``),I(`none`)):(c(`postgresql`),u(``),f(`localhost`),m(`5432`),g(`postgres`),v(``),b(`development`),S(`protected`),w(`disable`),E(``),O(``),A(``),M(`30000`),P(``),I(`none`)),te(null))},[e,n,a]);let z=e=>{if(!e)return;let t=e;c(t),m(String(a(t))),t===`sqlite`?(f(``),g(``),v(``),P(l)):d||f(`localhost`),te(null)},ae=()=>({name:l,type:s,host:d,port:Number(p),user:h,password:_,database:s===`sqlite`?d:void 0,erdName:s===`sqlite`?N:void 0,projectId:s===`sqlite`?F:void 0,environment:y,safeMode:x,sslMode:C,sslCa:T||void 0,sslCert:D||void 0,sslKey:k||void 0,queryTimeoutMs:Number(j)||3e4}),oe=async()=>{try{let{open:e}=await _i(async()=>{let{open:e}=await Promise.resolve().then(()=>Yh);return{open:e}},void 0),t=await e({multiple:!1,filters:[{name:`SQLite database`,extensions:[`db`,`sqlite`,`sqlite3`]}]});typeof t==`string`&&(f(t),l.trim()||u(t.split(/[\\/]/).pop()?.replace(/\.(db|sqlite3?|sqlite)$/i,``)||`SQLite database`),N.trim()||P(t.split(/[\\/]/).pop()?.replace(/\.(db|sqlite3?|sqlite)$/i,``)||`SQLite ERD`))}catch{te({success:!1,message:`File picker is unavailable. Enter the SQLite file path manually.`})}},se=async()=>{R(!0),te(null);let e=await i(ae());te(e),R(!1)},ce=async()=>{if(!l.trim())return;re(!0);let e=await r(ae());re(!1),e&&t(!1)},le=s===`sqlite`;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-md`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:ie?`Edit Server Account`:`New Server Account`})}),(0,G.jsxs)(Wr,{className:`space-y-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Database Type`}),(0,G.jsxs)(_r,{value:s,onValueChange:z,children:[(0,G.jsx)(mr,{className:`h-10`,children:(0,G.jsx)(gr,{children:B9.find(e=>e.value===s)?.label||s})}),(0,G.jsx)(pr,{children:B9.map(e=>(0,G.jsx)(fr,{value:e.value,children:e.label},e.value))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Server Name`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`My Production DB`,value:l,onChange:e=>u(e.target.value)})]}),le?(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`SQLite File Path`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{className:`h-10`,placeholder:`/path/to/database.sqlite`,value:d,onChange:e=>f(e.target.value)}),(0,G.jsxs)(U,{type:`button`,variant:`outline`,className:`h-10 shrink-0`,onClick:oe,children:[(0,G.jsx)(Jn,{className:`mr-1.5 h-3.5 w-3.5`}),`Choose`]})]})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(jr,{className:`col-span-2`,children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Host`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`localhost`,value:d,onChange:e=>f(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Port`}),(0,G.jsx)(wi,{className:`h-10`,type:`number`,value:p,onChange:e=>m(e.target.value)})]})]}),!le&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`User`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:s===`postgresql`?`postgres`:`root`,value:h,onChange:e=>g(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Password`}),(0,G.jsx)(wi,{className:`h-10`,type:`password`,placeholder:ie?`(saved)`:`password`,value:_,onChange:e=>v(e.target.value)})]})]}),!le&&(0,G.jsx)(Tke,{environment:y,safeMode:x,sslMode:C,sslCa:T,sslCert:D,sslKey:k,queryTimeoutMs:j,onEnvironmentChange:b,onSafeModeChange:S,onSslModeChange:w,onSslCaChange:E,onSslCertChange:O,onSslKeyChange:A,onQueryTimeoutChange:M}),le&&!ie&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD New Name`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`SQLite ERD name`,value:N,onChange:e=>P(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Workspace`}),(0,G.jsx)($n,{value:F,onChange:I,items:[{id:`none`,name:`Uncategorized`},...o],placeholder:`Workspace (optional)`,searchPlaceholder:`Search workspace...`,emptyMessage:`No workspace found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]}),ee&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-sm ${ee.success?`border-green-500/20 bg-green-500/5 text-green-700 dark:text-green-400`:`border-red-500/20 bg-red-500/5 text-red-700 dark:text-red-400`}`,children:[ee.success?(0,G.jsx)(Rn,{className:`h-4 w-4 shrink-0`}):(0,G.jsx)(La,{className:`h-4 w-4 shrink-0`}),(0,G.jsx)(`span`,{children:ee.message})]})]}),(0,G.jsxs)(Gr,{className:`gap-2`,children:[(0,G.jsxs)(U,{variant:`outline`,className:`h-9`,onClick:se,disabled:L,children:[L?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}):null,`Test Connection`]}),(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`ghost`,className:`h-9`}),children:`Cancel`}),(0,G.jsxs)(U,{className:`h-9 px-6`,disabled:!l.trim()||le&&(!d.trim()||!ie&&!N.trim())||ne,onClick:ce,children:[ne?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}):null,ie?`Save`:`Create`]})]})]})})}var Dke={postgresql:5432,mysql:3306,sqlite:0};function Oke(){let{user:e,isGuest:t}=la(),[n,r]=(0,W.useState)([]),[i,a]=(0,W.useState)(!1),o=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),s=(0,W.useCallback)(async()=>{if(e&&!t&&o){a(!0);try{let e=await Si(`/api/accounts`);if(!e.ok)throw Error(`Failed to load accounts`);let t=await e.json();r(t)}catch(e){l.error(e.message||`Failed to load database accounts`)}finally{a(!1)}}},[e,t,o]);return(0,W.useEffect)(()=>{s()},[s]),{accounts:n,isLoading:i,fetchAccounts:s,createAccount:async e=>{try{let t=await Si(`/api/accounts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();throw Error(e.error||`Failed to save account`)}let n=await t.json();return r(e=>[n,...e]),l.success(`Server account saved`),n}catch(e){return l.error(e.message||`Failed to save account`),null}},updateAccount:async(e,t)=>{try{let n=await Si(`/api/accounts/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json();throw Error(e.error||`Failed to update account`)}let i=await n.json();return r(t=>t.map(t=>t.id===e?i:t)),l.success(`Account updated`),i}catch(e){return l.error(e.message||`Failed to update account`),null}},deleteAccount:async e=>{try{if(!(await Si(`/api/accounts/${e}`,{method:`DELETE`})).ok)throw Error(`Failed to delete account`);r(t=>t.filter(t=>t.id!==e)),l.success(`Account deleted`)}catch(e){l.error(e.message||`Failed to delete account`)}},listDatabases:async e=>{try{let t=await Si(`/api/accounts/${e}/databases`,{method:`POST`});if(!t.ok){let e=await t.json();throw Error(e.error||`Failed to list databases`)}return(await t.json()).databases||[]}catch(e){return l.error(e.message||`Failed to list databases`),[]}},createDatabase:async(e,t)=>{try{let n=await Si(`/api/accounts/${e}/databases/create`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json();throw Error(e.error||`Failed to create database`)}let r=await n.json();return l.success(`Database "${r.name}" created`),r}catch(e){return l.error(e.message||`Failed to create database`),null}},testAccount:async e=>{try{let t=await Si(`/api/accounts/${e}/test`,{method:`POST`}),n=await t.json();return!t.ok||!n.success?{success:!1,message:n.error||n.message||`Connection failed`}:{success:!0,message:n.message||`Connection successful`}}catch(e){return{success:!1,message:e.message||`Failed to test connection`}}},getDefaultPort:e=>Dke[e]}}function kke(e){let{user:t,isGuest:n}=la(),[r,i]=(0,W.useState)([]),[a,o]=(0,W.useState)(!1),s=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),c=(0,W.useCallback)(async()=>{if(s&&t&&!n){o(!0);try{let t=e?`?accountId=${e}`:``,n=await Si(`/api/catalogs${t}`);if(!n.ok)throw Error(`Failed to load catalog`);let r=await n.json();i(r)}catch(e){l.error(e.message||`Failed to load database catalogs`)}finally{o(!1)}}},[t,n,s,e]);return(0,W.useEffect)(()=>{c()},[c]),{catalogs:r,isLoading:a,fetchCatalogs:c,createCatalog:async(e,t,n)=>{try{let r=await Si(`/api/catalogs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:e,databaseName:t,label:n})});if(!r.ok){let e=await r.json();throw Error(e.error||`Failed to create catalog`)}let a=await r.json();return i(e=>[a,...e]),l.success(`Database "${t}" connected`),a}catch(e){return l.error(e.message||`Failed to connect database`),null}},deleteCatalog:async e=>{try{let t=await Si(`/api/catalogs/${e}`,{method:`DELETE`});if(!t.ok)throw Error(`Failed to delete catalog`);let n=await t.json();return i(t=>t.filter(t=>t.id!==e)),l.success(`Database disconnected`),n}catch(e){return l.error(e.message||`Failed to disconnect database`),null}},importAsDbClient:async(e,t,n)=>{try{let r=await Si(`/api/catalogs/${e}/import`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t,project_id:n??null})});if(!r.ok){let e=await r.json();throw Error(e.error||`Failed to import schema`)}let i=await r.json();return l.success(`Imported ${i.tableCount} tables as "${t}"`),i}catch(e){return l.error(e.message||`Failed to import schema`),null}},migrateOldConnections:async()=>{try{let e=await Si(`/api/migrate-connections`,{method:`POST`});if(!e.ok)throw Error(`Migration failed`);let t=await e.json();return t.migrated>0&&(l.success(`Migrated ${t.migrated} old connections`),c()),t.migrated||0}catch(e){return l.error(`Migration failed: `+e.message),0}}}}function V9({open:e,onOpenChange:t,projects:n,onImportComplete:r,defaultProjectId:i}){let{accounts:a,isLoading:o,createAccount:s,updateAccount:c,deleteAccount:u,listDatabases:d,createDatabase:f,testAccount:p,getDefaultPort:m,fetchAccounts:h}=Oke(),{catalogs:g,fetchCatalogs:_,createCatalog:v,deleteCatalog:y,importAsDbClient:b}=kke(),[x,S]=(0,W.useState)(``),[C,w]=(0,W.useState)(!1),[T,E]=(0,W.useState)(null),[D,O]=(0,W.useState)(null),[k,A]=(0,W.useState)(new Set),[j,M]=(0,W.useState)(null),[N,P]=(0,W.useState)([]),[F,I]=(0,W.useState)(!1),[L,R]=(0,W.useState)(`connect`),[ee,te]=(0,W.useState)(null),[ne,re]=(0,W.useState)(``),[ie,z]=(0,W.useState)(``),[ae,oe]=(0,W.useState)(!1),[se,ce]=(0,W.useState)(!1),[le,ue]=(0,W.useState)(``),[de,B]=(0,W.useState)(`none`),[fe,pe]=(0,W.useState)(null),[me,he]=(0,W.useState)(``),[ge,_e]=(0,W.useState)(!1),ve=x.trim()?a.filter(e=>e.name.toLowerCase().includes(x.toLowerCase())||e.type.toLowerCase().includes(x.toLowerCase())||e.host?.toLowerCase().includes(x.toLowerCase())):a,V=N.find(e=>e.name===ne),H=()=>{E(null),R(`import`),w(!0)},ye=e=>{E(e),R(`connect`),w(!0)},be=async e=>{let n=T?await c(T.id,e):await s(e);if(n&&!T){if(e.type===`sqlite`){let i=e.database?.trim()||e.host.trim(),a=await v(n.id,i,n.name);if(a){_(),h();let i=e.projectId===`none`?null:e.projectId,o=await b(a.id,e.erdName?.trim()||n.name,i);o?.dbClient?.uid&&(t(!1),r?.(o.dbClient.uid))}}else setTimeout(()=>we(n,`import`),0)}return n},xe=async e=>{try{let{apiFetch:t}=await _i(async()=>{let{apiFetch:e}=await import(`./api-DuV0sTuY.js`).then(e=>e.r);return{apiFetch:e}},__vite__mapDeps([16,5,10])),n=await t(`/api/accounts/test-cred`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),r=await n.json();return!n.ok||!r.success?{success:!1,message:r.error||r.message||`Connection failed`}:{success:!0,message:r.message||`Connection successful`}}catch(e){return{success:!1,message:e.message||`Failed to test connection`}}},Se=async e=>{A(t=>new Set(t).add(e.id));let t=await p(e.id);A(t=>{let n=new Set(t);return n.delete(e.id),n}),t.success?(l.success(t.message),h()):l.error(t.message)},Ce=async()=>{D&&(await u(D.id),O(null))},we=async(e,t=`connect`)=>{R(t),I(!0),M(e),P([]),re(``),z(``),oe(!1),ue(``),B(i??`none`);let n=await d(e.id);P(n),I(!1)},Te=e=>{re(e),le.trim()&&le!==ne||ue(e)},Ee=async()=>{if(j&&ie.trim()){ce(!0);try{let e=await f(j.id,ie.trim());if(!e)return;P(t=>[...t.filter(t=>t.name!==e.name),e].sort((e,t)=>e.name.localeCompare(t.name))),z(``),oe(!1),Te(e.name)}finally{ce(!1)}}},De=async()=>{if(!j||!ne)return;te(ne);let e=g.find(e=>e.accountId===j.id&&e.databaseName===ne)||await v(j.id,ne);if(e&&(M(null),_(),h(),L===`import`)){let n=de===`none`?null:de,i=await b(e.id,le.trim()||ne,n);i?.dbClient?.uid&&(t(!1),r?.(i.dbClient.uid))}te(null)},Oe=e=>{he(e.label||e.databaseName),B(i??`none`),pe(e)},ke=async()=>{if(fe&&me.trim()&&de!==`none`){_e(!0);try{let e=de===`none`?null:de,n=await b(fe.id,me.trim(),e);n?.dbClient?.uid&&(pe(null),he(``),t(!1),r?.(n.dbClient.uid))}finally{_e(!1)}}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(vh,{open:e,onOpenChange:t,children:(0,G.jsxs)(yh,{side:`right`,className:`w-full p-0 flex flex-col gap-0 sm:w-[min(42rem,calc(100vw-2rem))] sm:max-w-none`,children:[(0,G.jsxs)(bh,{className:`p-5 pb-3 sm:p-6 sm:pb-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pr-10`,children:[(0,G.jsx)(xh,{className:`text-lg`,children:`Database Accounts`}),(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] h-4 px-1.5 text-amber-600 border-amber-400 dark:text-amber-400 dark:border-amber-500`,children:`Experimental`})]}),(0,G.jsx)(Sh,{className:`max-w-xl leading-relaxed`,children:`Create DB clients from external databases and local SQLite files`})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 py-3 sm:flex-row sm:px-6`,children:[(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Zr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(wi,{className:`pl-8`,placeholder:`Search accounts...`,value:x,onChange:e=>S(e.target.value)})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(U,{size:`lg`,className:`w-full shrink-0 sm:w-auto`,onClick:H,children:[(0,G.jsx)(jt,{className:`h-3.5 w-3.5 mr-1`}),`New DB Client`]})})]}),(0,G.jsx)(jn,{className:`min-h-0 flex-1 px-5 pb-5 sm:px-6 sm:pb-6`,children:o?(0,G.jsx)(`div`,{className:`space-y-2 pt-2`,children:[1,2,3].map(e=>(0,G.jsx)(Ei,{className:`h-16 w-full rounded-lg`},e))}):ve.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center pt-12 text-center`,children:[(0,G.jsx)(Mr,{className:`h-10 w-10 text-muted-foreground/40 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:x.trim()?`No accounts found`:`No database accounts yet`}),!x.trim()&&(0,G.jsxs)(U,{variant:`outline`,size:`sm`,className:`mt-3`,onClick:H,children:[(0,G.jsx)(jt,{className:`h-3.5 w-3.5 mr-1.5`}),`New DB Client`]})]}):(0,G.jsx)(`div`,{className:`space-y-2 pt-2`,children:ve.map(e=>(0,G.jsx)(wke,{account:e,catalogs:g.filter(t=>t.accountId===e.id),onEdit:ye,onDelete:O,onTest:Se,onAddCatalog:e=>we(e,`import`),onImportCatalog:Oe,onDeleteCatalog:async e=>{let t=await y(e.id);_(),h(),t&&t.deletedClients>0&&l.info(`${t.deletedClients} DB Client(s) deleted: ${t.clientNames.join(`, `)}`,{duration:5e3})},isTesting:k.has(e.id)},e.id))})})]})}),(0,G.jsx)(Eke,{open:C,onOpenChange:w,editing:T,onSave:be,onTest:xe,getDefaultPort:m,projects:n}),(0,G.jsx)(pi,{open:D!==null,onOpenChange:e=>!e&&O(null),children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-100`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)($r,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Delete Account`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Delete server account `,(0,G.jsx)(`strong`,{children:D?.name}),`? All connected databases (`,g.filter(e=>e.accountId===D?.id).length,`) will be disconnected. Diagrams using these databases still exist, but can no longer sync.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})}),(0,G.jsx)(pi,{open:j!==null,onOpenChange:e=>!e&&M(null),children:(0,G.jsxs)(ni,{children:[(0,G.jsx)(ii,{children:(0,G.jsx)(mi,{children:L===`import`?`Create DB Client`:`Select Database`})}),(0,G.jsx)(di,{children:F?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,G.jsx)(xo,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Production Database`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,G.jsx)($n,{value:ne,onChange:Te,items:N,placeholder:`Select production database`,searchPlaceholder:`Search database...`,emptyMessage:`No database found`,getItemValue:e=>e.name,getItemLabel:e=>e.isConnected?`${e.name} (connected)`:e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`}),j?.type===`sqlite`?null:(0,G.jsx)(U,{type:`button`,variant:`outline`,size:`icon-sm`,className:`h-9 w-9`,onClick:()=>oe(e=>!e),title:`Create database`,children:(0,G.jsx)(jt,{className:`h-3.5 w-3.5`})})]})]}),ae&&j?.type!==`sqlite`&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New Database`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,G.jsx)(wi,{value:ie,onChange:e=>z(e.target.value),placeholder:`new_database`,className:`h-9`,onKeyDown:e=>{e.key===`Enter`&&ie.trim()&&!se&&Ee()}}),(0,G.jsx)(U,{type:`button`,className:`h-9`,onClick:Ee,disabled:!ie.trim()||se,children:se?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 animate-spin`}):`Create`})]})]}),L===`import`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD File Name`}),(0,G.jsx)(wi,{value:le,onChange:e=>ue(e.target.value),placeholder:`ERD file name`,className:`h-9`,onKeyDown:e=>{e.key===`Enter`&&ne&&le.trim()&&!ee&&De()}})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsx)($n,{value:de,onChange:B,items:n,placeholder:`Select project`,searchPlaceholder:`Search project...`,emptyMessage:`No project found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]})]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),N.length>0&&(0,G.jsx)(ci,{onClick:De,disabled:!ne||L===`connect`&&V?.isConnected||L===`import`&&(!le.trim()||de===`none`)||ee!==null,children:ee?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}),`Creating...`]}):L===`import`?`Create DB Client`:`Connect`})]})]})}),(0,G.jsx)(pi,{open:fe!==null,onOpenChange:e=>!e&&pe(null),children:(0,G.jsxs)(ni,{children:[(0,G.jsx)(ii,{children:(0,G.jsx)(mi,{children:`Import as ERD Diagram`})}),(0,G.jsxs)(di,{children:[(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:[`Create a new ERD diagram from `,(0,G.jsx)(`strong`,{children:fe?.label||fe?.databaseName}),` tables.`]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD File Name`}),(0,G.jsx)(wi,{value:me,onChange:e=>he(e.target.value),placeholder:`Diagram name`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&me.trim()&&!ge&&ke()}})]}),(0,G.jsxs)(jr,{className:`mt-3`,children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsx)($n,{value:de,onChange:B,items:n,placeholder:`Select project`,searchPlaceholder:`Search project...`,emptyMessage:`No project found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{onClick:ke,disabled:!me.trim()||de===`none`||ge,children:ge?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}),`Importing...`]}):`Import`})]})]})})]})}function Ake({root:e,session:t,mainAI:n,paired:r,onPairChange:i,onFocusedSession:a}){let o=m(),s=v(),[c,u]=(0,W.useState)(null),f=(0,W.useRef)(null),h=(0,W.useCallback)(e=>f.current?.(e),[]),[_]=g(),[y,b]=(0,W.useState)(!1),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(null),[T,D]=(0,W.useState)(null),{rightPanelMode:O,setRightPanelMode:k,pendingPrompt:A,clearPrompt:j,pendingAction:M,clearPendingAction:N}=bn(),P=(0,W.useMemo)(()=>{let e=(t?z(t.file).split(`?`)[0]:o.pathname).match(/^\/(notes|diagrams|flowcharts|drawings|db-client)\/([^/]+)$/);return e?{entityType:{notes:`note`,diagrams:`diagram`,flowcharts:`flowchart`,drawings:`drawing`,"db-client":`dbClient`}[e[1]],entityUid:e[2]}:null},[o.pathname,t?.file.type,t?.file.uid]),F=P?.entityType===`diagram`,I=P?.entityType===`diagram`?`diagrams`:P?.entityType===`flowchart`?`flowcharts`:P?.entityType===`note`?`notes`:P?.entityType===`drawing`?`drawings`:null;(0,W.useEffect)(()=>{if(P?.entityType!==`dbClient`){D(null);return}D(null);let e=!1;return Si(`/api/db-clients/${encodeURIComponent(P.entityUid)}`).then(e=>e.ok?e.json():null).then(t=>{e||D(t)}).catch(()=>{e||D(null)}),()=>{e=!0}},[P,e.user?.id]);let{view:L,sidebarView:R,isPublicView:ee,isOnline:te,projects:ne,user:re,isProjectsLoading:ie,handleLogout:ae,handleViewChange:oe,handleNoteSelect:se,handleDrawingSelect:ce,refreshActiveDocument:le,handleSidebarProjectCreate:ue,handleSidebarProjectUpdate:de,handleSidebarProjectDelete:B,handleWorkspaceFilter:fe,selectedWorkspaceUid:me,handleHeaderDelete:he,handleHeaderRename:ge,handleHeaderSettingsSaved:_e,handleHeaderExportSQL:ve,handleHeaderExportImage:V,handleOpenImportModal:H,isImportModalOpen:ye,setIsImportModalOpen:be,handleExportMarkdown:xe,handleCopyMarkdown:Se,handleImportMarkdown:Ce,executeImportMarkdown:we,executeExportMarkdown:Te,handleDuplicate:Ee,syncError:De,isSyncing:Oe,isLocalSaving:ke,isRefreshing:Ae,hasPendingSyncs:je,syncDrafts:U,activeFileUid:Me,currentActiveId:Ne,initialShareSettings:Pe,activeDocument:Fe,isGuest:Ie,isReadOnlyFile:Le,getFileAccessRole:Re,featureLabel:ze,activeProjectName:Be,activeFileName:Ve,hasActiveItem:He,activeNote:Ue,activeDrawing:We,activeFlowchart:Ge,activeDiagram:Ke,notes:qe,diagrams:Je,flowcharts:Ye,drawings:Xe,setNodes:Ze,setEdges:Qe,activeDiagramId:$e,takeSnapshot:et,saveDiagram:tt,triggerDebouncedSync:nt,broadcastMessage:rt,setIsLocalSaving:it,viewportRef:at,lastLoadedDiagramIdRef:ot,fetchTrash:st,triggerTableRefresh:ct,setTableLoadingState:lt,setIsSettingsOpen:ut,setSettingsTab:dt,selectedNodeId:ft,setSelectedNodeId:pt,selectedEdgeId:mt,setSelectedEdgeId:ht,selectedEntity:gt,deleteEntity:_t,deleteEdge:vt,updateDiagram:yt,updateNote:bt,updateDrawing:xt,updateFlowchart:St,moveDiagramToProject:Ct,moveNoteToProject:wt,moveDrawingToProject:Tt,moveFlowchartToProject:Et,deleteDiagram:Dt,deleteNote:Ot,deleteDrawing:kt,deleteFlowchart:At,handleSidebarDiagramCreate:jt,handleSidebarNoteCreate:Mt,handleSidebarDrawingCreate:Nt,handleSidebarFlowchartCreate:Pt,isMoveToTrashAlertOpen:Ft,setIsMoveToTrashAlertOpen:It,isDeleteAlertOpen:Lt,setIsDeleteAlertOpen:Rt,isRenameDialogOpen:zt,setIsRenameDialogOpen:Bt,isDuplicateDialogOpen:Vt,setIsDuplicateDialogOpen:Ht,isPermanentDeleteConfirmOpen:Ut,setIsPermanentDeleteConfirmOpen:Wt,isImportNoteModalOpen:Gt,setIsImportNoteModalOpen:Kt,isExportNoteModalOpen:qt,setIsExportNoteModalOpen:Jt,newName:Yt,setNewName:Xt,renameProjectId:Zt,setRenameProjectId:Qt,duplicateName:$t,setDuplicateName:en,itemToDelete:tn,createDialogOpen:nn,setCreateDialogOpen:rn,createDialogView:an,setCreateDialogView:on,editDialogNote:sn,setEditDialogNote:cn,tableDeleteDoc:ln,setTableDeleteDoc:un,executeDuplicate:dn,confirmPermanentDelete:fn,handleEdgeUpdate:pn,handleEdgeFlip:mn,breadcrumbLabel:hn,refreshTeamScope:gn,flushPendingSaves:_n,teamScopeVersion:vn,isTeamScopeRefreshing:yn}=pa(),{nodes:xn,edges:Sn}=ta(),[Cn,wn]=(0,W.useState)(``),[Tn,En]=(0,W.useState)([]),[Dn,On]=(0,W.useState)(!1),[kn,An]=(0,W.useState)([]);re?.isSuperAdmin||re?.is_super_admin;let jn=re?.isSso?re.ssoPortalUrl??re.sso_portal_url:null;(0,W.useEffect)(()=>{Zi(jn)},[jn]);let Mn=(0,W.useCallback)(()=>{wn(``),En([]),An([]),k(`closed`),_n().catch(()=>{}),gn()},[_n,gn,k]),Nn=ua(Ie,!!re?.isSso,Mn),[Pn,Fn]=(0,W.useState)(!1),In=Gi(re,Nn.activeTeam,Nn.activeTeamId,Nn.isAvailable),Ln=Wi.filter(e=>e.value!==`db-client`||yi()).map(e=>({...e,locked:e.value!==`db-client`&&In(e.capability)}));(0,W.useEffect)(()=>{if(Ie){An([]);return}let e=!1;return Si(`/api/projects/selectable`).then(e=>e.ok?e.json():{data:[]}).then(t=>{e||An(Array.isArray(t.data)?t.data:[])}).catch(()=>{e||An([])}),()=>{e=!0}},[nn,Ie,zt,Nn.activeTeamId]);let Rn=(0,W.useRef)(!1),zn=(0,W.useCallback)(async e=>{if(!(Rn.current||e===Nn.activeTeamId)){Rn.current=!0;try{await JC(_n,U,{type:L,id:Ne,uid:Me}),Nn.selectTeam(e),wn(``),En([]),k(`closed`),await gn()}catch{l.error(`Could not switch workspaces. Check that your changes are saved and retry.`)}finally{Rn.current=!1}}},[Me,Ne,_n,gn,k,U,Nn.activeTeamId,Nn.selectTeam,L]),Bn=(0,W.useCallback)(async e=>(await JC(_n,U,{type:L,id:Ne,uid:Me}),Nn.createTeam(e)),[Me,Ne,_n,U,Nn.createTeam,L]),Vn=(0,W.useCallback)(e=>{e.manageUrl?window.location.assign(e.manageUrl):s(`/teams/${e.id}`)},[s]),Hn=(0,W.useCallback)(async e=>{await gn(),s(`/teams/${e.id}`)},[s,gn]);o.pathname===`/table/db-client`||o.pathname.startsWith(`/db-client/`)||o.pathname.startsWith(`/diagrams/`)&&_.get(`feature`)===`db-client`||/^\/(table\/(erd|notes|drawings|flowchart)|(notes|diagrams|drawings|flowcharts)\/)/.test(o.pathname),(0,W.useEffect)(()=>{let e=Cn.trim();if(e.length<2){En([]),On(!1);return}let t=!1,n=window.setTimeout(async()=>{On(!0);try{if(Ie){let n=e.toLowerCase(),r=new Map(ne.map(e=>[String(e.id),e])),i=[...Je.filter(e=>(e.source_type??e.sourceType)!==`production_db`).map(e=>({...e,type:`erd`,name:e.name})),...qe.map(e=>({...e,type:`notes`,name:e.title})),...Xe.map(e=>({...e,type:`drawings`,name:e.title})),...Ye.map(e=>({...e,type:`flowchart`,name:e.title}))],a=[...ne.filter(e=>e.name?.toLowerCase().includes(n)).map(e=>({...e,type:`workspace`})),...i.filter(e=>e.name?.toLowerCase().includes(n)).map(e=>({...e,workspace:r.get(String(e.project_id))}))].slice(0,20);t||En(a);return}let n=await Si(`/api/search?q=${encodeURIComponent(e)}`),r=n.ok?await n.json():{data:[]};t||En(Array.isArray(r.data)?r.data:[])}catch{t||En([])}finally{t||On(!1)}},220);return()=>{t=!0,window.clearTimeout(n)}},[Cn,Ie,ne,Je,qe,Xe,Ye]);let Un=(0,W.useCallback)(e=>{if(wn(``),e.type===`workspace`){oe(`erd`,!0,e.uid??e.id);return}let t=e.uid??e.id,n={erd:`/diagrams/${t}`,"db-client":`/db-client/${t}`,notes:`/notes/${t}`,drawings:`/drawings/${t}`,flowchart:`/flowcharts/${t}`}[e.type];n&&s(n)},[oe,s]),Wn=F&&(Ke?.source_type??Ke?.sourceType)===`production_db`,Gn=!Le(Fe),Kn=Ui(Fe,re?.id,Ie)&&Gn,qn=Kn,Jn=Re(Fe),Yn=ln??Fe,Xn=(Yn?.source_type??Yn?.sourceType)===`production_db`,Zn=(0,W.useMemo)(()=>{let e=P;if(!e)return null;switch(e.entityType){case`note`:return Ue?W6(`note`,{title:Ue.title,content:E(String(Ue.content||``))}):null;case`diagram`:if(!Ke||O!==`chat`)return null;let e=W6(`diagram`,{title:Ke.name,nodes:xn,edges:Sn});return(Ke.source_type??Ke.sourceType)===`production_db`?`[Current feature: DB Client]\nSource: live production database metadata\nCurrent tab: ${_.get(`tab`)||`data`}\n\n${e||``}`:e;case`flowchart`:if(!Ge)return null;let t=[],n=[];try{let e=JSON.parse(Ge.data||`{}`);t=e.nodes&&e.nodes.length>0?e.nodes:sa,n=e.edges&&e.edges.length>0?e.edges:Ji}catch{t=sa,n=Ji}return W6(`flowchart`,{title:Ge.title,nodes:t,edges:n});case`drawing`:return We?W6(`drawing`,{title:We.title}):null;default:return null}},[P,Ue,Ke,Ge,We,xn,Sn,_,O]),Qn=P?.entityType===`dbClient`||F&&(Ke?.source_type??Ke?.sourceType)===`production_db`,$n=(0,W.useMemo)(()=>re?.isSso&&Nn.activeTeam?.capabilities?.ai_assistant!==!0||P===null||ee||!Gn||P.entityType===`drawing`?!1:Qn?!0:(_.get(`tab`)||`erd`)===`erd`,[P,ee,Gn,Qn,_,Nn.activeTeam,re?.isSso]),er=(0,W.useMemo)(()=>{let e=P?.entityType===`dbClient`?T:Ue||Ke||Ge||We;return e?.project_id??e?.projectId??null},[P,T,Ue,Ke,Ge,We]),tr=(0,W.useMemo)(()=>{if(ee||Ie||!P||!Ve||Qn)return null;let e=P.entityType===`diagram`?`diagram`:P.entityType===`note`?`note`:P.entityType===`drawing`?`drawing`:P.entityType===`flowchart`?`flowchart`:null,t=Me||Ne||P.entityUid;return e&&t?{featureType:e,fileId:String(t),label:Ve}:null},[Ve,Me,Ne,P,Qn,Ie,ee]),nr=ne.find(e=>String(e.id)===String(er)),rr=nr?.team_id??nr?.teamId,ir=tr&&!ee&&!Ie&&rr&&String(rr)===String(Nn.activeTeamId)?String(Nn.activeTeamId):void 0,ar=(0,W.useMemo)(()=>mt&&Sn.some(e=>e.id===mt)?{type:`relationship`,id:mt}:ft&&xn.some(e=>e.id===ft)?{type:`table`,id:ft}:null,[Sn,xn,mt,ft]),or=(0,W.useCallback)((e,t)=>{window.dispatchEvent(new CustomEvent(`erd-discussion-anchor-selected`,{detail:{type:e,id:t}}))},[]),sr=(0,W.useCallback)(e=>{if(!tr)return;if(e.featureType===tr.featureType&&String(e.fileId)===tr.fileId){e.featureType===`diagram`&&e.anchorType!==`general`&&e.anchorId&&or(e.anchorType,e.anchorId);return}let t={diagram:Je,note:qe,drawing:Xe,flowchart:Ye}[e.featureType]?.find(t=>String(t.uid??t.id)===String(e.fileId)||String(t.id)===String(e.fileId));t&&(s(`${{diagram:`/diagrams`,note:`/notes`,drawing:`/drawings`,flowchart:`/flowcharts`}[e.featureType]}/${t.uid??t.id}`),e.featureType===`diagram`&&e.anchorType!==`general`&&e.anchorId&&window.setTimeout(()=>or(e.anchorType,e.anchorId),0))},[Je,tr,Ye,or,s,qe,Xe]),cr=(0,W.useCallback)(e=>Ki(Ue?.content,e),[Ue?.content]),lr=er&&tr&&ir?(0,G.jsx)(Vw,{projectId:String(er),teamId:ir,userId:re?.id?String(re.id):void 0,userName:re?.name||re?.email,fileContext:tr,anchorContext:ar,readOnly:Jn===`viewer`,onContextSelected:sr,anchorPreview:tr.featureType===`note`?cr:void 0},`${ir}:${er}:${tr.featureType}:${tr.fileId}`):null;(0,W.useEffect)(()=>{document.title=xke({pathname:o.pathname,activeFileName:Ve,breadcrumbLabel:hn,featureLabel:ze,searchFeature:_.get(`feature`)})},[Ve,ze,hn,o.pathname,_]),(0,W.useEffect)(()=>{if(typeof window>`u`||!(window.__TAURI__||window.__TAURI_INTERNALS__))return;let e=e=>{let t=e.target;(!t||t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&!t.isContentEditable)&&(navigator.platform.toLowerCase().includes(`mac`)?e.metaKey:e.ctrlKey)&&e.key===`,`&&(e.preventDefault(),ut(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ut]);let ur=bke(O,{aiChat:$n,history:!!(I&&P),repository:F&&!Wn}),dr=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent),fr=(0,W.useMemo)(()=>({label:dr?`⌘J`:`Ctrl+J`,ariaKeyShortcuts:dr?`Meta+J`:`Control+J`}),[dr]),[pr,mr]=(0,W.useState)(!1),hr=(0,W.useCallback)(()=>k(O===`chat`?`closed`:`chat`),[O,k]),gr=$n&&(!!Fe||Qn||O===`chat`);(0,W.useEffect)(()=>{if(!gr)return;let e=e=>{!(dr?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)||e.shiftKey||e.altKey||e.isComposing||e.defaultPrevented||e.key.toLowerCase()!==`j`||(e.preventDefault(),hr())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[gr,hr,dr]);let _r=(0,W.useCallback)((...e)=>(O===`repository`&&(Ni(),k(`closed`)),oe(...e)),[oe,O,k]);return(0,W.useEffect)(()=>{(!P||O===`chat`&&!$n)&&k(`closed`)},[P,O,$n,k]),(0,W.useEffect)(()=>{O===`repository`&&(!F||Wn)&&k(`closed`)},[O,F,Wn,k]),(0,G.jsxs)(G.Fragment,{children:[!te&&!ee&&(0,G.jsx)(ZTe,{}),!ee&&(0,G.jsx)(GT,{globalSearchResults:Tn,isGlobalSearchLoading:Dn,onGlobalSearchResultSelect:Un,projects:ne,onViewChange:_r,onProjectCreate:ue,onProjectUpdate:de,onProjectDelete:B,onLogout:ae,selectedWorkspaceUid:me,globalSearchQuery:Cn,onGlobalSearchChange:wn,user:re,isOnline:te,isProjectsLoading:ie,onOpenFeedback:()=>b(!0),teams:Nn.teams,teamsAvailable:Nn.isAvailable,licenseRequired:Nn.licenseRequired,activeTeamId:Nn.activeTeamId,onTeamsRefresh:()=>{Nn.fetchTeams()},onTeamSelect:zn,onTeamManage:Vn,onTeamCreate:Bn,onTeamCreated:Hn,onOpenLicenseSettings:()=>{dt(`license`),ut(!0)},ssoPortalUrl:re?.isSso?re.ssoPortalUrl??re.sso_portal_url:null}),(0,G.jsx)(jC.Provider,{value:c,children:(0,G.jsxs)(rne,{className:d(ee?`w-full`:``),children:[(0,G.jsx)(pe.Provider,{value:t?.scope??null,children:(0,G.jsx)(YT,{tabsRef:u,documentPath:t?z(t.file).split(`?`)[0]:void 0,sidebarDisabled:r,featureLabel:ze,activeProjectName:P?.entityType===`dbClient`?T?.project?.name:Be,activeFileName:P?.entityType===`dbClient`?hn||``:Ve,view:L,hasActiveItem:ee?!0:He,syncError:De,isSyncing:Oe,isLocalSaving:ke,isRefreshing:Ae,hasPendingSyncs:je,onSave:U,activeFileUid:Me,activeFileId:Ne,initialShareSettings:Pe,isPublicView:ee,onSettingsSaved:_e,isOnline:te,updatedAt:Fe?.updated_at,onDelete:Kn?he:void 0,onRename:Gn?ge:void 0,canManage:qn,onRefresh:le,onExportAll:Wn?void 0:()=>S(!0),onExportSQL:ve,onExportImage:V,onExportMarkdown:xe,onCopyMarkdown:Se,onImportMarkdown:Gn?Ce:void 0,onDuplicate:Ee,isGuest:Ie,breadcrumbLabel:hn,noteContent:Ue?.content,historyAvailable:!!I,discussionPanel:t?(0,G.jsx)(`span`,{ref:w,className:`contents`}):lr,aiAssistant:gr?{open:O===`chat`,answering:pr,onToggle:hr,shortcut:fr}:void 0})}),(0,G.jsx)(`div`,{className:`relative flex flex-1 flex-col gap-4 p-4 pt-4 min-h-0 overflow-hidden`,style:{isolation:`isolate`},children:yn?(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center rounded-xl border bg-muted/10`,role:`status`,"aria-live":`polite`,children:[(0,G.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),(0,G.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground`,children:`Loading workspace…`})]}):(0,G.jsx)(uT,{root:e,mainAI:n,teamState:Nn,discussionTarget:C,onFocusedSession:a,onPairChange:i,paneAIRef:f,children:(0,G.jsx)(p,{context:Nn},vn)})}),(0,G.jsx)(vE,{isOpen:Gt,onClose:()=>Kt(!1),onImport:we}),(0,G.jsx)(yE,{isOpen:qt,onClose:()=>Jt(!1),onExport:(e,t,n)=>{Ue&&(e===`markdown`?Te():e===`pdf`?B6.exportToPDF(Ue,t,n,Be||void 0):e===`print`?B6.printNote(Ue,t,Be||void 0):e===`word`&&B6.exportToWord(Ue,t,Be||void 0))}}),(0,G.jsx)(eE,{open:y,onOpenChange:b,isCloud:!!re?.isSso}),re?.isSso&&Nn.activeTeamId&&!ee&&(0,G.jsx)(iE,{teamId:Nn.activeTeamId}),(0,G.jsx)(AT,{isOpen:Ut,onOpenChange:Wt,mode:`permanent-delete`,itemType:tn?.type||``,onConfirm:fn,onAfterDelete:void 0}),!ee&&(0,G.jsx)(sE,{isOpen:zt,onOpenChange:e=>{Bt(e),e||cn(null)},view:L,activeDocument:sn??Fe,canMoveProject:Ui(sn??Fe,re?.id,Ie),newName:Yt,setNewName:Xt,projects:kn,requireProject:!0,selectedProjectId:Zt,setSelectedProjectId:Qt,updateDiagram:yt,updateNote:bt,updateDrawing:xt,updateFlowchart:St,onMoveDiagramToProject:Ct,onMoveNoteToProject:wt,onMoveDrawingToProject:Tt,onMoveFlowchartToProject:Et,onRenameSuccess:void 0}),!ee&&(0,G.jsx)(sE,{isOpen:nn,onOpenChange:e=>{rn(e)},mode:`create`,view:an,activeDocument:null,newName:Yt,setNewName:Xt,projects:kn,requireProject:!0,selectedProjectId:Zt,setSelectedProjectId:Qt,onProjectCreate:async e=>{let t=await ue(e);return t&&An(e=>[t,...e.filter(e=>String(e.id)!==String(t.id))]),t},fileTypes:Ln,onViewChange:on,onViewPlans:()=>Yi(jn),onOpenDbConnections:()=>Fn(!0),onCreate:(e,t)=>{let n=an;return n===`notes`?Mt(e,t):n===`erd`?jt(e,t):n===`drawings`?Nt(e,t):n===`flowchart`?Pt(e,t):null},onRenameSuccess:void 0}),yi()&&(0,G.jsx)(V9,{open:Pn,onOpenChange:Fn,projects:ne,defaultProjectId:ne.find(e=>e.uid===me)?.id?.toString()??null,onImportComplete:e=>s(`/db-client/${e}`)}),(0,G.jsx)(AT,{isOpen:Ft,onOpenChange:e=>{It(e),e||un(null)},activeDocument:Yn,view:L,deleteDiagram:Dt,deleteNote:Ot,deleteDrawing:kt,deleteFlowchart:At,fetchTrash:st,onAfterDelete:()=>{un(null),Xn?s(`/table/db-client`,{replace:!0}):oe(L,!0),lt(`loading`),ct()}}),!ee&&(0,G.jsx)(hE,{isOpen:!!mt&&!(F&&Gn&&!Wn),onOpenChange:e=>{e||ht(null)},selectedEdge:Sn.find(e=>e.id===mt)||null,nodes:xn,handleEdgeUpdate:pn,handleEdgeFlip:mn,deleteEdge:vt,moveOnly:Wn,readOnly:!Gn}),(0,G.jsx)(aE,{isOpen:Lt,onOpenChange:Rt,selectedEntity:gt,deleteEntity:_t,setSelectedNodeId:pt}),(0,G.jsx)(cE,{isOpen:Vt,onOpenChange:Ht,view:L,duplicateName:$t,setDuplicateName:en,executeDuplicate:dn,isRefreshing:Ae}),L===`erd`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(fE,{open:x,onOpenChange:S,nodes:xn,edges:Sn,fileName:Ve||`Untitled`}),(0,G.jsx)(mE,{isOpen:ye,onOpenChange:be,nodes:xn,edges:Sn,setNodes:Ze,setEdges:Qe,activeDiagramId:$e,takeSnapshot:et,saveDiagram:tt,triggerDebouncedSync:nt,broadcastMessage:rt,setIsLocalSaving:it,viewportRef:at,lastLoadedDiagramIdRef:ot})]}),(ur||$n)&&(0,G.jsxs)(QTe,{open:ur,children:[O===`repository`&&P?.entityType===`diagram`?(0,G.jsx)(yke,{diagramUid:P.entityUid,nodes:xn,edges:Sn,onClose:()=>k(`closed`)},P.entityUid):O===`history`&&I&&P?(0,G.jsx)(oke,{entityType:I,entityUid:P.entityUid,documentTitle:Ve||`Untitled`,onClose:()=>k(`closed`),onRestored:le,canRestore:qn},`${I}:${P.entityUid}`):null,$n&&(0,G.jsx)(`div`,{hidden:O!==`chat`,className:`contents`,children:(0,G.jsx)(ROe,{onAnsweringChange:mr,onClose:()=>k(`closed`),entityType:P.entityType,entityUid:P.entityUid,entityTitle:P.entityType===`dbClient`?T?.name||hn:P.entityType===`note`?Ue?.title:P.entityType===`diagram`?Ke?.name:P.entityType===`flowchart`?Ge?.title:null,entityContextText:Zn,viewType:Qn?`db-client`:void 0,projectId:er,pendingPrompt:A,onPromptUsed:j,pendingAction:M,onClearPendingAction:N,notes:qe,diagrams:Je,flowcharts:Ye,drawings:Xe,activeNoteContent:P?.entityType===`note`?Ue?.content:void 0,getPaneAI:h})})]})]})})]})}function jke({paired:e,onPairChange:t}){let n=pa(),r=bn(),i=ta(),[a,o]=(0,W.useState)(null),s=(0,W.useMemo)(()=>a?{...a.workspace,setIsSettingsOpen:n.setIsSettingsOpen,setSettingsTab:n.setSettingsTab,refreshTeamScope:n.refreshTeamScope,teamScopeVersion:n.teamScopeVersion,isTeamScopeRefreshing:n.isTeamScopeRefreshing,flushPendingSaves:n.flushPendingSaves,handleLogout:n.handleLogout}:n,[a,n]),c=(0,W.useMemo)(()=>a?{...a.ai,rightPanelMode:r.rightPanelMode,setRightPanelMode:r.setRightPanelMode}:r,[a,r]);return(0,G.jsx)(ma.Provider,{value:s,children:(0,G.jsx)(Dn,{value:c,children:(0,G.jsx)(na,{value:a?.canvas??i,children:(0,G.jsx)(Ake,{root:n,session:a,mainAI:r,paired:e,onPairChange:t,onFocusedSession:o})})})})}function Mke(){let e=ZT(),[t,n]=(0,W.useState)(!1);return(0,G.jsx)(Th,{open:!t&&e.open,onOpenChange:e.onOpenChange,className:`h-svh overflow-hidden`,style:{"--sidebar-width":`17rem`},children:(0,G.jsx)(Nn,{children:(0,G.jsx)(jke,{paired:t,onPairChange:n})})})}function Nke(){let e=v();return(0,G.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4 text-center max-w-md`,children:[(0,G.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,G.jsx)(ei,{className:`h-6 w-6 text-muted-foreground`})}),(0,G.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`404`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The page you're looking for doesn't exist.`}),(0,G.jsxs)(`button`,{onClick:()=>e(`/table/tables`),className:`inline-flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow hover:bg-primary/90 transition-colors`,children:[(0,G.jsx)(sr,{className:`h-4 w-4`}),`Back to Home`]})]})})}var H9=[{key:`notes`,label:`Notes`,createLabel:`Note`,icon:de,color:`text-amber-500`,bg:`bg-amber-500/10`,route:`/table/notes`,createFn:`handleSidebarNoteCreate`,totalKey:`notesTotal`},{key:`diagrams`,label:`ERD Builder`,createLabel:`ERD Builder`,icon:Cr,color:`text-cyan-400`,bg:`bg-cyan-500/20`,route:`/table/erd`,createFn:`handleSidebarDiagramCreate`,totalKey:`diagramsTotal`},{key:`drawings`,label:`Drawings`,createLabel:`Drawing`,icon:wr,color:`text-violet-500`,bg:`bg-violet-500/10`,route:`/table/drawings`,createFn:`handleSidebarDrawingCreate`,totalKey:`drawingsTotal`},{key:`flowcharts`,label:`Flowcharts`,createLabel:`Flowchart`,icon:Sr,color:`text-emerald-500`,bg:`bg-emerald-500/10`,route:`/table/flowcharts`,createFn:`handleSidebarFlowchartCreate`,totalKey:`flowchartsTotal`}];function Pke(){let e=new Date().getHours();return e<12?`Good morning`:e<17?`Good afternoon`:`Good evening`}function U9(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`Just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i<30?`${i}d ago`:new Date(e).toLocaleDateString(`en-US`)}function W9(e){switch(e){case`diagrams`:return(0,G.jsx)(Cr,{className:`h-4 w-4 text-blue-500`});case`notes`:return(0,G.jsx)(de,{className:`h-4 w-4 text-amber-500`});case`drawings`:return(0,G.jsx)(wr,{className:`h-4 w-4 text-violet-500`});case`flowcharts`:return(0,G.jsx)(Sr,{className:`h-4 w-4 text-emerald-500`});case`db-client`:return(0,G.jsx)(xr,{className:`h-4 w-4 text-cyan-400`});default:return null}}function G9(e){return(e.source_type??e.sourceType)===`production_db`}function K9(e){return e?._group===`db-client`||e?._type===`db-client`||G9(e)}function q9(e){switch(e._type){case`diagrams`:return K9(e)?`DB Client`:`ERD Builder`;case`notes`:return`Note`;case`drawings`:return`Drawing`;case`flowcharts`:return`Flowchart`;case`db-client`:return`DB Client`;default:return``}}function J9(e,t){let n=t.uid||t.id;if(K9(t))return`/db-client/${n}`;switch(e){case`diagrams`:return`/diagrams/${n}`;case`notes`:return`/notes/${n}`;case`drawings`:return`/drawings/${n}`;case`flowcharts`:return`/flowcharts/${n}`;case`db-client`:return`/db-client/${n}`;default:return`/`}}function Fke(){let e=v(),t=pa(),n=yi(),r=w(),i=!!(t.user?.isSso&&r.activeTeamId),a=e=>e===`diagrams`?`erd_builder`:e,o=e=>!i||r.isAvailable&&r.activeTeam?.capabilities?.[a(e)]===!0,s=H9.filter(e=>o(e.key)),c=t.user,l=c?.user_metadata?.full_name||c?.user_metadata?.name||c?.email?.split(`@`)[0]||``,[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(t.isGuest||!c){d(null),p(!0);return}let e=!1;return d(null),p(!1),(async()=>{try{let t=await Si(`/api/search/recent`);if(!t.ok)return;let n=await t.json();e||d(Array.isArray(n.data)?n.data:[])}catch{}finally{e||p(!0)}})(),()=>{e=!0}},[t.isGuest,t.teamScopeVersion,c]);let m=(0,W.useMemo)(()=>{if(u)return u.map(e=>({...e,_type:e.type,_group:e.group,_workspace:e.workspace?.name||e.project?.name||`—`,updated_at:e.updated_at??e.updatedAt}));let e=new Map((t.projects||[]).map(e=>[String(e.id),e.name])),n=t=>{let n=t.project_id??t.projectId;return t.projects?.name||t.project?.name||(n?e.get(String(n)):null)||`—`};return[...(t.diagrams||[]).filter(e=>!G9(e)).map(e=>({...e,_type:`diagrams`,_group:G9(e)?`db-client`:`diagrams`,_workspace:n(e)})),...(t.notes||[]).map(e=>({...e,_type:`notes`,_group:`notes`,_workspace:n(e)})),...(t.drawings||[]).map(e=>({...e,_type:`drawings`,_group:`drawings`,_workspace:n(e)})),...(t.flowcharts||[]).map(e=>({...e,_type:`flowcharts`,_group:`flowcharts`,_workspace:n(e)}))].filter(e=>!e.is_deleted).sort((e,t)=>new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime()).slice(0,10)},[t.diagrams,t.notes,t.drawings,t.flowcharts,t.projects,u]),[h,g]=(0,W.useState)(``),[_,y]=(0,W.useState)(`all`),b=(0,W.useMemo)(()=>{let e=h.trim().toLowerCase();return m.filter(t=>{let n=_===`all`||t._group===_,r=t.name||t.title||``;return n&&(!e||`${r} ${t._workspace}`.toLowerCase().includes(e))})},[m,_,h]),x=(0,W.useMemo)(()=>(t.diagrams||[]).filter(e=>!e.is_deleted&&!G9(e)).length+(t.notes||[]).filter(e=>!e.is_deleted).length+(t.drawings||[]).filter(e=>!e.is_deleted).length+(t.flowcharts||[]).filter(e=>!e.is_deleted).length,[t.diagrams,t.notes,t.drawings,t.flowcharts]),[S,C]=(0,W.useState)({});(0,W.useEffect)(()=>C({}),[t.teamScopeVersion]);let T=(0,W.useMemo)(()=>(t.projects||[]).filter(e=>!e.is_deleted).map(e=>{let t=S[String(e.id)]||{};return{...e,notesCount:t.notes??0,diagramsCount:t.diagrams??0,drawingsCount:t.drawings??0,flowchartsCount:t.flowcharts??0,dbClientsCount:t.db_clients??0,totalDocs:(t.notes??0)+(t.diagrams??0)+(t.drawings??0)+(t.flowcharts??0)+(t.db_clients??0)}}).sort((e,t)=>t.totalDocs-e.totalDocs).slice(0,4),[t.projects,S]);(0,W.useEffect)(()=>{let e=(t.projects||[]).filter(e=>!e.is_deleted).slice(0,4);if(e.length===0)return;let r=!1;return(async()=>{let t={};for(let i of e)try{let e=await Si(`/api/projects/${i.id}/summary?include_db_client=${n}`);e.ok&&!r&&(t[String(i.id)]=await e.json())}catch{}r||C(t)})(),()=>{r=!0}},[t.projects,n]);let[E,D]=(0,W.useState)(!1),O=t.isLoading||t.isProjectsLoading;(0,W.useEffect)(()=>{O||D(!0)},[O]);let k=!O&&f,A=k&&x===0&&!u?.length,j=k&&!A&&E,M=e=>{o(e.key)&&t.handleOpenCreateDocument?.(e.key===`diagrams`?`erd`:e.key===`flowcharts`?`flowchart`:e.key)},N=m[0];return(0,G.jsxs)(`div`,{className:`flex h-full w-full flex-col overflow-y-auto`,children:[l&&(0,G.jsx)(`div`,{className:`border-b border-border/60 px-5 py-5`,children:(0,G.jsxs)(`div`,{className:`flex items-end justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:[Pke(),`,`]}),(0,G.jsx)(`h1`,{className:`mt-0.5 text-xl font-semibold tracking-tight`,children:l}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Pick up where you left off.`})]}),j&&o(`diagrams`)&&(0,G.jsxs)(`button`,{onClick:()=>M(H9[1]),className:`hidden h-8 shrink-0 items-center gap-1.5 rounded-md bg-primary px-3 text-xs font-semibold text-primary-foreground shadow-sm transition-colors hover:bg-primary/90 sm:inline-flex`,children:[(0,G.jsx)(jt,{className:`size-3.5`}),`New ERD Builder`]})]})}),A&&(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-2xl flex-col items-center justify-center px-6 py-20 text-center`,children:[(0,G.jsx)(`div`,{className:`size-16 rounded-2xl bg-primary/10 border border-primary/20 flex items-center justify-center mb-5`,children:(0,G.jsx)(Qr,{className:`size-7 text-primary`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:`Let's get started`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1.5 max-w-md`,children:`Create your first document — notes, ERD Builder, flowcharts, or drawings — and start building your workspace.`}),(0,G.jsx)(`div`,{className:`flex flex-wrap justify-center gap-2 mt-5`,children:s.map(e=>(0,G.jsxs)(`button`,{onClick:()=>M(e),className:`inline-flex items-center gap-2 rounded-lg border px-4 py-2.5 text-sm font-medium transition-all hover:shadow-sm ${e.key===`diagrams`?`border-cyan-400/50`:`border-border/60`} ${e.bg} hover:scale-[1.02]`,children:[(0,G.jsx)(e.icon,{className:`h-4 w-4 ${e.color}`}),`New `,e.createLabel]},e.key))})]}),j&&(0,G.jsxs)(`main`,{className:`flex w-full flex-col gap-5 px-5 py-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1.35fr)_minmax(250px,0.65fr)]`,children:[(0,G.jsxs)(`section`,{className:`relative overflow-hidden rounded-xl border border-primary/25 bg-linear-to-br from-primary/10 via-card to-card p-4`,children:[(0,G.jsxs)(`div`,{className:`relative z-10 flex h-full min-h-32 flex-col justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-wider text-primary`,children:`Continue working`}),N?(0,G.jsxs)(`div`,{className:`mt-3 flex items-start gap-2.5`,children:[(0,G.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-background/80 shadow-sm`,children:W9(N._type)}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h2`,{className:`truncate text-lg font-semibold`,children:N.name||N.title||`(Untitled)`}),(0,G.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[q9(N),` · `,N._workspace,` · `,U9(N.updated_at)]})]})]}):(0,G.jsx)(`h2`,{className:`mt-4 text-xl font-semibold`,children:`Create your first document`})]}),(0,G.jsxs)(`button`,{onClick:()=>N?e(J9(N._type,N)):M(H9[1]),className:`inline-flex h-8 w-fit items-center gap-1.5 rounded-md bg-primary px-3 text-xs font-semibold text-primary-foreground transition-colors hover:bg-primary/90`,children:[N?`Open document`:`Create ERD Builder`,(0,G.jsx)(Ca,{className:`size-3.5`})]})]}),(0,G.jsx)(Qr,{className:`absolute -bottom-8 -right-5 size-36 text-primary/10`})]}),(0,G.jsxs)(`section`,{className:`rounded-xl border border-border/60 bg-card p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Create something new`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Start with the format you need.`})]}),(0,G.jsx)(jt,{className:`size-4 text-muted-foreground`})]}),(0,G.jsx)(`div`,{className:`mt-3 grid grid-cols-2 gap-2`,children:s.map(e=>(0,G.jsxs)(`button`,{onClick:()=>M(e),className:`group flex min-h-14 flex-col items-start justify-between rounded-lg border border-border/60 bg-background px-2.5 py-2 text-left transition-colors hover:border-primary/40 hover:bg-accent/40`,children:[(0,G.jsx)(e.icon,{className:`size-4 ${e.color}`}),(0,G.jsxs)(`span`,{className:`text-xs font-medium`,children:[`New `,e.createLabel]})]},e.key))})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 lg:grid-cols-[minmax(0,1.35fr)_minmax(250px,0.65fr)]`,children:[(0,G.jsxs)(`section`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2.5`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,G.jsx)(Ra,{className:`size-4 text-muted-foreground`}),`Recent files`]}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Jump back into your latest work.`})]}),(0,G.jsxs)(`div`,{className:`relative w-full sm:w-52`,children:[(0,G.jsx)(Zr,{className:`pointer-events-none absolute left-2.5 top-2.5 size-3.5 text-muted-foreground`}),(0,G.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:`Search files`,"aria-label":`Search recent files`,className:`h-8 w-full rounded-lg border border-border/60 bg-card pl-8 pr-3 text-xs outline-none placeholder:text-muted-foreground/60 focus:border-primary/50`})]})]}),(0,G.jsxs)(`div`,{className:`mb-2 flex items-center gap-1 overflow-x-auto pb-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>y(`all`),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===`all`?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:`All`}),H9.map(e=>(0,G.jsx)(`button`,{onClick:()=>y(e.key),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===e.key?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:e.label},e.key)),n&&(0,G.jsx)(`button`,{onClick:()=>y(`db-client`),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===`db-client`?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:`DB Client`})]}),(0,G.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/60 bg-card`,children:b.length===0?(0,G.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No matching files.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`hidden grid-cols-[minmax(0,1fr)_minmax(7rem,0.7fr)_auto_auto] gap-2.5 border-b border-border/50 px-3 py-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground sm:grid`,children:[(0,G.jsx)(`span`,{children:`File`}),(0,G.jsx)(`span`,{children:`Project`}),(0,G.jsx)(`span`,{children:`Updated`}),(0,G.jsx)(`span`,{"aria-hidden":`true`})]}),b.map(t=>(0,G.jsxs)(`button`,{onClick:()=>e(J9(t._type,t)),className:`group grid w-full grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2.5 border-b border-border/50 px-3 py-2.5 text-left last:border-0 hover:bg-accent/30 sm:grid-cols-[minmax(0,1fr)_minmax(7rem,0.7fr)_auto_auto]`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,G.jsx)(`div`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md bg-background`,children:W9(t._type)}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:t.name||t.title||`(Untitled)`}),(0,G.jsx)(`p`,{className:`mt-0.5 truncate text-[11px] text-muted-foreground`,children:q9(t)})]})]}),(0,G.jsx)(`span`,{className:`hidden min-w-0 truncate text-xs text-muted-foreground sm:block`,children:t._workspace}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:U9(t.updated_at)}),(0,G.jsx)(Ca,{className:`size-3.5 shrink-0 text-muted-foreground/30 transition-colors group-hover:text-primary`})]},`${t._type}-${t.id}`))]})})]}),T.length>0&&(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`mb-2`,children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,G.jsx)(to,{className:`size-4 text-muted-foreground`}),`Projects`]}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Your projects at a glance.`})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:T.map(e=>(0,G.jsxs)(`button`,{onClick:()=>t.onViewChange?.(`erd`,!0,e.uid??e.id),className:`group flex w-full items-center gap-2.5 rounded-lg border border-border/60 bg-card p-2.5 text-left transition-colors hover:border-primary/40 hover:bg-accent/30`,children:[(0,G.jsx)(`div`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md bg-primary/10`,children:(0,G.jsx)(to,{className:`size-3.5 text-primary`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[e.totalDocs,` `,e.totalDocs===1?`file`:`files`]})]}),(0,G.jsx)(Ca,{className:`size-4 text-muted-foreground/30 transition-colors group-hover:text-primary`})]},e.id))})]})]})]})]})}function Ike(){let e=new URLSearchParams(window.location.search).get(`authorization_id`)||``,[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(e?``:`Authorization ID is missing.`),[a,o]=(0,W.useState)(!!e),[s,c]=(0,W.useState)(!1);(0,W.useEffect)(()=>{e&&Si(`/api/oauth/authorizations/${encodeURIComponent(e)}`,{cache:`no-store`}).then(async e=>{let t=await e.json();if(!e.ok)throw Error(t.error||`Authorization request could not be loaded.`);t.redirect_url?window.location.assign(t.redirect_url):n(t)}).catch(e=>i(e instanceof Error?e.message:`Authorization request could not be loaded.`)).finally(()=>o(!1))},[e]);async function l(t){c(!0),i(``);try{let n=await Si(`/api/oauth/authorizations/${encodeURIComponent(e)}/${t}`,{method:`POST`}),r=await n.json();if(!n.ok||!r.redirect_url)throw Error(r.error||`Authorization decision failed.`);window.location.assign(r.redirect_url)}catch(e){i(e instanceof Error?e.message:`Authorization decision failed.`),c(!1)}}return(0,G.jsx)(`main`,{className:`flex min-h-svh items-center justify-center bg-muted/30 p-6`,children:(0,G.jsxs)(Lr,{className:`w-full max-w-lg`,children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(`div`,{className:`mb-2 flex size-10 items-center justify-center rounded-full bg-primary/10 text-primary`,children:(0,G.jsx)(Ho,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsx)(zr,{children:`Authorize MCP access`}),(0,G.jsx)(Kr,{children:t?`${t.client.name} wants read-only access to your ERD Builder Pro Web App workspace.`:`Reviewing the authorization request…`})]}),(0,G.jsxs)(Rr,{className:`space-y-4 text-sm`,children:[a&&(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Loading authorization details…`}),r&&(0,G.jsx)(`p`,{role:`alert`,className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:r}),t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`Requesting client`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t.client.name}),(0,G.jsxs)(`p`,{className:`mt-1 break-all font-mono text-xs text-muted-foreground`,children:[`Redirect: `,t.redirect_uri]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`This client can read`}),(0,G.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Projects, regular ERDs, Notes, Flowcharts, Drawings, and document history in the Personal workspace and active Teams accessible to `,t.user.email,`. This authorization covers all permitted workspaces and follows your current access permissions.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`It cannot access`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`DB Client, production database diagrams, SQL execution, database credentials, local files, or write operations.`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`OAuth scopes`}),(0,G.jsx)(`p`,{className:`mt-1 break-words font-mono text-xs text-muted-foreground`,children:t.scope||`email`})]})]})]}),t&&(0,G.jsxs)(Ur,{className:`justify-end gap-2`,children:[(0,G.jsx)(U,{variant:`outline`,disabled:s,onClick:()=>l(`deny`),children:`Deny`}),(0,G.jsx)(U,{disabled:s,onClick:()=>l(`approve`),children:s?`Submitting…`:`Allow read-only access`})]})]})})}function Lke({user:e,onComplete:t}){let[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),p=async r=>{if(r.preventDefault(),!(i.length<8||i!==o)){f(!0);try{let r=await Si(`/api/account`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPassword:n,newPassword:i})}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||`Unable to change password.`);t({...e,...a.user,mustChangePassword:!1}),l.success(`Password updated`)}catch(e){l.error(e?.message||`Unable to change password.`)}finally{f(!1)}}},m=c?`text`:`password`,h=(0,G.jsx)(`button`,{type:`button`,"aria-label":c?`Hide passwords`:`Show passwords`,onClick:()=>u(e=>!e),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:c?(0,G.jsx)(kr,{className:`size-4`}):(0,G.jsx)(Ka,{className:`size-4`})});return(0,G.jsx)(`main`,{className:`flex min-h-screen items-center justify-center bg-background p-6`,children:(0,G.jsxs)(`form`,{onSubmit:p,className:`flex w-full max-w-sm flex-col gap-5 rounded-xl border bg-card p-6 shadow-sm`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(po,{className:`size-6 text-primary`}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Change your password`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Use the temporary password provided by your Team administrator, then set a new password before continuing.`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`temporary-password`,children:`Temporary password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`temporary-password`,type:m,className:`pr-10`,value:n,onChange:e=>r(e.target.value),required:!0}),h]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`new-password`,children:`New password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`new-password`,type:m,className:`pr-10`,minLength:8,value:i,onChange:e=>a(e.target.value),required:!0}),h]}),(0,G.jsx)(Or,{children:`At least 8 characters.`})]}),(0,G.jsxs)(jr,{"data-invalid":o.length>0&&o!==i,children:[(0,G.jsx)(Dr,{htmlFor:`confirm-password`,children:`Confirm new password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`confirm-password`,type:m,className:`pr-10`,minLength:8,value:o,onChange:e=>s(e.target.value),"aria-invalid":o.length>0&&o!==i,required:!0}),h]})]}),(0,G.jsxs)(U,{type:`submit`,disabled:d||i.length<8||i!==o,children:[d&&(0,G.jsx)(xo,{className:`animate-spin`}),` Save new password`]})]})})}function Rke(e,t){let[n,r]=(0,W.useState)(()=>{try{let t=localStorage.getItem(e);if(t)return{...JSON.parse(t)}}catch{}return Object.fromEntries(t.map(e=>[e.id,e.defaultVisible]))});return(0,W.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[n,e]),{visible:n,toggle:(0,W.useCallback)(e=>{r(t=>({...t,[e]:!t[e]}))},[]),visibleCols:(0,W.useCallback)(()=>t.filter(e=>!e.hideable||(n[e.id]??e.defaultVisible)),[n])}}function zke(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(0),[i,a]=(0,W.useState)(!1);return{dbClients:e,dbClientsTotal:n,isDbClientsLoading:i,fetchDbClients:(0,W.useCallback)(async({projectId:e,query:n=``,page:i=1}={})=>{a(!0);try{let a=new URLSearchParams({limit:`10`,offset:String((i-1)*10)});e!=null&&e!==`all`&&a.set(`project_id`,String(e)),n.trim()&&a.set(`q`,n.trim());let o=await Si(`/api/db-clients?${a}`);if(!o.ok)throw Error(`Failed to load DB Clients`);let s=await o.json();t(Array.isArray(s.data)?s.data:[]),r(Number(s.total)||0)}catch(e){l.error(e.message||`Failed to load DB Clients`)}finally{a(!1)}},[]),deleteDbClient:(0,W.useCallback)(async e=>(await Si(`/api/db-clients/${encodeURIComponent(e)}`,{method:`DELETE`})).ok?(t(t=>t.filter(t=>String(t.uid??t.id)!==String(e))),r(e=>Math.max(0,e-1)),l.success(`DB Client moved to trash`),!0):(l.error(`Failed to move DB Client to trash`),!1),[])}}var Y9=[10,20,50,100],Bke={notes:`/notes`,erd:`/diagrams`,flowchart:`/flowcharts`,"db-client":`/db-client`,drawings:`/drawings`},Vke={notes:`New Note`,erd:`New ERD Builder`,flowchart:`New Flowchart`,"db-client":`New DB Client`,drawings:`New Drawing`},X9=[{id:`name`,label:`Name`,defaultVisible:!0,hideable:!1,width:`w-[40%]`},{id:`type`,label:`Type`,defaultVisible:!0,hideable:!0,width:`w-[12%]`},{id:`creator`,label:`Creator`,defaultVisible:!0,hideable:!0,width:`w-[12%]`},{id:`updated`,label:`Updated`,defaultVisible:!1,hideable:!0,width:`w-[13%]`},{id:`status`,label:`Status`,defaultVisible:!0,hideable:!0,width:`w-[8%]`},{id:`created`,label:`Created`,defaultVisible:!0,hideable:!0,width:`w-[13%]`},{id:`expires`,label:`Expires`,defaultVisible:!1,hideable:!0,width:`w-[12%]`},{id:`actions`,label:`Actions`,defaultVisible:!0,hideable:!1,width:`w-[6%]`}];function Z9(e,t=!1){if(!e)return`—`;let n=new Date(e);return Number.isNaN(n.getTime())?`—`:new Intl.DateTimeFormat(`id-ID`,t?{dateStyle:`long`}:{dateStyle:`medium`,timeStyle:`short`}).format(n)}function Hke(){let{projectKey:e=``}=h(),[t,n]=g(),r=v(),{user:i,isGuest:a}=la(),{projects:o,isProjectsLoading:s,handleOpenCreateDocument:c,setBreadcrumbLabel:l,updateNote:u,updateDiagram:f,updateDrawing:p,updateFlowchart:m,moveNoteToProject:_,moveDiagramToProject:y,moveDrawingToProject:b,moveFlowchartToProject:x,deleteNote:S,deleteDiagram:C,deleteDrawing:w,deleteFlowchart:T,fetchTrash:E}=pa(),{deleteDbClient:D}=zke(),{toggle:O,visibleCols:k}=Rke(`project-files-column-visibility`,X9),A=k(),j=e===Xi,M=j?null:o.find(t=>t.uid===e||String(t.id)===e)??null,N=j?`null`:M?String(M.id):null,P=Ui(M,i?.id,a)&&[`viewer`,`commenter`].includes(M?.accessRole??M?.access_role),F=Wi.filter(e=>e.value!==`db-client`||yi()),I=t.get(`type`),L=F.some(e=>e.value===I)?I:`all`,R=Math.max(1,Number(t.get(`page`))||1),ee=Y9.includes(Number(t.get(`per_page`)))?Number(t.get(`per_page`)):10,te=t.get(`q`)??``,[ne,re]=(0,W.useState)(te),[ie,z]=(0,W.useState)(0),[ae,oe]=(0,W.useState)(null),[se,ce]=(0,W.useState)(``),[le,ue]=(0,W.useState)(`none`),[de,B]=(0,W.useState)(null),[fe,pe]=(0,W.useState)(!1),me=()=>z(e=>e+1),{data:he,total:ge,counts:_e,locked:ve,isLoading:V}=NT({projectId:N,type:L,page:R,perPage:ee,q:te},ie),H=Math.max(1,Math.ceil(ge/ee)),ye=e=>{n(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e))r===null?n.delete(t):n.set(t,r);return n},{replace:!0})};(0,W.useEffect)(()=>{re(te)},[e]);let be=j?`Unassigned`:M?.name??null;if((0,W.useEffect)(()=>(l(be),()=>l(null)),[be,l]),(0,W.useEffect)(()=>{if(ne===te)return;let e=window.setTimeout(()=>ye({q:ne.trim()||null,page:null}),300);return()=>window.clearTimeout(e)},[ne]),!j&&!M)return(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:s?`Loading project…`:`Project not found.`});let xe=F.reduce((e,t)=>e+_e[t.value],0),Se=[{value:`all`,label:`All`,count:xe,icon:null,isLocked:!1},...F.map(e=>({value:e.value,label:e.label,count:_e[e.value],icon:e.icon,isLocked:ve.includes(e.value)}))],Ce=L!==`all`&&ve.includes(L),we=L===`all`?`notes`:L,Te=j?no:eo,Ee=i?.isSso?i.ssoPortalUrl??i.sso_portal_url:null,De=e=>r(`${Bke[e.type]}/${e.uid??e.id}`),Oe=e=>{oe(e),ce(e.title||e.name||``)};return(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted`,children:(0,G.jsx)(Te,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h1`,{className:`truncate text-lg font-semibold`,children:j?`Unassigned`:M?.name}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:j?`Files without a project. Edit a file to move it into a project.`:`${xe} ${xe===1?`file`:`files`}`})]})]}),!j&&(0,G.jsxs)(U,{size:`sm`,onClick:()=>c(we),children:[(0,G.jsx)(jt,{className:`size-4`,"aria-hidden":`true`}),`New file`]})]}),(0,G.jsx)(`div`,{role:`tablist`,"aria-label":`File types`,className:`flex shrink-0 gap-1 overflow-x-auto border-b`,children:Se.map(e=>{let t=e.icon,n=L===e.value;return(0,G.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>ye({type:e.value===`all`?null:e.value,page:null}),className:d(`-mb-px flex shrink-0 items-center gap-1.5 border-b-2 border-transparent px-3 py-2 text-sm text-muted-foreground transition-colors hover:text-foreground`,n&&`border-primary font-medium text-foreground`),children:[t&&(0,G.jsx)(t,{className:`size-4`,"aria-hidden":`true`}),e.label,e.isLocked?(0,G.jsx)(So,{className:`size-3.5`,"aria-label":`Not in your plan`}):(0,G.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 text-xs tabular-nums`,children:e.count})]},e.value)})}),Ce?(0,G.jsxs)(`section`,{className:`max-w-md rounded-lg border border-primary/20 bg-primary/5 p-4 text-sm`,children:[(0,G.jsxs)(`p`,{className:`font-medium`,children:[F.find(e=>e.value===L)?.label,` needs a paid Cloud plan`]}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Files of this type stay saved and come back after an upgrade.`}),Ee&&(0,G.jsxs)(U,{size:`sm`,className:`mt-3`,onClick:()=>Yi(Ee),children:[`View Cloud plans`,(0,G.jsx)(Ca,{className:`size-4`})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative w-full max-w-64`,children:[(0,G.jsx)(Zr,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(wi,{type:`search`,"aria-label":`Search files`,placeholder:`Search files...`,value:ne,onChange:e=>re(e.target.value),className:`h-8 pl-8 text-xs`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[yi()&&!j&&(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>pe(!0),children:[(0,G.jsx)(xr,{className:`size-4`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:`Database connections`})]}),(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`outline`,size:`icon-sm`,"aria-label":`Columns`,title:`Columns`,children:(0,G.jsx)(Ha,{className:`size-4`})})}),(0,G.jsx)(Gt,{align:`end`,className:`w-44`,children:X9.filter(e=>e.hideable).map(e=>(0,G.jsx)(Ut,{checked:A.some(t=>t.id===e.id),onCheckedChange:()=>O(e.id),children:e.label},e.id))})]})]})]}),(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-col overflow-hidden rounded-xl border`,children:[(0,G.jsx)(`div`,{className:`min-h-0 overflow-auto`,children:(0,G.jsxs)(Qh,{children:[(0,G.jsx)($h,{children:(0,G.jsx)(tg,{children:A.map(e=>(0,G.jsx)(ng,{className:e.width,children:e.label},e.id))})}),(0,G.jsx)(eg,{children:he.length===0?(0,G.jsx)(tg,{children:(0,G.jsxs)(rg,{colSpan:A.length,className:`h-32 text-center text-muted-foreground`,children:[V?`Loading…`:te?`No files match your search.`:`No files here yet.`,!V&&!te&&!j&&(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsxs)(U,{size:`sm`,variant:`outline`,onClick:()=>c(we),children:[(0,G.jsx)(jt,{className:`size-4`,"aria-hidden":`true`}),L===`all`?`New file`:Vke[L]]})})]})}):he.map(e=>{let t=Wi.find(t=>t.value===e.type),n=t.icon,r=e.type===`db-client`||Ui(e,i?.id,a)&&!P;return(0,G.jsx)(tg,{className:`group cursor-pointer`,onClick:()=>De(e),children:A.map(a=>{switch(a.id){case`name`:return(0,G.jsx)(rg,{className:`font-medium`,children:(0,G.jsx)(`span`,{className:`block max-w-70 truncate`,children:e.title||e.name||`Untitled`})},`name`);case`type`:return(0,G.jsx)(rg,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 whitespace-nowrap text-xs text-muted-foreground`,children:[(0,G.jsx)(n,{className:`size-4`,"aria-hidden":`true`}),t.label]})},`type`);case`creator`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:e.user?.name||e.user?.email||(e.type===`db-client`?i?.name||i?.email:null)||`—`},`creator`);case`updated`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:Z9(e.updated_at)},`updated`);case`status`:return(0,G.jsx)(rg,{children:(0,G.jsx)(`span`,{className:d(`inline-flex rounded-full px-2 py-0.5 text-xs`,e.is_public?`bg-green-500/10 text-green-500`:`bg-muted text-muted-foreground`),children:e.is_public?`Public`:`Private`})},`status`);case`created`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:Z9(e.created_at)},`created`);case`expires`:{let t=e.expiry_date&&new Date(e.expiry_date)<new Date;return(0,G.jsx)(rg,{className:d(`text-xs text-muted-foreground`,t&&`font-medium text-red-500`),children:Z9(e.expiry_date,!0)},`expires`)}case`actions`:return(0,G.jsx)(rg,{className:`text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon`,className:`size-8`,"aria-label":`Actions for ${e.title||e.name||`file`}`,children:(0,G.jsx)(Tr,{className:`size-4`})})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-44`,children:[(0,G.jsxs)(It,{onClick:()=>Oe(e),children:[(0,G.jsx)(ar,{className:`mr-2 size-4`}),`Edit`]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>B(e),className:`text-destructive`,children:[(0,G.jsx)($r,{className:`mr-2 size-4`}),`Delete`]})]})]})]})},`actions`);default:return null}})},`${e.type}:${e.uid??e.id}`)})})]})}),(0,G.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2 border-t px-4 py-2 text-xs text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{id:`rows-per-page-label`,children:`Rows per page`}),(0,G.jsxs)(_r,{value:String(ee),onValueChange:e=>e&&ye({per_page:e===`10`?null:e,page:null}),children:[(0,G.jsx)(mr,{size:`sm`,"aria-labelledby":`rows-per-page-label`,className:`h-7 w-18`,children:(0,G.jsx)(gr,{children:ee})}),(0,G.jsx)(pr,{children:Y9.map(e=>(0,G.jsx)(fr,{value:String(e),children:e},e))})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{children:[`Page `,Math.min(R,H),` of `,H]}),(0,G.jsx)(U,{variant:`outline`,size:`icon-xs`,"aria-label":`Previous page`,disabled:R<=1,onClick:()=>ye({page:R-1>1?String(R-1):null}),children:(0,G.jsx)(lr,{className:`size-4`})}),(0,G.jsx)(U,{variant:`outline`,size:`icon-xs`,"aria-label":`Next page`,disabled:R>=H,onClick:()=>ye({page:String(R+1)}),children:(0,G.jsx)(St,{className:`size-4`})})]})]})]})]}),(0,G.jsx)(sE,{isOpen:ae!==null,onOpenChange:e=>{e||oe(null)},view:ae?.type??`notes`,activeDocument:ae,canMoveProject:ae?Ui(ae,i?.id,a):!1,newName:se,setNewName:ce,projects:o,requireProject:!0,selectedProjectId:le,setSelectedProjectId:ue,updateDiagram:f,updateNote:u,updateDrawing:p,updateFlowchart:m,updateDbClient:async(e,t)=>{if(!(await Si(`/api/db-clients/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})})).ok)throw Error(`Failed to rename DB Client`);me()},onMoveDiagramToProject:y,onMoveNoteToProject:_,onMoveDrawingToProject:b,onMoveFlowchartToProject:x,onRenameSuccess:async()=>me()}),(0,G.jsx)(AT,{isOpen:de!==null,onOpenChange:e=>{e||B(null)},activeDocument:de,view:de?.type,deleteDiagram:C,deleteNote:S,deleteDrawing:w,deleteFlowchart:T,fetchTrash:E,onConfirm:de?.type===`db-client`?()=>{let e=de.uid??de.id;D(String(e)).then(()=>{B(null),me()})}:void 0,onAfterDelete:()=>{B(null),me()}}),yi()&&!j&&(0,G.jsx)(V9,{open:fe,onOpenChange:pe,projects:o,defaultProjectId:M?String(M.id):null,onImportComplete:e=>r(`/db-client/${e}`)})]})}var Q9={notes:`notes`,erd:`erd`,flowchart:`flowchart`,flowcharts:`flowchart`,drawings:`drawings`,"db-client":`db-client`};function Uke(){let{feature:e=``}=h(),[t]=g(),n=t.get(`workspace`);if(!n)return(0,G.jsx)(x,{to:`/`,replace:!0});let r=new URLSearchParams;return Q9[e]&&r.set(`type`,Q9[e]),(0,G.jsx)(x,{to:`/projects/${encodeURIComponent(n)}${r.size?`?${r}`:``}`,replace:!0})}var Wke=(0,W.lazy)(()=>_i(()=>import(`./NoteEditorRoute-CFk0YU66.js`).then(e=>({default:e.NoteEditorRoute})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,4,1,22]))),Gke=(0,W.lazy)(()=>_i(()=>import(`./DiagramEditorRoute-pw5JFieq.js`).then(e=>({default:e.DiagramEditorRoute})),__vite__mapDeps([23,5,7,9,12,8,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54]))),Kke=(0,W.lazy)(()=>Promise.all([_i(()=>import(`./DbClientEditorRoute-BjEkIYEP.js`),__vite__mapDeps([59,5,7,8,9,12,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])),M()]).then(([e])=>({default:e.DbClientEditorRoute}))),qke=(0,W.lazy)(()=>_i(()=>import(`./DrawingEditorRoute-D0jtN-sA.js`).then(e=>({default:e.DrawingEditorRoute})),__vite__mapDeps([57,5,7,9,30,8,25,58,48,10,16,11,12,13,14,15,17,18,19,20,21,4,1,22]))),Jke=(0,W.lazy)(()=>_i(()=>import(`./FlowchartEditorRoute-DdgCEBK6.js`).then(e=>({default:e.FlowchartEditorRoute})),__vite__mapDeps([55,5,7,8,9,12,13,14,15,10,16,25,28,27,26,29,30,31,32,33,34,35,36,37,38,39,40,20,56,47,50,42,11,17,18,19,21,4,1,22,52,54]))),Yke=(0,W.lazy)(()=>_i(()=>import(`./TeamManagementRoute-DD0y4lvh.js`).then(e=>({default:e.TeamManagementRoute})),__vite__mapDeps([60,5,7,8,9,25,29,27,26,30,31,32,33,43,35,36,37,38,46,39,61,16,10,42,20,22,52]))),Xke=(0,W.lazy)(()=>_i(()=>import(`./TeamInventoryRoute-a3M5BBKT.js`).then(e=>({default:e.TeamInventoryRoute})),__vite__mapDeps([62,5,7,8,9,25,43,36,37,27,16,10,20]))),Zke=(0,W.lazy)(()=>_i(()=>import(`./LibraryRoute-BGKi1fBG.js`).then(e=>({default:e.LibraryRoute})),__vite__mapDeps([63,5,7,8,9,25,26,27,43,44,35,30,31,32,36,37,64,40,50,16,10]))),Qke=(0,W.lazy)(()=>_i(()=>import(`./UserManagementRoute-4b4y-hfW.js`).then(e=>({default:e.UserManagementRoute})),__vite__mapDeps([65,5,7,8,9,25,26,27,43,44,36,37,39,66,16,10,42,32,20]))),$ke=(0,W.lazy)(()=>_i(()=>import(`./AdminRoute-BUI-EDRz.js`).then(e=>({default:e.AdminRoute})),__vite__mapDeps([67,5,7,9,10,11,8,12,13,14,15,16,17,18,19,20,21,4,1,22])));function $9(e){return(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs text-muted-foreground`,children:`Opening file…`}),children:e})}function eAe(){let{isAuthenticated:e,user:t,setUser:n,isGuest:r,handleLogin:i,handleGuestLogin:a,handleLogout:o}=la(),s=v(),c=m(),[l,u]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let e,t;return typeof window>`u`||!window.__TAURI__&&!window.__TAURI_INTERNALS__?void 0:((async()=>{let{listen:n}=await _i(async()=>{let{listen:e}=await import(`./event-C6gFlqUR.js`);return{listen:e}},__vite__mapDeps([0,1]));e=await n(`menu-about`,()=>{u(!0)}),t=await n(`menu-check-update`,()=>{window.dispatchEvent(new CustomEvent(`menu-check-update`,{detail:{}}))})})(),()=>{e?.(),t?.()})},[]);let d=(0,W.useRef)(!1);(0,W.useEffect)(()=>{e===!1?d.current=!0:e===!0&&d.current&&(d.current=!1,c.pathname!==`/oauth/consent`&&s(`/`))},[e,c.pathname,s]);let{isPublicView:f,setIsPublicView:p,publicData:h,isPublicLoading:g,forbiddenDoc:_,fetchPublicDocument:y}=AC(()=>{}),x=ra();return e===null&&!x?(0,G.jsx)(mh,{type:`init`}):g?(0,G.jsx)(mh,{type:`public`}):_?(0,G.jsx)(Jte,{title:_.title,message:_.message,statusCode:_.status,documentUid:x?.uid,onSubmitToken:async e=>{if(x){if(await y(x.type,x.uid,void 0,void 0,e))sessionStorage.setItem(`share_token_${x.uid}`,e);else throw Error(`Invalid token`)}},onReturn:()=>window.location.href=`/`}):!e&&!x?(0,G.jsx)(us,{onLogin:e=>i(e),onGuestLogin:a}):c.pathname===`/oauth/consent`?(0,G.jsx)(Ike,{}):t?.mustChangePassword?(0,G.jsx)(Lke,{user:t,onComplete:n}):(0,G.jsxs)(aa,{isPublicView:f,publicData:h,isPublicLoading:g,forbiddenDoc:_,fetchPublicDocument:y,setIsPublicView:p,handleLogout:o,children:[(0,G.jsx)(S,{children:(0,G.jsxs)(b,{element:(0,G.jsx)(Mke,{}),children:[(0,G.jsx)(b,{path:`projects/:projectKey`,element:(0,G.jsx)(Hke,{})}),(0,G.jsx)(b,{path:`table/:feature`,element:(0,G.jsx)(Uke,{})}),(0,G.jsx)(b,{path:`notes/:id`,element:(0,G.jsx)(QC,{capability:`notes`,children:$9((0,G.jsx)(Wke,{}))})}),(0,G.jsx)(b,{path:`diagrams/:id`,element:(0,G.jsx)(QC,{capability:`erd_builder`,children:$9((0,G.jsx)(Gke,{}))})}),(0,G.jsx)(b,{path:`db-client/:id`,element:(0,G.jsx)(QC,{capability:`desktop_only`,children:$9((0,G.jsx)(Kke,{}))})}),(0,G.jsx)(b,{path:`drawings/:id`,element:(0,G.jsx)(QC,{capability:`drawings`,children:$9((0,G.jsx)(qke,{}))})}),(0,G.jsx)(b,{path:`flowcharts/:id`,element:(0,G.jsx)(QC,{capability:`flowcharts`,children:$9((0,G.jsx)(Jke,{}))})}),(0,G.jsx)(b,{path:`trash`,element:$9((0,G.jsx)($ke,{}))}),(0,G.jsx)(b,{path:`library`,element:$9((0,G.jsx)(Zke,{}))}),(0,G.jsx)(b,{path:`teams/:id`,element:$9((0,G.jsx)(Yke,{}))}),(0,G.jsx)(b,{path:`team-workspaces`,element:$9((0,G.jsx)(Xke,{}))}),(0,G.jsx)(b,{path:`users`,element:$9((0,G.jsx)(Qke,{}))}),(0,G.jsx)(b,{index:!0,element:(0,G.jsx)(Fke,{})}),(0,G.jsx)(b,{path:`*`,element:(0,G.jsx)(Nke,{})})]})}),(0,G.jsx)(DC,{}),(0,G.jsx)(kC,{open:l,onOpenChange:u})]})}function tAe(){return(0,G.jsx)(eAe,{})}typeof window<`u`&&`__TAURI_INTERNALS__`in window&&document.body.setAttribute(`data-tauri`,`true`);var nAe=window.fetch;window.fetch=async(...e)=>{let t=await nAe(...e),n=typeof e[0]==`string`?e[0]:e[0]instanceof Request?e[0].url:typeof e[0]==`object`&&`href`in e[0]?e[0].href:``,r=n.includes(`/api/login`)||n.includes(`/api/logout`)||n.includes(`/api/me`);n.includes(`supabase.co`);let i=vi(),a=(n.startsWith(`/api/`)||i&&n.startsWith(i))&&!n.includes(`supabase.co`),o=sessionStorage.getItem(`auth_mode`)===`guest`;return t.status===401&&a&&!r&&navigator.onLine&&!o&&(bi(),window.dispatchEvent(new Event(`auth:unauthorized`))),t},`serviceWorker`in navigator&&(window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||`__TAURI_INTERNALS__`in window?navigator.serviceWorker.getRegistrations().then(e=>{e.forEach(e=>e.unregister())}):window.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/sw.js`).catch(()=>{})})),(0,ga.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(W.StrictMode,{children:(0,G.jsx)(C,{children:(0,G.jsx)(se,{children:(0,G.jsx)(Ft,{children:(0,G.jsxs)(da,{children:[(0,G.jsx)(tAe,{}),(0,G.jsx)(ns,{position:`top-center`})]})})})})}));export{es as $,$a as $t,mw as A,Sa as An,Co as At,tg as B,po as Bt,_8 as C,ka as Cn,Ao as Ct,hE as D,Ta as Dn,Eo as Dt,zD as E,Ea as En,Do as Et,Qh as F,vo as Ft,vh as G,so as Gt,Kh as H,uo as Ht,eg as I,_o as It,xh as J,io as Jt,yh as K,oo as Kt,rg as L,go as Lt,gw as M,xo as Mt,_w as N,bo as Nt,lT as O,wa as On,To as Ot,Kne as P,yo as Pt,ts as Q,eo as Qt,ng as R,ho as Rt,E8 as S,Aa as Sn,jo as St,LD as T,Da as Tn,Oo as Tt,Vh as U,lo as Ut,Nne as V,fo as Vt,zh as W,co as Wt,ph as X,no as Xt,_h as Y,ro as Yt,ws as Z,to as Zt,nDe as _,Fa as _n,Io as _t,sDe as a,qa as an,Jo as at,O8 as b,Ma as bn,No as bt,B8 as c,Wa as cn,Go as ct,R8 as d,Va as dn,Ho as dt,Qa as en,$o as et,I8 as f,Ba as fn,Vo as ft,rDe as g,Ia as gn,Lo as gt,F8 as h,La as hn,Ro as ht,I5 as i,Ja as in,Yo as it,vw as j,xa as jn,So as jt,Xw as k,Ca as kn,wo as kt,iDe as l,Ua as ln,Wo as lt,P8 as m,Ra as mn,zo as mt,ike as n,Xa as nn,Zo as nt,V8 as o,Ka as on,qo as ot,L8 as p,za as pn,Bo as pt,bh as q,ao as qt,L7 as r,Ya as rn,Xo as rt,z8 as s,Ga as sn,Ko as st,n9 as t,Za as tn,Qo as tt,aDe as u,Ha as un,Uo as ut,tDe as v,Pa as vn,Fo as vt,ID as w,Oa as wn,ko as wt,qEe as x,ja as xn,Mo as xt,N8 as y,Na as yn,Po as yt,$h as z,mo as zt};
|
|
785
|
+
`),r=_e(n);return{...r,dbml:ue(r.nodes,r.edges),warnings:[]}}var D9=e=>e.trim().toLowerCase(),O9=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``)||``;function k9(e,t,n,r){let i=new Map(e.map(e=>[D9(e.data.name),e])),a=new Map,o=new Map,s=n.map((e,t)=>{let n=i.get(D9(e.data.name));if(!n)return{...e,position:e.position||{x:t%4*320+50,y:Math.floor(t/4)*320+50}};a.set(e.id,n.id);let r=e.data.columns.map(t=>{let r=n.data.columns.find(e=>D9(e.name)===D9(t.name));return r&&o.set(`${e.id}:${t.id}`,r.id),r?{...t,id:r.id}:t}),s=(t=[])=>t.map(t=>o.get(`${e.id}:${t}`)||t);return{...e,id:n.id,position:n.position,data:{...e.data,id:n.data.id,x:n.data.x,y:n.data.y,color:n.data.color,collapsed:n.data.collapsed,hidden_columns:n.data.hidden_columns,columns:r,constraints:(e.data.constraints||[]).map(e=>({...e,entity_id:n.data.id,column_ids:s(e.column_ids)})),indexes:(e.data.indexes||[]).map(e=>({...e,entity_id:n.data.id,column_ids:s(e.column_ids)}))}}});return{nodes:s,edges:r.map(e=>{let r=n.find(t=>t.id===e.source),i=n.find(t=>t.id===e.target),o=a.get(e.source)||e.source,c=a.get(e.target)||e.target,l=r?.data.columns.find(t=>t.id===O9(e.sourceHandle)),u=i?.data.columns.find(t=>t.id===O9(e.targetHandle)),d=s.find(e=>e.id===o),f=s.find(e=>e.id===c),p=d?.data.columns.find(e=>D9(e.name)===D9(l?.name||``)),m=f?.data.columns.find(e=>D9(e.name)===D9(u?.name||``)),h=p?`col-${p.id}-${(d?.position.x||0)<(f?.position.x||0)?`source`:`source-l`}`:void 0,g=m?`col-${m.id}-${(d?.position.x||0)<(f?.position.x||0)?`target`:`target-r`}`:void 0,_=me(t,o,c,h,g);return{...e,id:_?.id||e.id,source:o,target:c,sourceHandle:_?.sourceHandle||h,targetHandle:_?.targetHandle||g}})}}var A9=`WORKTREE`;async function j9(e,t){let n=await Si(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error||`Repository request failed`);return r}async function M9(e,t,n){let r=await Si(e,{method:t,...n?{headers:{"Content-Type":`application/json`},body:JSON.stringify({repository_path:n.repositoryPath,ref:n.ref,source_id:n.sourceId})}:{}}),i=r.status===204?null:await r.json().catch(()=>({}));if(!r.ok)throw Error(i?.error||`Repository link request failed`);return i}function yke({diagramUid:e,nodes:t,edges:n,onClose:r}){let i=`erdbpro:repository-link:${e}`,a=`/api/repositories/link/${encodeURIComponent(e)}`,[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(A9),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(``),[_,v]=(0,W.useState)([]),[y,b]=(0,W.useState)(null),x=(0,W.useRef)(null),S=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),C=(0,W.useCallback)(e=>{let t=JSON.stringify(e);x.current!==t&&(localStorage.setItem(i,JSON.stringify(e)),M9(a,`PUT`,e).then(()=>{x.current=t,localStorage.removeItem(i)}).catch(()=>{}))},[a,i]),w=(0,W.useCallback)(async(e,t,n=``)=>{let r=await j9(`/api/repositories/inspect`,{repository_path:e,ref:t}),i=r.sources.find(e=>e.id===n)?.id||r.sources[0]?.id||``;return s(r.root),u(r),f(t),g(i),m(e=>e||r.current_ref||r.refs.find(e=>e.current)?.value||``),i&&C({repositoryPath:r.root,ref:t,sourceId:i}),r},[C]);(0,W.useEffect)(()=>{b(`connect`),M9(a,`GET`).then(e=>{if(e?.repositoryPath)return x.current=JSON.stringify(e),e;try{return JSON.parse(localStorage.getItem(i)||`null`)}catch{return null}}).then(e=>e?.repositoryPath?w(e.repositoryPath,e.ref||A9,e.sourceId):void 0).catch(e=>l.error(e.message)).finally(()=>b(null))},[w,a,i]),(0,W.useEffect)(()=>()=>Ni(),[]);let T=(0,W.useMemo)(()=>c?[{value:A9,label:`Working tree`},...c.refs.map(e=>({value:e.value,label:`${e.name}${e.current?` (current)`:``}`})),...c.commits.map(e=>({value:e.value,label:`${e.short} · ${e.subject}`}))]:[],[c]),E=c?.sources.find(e=>e.id===h),D=async()=>{if(o.trim()){b(`connect`),v([]);try{(await w(o.trim(),A9)).sources.length?l.success(`Repository connected`):l.info(`Repository connected, but no supported schema source was found`)}catch(e){l.error(e.message)}finally{b(null)}}},O=async e=>{if(c){b(`connect`),v([]);try{await w(c.root,e,h)}catch(e){l.error(e.message)}finally{b(null)}}},k=async e=>{if(!c||!h)throw Error(`Select a schema source first`);let[t]=await Promise.all([j9(`/api/repositories/read`,{repository_path:c.root,ref:e,source_id:h}),M()]),n=vke(t.source.kind,t.files);if(!n.nodes.length)throw Error(`No tables could be parsed from this schema source`);return{...t,...n}},A=async()=>{b(`preview`),v([]);try{let e=await k(d),r=k9(t,n,e.nodes,e.edges);v(e.warnings),Oi({proposedNodes:r.nodes,proposedEdges:r.edges,sourceLabel:P9(d,T),commit:e.commit,dbmlSource:e.dbml,canApply:!0}),C({repositoryPath:c.root,ref:d,sourceId:h}),l.info(`Repository schema preview opened on the canvas`)}catch(e){l.error(e.message)}finally{b(null)}},j=async()=>{if(p&&p!==d){b(`compare`),v([]);try{let[e,t]=await Promise.all([k(p),k(d)]),n=k9(e.nodes,e.edges,t.nodes,t.edges);v([...e.warnings,...t.warnings]),Oi({originalNodes:e.nodes,originalEdges:e.edges,proposedNodes:n.nodes,proposedEdges:n.edges,sourceLabel:`${P9(p,T)} → ${P9(d,T)}`,commit:t.commit,canApply:!1}),l.info(`Git ref comparison opened on the canvas`)}catch(e){l.error(e.message)}finally{b(null)}}},N=async()=>{let{open:e}=await _i(async()=>{let{open:e}=await Promise.resolve().then(()=>Yh);return{open:e}},void 0),t=await e({directory:!0,multiple:!1,title:`Select Git repository`});typeof t==`string`&&s(t)};return(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b p-4`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h2`,{className:`font-semibold`,children:`Repository Schema`}),(0,G.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:c?.root||`Link this ERD to a local Git repository`})]}),(0,G.jsx)(U,{variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>{Ni(),r()},"aria-label":`Close repository panel`,children:(0,G.jsx)(Pr,{className:`size-4`})})]}),(0,G.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto p-4`,children:[c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Schema source`}),(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,onClick:async()=>{try{await M9(a,`DELETE`),x.current=null,localStorage.removeItem(i),Ni(),u(null),g(``),v([])}catch(e){l.error(e.message)}},children:[(0,G.jsx)(Xo,{className:`size-3.5`}),`Disconnect`]})]}),(0,G.jsx)(N9,{label:`Git ref`,children:(0,G.jsx)($n,{value:d,onChange:e=>void O(e),items:T,disabled:y!==null,placeholder:`Select Git ref`,searchPlaceholder:`Search branch or commit...`,emptyMessage:`No Git ref found`,className:`h-9 text-sm`,getItemValue:e=>e.value,getItemLabel:e=>e.label,filterItem:(e,t)=>e.label.toLowerCase().includes(t.toLowerCase())})}),(0,G.jsx)(N9,{label:`Schema`,children:(0,G.jsxs)(_r,{value:h,disabled:y!==null||!c.sources.length,onValueChange:e=>{e&&(g(e),C({repositoryPath:c.root,ref:d,sourceId:e}))},children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{placeholder:`Select schema`,children:E?.label})}),(0,G.jsx)(pr,{children:c.sources.map(e=>(0,G.jsx)(fr,{value:e.id,children:e.label},e.id))})]})}),!c.sources.length&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Supported sources: Laravel migrations, DBML, and SQL schema/migration files.`}),(0,G.jsxs)(U,{className:`w-full`,disabled:!h||y!==null,onClick:()=>void A(),children:[y===`preview`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(cr,{className:`size-4`}),`Preview against current ERD`]})]}),(0,G.jsxs)(`section`,{className:`space-y-3 border-t pt-5`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Compare Git refs`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`Compare branches or commits without checking them out. This preview cannot modify the current ERD.`})]}),(0,G.jsx)(N9,{label:`Base ref`,children:(0,G.jsx)($n,{value:p,onChange:m,items:T.filter(e=>e.value!==A9),disabled:y!==null,placeholder:`Select base ref`,searchPlaceholder:`Search branch or commit...`,emptyMessage:`No Git ref found`,className:`h-9 text-sm`,getItemValue:e=>e.value,getItemLabel:e=>e.label,filterItem:(e,t)=>e.label.toLowerCase().includes(t.toLowerCase())})}),(0,G.jsxs)(U,{variant:`outline`,className:`w-full`,disabled:!h||!p||p===d||y!==null,onClick:()=>void j(),children:[y===`compare`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(ao,{className:`size-4`}),`Compare with selected ref`]})]})]}):(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-lg bg-muted`,children:(0,G.jsx)(ir,{className:`size-5 text-muted-foreground`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Connect a repository`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`Only supported schema files are read. The repository and active branch are never modified.`})]}),(0,G.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:`Repository path`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{value:o,onChange:e=>s(e.target.value),placeholder:`/path/to/project`,onKeyDown:e=>{e.key===`Enter`&&D()}}),S&&(0,G.jsx)(U,{variant:`outline`,size:`icon`,onClick:()=>void N(),"aria-label":`Browse repository`,children:(0,G.jsx)(no,{className:`size-4`})})]})]}),(0,G.jsxs)(U,{className:`w-full`,disabled:!o.trim()||y!==null,onClick:()=>void D(),children:[y===`connect`?(0,G.jsx)(xo,{className:`size-4 animate-spin`}):(0,G.jsx)(ir,{className:`size-4`}),`Connect repository`]})]}),_.length>0&&(0,G.jsxs)(`section`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(ei,{className:`size-4`}),_.length,` migration statement`,_.length===1?``:`s`,` need review`]}),(0,G.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted-foreground`,children:_.slice(0,8).map(e=>(0,G.jsx)(`li`,{className:`break-words`,children:e},e))})]})]})]})}function N9({label:e,children:t}){return(0,G.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:e}),t]})}function P9(e,t){return t.find(t=>t.value===e)?.label||e.slice(0,12)}function bke(e,t){switch(e){case`chat`:return t.aiChat;case`history`:return t.history;case`repository`:return t.repository;default:return!1}}var F9=`ERD Builder Pro`;function xke({pathname:e,activeFileName:t,breadcrumbLabel:n,featureLabel:r,searchFeature:i}){let a=e.replace(/\/+$/,``)||`/`;return/^\/(?:notes|diagrams|db-client|flowcharts|drawings)\/[^/]+$/.test(a)&&t?`${t} | ${F9}`:a===`/`?`Dashboard | ${F9}`:a===`/trash`?`Trash | ${F9}`:a===`/library`?`Library | ${F9}`:a===`/team-workspaces`?`Team Workspaces | ${F9}`:a===`/users`?`User Management | ${F9}`:a.startsWith(`/teams/`)?`${n||`Team management`} | ${F9}`:a.startsWith(`/projects/`)?`${n||`Project`} | ${F9}`:a.startsWith(`/notes/`)?`Notes | ${F9}`:a.startsWith(`/diagrams/`)?`${i===`db-client`?`DB Client`:`Diagram`} | ${F9}`:a.startsWith(`/db-client/`)?`${n||`DB Client`} | ${F9}`:a.startsWith(`/flowcharts/`)?`Flowchart | ${F9}`:a.startsWith(`/drawings/`)?`Drawing | ${F9}`:F9}var Ske={postgresql:`PostgreSQL`,mysql:`MySQL`,sqlite:`SQLite`},Cke={postgresql:`bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20`,mysql:`bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/20`,sqlite:`bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/20`};function wke({account:e,catalogs:t,onEdit:n,onDelete:r,onTest:i,onAddCatalog:a,onImportCatalog:o,onDeleteCatalog:s,isTesting:c}){let[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),{id:p,name:m,type:h,host:g,port:_}=e,v=h===`sqlite`?g||`Local file`:g?`${g}:${_||``}`:`-`,y=e=>{e.stopPropagation(),u(!l)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rounded-lg border transition-colors hover:bg-accent/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 cursor-pointer`,onClick:y,children:[(0,G.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-full border bg-muted/50`,children:(0,G.jsx)(Mr,{className:`h-4 w-4 text-muted-foreground`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,G.jsx)(`span`,{className:`truncate pr-2 text-sm font-medium`,title:m,children:m}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] px-1.5 py-0 h-4 ${Cke[h]}`,children:Ske[h]}),(0,G.jsx)(Vh,{variant:`outline`,className:e.environment===`production`?`h-4 border-red-500/30 bg-red-500/10 px-1.5 py-0 text-[10px] uppercase text-red-600`:`h-4 px-1.5 py-0 text-[10px] uppercase`,children:e.environment||`development`}),e.safeMode===`read-only`&&(0,G.jsx)(Vh,{variant:`outline`,className:`h-4 border-emerald-500/30 bg-emerald-500/10 px-1.5 py-0 text-[10px] text-emerald-600`,children:`READ ONLY`}),e.sslMode&&e.sslMode!==`disable`&&(0,G.jsx)(Vh,{variant:`outline`,className:`h-4 px-1.5 py-0 text-[10px]`,children:`TLS`}),t.length>0&&(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] px-1.5 py-0 h-4 bg-muted`,children:h===`sqlite`?`1 DB`:`${t.length} DB`})]})]}),(0,G.jsx)(`div`,{className:`mt-2 truncate text-xs text-muted-foreground`,title:v,children:v})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-7 w-7`,onClick:y,children:l?(0,G.jsx)(Xt,{className:`h-3.5 w-3.5`}):(0,G.jsx)(St,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-7 w-7`}),onClick:e=>e.stopPropagation(),children:(0,G.jsx)(Tr,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-36`,children:[(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),i(e)},disabled:c,className:`cursor-pointer`,children:[c?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,G.jsx)(ka,{className:`h-3.5 w-3.5 mr-2`}),`Test`]}),(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),n(e)},className:`cursor-pointer`,children:[(0,G.jsx)(ar,{className:`h-3.5 w-3.5 mr-2`}),`Edit`]}),(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:t=>{t.stopPropagation(),r(e)},className:`cursor-pointer text-destructive focus:text-destructive`,children:[(0,G.jsx)($r,{className:`h-3.5 w-3.5 mr-2`}),`Delete`]})]})]})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t px-3 py-2 space-y-1.5`,children:[t.length===0?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground py-1`,children:`No databases connected yet`}):(0,G.jsx)(jn,{className:`max-h-48`,children:t.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between rounded-md px-2 py-1.5 hover:bg-accent/50 group/cat`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(Cr,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs truncate`,children:e.label||e.databaseName}),e.label&&e.label!==e.databaseName&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.databaseName,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover/cat:opacity-100 transition-opacity`,children:[(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-6 w-6`,title:`Import as ERD`,onClick:t=>{t.stopPropagation(),o(e)},children:(0,G.jsx)(Cr,{className:`h-3 w-3`})}),(0,G.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`h-6 w-6 text-destructive hover:text-destructive`,title:`Disconnect database`,onClick:t=>{t.stopPropagation(),f(e)},children:(0,G.jsx)(Xo,{className:`h-3 w-3`})})]})]},e.id))}),h!==`sqlite`&&(0,G.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full h-7 text-xs justify-start text-muted-foreground hover:text-foreground`,onClick:t=>{t.stopPropagation(),a(e)},children:[(0,G.jsx)(jt,{className:`h-3 w-3 mr-1.5`}),`Add Database`]})]})]}),(0,G.jsx)(pi,{open:d!==null,onOpenChange:e=>!e&&f(null),children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-[400px]`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)(Xo,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Disconnect Database`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Disconnect `,(0,G.jsx)(`strong`,{children:d?.label||d?.databaseName}),`? ERD Builder files created from this database will also be deleted.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:()=>{d&&s(d),f(null)},children:`Disconnect`})]})]})})]})}var I9=`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,L9={local:`Local`,development:`Development`,staging:`Staging`,production:`Production`},R9={normal:`Normal`,protected:`Protected`,"read-only":`Read-only`},z9={disable:`Disable`,require:`Require`,"verify-ca":`Verify CA`,"verify-full":`Verify Full`};function Tke(e){return(0,G.jsxs)(`div`,{className:`space-y-3 rounded-lg border bg-muted/20 p-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Environment`}),(0,G.jsxs)(_r,{value:e.environment,onValueChange:t=>e.onEnvironmentChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:L9[e.environment]})}),(0,G.jsx)(pr,{children:Object.entries(L9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Safe Mode`}),(0,G.jsxs)(_r,{value:e.safeMode,onValueChange:t=>e.onSafeModeChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:R9[e.safeMode]})}),(0,G.jsx)(pr,{children:Object.entries(R9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`TLS / SSL`}),(0,G.jsxs)(_r,{value:e.sslMode,onValueChange:t=>e.onSslModeChange(t),children:[(0,G.jsx)(mr,{children:(0,G.jsx)(gr,{children:z9[e.sslMode]})}),(0,G.jsx)(pr,{children:Object.entries(z9).map(([e,t])=>(0,G.jsx)(fr,{value:e,children:t},e))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:I9,children:`Query timeout (ms)`}),(0,G.jsx)(wi,{type:`number`,min:1e3,max:6e5,value:e.queryTimeoutMs,onChange:t=>e.onQueryTimeoutChange(t.target.value)})]})]}),e.sslMode!==`disable`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(wi,{placeholder:`CA certificate path (optional)`,value:e.sslCa,onChange:t=>e.onSslCaChange(t.target.value)}),(0,G.jsx)(wi,{placeholder:`Client certificate path (optional)`,value:e.sslCert,onChange:t=>e.onSslCertChange(t.target.value)}),(0,G.jsx)(wi,{placeholder:`Client private key path (optional)`,value:e.sslKey,onChange:t=>e.onSslKeyChange(t.target.value)})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Protected and Production connections require the table name for destructive actions.`})]})}var B9=[{value:`postgresql`,label:`PostgreSQL`,defaultPort:5432},{value:`mysql`,label:`MySQL`,defaultPort:3306},{value:`sqlite`,label:`SQLite`,defaultPort:0}];function Eke({open:e,onOpenChange:t,editing:n,onSave:r,onTest:i,getDefaultPort:a,projects:o=[]}){let[s,c]=(0,W.useState)(n?.type||`postgresql`),[l,u]=(0,W.useState)(n?.name||``),[d,f]=(0,W.useState)(n?.host||``),[p,m]=(0,W.useState)(String(n?.port??a(s))),[h,g]=(0,W.useState)(n?.user||``),[_,v]=(0,W.useState)(``),[y,b]=(0,W.useState)(n?.environment||`development`),[x,S]=(0,W.useState)(n?.safeMode||`protected`),[C,w]=(0,W.useState)(n?.sslMode||`disable`),[T,E]=(0,W.useState)(n?.sslCa||``),[D,O]=(0,W.useState)(n?.sslCert||``),[k,A]=(0,W.useState)(n?.sslKey||``),[j,M]=(0,W.useState)(String(n?.queryTimeoutMs||3e4)),[N,P]=(0,W.useState)(``),[F,I]=(0,W.useState)(`none`),[L,R]=(0,W.useState)(!1),[ee,te]=(0,W.useState)(null),[ne,re]=(0,W.useState)(!1),ie=!!n;(0,W.useEffect)(()=>{e&&(n?(c(n.type),u(n.name),f(n.host||``),m(String(n.port??a(n.type))),g(n.user||``),v(``),b(n.environment||`development`),S(n.safeMode||`protected`),w(n.sslMode||`disable`),E(n.sslCa||``),O(n.sslCert||``),A(n.sslKey||``),M(String(n.queryTimeoutMs||3e4)),P(``),I(`none`)):(c(`postgresql`),u(``),f(`localhost`),m(`5432`),g(`postgres`),v(``),b(`development`),S(`protected`),w(`disable`),E(``),O(``),A(``),M(`30000`),P(``),I(`none`)),te(null))},[e,n,a]);let z=e=>{if(!e)return;let t=e;c(t),m(String(a(t))),t===`sqlite`?(f(``),g(``),v(``),P(l)):d||f(`localhost`),te(null)},ae=()=>({name:l,type:s,host:d,port:Number(p),user:h,password:_,database:s===`sqlite`?d:void 0,erdName:s===`sqlite`?N:void 0,projectId:s===`sqlite`?F:void 0,environment:y,safeMode:x,sslMode:C,sslCa:T||void 0,sslCert:D||void 0,sslKey:k||void 0,queryTimeoutMs:Number(j)||3e4}),oe=async()=>{try{let{open:e}=await _i(async()=>{let{open:e}=await Promise.resolve().then(()=>Yh);return{open:e}},void 0),t=await e({multiple:!1,filters:[{name:`SQLite database`,extensions:[`db`,`sqlite`,`sqlite3`]}]});typeof t==`string`&&(f(t),l.trim()||u(t.split(/[\\/]/).pop()?.replace(/\.(db|sqlite3?|sqlite)$/i,``)||`SQLite database`),N.trim()||P(t.split(/[\\/]/).pop()?.replace(/\.(db|sqlite3?|sqlite)$/i,``)||`SQLite ERD`))}catch{te({success:!1,message:`File picker is unavailable. Enter the SQLite file path manually.`})}},se=async()=>{R(!0),te(null);let e=await i(ae());te(e),R(!1)},ce=async()=>{if(!l.trim())return;re(!0);let e=await r(ae());re(!1),e&&t(!1)},le=s===`sqlite`;return(0,G.jsx)(Yr,{open:e,onOpenChange:t,children:(0,G.jsxs)(Vr,{className:`sm:max-w-md`,children:[(0,G.jsx)(Jr,{children:(0,G.jsx)(Hr,{children:ie?`Edit Server Account`:`New Server Account`})}),(0,G.jsxs)(Wr,{className:`space-y-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Database Type`}),(0,G.jsxs)(_r,{value:s,onValueChange:z,children:[(0,G.jsx)(mr,{className:`h-10`,children:(0,G.jsx)(gr,{children:B9.find(e=>e.value===s)?.label||s})}),(0,G.jsx)(pr,{children:B9.map(e=>(0,G.jsx)(fr,{value:e.value,children:e.label},e.value))})]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Server Name`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`My Production DB`,value:l,onChange:e=>u(e.target.value)})]}),le?(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`SQLite File Path`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(wi,{className:`h-10`,placeholder:`/path/to/database.sqlite`,value:d,onChange:e=>f(e.target.value)}),(0,G.jsxs)(U,{type:`button`,variant:`outline`,className:`h-10 shrink-0`,onClick:oe,children:[(0,G.jsx)(Jn,{className:`mr-1.5 h-3.5 w-3.5`}),`Choose`]})]})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(jr,{className:`col-span-2`,children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Host`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`localhost`,value:d,onChange:e=>f(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Port`}),(0,G.jsx)(wi,{className:`h-10`,type:`number`,value:p,onChange:e=>m(e.target.value)})]})]}),!le&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`User`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:s===`postgresql`?`postgres`:`root`,value:h,onChange:e=>g(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Password`}),(0,G.jsx)(wi,{className:`h-10`,type:`password`,placeholder:ie?`(saved)`:`password`,value:_,onChange:e=>v(e.target.value)})]})]}),!le&&(0,G.jsx)(Tke,{environment:y,safeMode:x,sslMode:C,sslCa:T,sslCert:D,sslKey:k,queryTimeoutMs:j,onEnvironmentChange:b,onSafeModeChange:S,onSslModeChange:w,onSslCaChange:E,onSslCertChange:O,onSslKeyChange:A,onQueryTimeoutChange:M}),le&&!ie&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD New Name`}),(0,G.jsx)(wi,{className:`h-10`,placeholder:`SQLite ERD name`,value:N,onChange:e=>P(e.target.value)})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Workspace`}),(0,G.jsx)($n,{value:F,onChange:I,items:[{id:`none`,name:`Uncategorized`},...o],placeholder:`Workspace (optional)`,searchPlaceholder:`Search workspace...`,emptyMessage:`No workspace found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]}),ee&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border px-3 py-2 text-sm ${ee.success?`border-green-500/20 bg-green-500/5 text-green-700 dark:text-green-400`:`border-red-500/20 bg-red-500/5 text-red-700 dark:text-red-400`}`,children:[ee.success?(0,G.jsx)(Rn,{className:`h-4 w-4 shrink-0`}):(0,G.jsx)(La,{className:`h-4 w-4 shrink-0`}),(0,G.jsx)(`span`,{children:ee.message})]})]}),(0,G.jsxs)(Gr,{className:`gap-2`,children:[(0,G.jsxs)(U,{variant:`outline`,className:`h-9`,onClick:se,disabled:L,children:[L?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}):null,`Test Connection`]}),(0,G.jsx)(qr,{render:(0,G.jsx)(U,{variant:`ghost`,className:`h-9`}),children:`Cancel`}),(0,G.jsxs)(U,{className:`h-9 px-6`,disabled:!l.trim()||le&&(!d.trim()||!ie&&!N.trim())||ne,onClick:ce,children:[ne?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}):null,ie?`Save`:`Create`]})]})]})})}var Dke={postgresql:5432,mysql:3306,sqlite:0};function Oke(){let{user:e,isGuest:t}=la(),[n,r]=(0,W.useState)([]),[i,a]=(0,W.useState)(!1),o=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),s=(0,W.useCallback)(async()=>{if(e&&!t&&o){a(!0);try{let e=await Si(`/api/accounts`);if(!e.ok)throw Error(`Failed to load accounts`);let t=await e.json();r(t)}catch(e){l.error(e.message||`Failed to load database accounts`)}finally{a(!1)}}},[e,t,o]);return(0,W.useEffect)(()=>{s()},[s]),{accounts:n,isLoading:i,fetchAccounts:s,createAccount:async e=>{try{let t=await Si(`/api/accounts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();throw Error(e.error||`Failed to save account`)}let n=await t.json();return r(e=>[n,...e]),l.success(`Server account saved`),n}catch(e){return l.error(e.message||`Failed to save account`),null}},updateAccount:async(e,t)=>{try{let n=await Si(`/api/accounts/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json();throw Error(e.error||`Failed to update account`)}let i=await n.json();return r(t=>t.map(t=>t.id===e?i:t)),l.success(`Account updated`),i}catch(e){return l.error(e.message||`Failed to update account`),null}},deleteAccount:async e=>{try{if(!(await Si(`/api/accounts/${e}`,{method:`DELETE`})).ok)throw Error(`Failed to delete account`);r(t=>t.filter(t=>t.id!==e)),l.success(`Account deleted`)}catch(e){l.error(e.message||`Failed to delete account`)}},listDatabases:async e=>{try{let t=await Si(`/api/accounts/${e}/databases`,{method:`POST`});if(!t.ok){let e=await t.json();throw Error(e.error||`Failed to list databases`)}return(await t.json()).databases||[]}catch(e){return l.error(e.message||`Failed to list databases`),[]}},createDatabase:async(e,t)=>{try{let n=await Si(`/api/accounts/${e}/databases/create`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json();throw Error(e.error||`Failed to create database`)}let r=await n.json();return l.success(`Database "${r.name}" created`),r}catch(e){return l.error(e.message||`Failed to create database`),null}},testAccount:async e=>{try{let t=await Si(`/api/accounts/${e}/test`,{method:`POST`}),n=await t.json();return!t.ok||!n.success?{success:!1,message:n.error||n.message||`Connection failed`}:{success:!0,message:n.message||`Connection successful`}}catch(e){return{success:!1,message:e.message||`Failed to test connection`}}},getDefaultPort:e=>Dke[e]}}function kke(e){let{user:t,isGuest:n}=la(),[r,i]=(0,W.useState)([]),[a,o]=(0,W.useState)(!1),s=typeof window<`u`&&!!(window.__TAURI__||window.__TAURI_INTERNALS__),c=(0,W.useCallback)(async()=>{if(s&&t&&!n){o(!0);try{let t=e?`?accountId=${e}`:``,n=await Si(`/api/catalogs${t}`);if(!n.ok)throw Error(`Failed to load catalog`);let r=await n.json();i(r)}catch(e){l.error(e.message||`Failed to load database catalogs`)}finally{o(!1)}}},[t,n,s,e]);return(0,W.useEffect)(()=>{c()},[c]),{catalogs:r,isLoading:a,fetchCatalogs:c,createCatalog:async(e,t,n)=>{try{let r=await Si(`/api/catalogs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:e,databaseName:t,label:n})});if(!r.ok){let e=await r.json();throw Error(e.error||`Failed to create catalog`)}let a=await r.json();return i(e=>[a,...e]),l.success(`Database "${t}" connected`),a}catch(e){return l.error(e.message||`Failed to connect database`),null}},deleteCatalog:async e=>{try{let t=await Si(`/api/catalogs/${e}`,{method:`DELETE`});if(!t.ok)throw Error(`Failed to delete catalog`);let n=await t.json();return i(t=>t.filter(t=>t.id!==e)),l.success(`Database disconnected`),n}catch(e){return l.error(e.message||`Failed to disconnect database`),null}},importAsDbClient:async(e,t,n)=>{try{let r=await Si(`/api/catalogs/${e}/import`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t,project_id:n??null})});if(!r.ok){let e=await r.json();throw Error(e.error||`Failed to import schema`)}let i=await r.json();return l.success(`Imported ${i.tableCount} tables as "${t}"`),i}catch(e){return l.error(e.message||`Failed to import schema`),null}},migrateOldConnections:async()=>{try{let e=await Si(`/api/migrate-connections`,{method:`POST`});if(!e.ok)throw Error(`Migration failed`);let t=await e.json();return t.migrated>0&&(l.success(`Migrated ${t.migrated} old connections`),c()),t.migrated||0}catch(e){return l.error(`Migration failed: `+e.message),0}}}}function V9({open:e,onOpenChange:t,projects:n,onImportComplete:r,defaultProjectId:i}){let{accounts:a,isLoading:o,createAccount:s,updateAccount:c,deleteAccount:u,listDatabases:d,createDatabase:f,testAccount:p,getDefaultPort:m,fetchAccounts:h}=Oke(),{catalogs:g,fetchCatalogs:_,createCatalog:v,deleteCatalog:y,importAsDbClient:b}=kke(),[x,S]=(0,W.useState)(``),[C,w]=(0,W.useState)(!1),[T,E]=(0,W.useState)(null),[D,O]=(0,W.useState)(null),[k,A]=(0,W.useState)(new Set),[j,M]=(0,W.useState)(null),[N,P]=(0,W.useState)([]),[F,I]=(0,W.useState)(!1),[L,R]=(0,W.useState)(`connect`),[ee,te]=(0,W.useState)(null),[ne,re]=(0,W.useState)(``),[ie,z]=(0,W.useState)(``),[ae,oe]=(0,W.useState)(!1),[se,ce]=(0,W.useState)(!1),[le,ue]=(0,W.useState)(``),[de,B]=(0,W.useState)(`none`),[fe,pe]=(0,W.useState)(null),[me,he]=(0,W.useState)(``),[ge,_e]=(0,W.useState)(!1),ve=x.trim()?a.filter(e=>e.name.toLowerCase().includes(x.toLowerCase())||e.type.toLowerCase().includes(x.toLowerCase())||e.host?.toLowerCase().includes(x.toLowerCase())):a,V=N.find(e=>e.name===ne),H=()=>{E(null),R(`import`),w(!0)},ye=e=>{E(e),R(`connect`),w(!0)},be=async e=>{let n=T?await c(T.id,e):await s(e);if(n&&!T){if(e.type===`sqlite`){let i=e.database?.trim()||e.host.trim(),a=await v(n.id,i,n.name);if(a){_(),h();let i=e.projectId===`none`?null:e.projectId,o=await b(a.id,e.erdName?.trim()||n.name,i);o?.dbClient?.uid&&(t(!1),r?.(o.dbClient.uid))}}else setTimeout(()=>we(n,`import`),0)}return n},xe=async e=>{try{let{apiFetch:t}=await _i(async()=>{let{apiFetch:e}=await import(`./api-DuV0sTuY.js`).then(e=>e.r);return{apiFetch:e}},__vite__mapDeps([16,5,10])),n=await t(`/api/accounts/test-cred`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),r=await n.json();return!n.ok||!r.success?{success:!1,message:r.error||r.message||`Connection failed`}:{success:!0,message:r.message||`Connection successful`}}catch(e){return{success:!1,message:e.message||`Failed to test connection`}}},Se=async e=>{A(t=>new Set(t).add(e.id));let t=await p(e.id);A(t=>{let n=new Set(t);return n.delete(e.id),n}),t.success?(l.success(t.message),h()):l.error(t.message)},Ce=async()=>{D&&(await u(D.id),O(null))},we=async(e,t=`connect`)=>{R(t),I(!0),M(e),P([]),re(``),z(``),oe(!1),ue(``),B(i??`none`);let n=await d(e.id);P(n),I(!1)},Te=e=>{re(e),le.trim()&&le!==ne||ue(e)},Ee=async()=>{if(j&&ie.trim()){ce(!0);try{let e=await f(j.id,ie.trim());if(!e)return;P(t=>[...t.filter(t=>t.name!==e.name),e].sort((e,t)=>e.name.localeCompare(t.name))),z(``),oe(!1),Te(e.name)}finally{ce(!1)}}},De=async()=>{if(!j||!ne)return;te(ne);let e=g.find(e=>e.accountId===j.id&&e.databaseName===ne)||await v(j.id,ne);if(e&&(M(null),_(),h(),L===`import`)){let n=de===`none`?null:de,i=await b(e.id,le.trim()||ne,n);i?.dbClient?.uid&&(t(!1),r?.(i.dbClient.uid))}te(null)},Oe=e=>{he(e.label||e.databaseName),B(i??`none`),pe(e)},ke=async()=>{if(fe&&me.trim()&&de!==`none`){_e(!0);try{let e=de===`none`?null:de,n=await b(fe.id,me.trim(),e);n?.dbClient?.uid&&(pe(null),he(``),t(!1),r?.(n.dbClient.uid))}finally{_e(!1)}}};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(vh,{open:e,onOpenChange:t,children:(0,G.jsxs)(yh,{side:`right`,className:`w-full p-0 flex flex-col gap-0 sm:w-[min(42rem,calc(100vw-2rem))] sm:max-w-none`,children:[(0,G.jsxs)(bh,{className:`p-5 pb-3 sm:p-6 sm:pb-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pr-10`,children:[(0,G.jsx)(xh,{className:`text-lg`,children:`Database Accounts`}),(0,G.jsx)(Vh,{variant:`outline`,className:`text-[10px] h-4 px-1.5 text-amber-600 border-amber-400 dark:text-amber-400 dark:border-amber-500`,children:`Experimental`})]}),(0,G.jsx)(Sh,{className:`max-w-xl leading-relaxed`,children:`Create DB clients from external databases and local SQLite files`})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 py-3 sm:flex-row sm:px-6`,children:[(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Zr,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(wi,{className:`pl-8`,placeholder:`Search accounts...`,value:x,onChange:e=>S(e.target.value)})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(U,{size:`lg`,className:`w-full shrink-0 sm:w-auto`,onClick:H,children:[(0,G.jsx)(jt,{className:`h-3.5 w-3.5 mr-1`}),`New DB Client`]})})]}),(0,G.jsx)(jn,{className:`min-h-0 flex-1 px-5 pb-5 sm:px-6 sm:pb-6`,children:o?(0,G.jsx)(`div`,{className:`space-y-2 pt-2`,children:[1,2,3].map(e=>(0,G.jsx)(Ei,{className:`h-16 w-full rounded-lg`},e))}):ve.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center pt-12 text-center`,children:[(0,G.jsx)(Mr,{className:`h-10 w-10 text-muted-foreground/40 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:x.trim()?`No accounts found`:`No database accounts yet`}),!x.trim()&&(0,G.jsxs)(U,{variant:`outline`,size:`sm`,className:`mt-3`,onClick:H,children:[(0,G.jsx)(jt,{className:`h-3.5 w-3.5 mr-1.5`}),`New DB Client`]})]}):(0,G.jsx)(`div`,{className:`space-y-2 pt-2`,children:ve.map(e=>(0,G.jsx)(wke,{account:e,catalogs:g.filter(t=>t.accountId===e.id),onEdit:ye,onDelete:O,onTest:Se,onAddCatalog:e=>we(e,`import`),onImportCatalog:Oe,onDeleteCatalog:async e=>{let t=await y(e.id);_(),h(),t&&t.deletedClients>0&&l.info(`${t.deletedClients} DB Client(s) deleted: ${t.clientNames.join(`, `)}`,{duration:5e3})},isTesting:k.has(e.id)},e.id))})})]})}),(0,G.jsx)(Eke,{open:C,onOpenChange:w,editing:T,onSave:be,onTest:xe,getDefaultPort:m,projects:n}),(0,G.jsx)(pi,{open:D!==null,onOpenChange:e=>!e&&O(null),children:(0,G.jsxs)(ni,{size:`sm`,className:`max-w-100`,children:[(0,G.jsxs)(ii,{children:[(0,G.jsx)(si,{className:`bg-destructive/10`,children:(0,G.jsx)($r,{className:`w-5 h-5 text-destructive`})}),(0,G.jsx)(mi,{children:`Delete Account`})]}),(0,G.jsx)(di,{children:(0,G.jsxs)(li,{children:[`Delete server account `,(0,G.jsx)(`strong`,{children:D?.name}),`? All connected databases (`,g.filter(e=>e.accountId===D?.id).length,`) will be disconnected. Diagrams using these databases still exist, but can no longer sync.`]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})}),(0,G.jsx)(pi,{open:j!==null,onOpenChange:e=>!e&&M(null),children:(0,G.jsxs)(ni,{children:[(0,G.jsx)(ii,{children:(0,G.jsx)(mi,{children:L===`import`?`Create DB Client`:`Select Database`})}),(0,G.jsx)(di,{children:F?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,G.jsx)(xo,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Production Database`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,G.jsx)($n,{value:ne,onChange:Te,items:N,placeholder:`Select production database`,searchPlaceholder:`Search database...`,emptyMessage:`No database found`,getItemValue:e=>e.name,getItemLabel:e=>e.isConnected?`${e.name} (connected)`:e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`}),j?.type===`sqlite`?null:(0,G.jsx)(U,{type:`button`,variant:`outline`,size:`icon-sm`,className:`h-9 w-9`,onClick:()=>oe(e=>!e),title:`Create database`,children:(0,G.jsx)(jt,{className:`h-3.5 w-3.5`})})]})]}),ae&&j?.type!==`sqlite`&&(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`New Database`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,G.jsx)(wi,{value:ie,onChange:e=>z(e.target.value),placeholder:`new_database`,className:`h-9`,onKeyDown:e=>{e.key===`Enter`&&ie.trim()&&!se&&Ee()}}),(0,G.jsx)(U,{type:`button`,className:`h-9`,onClick:Ee,disabled:!ie.trim()||se,children:se?(0,G.jsx)(xo,{className:`h-3.5 w-3.5 animate-spin`}):`Create`})]})]}),L===`import`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD File Name`}),(0,G.jsx)(wi,{value:le,onChange:e=>ue(e.target.value),placeholder:`ERD file name`,className:`h-9`,onKeyDown:e=>{e.key===`Enter`&&ne&&le.trim()&&!ee&&De()}})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsx)($n,{value:de,onChange:B,items:n,placeholder:`Select project`,searchPlaceholder:`Search project...`,emptyMessage:`No project found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]})]})}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),N.length>0&&(0,G.jsx)(ci,{onClick:De,disabled:!ne||L===`connect`&&V?.isConnected||L===`import`&&(!le.trim()||de===`none`)||ee!==null,children:ee?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}),`Creating...`]}):L===`import`?`Create DB Client`:`Connect`})]})]})}),(0,G.jsx)(pi,{open:fe!==null,onOpenChange:e=>!e&&pe(null),children:(0,G.jsxs)(ni,{children:[(0,G.jsx)(ii,{children:(0,G.jsx)(mi,{children:`Import as ERD Diagram`})}),(0,G.jsxs)(di,{children:[(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:[`Create a new ERD diagram from `,(0,G.jsx)(`strong`,{children:fe?.label||fe?.databaseName}),` tables.`]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`ERD File Name`}),(0,G.jsx)(wi,{value:me,onChange:e=>he(e.target.value),placeholder:`Diagram name`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&me.trim()&&!ge&&ke()}})]}),(0,G.jsxs)(jr,{className:`mt-3`,children:[(0,G.jsx)(Dr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70 px-1`,children:`Project`}),(0,G.jsx)($n,{value:de,onChange:B,items:n,placeholder:`Select project`,searchPlaceholder:`Search project...`,emptyMessage:`No project found`,getItemValue:e=>String(e.id),getItemLabel:e=>e.name,filterItem:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase()),className:`h-9 text-sm`})]})]}),(0,G.jsxs)(fi,{children:[(0,G.jsx)(oi,{children:`Cancel`}),(0,G.jsx)(ci,{onClick:ke,disabled:!me.trim()||de===`none`||ge,children:ge?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xo,{className:`h-3.5 w-3.5 mr-2 animate-spin`}),`Importing...`]}):`Import`})]})]})})]})}function Ake({root:e,session:t,mainAI:n,paired:r,onPairChange:i,onFocusedSession:a}){let o=m(),s=v(),[c,u]=(0,W.useState)(null),f=(0,W.useRef)(null),h=(0,W.useCallback)(e=>f.current?.(e),[]),[_]=g(),[y,b]=(0,W.useState)(!1),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(null),[T,D]=(0,W.useState)(null),{rightPanelMode:O,setRightPanelMode:k,pendingPrompt:A,clearPrompt:j,pendingAction:M,clearPendingAction:N}=bn(),P=(0,W.useMemo)(()=>{let e=(t?z(t.file).split(`?`)[0]:o.pathname).match(/^\/(notes|diagrams|flowcharts|drawings|db-client)\/([^/]+)$/);return e?{entityType:{notes:`note`,diagrams:`diagram`,flowcharts:`flowchart`,drawings:`drawing`,"db-client":`dbClient`}[e[1]],entityUid:e[2]}:null},[o.pathname,t?.file.type,t?.file.uid]),F=P?.entityType===`diagram`,I=P?.entityType===`diagram`?`diagrams`:P?.entityType===`flowchart`?`flowcharts`:P?.entityType===`note`?`notes`:P?.entityType===`drawing`?`drawings`:null;(0,W.useEffect)(()=>{if(P?.entityType!==`dbClient`){D(null);return}D(null);let e=!1;return Si(`/api/db-clients/${encodeURIComponent(P.entityUid)}`).then(e=>e.ok?e.json():null).then(t=>{e||D(t)}).catch(()=>{e||D(null)}),()=>{e=!0}},[P,e.user?.id]);let{view:L,sidebarView:R,isPublicView:ee,isOnline:te,projects:ne,user:re,isProjectsLoading:ie,handleLogout:ae,handleViewChange:oe,handleNoteSelect:se,handleDrawingSelect:ce,refreshActiveDocument:le,handleSidebarProjectCreate:ue,handleSidebarProjectUpdate:de,handleSidebarProjectDelete:B,handleWorkspaceFilter:fe,selectedWorkspaceUid:me,handleHeaderDelete:he,handleHeaderRename:ge,handleHeaderSettingsSaved:_e,handleHeaderExportSQL:ve,handleHeaderExportImage:V,handleOpenImportModal:H,isImportModalOpen:ye,setIsImportModalOpen:be,handleExportMarkdown:xe,handleCopyMarkdown:Se,handleImportMarkdown:Ce,executeImportMarkdown:we,executeExportMarkdown:Te,handleDuplicate:Ee,syncError:De,isSyncing:Oe,isLocalSaving:ke,isRefreshing:Ae,hasPendingSyncs:je,syncDrafts:U,activeFileUid:Me,currentActiveId:Ne,initialShareSettings:Pe,activeDocument:Fe,isGuest:Ie,isReadOnlyFile:Le,getFileAccessRole:Re,featureLabel:ze,activeProjectName:Be,activeFileName:Ve,hasActiveItem:He,activeNote:Ue,activeDrawing:We,activeFlowchart:Ge,activeDiagram:Ke,notes:qe,diagrams:Je,flowcharts:Ye,drawings:Xe,setNodes:Ze,setEdges:Qe,activeDiagramId:$e,takeSnapshot:et,saveDiagram:tt,triggerDebouncedSync:nt,broadcastMessage:rt,setIsLocalSaving:it,viewportRef:at,lastLoadedDiagramIdRef:ot,fetchTrash:st,triggerTableRefresh:ct,setTableLoadingState:lt,setIsSettingsOpen:ut,setSettingsTab:dt,selectedNodeId:ft,setSelectedNodeId:pt,selectedEdgeId:mt,setSelectedEdgeId:ht,selectedEntity:gt,deleteEntity:_t,deleteEdge:vt,updateDiagram:yt,updateNote:bt,updateDrawing:xt,updateFlowchart:St,moveDiagramToProject:Ct,moveNoteToProject:wt,moveDrawingToProject:Tt,moveFlowchartToProject:Et,deleteDiagram:Dt,deleteNote:Ot,deleteDrawing:kt,deleteFlowchart:At,handleSidebarDiagramCreate:jt,handleSidebarNoteCreate:Mt,handleSidebarDrawingCreate:Nt,handleSidebarFlowchartCreate:Pt,isMoveToTrashAlertOpen:Ft,setIsMoveToTrashAlertOpen:It,isDeleteAlertOpen:Lt,setIsDeleteAlertOpen:Rt,isRenameDialogOpen:zt,setIsRenameDialogOpen:Bt,isDuplicateDialogOpen:Vt,setIsDuplicateDialogOpen:Ht,isPermanentDeleteConfirmOpen:Ut,setIsPermanentDeleteConfirmOpen:Wt,isImportNoteModalOpen:Gt,setIsImportNoteModalOpen:Kt,isExportNoteModalOpen:qt,setIsExportNoteModalOpen:Jt,newName:Yt,setNewName:Xt,renameProjectId:Zt,setRenameProjectId:Qt,duplicateName:$t,setDuplicateName:en,itemToDelete:tn,createDialogOpen:nn,setCreateDialogOpen:rn,createDialogView:an,setCreateDialogView:on,editDialogNote:sn,setEditDialogNote:cn,tableDeleteDoc:ln,setTableDeleteDoc:un,executeDuplicate:dn,confirmPermanentDelete:fn,handleEdgeUpdate:pn,handleEdgeFlip:mn,breadcrumbLabel:hn,refreshTeamScope:gn,flushPendingSaves:_n,teamScopeVersion:vn,isTeamScopeRefreshing:yn}=pa(),{nodes:xn,edges:Sn}=ta(),[Cn,wn]=(0,W.useState)(``),[Tn,En]=(0,W.useState)([]),[Dn,On]=(0,W.useState)(!1),[kn,An]=(0,W.useState)([]);re?.isSuperAdmin||re?.is_super_admin;let jn=re?.isSso?re.ssoPortalUrl??re.sso_portal_url:null;(0,W.useEffect)(()=>{Zi(jn)},[jn]);let Mn=(0,W.useCallback)(()=>{wn(``),En([]),An([]),k(`closed`),_n().catch(()=>{}),gn()},[_n,gn,k]),Nn=ua(Ie,!!re?.isSso,Mn),[Pn,Fn]=(0,W.useState)(!1),In=Gi(re,Nn.activeTeam,Nn.activeTeamId,Nn.isAvailable),Ln=Wi.filter(e=>e.value!==`db-client`||yi()).map(e=>({...e,locked:e.value!==`db-client`&&In(e.capability)}));(0,W.useEffect)(()=>{if(Ie){An([]);return}let e=!1;return Si(`/api/projects/selectable`).then(e=>e.ok?e.json():{data:[]}).then(t=>{e||An(Array.isArray(t.data)?t.data:[])}).catch(()=>{e||An([])}),()=>{e=!0}},[nn,Ie,zt,Nn.activeTeamId]);let Rn=(0,W.useRef)(!1),zn=(0,W.useCallback)(async e=>{if(!(Rn.current||e===Nn.activeTeamId)){Rn.current=!0;try{await JC(_n,U,{type:L,id:Ne,uid:Me}),Nn.selectTeam(e),wn(``),En([]),k(`closed`),await gn()}catch{l.error(`Could not switch workspaces. Check that your changes are saved and retry.`)}finally{Rn.current=!1}}},[Me,Ne,_n,gn,k,U,Nn.activeTeamId,Nn.selectTeam,L]),Bn=(0,W.useCallback)(async e=>(await JC(_n,U,{type:L,id:Ne,uid:Me}),Nn.createTeam(e)),[Me,Ne,_n,U,Nn.createTeam,L]),Vn=(0,W.useCallback)(e=>{e.manageUrl?window.location.assign(e.manageUrl):s(`/teams/${e.id}`)},[s]),Hn=(0,W.useCallback)(async e=>{await gn(),s(`/teams/${e.id}`)},[s,gn]);o.pathname===`/table/db-client`||o.pathname.startsWith(`/db-client/`)||o.pathname.startsWith(`/diagrams/`)&&_.get(`feature`)===`db-client`||/^\/(table\/(erd|notes|drawings|flowchart)|(notes|diagrams|drawings|flowcharts)\/)/.test(o.pathname),(0,W.useEffect)(()=>{let e=Cn.trim();if(e.length<2){En([]),On(!1);return}let t=!1,n=window.setTimeout(async()=>{On(!0);try{if(Ie){let n=e.toLowerCase(),r=new Map(ne.map(e=>[String(e.id),e])),i=[...Je.filter(e=>(e.source_type??e.sourceType)!==`production_db`).map(e=>({...e,type:`erd`,name:e.name})),...qe.map(e=>({...e,type:`notes`,name:e.title})),...Xe.map(e=>({...e,type:`drawings`,name:e.title})),...Ye.map(e=>({...e,type:`flowchart`,name:e.title}))],a=[...ne.filter(e=>e.name?.toLowerCase().includes(n)).map(e=>({...e,type:`workspace`})),...i.filter(e=>e.name?.toLowerCase().includes(n)).map(e=>({...e,workspace:r.get(String(e.project_id))}))].slice(0,20);t||En(a);return}let n=await Si(`/api/search?q=${encodeURIComponent(e)}`),r=n.ok?await n.json():{data:[]};t||En(Array.isArray(r.data)?r.data:[])}catch{t||En([])}finally{t||On(!1)}},220);return()=>{t=!0,window.clearTimeout(n)}},[Cn,Ie,ne,Je,qe,Xe,Ye]);let Un=(0,W.useCallback)(e=>{if(wn(``),e.type===`workspace`){oe(`erd`,!0,e.uid??e.id);return}let t=e.uid??e.id,n={erd:`/diagrams/${t}`,"db-client":`/db-client/${t}`,notes:`/notes/${t}`,drawings:`/drawings/${t}`,flowchart:`/flowcharts/${t}`}[e.type];n&&s(n)},[oe,s]),Wn=F&&(Ke?.source_type??Ke?.sourceType)===`production_db`,Gn=!Le(Fe),Kn=Ui(Fe,re?.id,Ie)&&Gn,qn=Kn,Jn=Re(Fe),Yn=ln??Fe,Xn=(Yn?.source_type??Yn?.sourceType)===`production_db`,Zn=(0,W.useMemo)(()=>{let e=P;if(!e)return null;switch(e.entityType){case`note`:return Ue?W6(`note`,{title:Ue.title,content:E(String(Ue.content||``))}):null;case`diagram`:if(!Ke||O!==`chat`)return null;let e=W6(`diagram`,{title:Ke.name,nodes:xn,edges:Sn});return(Ke.source_type??Ke.sourceType)===`production_db`?`[Current feature: DB Client]\nSource: live production database metadata\nCurrent tab: ${_.get(`tab`)||`data`}\n\n${e||``}`:e;case`flowchart`:if(!Ge)return null;let t=[],n=[];try{let e=JSON.parse(Ge.data||`{}`);t=e.nodes&&e.nodes.length>0?e.nodes:sa,n=e.edges&&e.edges.length>0?e.edges:Ji}catch{t=sa,n=Ji}return W6(`flowchart`,{title:Ge.title,nodes:t,edges:n});case`drawing`:return We?W6(`drawing`,{title:We.title}):null;default:return null}},[P,Ue,Ke,Ge,We,xn,Sn,_,O]),Qn=P?.entityType===`dbClient`||F&&(Ke?.source_type??Ke?.sourceType)===`production_db`,$n=(0,W.useMemo)(()=>re?.isSso&&Nn.activeTeam?.capabilities?.ai_assistant!==!0||P===null||ee||!Gn||P.entityType===`drawing`?!1:Qn?!0:(_.get(`tab`)||`erd`)===`erd`,[P,ee,Gn,Qn,_,Nn.activeTeam,re?.isSso]),er=(0,W.useMemo)(()=>{let e=P?.entityType===`dbClient`?T:Ue||Ke||Ge||We;return e?.project_id??e?.projectId??null},[P,T,Ue,Ke,Ge,We]),tr=(0,W.useMemo)(()=>{if(ee||Ie||!P||!Ve||Qn)return null;let e=P.entityType===`diagram`?`diagram`:P.entityType===`note`?`note`:P.entityType===`drawing`?`drawing`:P.entityType===`flowchart`?`flowchart`:null,t=Me||Ne||P.entityUid;return e&&t?{featureType:e,fileId:String(t),label:Ve}:null},[Ve,Me,Ne,P,Qn,Ie,ee]),nr=ne.find(e=>String(e.id)===String(er)),rr=nr?.team_id??nr?.teamId,ir=tr&&!ee&&!Ie&&rr&&String(rr)===String(Nn.activeTeamId)?String(Nn.activeTeamId):void 0,ar=(0,W.useMemo)(()=>mt&&Sn.some(e=>e.id===mt)?{type:`relationship`,id:mt}:ft&&xn.some(e=>e.id===ft)?{type:`table`,id:ft}:null,[Sn,xn,mt,ft]),or=(0,W.useCallback)((e,t)=>{window.dispatchEvent(new CustomEvent(`erd-discussion-anchor-selected`,{detail:{type:e,id:t}}))},[]),sr=(0,W.useCallback)(e=>{if(!tr)return;if(e.featureType===tr.featureType&&String(e.fileId)===tr.fileId){e.featureType===`diagram`&&e.anchorType!==`general`&&e.anchorId&&or(e.anchorType,e.anchorId);return}let t={diagram:Je,note:qe,drawing:Xe,flowchart:Ye}[e.featureType]?.find(t=>String(t.uid??t.id)===String(e.fileId)||String(t.id)===String(e.fileId));t&&(s(`${{diagram:`/diagrams`,note:`/notes`,drawing:`/drawings`,flowchart:`/flowcharts`}[e.featureType]}/${t.uid??t.id}`),e.featureType===`diagram`&&e.anchorType!==`general`&&e.anchorId&&window.setTimeout(()=>or(e.anchorType,e.anchorId),0))},[Je,tr,Ye,or,s,qe,Xe]),cr=(0,W.useCallback)(e=>Ki(Ue?.content,e),[Ue?.content]),lr=er&&tr&&ir?(0,G.jsx)(Vw,{projectId:String(er),teamId:ir,userId:re?.id?String(re.id):void 0,userName:re?.name||re?.email,fileContext:tr,anchorContext:ar,readOnly:Jn===`viewer`,onContextSelected:sr,anchorPreview:tr.featureType===`note`?cr:void 0},`${ir}:${er}:${tr.featureType}:${tr.fileId}`):null;(0,W.useEffect)(()=>{document.title=xke({pathname:o.pathname,activeFileName:Ve,breadcrumbLabel:hn,featureLabel:ze,searchFeature:_.get(`feature`)})},[Ve,ze,hn,o.pathname,_]),(0,W.useEffect)(()=>{if(typeof window>`u`||!(window.__TAURI__||window.__TAURI_INTERNALS__))return;let e=e=>{let t=e.target;(!t||t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&!t.isContentEditable)&&(navigator.platform.toLowerCase().includes(`mac`)?e.metaKey:e.ctrlKey)&&e.key===`,`&&(e.preventDefault(),ut(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ut]);let ur=bke(O,{aiChat:$n,history:!!(I&&P),repository:F&&!Wn}),dr=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent),fr=(0,W.useMemo)(()=>({label:dr?`⌘J`:`Ctrl+J`,ariaKeyShortcuts:dr?`Meta+J`:`Control+J`}),[dr]),[pr,mr]=(0,W.useState)(!1),hr=(0,W.useCallback)(()=>k(O===`chat`?`closed`:`chat`),[O,k]),gr=$n&&(!!Fe||Qn||O===`chat`);(0,W.useEffect)(()=>{if(!gr)return;let e=e=>{!(dr?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)||e.shiftKey||e.altKey||e.isComposing||e.defaultPrevented||e.key.toLowerCase()!==`j`||(e.preventDefault(),hr())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[gr,hr,dr]);let _r=(0,W.useCallback)((...e)=>(O===`repository`&&(Ni(),k(`closed`)),oe(...e)),[oe,O,k]);return(0,W.useEffect)(()=>{(!P||O===`chat`&&!$n)&&k(`closed`)},[P,O,$n,k]),(0,W.useEffect)(()=>{O===`repository`&&(!F||Wn)&&k(`closed`)},[O,F,Wn,k]),(0,G.jsxs)(G.Fragment,{children:[!te&&!ee&&(0,G.jsx)(ZTe,{}),!ee&&(0,G.jsx)(GT,{globalSearchResults:Tn,isGlobalSearchLoading:Dn,onGlobalSearchResultSelect:Un,projects:ne,onViewChange:_r,onProjectCreate:ue,onProjectUpdate:de,onProjectDelete:B,onLogout:ae,selectedWorkspaceUid:me,globalSearchQuery:Cn,onGlobalSearchChange:wn,user:re,isOnline:te,isProjectsLoading:ie,onOpenFeedback:()=>b(!0),teams:Nn.teams,teamsAvailable:Nn.isAvailable,licenseRequired:Nn.licenseRequired,activeTeamId:Nn.activeTeamId,onTeamsRefresh:()=>{Nn.fetchTeams()},onTeamSelect:zn,onTeamManage:Vn,onTeamCreate:Bn,onTeamCreated:Hn,onOpenLicenseSettings:()=>{dt(`license`),ut(!0)},ssoPortalUrl:re?.isSso?re.ssoPortalUrl??re.sso_portal_url:null}),(0,G.jsx)(jC.Provider,{value:c,children:(0,G.jsxs)(rne,{className:d(ee?`w-full`:``),children:[(0,G.jsx)(pe.Provider,{value:t?.scope??null,children:(0,G.jsx)(YT,{tabsRef:u,documentPath:t?z(t.file).split(`?`)[0]:void 0,sidebarDisabled:r,featureLabel:ze,activeProjectName:P?.entityType===`dbClient`?T?.project?.name:Be,activeFileName:P?.entityType===`dbClient`?hn||``:Ve,view:L,hasActiveItem:ee?!0:He,syncError:De,isSyncing:Oe,isLocalSaving:ke,isRefreshing:Ae,hasPendingSyncs:je,onSave:U,activeFileUid:Me,activeFileId:Ne,initialShareSettings:Pe,isPublicView:ee,onSettingsSaved:_e,isOnline:te,updatedAt:Fe?.updated_at,onDelete:Kn?he:void 0,onRename:Gn?ge:void 0,canManage:qn,onRefresh:le,onExportAll:Wn?void 0:()=>S(!0),onExportSQL:ve,onExportImage:V,onExportMarkdown:xe,onCopyMarkdown:Se,onImportMarkdown:Gn?Ce:void 0,onDuplicate:Ee,isGuest:Ie,breadcrumbLabel:hn,noteContent:Ue?.content,historyAvailable:!!I,discussionPanel:t?(0,G.jsx)(`span`,{ref:w,className:`contents`}):lr,aiAssistant:gr?{open:O===`chat`,answering:pr,onToggle:hr,shortcut:fr}:void 0})}),(0,G.jsx)(`div`,{className:`relative flex flex-1 flex-col gap-4 p-4 pt-4 min-h-0 overflow-hidden`,style:{isolation:`isolate`},children:yn?(0,G.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center rounded-xl border bg-muted/10`,role:`status`,"aria-live":`polite`,children:[(0,G.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary/30 border-t-primary`}),(0,G.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground`,children:`Loading workspace…`})]}):(0,G.jsx)(uT,{root:e,mainAI:n,teamState:Nn,discussionTarget:C,onFocusedSession:a,onPairChange:i,paneAIRef:f,children:(0,G.jsx)(p,{context:Nn},vn)})}),(0,G.jsx)(vE,{isOpen:Gt,onClose:()=>Kt(!1),onImport:we}),(0,G.jsx)(yE,{isOpen:qt,onClose:()=>Jt(!1),onExport:(e,t,n)=>{Ue&&(e===`markdown`?Te():e===`pdf`?B6.exportToPDF(Ue,t,n,Be||void 0):e===`print`?B6.printNote(Ue,t,Be||void 0):e===`word`&&B6.exportToWord(Ue,t,Be||void 0))}}),(0,G.jsx)(eE,{open:y,onOpenChange:b,isCloud:!!re?.isSso}),re?.isSso&&Nn.activeTeamId&&!ee&&(0,G.jsx)(iE,{teamId:Nn.activeTeamId}),(0,G.jsx)(AT,{isOpen:Ut,onOpenChange:Wt,mode:`permanent-delete`,itemType:tn?.type||``,onConfirm:fn,onAfterDelete:void 0}),!ee&&(0,G.jsx)(sE,{isOpen:zt,onOpenChange:e=>{Bt(e),e||cn(null)},view:L,activeDocument:sn??Fe,canMoveProject:Ui(sn??Fe,re?.id,Ie),newName:Yt,setNewName:Xt,projects:kn,requireProject:!0,selectedProjectId:Zt,setSelectedProjectId:Qt,updateDiagram:yt,updateNote:bt,updateDrawing:xt,updateFlowchart:St,onMoveDiagramToProject:Ct,onMoveNoteToProject:wt,onMoveDrawingToProject:Tt,onMoveFlowchartToProject:Et,onRenameSuccess:void 0}),!ee&&(0,G.jsx)(sE,{isOpen:nn,onOpenChange:e=>{rn(e)},mode:`create`,view:an,activeDocument:null,newName:Yt,setNewName:Xt,projects:kn,requireProject:!0,selectedProjectId:Zt,setSelectedProjectId:Qt,onProjectCreate:async e=>{let t=await ue(e);return t&&An(e=>[t,...e.filter(e=>String(e.id)!==String(t.id))]),t},fileTypes:Ln,onViewChange:on,onViewPlans:()=>Yi(jn),onOpenDbConnections:()=>Fn(!0),onCreate:(e,t)=>{let n=an;return n===`notes`?Mt(e,t):n===`erd`?jt(e,t):n===`drawings`?Nt(e,t):n===`flowchart`?Pt(e,t):null},onRenameSuccess:void 0}),yi()&&(0,G.jsx)(V9,{open:Pn,onOpenChange:Fn,projects:ne,defaultProjectId:ne.find(e=>e.uid===me)?.id?.toString()??null,onImportComplete:e=>s(`/db-client/${e}`)}),(0,G.jsx)(AT,{isOpen:Ft,onOpenChange:e=>{It(e),e||un(null)},activeDocument:Yn,view:L,deleteDiagram:Dt,deleteNote:Ot,deleteDrawing:kt,deleteFlowchart:At,fetchTrash:st,onAfterDelete:()=>{un(null),Xn?s(`/table/db-client`,{replace:!0}):oe(L,!0),lt(`loading`),ct()}}),!ee&&(0,G.jsx)(hE,{isOpen:!!mt&&!(F&&Gn&&!Wn),onOpenChange:e=>{e||ht(null)},selectedEdge:Sn.find(e=>e.id===mt)||null,nodes:xn,handleEdgeUpdate:pn,handleEdgeFlip:mn,deleteEdge:vt,moveOnly:Wn,readOnly:!Gn}),(0,G.jsx)(aE,{isOpen:Lt,onOpenChange:Rt,selectedEntity:gt,deleteEntity:_t,setSelectedNodeId:pt}),(0,G.jsx)(cE,{isOpen:Vt,onOpenChange:Ht,view:L,duplicateName:$t,setDuplicateName:en,executeDuplicate:dn,isRefreshing:Ae}),L===`erd`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(fE,{open:x,onOpenChange:S,nodes:xn,edges:Sn,fileName:Ve||`Untitled`}),(0,G.jsx)(mE,{isOpen:ye,onOpenChange:be,nodes:xn,edges:Sn,setNodes:Ze,setEdges:Qe,activeDiagramId:$e,takeSnapshot:et,saveDiagram:tt,triggerDebouncedSync:nt,broadcastMessage:rt,setIsLocalSaving:it,viewportRef:at,lastLoadedDiagramIdRef:ot})]}),(ur||$n)&&(0,G.jsxs)(QTe,{open:ur,children:[O===`repository`&&P?.entityType===`diagram`?(0,G.jsx)(yke,{diagramUid:P.entityUid,nodes:xn,edges:Sn,onClose:()=>k(`closed`)},P.entityUid):O===`history`&&I&&P?(0,G.jsx)(oke,{entityType:I,entityUid:P.entityUid,documentTitle:Ve||`Untitled`,onClose:()=>k(`closed`),onRestored:le,canRestore:qn},`${I}:${P.entityUid}`):null,$n&&(0,G.jsx)(`div`,{hidden:O!==`chat`,className:`contents`,children:(0,G.jsx)(ROe,{onAnsweringChange:mr,onClose:()=>k(`closed`),entityType:P.entityType,entityUid:P.entityUid,entityTitle:P.entityType===`dbClient`?T?.name||hn:P.entityType===`note`?Ue?.title:P.entityType===`diagram`?Ke?.name:P.entityType===`flowchart`?Ge?.title:null,entityContextText:Zn,viewType:Qn?`db-client`:void 0,projectId:er,pendingPrompt:A,onPromptUsed:j,pendingAction:M,onClearPendingAction:N,notes:qe,diagrams:Je,flowcharts:Ye,drawings:Xe,activeNoteContent:P?.entityType===`note`?Ue?.content:void 0,getPaneAI:h})})]})]})})]})}function jke({paired:e,onPairChange:t}){let n=pa(),r=bn(),i=ta(),[a,o]=(0,W.useState)(null),s=(0,W.useMemo)(()=>a?{...a.workspace,setIsSettingsOpen:n.setIsSettingsOpen,setSettingsTab:n.setSettingsTab,refreshTeamScope:n.refreshTeamScope,teamScopeVersion:n.teamScopeVersion,isTeamScopeRefreshing:n.isTeamScopeRefreshing,flushPendingSaves:n.flushPendingSaves,handleLogout:n.handleLogout}:n,[a,n]),c=(0,W.useMemo)(()=>a?{...a.ai,rightPanelMode:r.rightPanelMode,setRightPanelMode:r.setRightPanelMode}:r,[a,r]);return(0,G.jsx)(ma.Provider,{value:s,children:(0,G.jsx)(Dn,{value:c,children:(0,G.jsx)(na,{value:a?.canvas??i,children:(0,G.jsx)(Ake,{root:n,session:a,mainAI:r,paired:e,onPairChange:t,onFocusedSession:o})})})})}function Mke(){let e=ZT(),[t,n]=(0,W.useState)(!1);return(0,G.jsx)(Th,{open:!t&&e.open,onOpenChange:e.onOpenChange,className:`h-svh overflow-hidden`,style:{"--sidebar-width":`17rem`},children:(0,G.jsx)(Nn,{children:(0,G.jsx)(jke,{paired:t,onPairChange:n})})})}function Nke(){let e=v();return(0,G.jsx)(`div`,{className:`flex h-full w-full items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4 text-center max-w-md`,children:[(0,G.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,G.jsx)(ei,{className:`h-6 w-6 text-muted-foreground`})}),(0,G.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`404`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The page you're looking for doesn't exist.`}),(0,G.jsxs)(`button`,{onClick:()=>e(`/table/tables`),className:`inline-flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow hover:bg-primary/90 transition-colors`,children:[(0,G.jsx)(sr,{className:`h-4 w-4`}),`Back to Home`]})]})})}var H9=[{key:`notes`,label:`Notes`,createLabel:`Note`,icon:de,color:`text-amber-500`,bg:`bg-amber-500/10`,route:`/table/notes`,createFn:`handleSidebarNoteCreate`,totalKey:`notesTotal`},{key:`diagrams`,label:`ERD Builder`,createLabel:`ERD Builder`,icon:Cr,color:`text-cyan-400`,bg:`bg-cyan-500/20`,route:`/table/erd`,createFn:`handleSidebarDiagramCreate`,totalKey:`diagramsTotal`},{key:`drawings`,label:`Drawings`,createLabel:`Drawing`,icon:wr,color:`text-violet-500`,bg:`bg-violet-500/10`,route:`/table/drawings`,createFn:`handleSidebarDrawingCreate`,totalKey:`drawingsTotal`},{key:`flowcharts`,label:`Flowcharts`,createLabel:`Flowchart`,icon:Sr,color:`text-emerald-500`,bg:`bg-emerald-500/10`,route:`/table/flowcharts`,createFn:`handleSidebarFlowchartCreate`,totalKey:`flowchartsTotal`}];function Pke(){let e=new Date().getHours();return e<12?`Good morning`:e<17?`Good afternoon`:`Good evening`}function U9(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`Just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i<30?`${i}d ago`:new Date(e).toLocaleDateString(`en-US`)}function W9(e){switch(e){case`diagrams`:return(0,G.jsx)(Cr,{className:`h-4 w-4 text-blue-500`});case`notes`:return(0,G.jsx)(de,{className:`h-4 w-4 text-amber-500`});case`drawings`:return(0,G.jsx)(wr,{className:`h-4 w-4 text-violet-500`});case`flowcharts`:return(0,G.jsx)(Sr,{className:`h-4 w-4 text-emerald-500`});case`db-client`:return(0,G.jsx)(xr,{className:`h-4 w-4 text-cyan-400`});default:return null}}function G9(e){return(e.source_type??e.sourceType)===`production_db`}function K9(e){return e?._group===`db-client`||e?._type===`db-client`||G9(e)}function q9(e){switch(e._type){case`diagrams`:return K9(e)?`DB Client`:`ERD Builder`;case`notes`:return`Note`;case`drawings`:return`Drawing`;case`flowcharts`:return`Flowchart`;case`db-client`:return`DB Client`;default:return``}}function J9(e,t){let n=t.uid||t.id;if(K9(t))return`/db-client/${n}`;switch(e){case`diagrams`:return`/diagrams/${n}`;case`notes`:return`/notes/${n}`;case`drawings`:return`/drawings/${n}`;case`flowcharts`:return`/flowcharts/${n}`;case`db-client`:return`/db-client/${n}`;default:return`/`}}function Fke(){let e=v(),t=pa(),n=yi(),r=w(),i=!!(t.user?.isSso&&r.activeTeamId),a=e=>e===`diagrams`?`erd_builder`:e,o=e=>!i||r.isAvailable&&r.activeTeam?.capabilities?.[a(e)]===!0,s=H9.filter(e=>o(e.key)),c=t.user,l=c?.user_metadata?.full_name||c?.user_metadata?.name||c?.email?.split(`@`)[0]||``,[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(t.isGuest||!c){d(null),p(!0);return}let e=!1;return d(null),p(!1),(async()=>{try{let t=await Si(`/api/search/recent`);if(!t.ok)return;let n=await t.json();e||d(Array.isArray(n.data)?n.data:[])}catch{}finally{e||p(!0)}})(),()=>{e=!0}},[t.isGuest,t.teamScopeVersion,c]);let m=(0,W.useMemo)(()=>{if(u)return u.map(e=>({...e,_type:e.type,_group:e.group,_workspace:e.workspace?.name||e.project?.name||`—`,updated_at:e.updated_at??e.updatedAt}));let e=new Map((t.projects||[]).map(e=>[String(e.id),e.name])),n=t=>{let n=t.project_id??t.projectId;return t.projects?.name||t.project?.name||(n?e.get(String(n)):null)||`—`};return[...(t.diagrams||[]).filter(e=>!G9(e)).map(e=>({...e,_type:`diagrams`,_group:G9(e)?`db-client`:`diagrams`,_workspace:n(e)})),...(t.notes||[]).map(e=>({...e,_type:`notes`,_group:`notes`,_workspace:n(e)})),...(t.drawings||[]).map(e=>({...e,_type:`drawings`,_group:`drawings`,_workspace:n(e)})),...(t.flowcharts||[]).map(e=>({...e,_type:`flowcharts`,_group:`flowcharts`,_workspace:n(e)}))].filter(e=>!e.is_deleted).sort((e,t)=>new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime()).slice(0,10)},[t.diagrams,t.notes,t.drawings,t.flowcharts,t.projects,u]),[h,g]=(0,W.useState)(``),[_,y]=(0,W.useState)(`all`),b=(0,W.useMemo)(()=>{let e=h.trim().toLowerCase();return m.filter(t=>{let n=_===`all`||t._group===_,r=t.name||t.title||``;return n&&(!e||`${r} ${t._workspace}`.toLowerCase().includes(e))})},[m,_,h]),x=(0,W.useMemo)(()=>(t.diagrams||[]).filter(e=>!e.is_deleted&&!G9(e)).length+(t.notes||[]).filter(e=>!e.is_deleted).length+(t.drawings||[]).filter(e=>!e.is_deleted).length+(t.flowcharts||[]).filter(e=>!e.is_deleted).length,[t.diagrams,t.notes,t.drawings,t.flowcharts]),[S,C]=(0,W.useState)({});(0,W.useEffect)(()=>C({}),[t.teamScopeVersion]);let T=(0,W.useMemo)(()=>(t.projects||[]).filter(e=>!e.is_deleted).map(e=>{let t=S[String(e.id)]||{};return{...e,notesCount:t.notes??0,diagramsCount:t.diagrams??0,drawingsCount:t.drawings??0,flowchartsCount:t.flowcharts??0,dbClientsCount:t.db_clients??0,totalDocs:(t.notes??0)+(t.diagrams??0)+(t.drawings??0)+(t.flowcharts??0)+(t.db_clients??0)}}).sort((e,t)=>t.totalDocs-e.totalDocs).slice(0,4),[t.projects,S]);(0,W.useEffect)(()=>{let e=(t.projects||[]).filter(e=>!e.is_deleted).slice(0,4);if(e.length===0)return;let r=!1;return(async()=>{let t={};for(let i of e)try{let e=await Si(`/api/projects/${i.id}/summary?include_db_client=${n}`);e.ok&&!r&&(t[String(i.id)]=await e.json())}catch{}r||C(t)})(),()=>{r=!0}},[t.projects,n]);let[E,D]=(0,W.useState)(!1),O=t.isLoading||t.isProjectsLoading;(0,W.useEffect)(()=>{O||D(!0)},[O]);let k=!O&&f,A=k&&x===0&&!u?.length,j=k&&!A&&E,M=e=>{o(e.key)&&t.handleOpenCreateDocument?.(e.key===`diagrams`?`erd`:e.key===`flowcharts`?`flowchart`:e.key)},N=m[0];return(0,G.jsxs)(`div`,{className:`flex h-full w-full flex-col overflow-y-auto`,children:[l&&(0,G.jsx)(`div`,{className:`border-b border-border/60 px-5 py-5`,children:(0,G.jsxs)(`div`,{className:`flex items-end justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:[Pke(),`,`]}),(0,G.jsx)(`h1`,{className:`mt-0.5 text-xl font-semibold tracking-tight`,children:l}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Pick up where you left off.`})]}),j&&o(`diagrams`)&&(0,G.jsxs)(`button`,{onClick:()=>M(H9[1]),className:`hidden h-8 shrink-0 items-center gap-1.5 rounded-md bg-primary px-3 text-xs font-semibold text-primary-foreground shadow-sm transition-colors hover:bg-primary/90 sm:inline-flex`,children:[(0,G.jsx)(jt,{className:`size-3.5`}),`New ERD Builder`]})]})}),A&&(0,G.jsxs)(`div`,{className:`mx-auto flex max-w-2xl flex-col items-center justify-center px-6 py-20 text-center`,children:[(0,G.jsx)(`div`,{className:`size-16 rounded-2xl bg-primary/10 border border-primary/20 flex items-center justify-center mb-5`,children:(0,G.jsx)(Qr,{className:`size-7 text-primary`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:`Let's get started`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1.5 max-w-md`,children:`Create your first document — notes, ERD Builder, flowcharts, or drawings — and start building your workspace.`}),(0,G.jsx)(`div`,{className:`flex flex-wrap justify-center gap-2 mt-5`,children:s.map(e=>(0,G.jsxs)(`button`,{onClick:()=>M(e),className:`inline-flex items-center gap-2 rounded-lg border px-4 py-2.5 text-sm font-medium transition-all hover:shadow-sm ${e.key===`diagrams`?`border-cyan-400/50`:`border-border/60`} ${e.bg} hover:scale-[1.02]`,children:[(0,G.jsx)(e.icon,{className:`h-4 w-4 ${e.color}`}),`New `,e.createLabel]},e.key))})]}),j&&(0,G.jsxs)(`main`,{className:`flex w-full flex-col gap-5 px-5 py-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1.35fr)_minmax(250px,0.65fr)]`,children:[(0,G.jsxs)(`section`,{className:`relative overflow-hidden rounded-xl border border-primary/25 bg-linear-to-br from-primary/10 via-card to-card p-4`,children:[(0,G.jsxs)(`div`,{className:`relative z-10 flex h-full min-h-32 flex-col justify-between gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-wider text-primary`,children:`Continue working`}),N?(0,G.jsxs)(`div`,{className:`mt-3 flex items-start gap-2.5`,children:[(0,G.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-background/80 shadow-sm`,children:W9(N._type)}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h2`,{className:`truncate text-lg font-semibold`,children:N.name||N.title||`(Untitled)`}),(0,G.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[q9(N),` · `,N._workspace,` · `,U9(N.updated_at)]})]})]}):(0,G.jsx)(`h2`,{className:`mt-4 text-xl font-semibold`,children:`Create your first document`})]}),(0,G.jsxs)(`button`,{onClick:()=>N?e(J9(N._type,N)):M(H9[1]),className:`inline-flex h-8 w-fit items-center gap-1.5 rounded-md bg-primary px-3 text-xs font-semibold text-primary-foreground transition-colors hover:bg-primary/90`,children:[N?`Open document`:`Create ERD Builder`,(0,G.jsx)(Ca,{className:`size-3.5`})]})]}),(0,G.jsx)(Qr,{className:`absolute -bottom-8 -right-5 size-36 text-primary/10`})]}),(0,G.jsxs)(`section`,{className:`rounded-xl border border-border/60 bg-card p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Create something new`}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Start with the format you need.`})]}),(0,G.jsx)(jt,{className:`size-4 text-muted-foreground`})]}),(0,G.jsx)(`div`,{className:`mt-3 grid grid-cols-2 gap-2`,children:s.map(e=>(0,G.jsxs)(`button`,{onClick:()=>M(e),className:`group flex min-h-14 flex-col items-start justify-between rounded-lg border border-border/60 bg-background px-2.5 py-2 text-left transition-colors hover:border-primary/40 hover:bg-accent/40`,children:[(0,G.jsx)(e.icon,{className:`size-4 ${e.color}`}),(0,G.jsxs)(`span`,{className:`text-xs font-medium`,children:[`New `,e.createLabel]})]},e.key))})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 lg:grid-cols-[minmax(0,1.35fr)_minmax(250px,0.65fr)]`,children:[(0,G.jsxs)(`section`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2.5`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,G.jsx)(Ra,{className:`size-4 text-muted-foreground`}),`Recent files`]}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Jump back into your latest work.`})]}),(0,G.jsxs)(`div`,{className:`relative w-full sm:w-52`,children:[(0,G.jsx)(Zr,{className:`pointer-events-none absolute left-2.5 top-2.5 size-3.5 text-muted-foreground`}),(0,G.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:`Search files`,"aria-label":`Search recent files`,className:`h-8 w-full rounded-lg border border-border/60 bg-card pl-8 pr-3 text-xs outline-none placeholder:text-muted-foreground/60 focus:border-primary/50`})]})]}),(0,G.jsxs)(`div`,{className:`mb-2 flex items-center gap-1 overflow-x-auto pb-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>y(`all`),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===`all`?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:`All`}),H9.map(e=>(0,G.jsx)(`button`,{onClick:()=>y(e.key),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===e.key?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:e.label},e.key)),n&&(0,G.jsx)(`button`,{onClick:()=>y(`db-client`),className:`rounded-md px-2.5 py-1 text-xs font-medium ${_===`db-client`?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:`DB Client`})]}),(0,G.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border/60 bg-card`,children:b.length===0?(0,G.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No matching files.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`hidden grid-cols-[minmax(0,1fr)_minmax(7rem,0.7fr)_auto_auto] gap-2.5 border-b border-border/50 px-3 py-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground sm:grid`,children:[(0,G.jsx)(`span`,{children:`File`}),(0,G.jsx)(`span`,{children:`Project`}),(0,G.jsx)(`span`,{children:`Updated`}),(0,G.jsx)(`span`,{"aria-hidden":`true`})]}),b.map(t=>(0,G.jsxs)(`button`,{onClick:()=>e(J9(t._type,t)),className:`group grid w-full grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2.5 border-b border-border/50 px-3 py-2.5 text-left last:border-0 hover:bg-accent/30 sm:grid-cols-[minmax(0,1fr)_minmax(7rem,0.7fr)_auto_auto]`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,G.jsx)(`div`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md bg-background`,children:W9(t._type)}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:t.name||t.title||`(Untitled)`}),(0,G.jsx)(`p`,{className:`mt-0.5 truncate text-[11px] text-muted-foreground`,children:q9(t)})]})]}),(0,G.jsx)(`span`,{className:`hidden min-w-0 truncate text-xs text-muted-foreground sm:block`,children:t._workspace}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:U9(t.updated_at)}),(0,G.jsx)(Ca,{className:`size-3.5 shrink-0 text-muted-foreground/30 transition-colors group-hover:text-primary`})]},`${t._type}-${t.id}`))]})})]}),T.length>0&&(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`mb-2`,children:[(0,G.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,G.jsx)(to,{className:`size-4 text-muted-foreground`}),`Projects`]}),(0,G.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Your projects at a glance.`})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:T.map(e=>(0,G.jsxs)(`button`,{onClick:()=>t.onViewChange?.(`erd`,!0,e.uid??e.id),className:`group flex w-full items-center gap-2.5 rounded-lg border border-border/60 bg-card p-2.5 text-left transition-colors hover:border-primary/40 hover:bg-accent/30`,children:[(0,G.jsx)(`div`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md bg-primary/10`,children:(0,G.jsx)(to,{className:`size-3.5 text-primary`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[e.totalDocs,` `,e.totalDocs===1?`file`:`files`]})]}),(0,G.jsx)(Ca,{className:`size-4 text-muted-foreground/30 transition-colors group-hover:text-primary`})]},e.id))})]})]})]})]})}function Ike(){let e=new URLSearchParams(window.location.search).get(`authorization_id`)||``,[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(e?``:`Authorization ID is missing.`),[a,o]=(0,W.useState)(!!e),[s,c]=(0,W.useState)(!1);(0,W.useEffect)(()=>{e&&Si(`/api/oauth/authorizations/${encodeURIComponent(e)}`,{cache:`no-store`}).then(async e=>{let t=await e.json();if(!e.ok)throw Error(t.error||`Authorization request could not be loaded.`);t.redirect_url?window.location.assign(t.redirect_url):n(t)}).catch(e=>i(e instanceof Error?e.message:`Authorization request could not be loaded.`)).finally(()=>o(!1))},[e]);async function l(t){c(!0),i(``);try{let n=await Si(`/api/oauth/authorizations/${encodeURIComponent(e)}/${t}`,{method:`POST`}),r=await n.json();if(!n.ok||!r.redirect_url)throw Error(r.error||`Authorization decision failed.`);window.location.assign(r.redirect_url)}catch(e){i(e instanceof Error?e.message:`Authorization decision failed.`),c(!1)}}return(0,G.jsx)(`main`,{className:`flex min-h-svh items-center justify-center bg-muted/30 p-6`,children:(0,G.jsxs)(Lr,{className:`w-full max-w-lg`,children:[(0,G.jsxs)(Br,{children:[(0,G.jsx)(`div`,{className:`mb-2 flex size-10 items-center justify-center rounded-full bg-primary/10 text-primary`,children:(0,G.jsx)(Ho,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsx)(zr,{children:`Authorize MCP access`}),(0,G.jsx)(Kr,{children:t?`${t.client.name} wants read-only access to your ERD Builder Pro Web App workspace.`:`Reviewing the authorization request…`})]}),(0,G.jsxs)(Rr,{className:`space-y-4 text-sm`,children:[a&&(0,G.jsx)(`p`,{className:`text-muted-foreground`,children:`Loading authorization details…`}),r&&(0,G.jsx)(`p`,{role:`alert`,className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:r}),t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`Requesting client`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t.client.name}),(0,G.jsxs)(`p`,{className:`mt-1 break-all font-mono text-xs text-muted-foreground`,children:[`Redirect: `,t.redirect_uri]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`This client can read`}),(0,G.jsxs)(`p`,{className:`mt-1 text-muted-foreground`,children:[`Projects, regular ERDs, Notes, Flowcharts, Drawings, and document history in the Personal workspace and active Teams accessible to `,t.user.email,`. This authorization covers all permitted workspaces and follows your current access permissions.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`It cannot access`}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`DB Client, production database diagrams, SQL execution, database credentials, local files, or write operations.`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:`OAuth scopes`}),(0,G.jsx)(`p`,{className:`mt-1 break-words font-mono text-xs text-muted-foreground`,children:t.scope||`email`})]})]})]}),t&&(0,G.jsxs)(Ur,{className:`justify-end gap-2`,children:[(0,G.jsx)(U,{variant:`outline`,disabled:s,onClick:()=>l(`deny`),children:`Deny`}),(0,G.jsx)(U,{disabled:s,onClick:()=>l(`approve`),children:s?`Submitting…`:`Allow read-only access`})]})]})})}function Lke({user:e,onComplete:t}){let[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(``),[c,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),p=async r=>{if(r.preventDefault(),!(i.length<8||i!==o)){f(!0);try{let r=await Si(`/api/account`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPassword:n,newPassword:i})}),a=await r.json().catch(()=>({}));if(!r.ok)throw Error(a.error||`Unable to change password.`);t({...e,...a.user,mustChangePassword:!1}),l.success(`Password updated`)}catch(e){l.error(e?.message||`Unable to change password.`)}finally{f(!1)}}},m=c?`text`:`password`,h=(0,G.jsx)(`button`,{type:`button`,"aria-label":c?`Hide passwords`:`Show passwords`,onClick:()=>u(e=>!e),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:c?(0,G.jsx)(kr,{className:`size-4`}):(0,G.jsx)(Ka,{className:`size-4`})});return(0,G.jsx)(`main`,{className:`flex min-h-screen items-center justify-center bg-background p-6`,children:(0,G.jsxs)(`form`,{onSubmit:p,className:`flex w-full max-w-sm flex-col gap-5 rounded-xl border bg-card p-6 shadow-sm`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(po,{className:`size-6 text-primary`}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Change your password`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Use the temporary password provided by your Team administrator, then set a new password before continuing.`})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`temporary-password`,children:`Temporary password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`temporary-password`,type:m,className:`pr-10`,value:n,onChange:e=>r(e.target.value),required:!0}),h]})]}),(0,G.jsxs)(jr,{children:[(0,G.jsx)(Dr,{htmlFor:`new-password`,children:`New password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`new-password`,type:m,className:`pr-10`,minLength:8,value:i,onChange:e=>a(e.target.value),required:!0}),h]}),(0,G.jsx)(Or,{children:`At least 8 characters.`})]}),(0,G.jsxs)(jr,{"data-invalid":o.length>0&&o!==i,children:[(0,G.jsx)(Dr,{htmlFor:`confirm-password`,children:`Confirm new password`}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(wi,{id:`confirm-password`,type:m,className:`pr-10`,minLength:8,value:o,onChange:e=>s(e.target.value),"aria-invalid":o.length>0&&o!==i,required:!0}),h]})]}),(0,G.jsxs)(U,{type:`submit`,disabled:d||i.length<8||i!==o,children:[d&&(0,G.jsx)(xo,{className:`animate-spin`}),` Save new password`]})]})})}function Rke(e,t){let[n,r]=(0,W.useState)(()=>{try{let t=localStorage.getItem(e);if(t)return{...JSON.parse(t)}}catch{}return Object.fromEntries(t.map(e=>[e.id,e.defaultVisible]))});return(0,W.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[n,e]),{visible:n,toggle:(0,W.useCallback)(e=>{r(t=>({...t,[e]:!t[e]}))},[]),visibleCols:(0,W.useCallback)(()=>t.filter(e=>!e.hideable||(n[e.id]??e.defaultVisible)),[n])}}function zke(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(0),[i,a]=(0,W.useState)(!1);return{dbClients:e,dbClientsTotal:n,isDbClientsLoading:i,fetchDbClients:(0,W.useCallback)(async({projectId:e,query:n=``,page:i=1}={})=>{a(!0);try{let a=new URLSearchParams({limit:`10`,offset:String((i-1)*10)});e!=null&&e!==`all`&&a.set(`project_id`,String(e)),n.trim()&&a.set(`q`,n.trim());let o=await Si(`/api/db-clients?${a}`);if(!o.ok)throw Error(`Failed to load DB Clients`);let s=await o.json();t(Array.isArray(s.data)?s.data:[]),r(Number(s.total)||0)}catch(e){l.error(e.message||`Failed to load DB Clients`)}finally{a(!1)}},[]),deleteDbClient:(0,W.useCallback)(async e=>(await Si(`/api/db-clients/${encodeURIComponent(e)}`,{method:`DELETE`})).ok?(t(t=>t.filter(t=>String(t.uid??t.id)!==String(e))),r(e=>Math.max(0,e-1)),l.success(`DB Client moved to trash`),!0):(l.error(`Failed to move DB Client to trash`),!1),[])}}var Y9=[10,20,50,100],Bke={notes:`/notes`,erd:`/diagrams`,flowchart:`/flowcharts`,"db-client":`/db-client`,drawings:`/drawings`},Vke={notes:`New Note`,erd:`New ERD Builder`,flowchart:`New Flowchart`,"db-client":`New DB Client`,drawings:`New Drawing`},X9=[{id:`name`,label:`Name`,defaultVisible:!0,hideable:!1,width:`w-[40%]`},{id:`type`,label:`Type`,defaultVisible:!0,hideable:!0,width:`w-[12%]`},{id:`creator`,label:`Creator`,defaultVisible:!0,hideable:!0,width:`w-[12%]`},{id:`updated`,label:`Updated`,defaultVisible:!1,hideable:!0,width:`w-[13%]`},{id:`status`,label:`Status`,defaultVisible:!0,hideable:!0,width:`w-[8%]`},{id:`created`,label:`Created`,defaultVisible:!0,hideable:!0,width:`w-[13%]`},{id:`expires`,label:`Expires`,defaultVisible:!1,hideable:!0,width:`w-[12%]`},{id:`actions`,label:`Actions`,defaultVisible:!0,hideable:!1,width:`w-[6%]`}];function Z9(e,t=!1){if(!e)return`—`;let n=new Date(e);return Number.isNaN(n.getTime())?`—`:new Intl.DateTimeFormat(`id-ID`,t?{dateStyle:`long`}:{dateStyle:`medium`,timeStyle:`short`}).format(n)}function Hke(){let{projectKey:e=``}=h(),[t,n]=g(),r=v(),{user:i,isGuest:a}=la(),{projects:o,isProjectsLoading:s,handleOpenCreateDocument:c,setBreadcrumbLabel:l,updateNote:u,updateDiagram:f,updateDrawing:p,updateFlowchart:m,moveNoteToProject:_,moveDiagramToProject:y,moveDrawingToProject:b,moveFlowchartToProject:x,deleteNote:S,deleteDiagram:C,deleteDrawing:w,deleteFlowchart:T,fetchTrash:E}=pa(),{deleteDbClient:D}=zke(),{toggle:O,visibleCols:k}=Rke(`project-files-column-visibility`,X9),A=k(),j=e===Xi,M=j?null:o.find(t=>t.uid===e||String(t.id)===e)??null,N=j?`null`:M?String(M.id):null,P=Ui(M,i?.id,a)&&[`viewer`,`commenter`].includes(M?.accessRole??M?.access_role),F=Wi.filter(e=>e.value!==`db-client`||yi()),I=t.get(`type`),L=F.some(e=>e.value===I)?I:`all`,R=Math.max(1,Number(t.get(`page`))||1),ee=Y9.includes(Number(t.get(`per_page`)))?Number(t.get(`per_page`)):10,te=t.get(`q`)??``,[ne,re]=(0,W.useState)(te),[ie,z]=(0,W.useState)(0),[ae,oe]=(0,W.useState)(null),[se,ce]=(0,W.useState)(``),[le,ue]=(0,W.useState)(`none`),[de,B]=(0,W.useState)(null),[fe,pe]=(0,W.useState)(!1),me=()=>z(e=>e+1),{data:he,total:ge,counts:_e,locked:ve,isLoading:V}=NT({projectId:N,type:L,page:R,perPage:ee,q:te},ie),H=Math.max(1,Math.ceil(ge/ee)),ye=e=>{n(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e))r===null?n.delete(t):n.set(t,r);return n},{replace:!0})};(0,W.useEffect)(()=>{re(te)},[e]);let be=j?`Unassigned`:M?.name??null;if((0,W.useEffect)(()=>(l(be),()=>l(null)),[be,l]),(0,W.useEffect)(()=>{if(ne===te)return;let e=window.setTimeout(()=>ye({q:ne.trim()||null,page:null}),300);return()=>window.clearTimeout(e)},[ne]),!j&&!M)return(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:s?`Loading project…`:`Project not found.`});let xe=F.reduce((e,t)=>e+_e[t.value],0),Se=[{value:`all`,label:`All`,count:xe,icon:null,isLocked:!1},...F.map(e=>({value:e.value,label:e.label,count:_e[e.value],icon:e.icon,isLocked:ve.includes(e.value)}))],Ce=L!==`all`&&ve.includes(L),we=L===`all`?`notes`:L,Te=j?no:eo,Ee=i?.isSso?i.ssoPortalUrl??i.sso_portal_url:null,De=e=>r(`${Bke[e.type]}/${e.uid??e.id}`),Oe=e=>{oe(e),ce(e.title||e.name||``)};return(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted`,children:(0,G.jsx)(Te,{className:`size-5`,"aria-hidden":`true`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h1`,{className:`truncate text-lg font-semibold`,children:j?`Unassigned`:M?.name}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:j?`Files without a project. Edit a file to move it into a project.`:`${xe} ${xe===1?`file`:`files`}`})]})]}),!j&&(0,G.jsxs)(U,{size:`sm`,onClick:()=>c(we),children:[(0,G.jsx)(jt,{className:`size-4`,"aria-hidden":`true`}),`New file`]})]}),(0,G.jsx)(`div`,{role:`tablist`,"aria-label":`File types`,className:`flex shrink-0 gap-1 overflow-x-auto border-b`,children:Se.map(e=>{let t=e.icon,n=L===e.value;return(0,G.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>ye({type:e.value===`all`?null:e.value,page:null}),className:d(`-mb-px flex shrink-0 items-center gap-1.5 border-b-2 border-transparent px-3 py-2 text-sm text-muted-foreground transition-colors hover:text-foreground`,n&&`border-primary font-medium text-foreground`),children:[t&&(0,G.jsx)(t,{className:`size-4`,"aria-hidden":`true`}),e.label,e.isLocked?(0,G.jsx)(So,{className:`size-3.5`,"aria-label":`Not in your plan`}):(0,G.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 text-xs tabular-nums`,children:e.count})]},e.value)})}),Ce?(0,G.jsxs)(`section`,{className:`max-w-md rounded-lg border border-primary/20 bg-primary/5 p-4 text-sm`,children:[(0,G.jsxs)(`p`,{className:`font-medium`,children:[F.find(e=>e.value===L)?.label,` needs a paid Cloud plan`]}),(0,G.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Files of this type stay saved and come back after an upgrade.`}),Ee&&(0,G.jsxs)(U,{size:`sm`,className:`mt-3`,onClick:()=>Yi(Ee),children:[`View Cloud plans`,(0,G.jsx)(Ca,{className:`size-4`})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative w-full max-w-64`,children:[(0,G.jsx)(Zr,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,G.jsx)(wi,{type:`search`,"aria-label":`Search files`,placeholder:`Search files...`,value:ne,onChange:e=>re(e.target.value),className:`h-8 pl-8 text-xs`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[yi()&&!j&&(0,G.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>pe(!0),children:[(0,G.jsx)(xr,{className:`size-4`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:`Database connections`})]}),(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`outline`,size:`icon-sm`,"aria-label":`Columns`,title:`Columns`,children:(0,G.jsx)(Ha,{className:`size-4`})})}),(0,G.jsx)(Gt,{align:`end`,className:`w-44`,children:X9.filter(e=>e.hideable).map(e=>(0,G.jsx)(Ut,{checked:A.some(t=>t.id===e.id),onCheckedChange:()=>O(e.id),children:e.label},e.id))})]})]})]}),(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-col overflow-hidden rounded-xl border`,children:[(0,G.jsx)(`div`,{className:`min-h-0 overflow-auto`,children:(0,G.jsxs)(Qh,{children:[(0,G.jsx)($h,{children:(0,G.jsx)(tg,{children:A.map(e=>(0,G.jsx)(ng,{className:e.width,children:e.label},e.id))})}),(0,G.jsx)(eg,{children:he.length===0?(0,G.jsx)(tg,{children:(0,G.jsxs)(rg,{colSpan:A.length,className:`h-32 text-center text-muted-foreground`,children:[V?`Loading…`:te?`No files match your search.`:`No files here yet.`,!V&&!te&&!j&&(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsxs)(U,{size:`sm`,variant:`outline`,onClick:()=>c(we),children:[(0,G.jsx)(jt,{className:`size-4`,"aria-hidden":`true`}),L===`all`?`New file`:Vke[L]]})})]})}):he.map(e=>{let t=Wi.find(t=>t.value===e.type),n=t.icon,r=e.type===`db-client`||Ui(e,i?.id,a)&&!P;return(0,G.jsx)(tg,{className:`group cursor-pointer`,onClick:()=>De(e),children:A.map(a=>{switch(a.id){case`name`:return(0,G.jsx)(rg,{className:`font-medium`,children:(0,G.jsx)(`span`,{className:`block max-w-70 truncate`,children:e.title||e.name||`Untitled`})},`name`);case`type`:return(0,G.jsx)(rg,{children:(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 whitespace-nowrap text-xs text-muted-foreground`,children:[(0,G.jsx)(n,{className:`size-4`,"aria-hidden":`true`}),t.label]})},`type`);case`creator`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:e.user?.name||e.user?.email||(e.type===`db-client`?i?.name||i?.email:null)||`—`},`creator`);case`updated`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:Z9(e.updated_at)},`updated`);case`status`:return(0,G.jsx)(rg,{children:(0,G.jsx)(`span`,{className:d(`inline-flex rounded-full px-2 py-0.5 text-xs`,e.is_public?`bg-green-500/10 text-green-500`:`bg-muted text-muted-foreground`),children:e.is_public?`Public`:`Private`})},`status`);case`created`:return(0,G.jsx)(rg,{className:`text-xs text-muted-foreground`,children:Z9(e.created_at)},`created`);case`expires`:{let t=e.expiry_date&&new Date(e.expiry_date)<new Date;return(0,G.jsx)(rg,{className:d(`text-xs text-muted-foreground`,t&&`font-medium text-red-500`),children:Z9(e.expiry_date,!0)},`expires`)}case`actions`:return(0,G.jsx)(rg,{className:`text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(qt,{children:[(0,G.jsx)(zt,{render:(0,G.jsx)(U,{variant:`ghost`,size:`icon`,className:`size-8`,"aria-label":`Actions for ${e.title||e.name||`file`}`,children:(0,G.jsx)(Tr,{className:`size-4`})})}),(0,G.jsxs)(Gt,{align:`end`,className:`w-44`,children:[(0,G.jsxs)(It,{onClick:()=>Oe(e),children:[(0,G.jsx)(ar,{className:`mr-2 size-4`}),`Edit`]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kt,{}),(0,G.jsxs)(It,{onClick:()=>B(e),className:`text-destructive`,children:[(0,G.jsx)($r,{className:`mr-2 size-4`}),`Delete`]})]})]})]})},`actions`);default:return null}})},`${e.type}:${e.uid??e.id}`)})})]})}),(0,G.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2 border-t px-4 py-2 text-xs text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{id:`rows-per-page-label`,children:`Rows per page`}),(0,G.jsxs)(_r,{value:String(ee),onValueChange:e=>e&&ye({per_page:e===`10`?null:e,page:null}),children:[(0,G.jsx)(mr,{size:`sm`,"aria-labelledby":`rows-per-page-label`,className:`h-7 w-18`,children:(0,G.jsx)(gr,{children:ee})}),(0,G.jsx)(pr,{children:Y9.map(e=>(0,G.jsx)(fr,{value:String(e),children:e},e))})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{children:[`Page `,Math.min(R,H),` of `,H]}),(0,G.jsx)(U,{variant:`outline`,size:`icon-xs`,"aria-label":`Previous page`,disabled:R<=1,onClick:()=>ye({page:R-1>1?String(R-1):null}),children:(0,G.jsx)(lr,{className:`size-4`})}),(0,G.jsx)(U,{variant:`outline`,size:`icon-xs`,"aria-label":`Next page`,disabled:R>=H,onClick:()=>ye({page:String(R+1)}),children:(0,G.jsx)(St,{className:`size-4`})})]})]})]})]}),(0,G.jsx)(sE,{isOpen:ae!==null,onOpenChange:e=>{e||oe(null)},view:ae?.type??`notes`,activeDocument:ae,canMoveProject:ae?Ui(ae,i?.id,a):!1,newName:se,setNewName:ce,projects:o,requireProject:!0,selectedProjectId:le,setSelectedProjectId:ue,updateDiagram:f,updateNote:u,updateDrawing:p,updateFlowchart:m,updateDbClient:async(e,t)=>{if(!(await Si(`/api/db-clients/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})})).ok)throw Error(`Failed to rename DB Client`);me()},onMoveDiagramToProject:y,onMoveNoteToProject:_,onMoveDrawingToProject:b,onMoveFlowchartToProject:x,onRenameSuccess:async()=>me()}),(0,G.jsx)(AT,{isOpen:de!==null,onOpenChange:e=>{e||B(null)},activeDocument:de,view:de?.type,deleteDiagram:C,deleteNote:S,deleteDrawing:w,deleteFlowchart:T,fetchTrash:E,onConfirm:de?.type===`db-client`?()=>{let e=de.uid??de.id;D(String(e)).then(()=>{B(null),me()})}:void 0,onAfterDelete:()=>{B(null),me()}}),yi()&&!j&&(0,G.jsx)(V9,{open:fe,onOpenChange:pe,projects:o,defaultProjectId:M?String(M.id):null,onImportComplete:e=>r(`/db-client/${e}`)})]})}var Q9={notes:`notes`,erd:`erd`,flowchart:`flowchart`,flowcharts:`flowchart`,drawings:`drawings`,"db-client":`db-client`};function Uke(){let{feature:e=``}=h(),[t]=g(),n=t.get(`workspace`);if(!n)return(0,G.jsx)(x,{to:`/`,replace:!0});let r=new URLSearchParams;return Q9[e]&&r.set(`type`,Q9[e]),(0,G.jsx)(x,{to:`/projects/${encodeURIComponent(n)}${r.size?`?${r}`:``}`,replace:!0})}var Wke=(0,W.lazy)(()=>_i(()=>import(`./NoteEditorRoute-OhCVPcxP.js`).then(e=>({default:e.NoteEditorRoute})),__vite__mapDeps([6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,4,1,22]))),Gke=(0,W.lazy)(()=>_i(()=>import(`./DiagramEditorRoute-D5Hde5-D.js`).then(e=>({default:e.DiagramEditorRoute})),__vite__mapDeps([23,5,7,9,12,8,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54]))),Kke=(0,W.lazy)(()=>Promise.all([_i(()=>import(`./DbClientEditorRoute-Dh00hTFE.js`),__vite__mapDeps([59,5,7,8,9,12,13,14,15,10,16,17,11,18,19,20,21,4,1,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])),M()]).then(([e])=>({default:e.DbClientEditorRoute}))),qke=(0,W.lazy)(()=>_i(()=>import(`./DrawingEditorRoute-D-2RJREu.js`).then(e=>({default:e.DrawingEditorRoute})),__vite__mapDeps([57,5,7,9,30,8,25,58,48,10,16,11,12,13,14,15,17,18,19,20,21,4,1,22]))),Jke=(0,W.lazy)(()=>_i(()=>import(`./FlowchartEditorRoute-DFGhMS9_.js`).then(e=>({default:e.FlowchartEditorRoute})),__vite__mapDeps([55,5,7,8,9,12,13,14,15,10,16,25,28,27,26,29,30,31,32,33,34,35,36,37,38,39,40,20,56,47,50,42,11,17,18,19,21,4,1,22,52,54]))),Yke=(0,W.lazy)(()=>_i(()=>import(`./TeamManagementRoute-Dk1qx63g.js`).then(e=>({default:e.TeamManagementRoute})),__vite__mapDeps([60,5,7,8,9,25,29,27,26,30,31,32,33,43,35,36,37,38,46,39,61,16,10,42,20,22,52]))),Xke=(0,W.lazy)(()=>_i(()=>import(`./TeamInventoryRoute-Df11PTDL.js`).then(e=>({default:e.TeamInventoryRoute})),__vite__mapDeps([62,5,7,8,9,25,43,36,37,27,16,10,20]))),Zke=(0,W.lazy)(()=>_i(()=>import(`./LibraryRoute-BPXgAtDw.js`).then(e=>({default:e.LibraryRoute})),__vite__mapDeps([63,5,7,8,9,25,26,27,43,44,35,30,31,32,36,37,64,40,50,16,10]))),Qke=(0,W.lazy)(()=>_i(()=>import(`./UserManagementRoute-Bb-Hh32e.js`).then(e=>({default:e.UserManagementRoute})),__vite__mapDeps([65,5,7,8,9,25,26,27,43,44,36,37,39,66,16,10,42,32,20]))),$ke=(0,W.lazy)(()=>_i(()=>import(`./AdminRoute-Di7g34Fy.js`).then(e=>({default:e.AdminRoute})),__vite__mapDeps([67,5,7,9,10,11,8,12,13,14,15,16,17,18,19,20,21,4,1,22])));function $9(e){return(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-xs text-muted-foreground`,children:`Opening file…`}),children:e})}function eAe(){let{isAuthenticated:e,user:t,setUser:n,isGuest:r,handleLogin:i,handleGuestLogin:a,handleLogout:o}=la(),s=v(),c=m(),[l,u]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let e,t;return typeof window>`u`||!window.__TAURI__&&!window.__TAURI_INTERNALS__?void 0:((async()=>{let{listen:n}=await _i(async()=>{let{listen:e}=await import(`./event-C6gFlqUR.js`);return{listen:e}},__vite__mapDeps([0,1]));e=await n(`menu-about`,()=>{u(!0)}),t=await n(`menu-check-update`,()=>{window.dispatchEvent(new CustomEvent(`menu-check-update`,{detail:{}}))})})(),()=>{e?.(),t?.()})},[]);let d=(0,W.useRef)(!1);(0,W.useEffect)(()=>{e===!1?d.current=!0:e===!0&&d.current&&(d.current=!1,c.pathname!==`/oauth/consent`&&s(`/`))},[e,c.pathname,s]);let{isPublicView:f,setIsPublicView:p,publicData:h,isPublicLoading:g,forbiddenDoc:_,fetchPublicDocument:y}=AC(()=>{}),x=ra();return e===null&&!x?(0,G.jsx)(mh,{type:`init`}):g?(0,G.jsx)(mh,{type:`public`}):_?(0,G.jsx)(Jte,{title:_.title,message:_.message,statusCode:_.status,documentUid:x?.uid,onSubmitToken:async e=>{if(x){if(await y(x.type,x.uid,void 0,void 0,e))sessionStorage.setItem(`share_token_${x.uid}`,e);else throw Error(`Invalid token`)}},onReturn:()=>window.location.href=`/`}):!e&&!x?(0,G.jsx)(us,{onLogin:e=>i(e),onGuestLogin:a}):c.pathname===`/oauth/consent`?(0,G.jsx)(Ike,{}):t?.mustChangePassword?(0,G.jsx)(Lke,{user:t,onComplete:n}):(0,G.jsxs)(aa,{isPublicView:f,publicData:h,isPublicLoading:g,forbiddenDoc:_,fetchPublicDocument:y,setIsPublicView:p,handleLogout:o,children:[(0,G.jsx)(S,{children:(0,G.jsxs)(b,{element:(0,G.jsx)(Mke,{}),children:[(0,G.jsx)(b,{path:`projects/:projectKey`,element:(0,G.jsx)(Hke,{})}),(0,G.jsx)(b,{path:`table/:feature`,element:(0,G.jsx)(Uke,{})}),(0,G.jsx)(b,{path:`notes/:id`,element:(0,G.jsx)(QC,{capability:`notes`,children:$9((0,G.jsx)(Wke,{}))})}),(0,G.jsx)(b,{path:`diagrams/:id`,element:(0,G.jsx)(QC,{capability:`erd_builder`,children:$9((0,G.jsx)(Gke,{}))})}),(0,G.jsx)(b,{path:`db-client/:id`,element:(0,G.jsx)(QC,{capability:`desktop_only`,children:$9((0,G.jsx)(Kke,{}))})}),(0,G.jsx)(b,{path:`drawings/:id`,element:(0,G.jsx)(QC,{capability:`drawings`,children:$9((0,G.jsx)(qke,{}))})}),(0,G.jsx)(b,{path:`flowcharts/:id`,element:(0,G.jsx)(QC,{capability:`flowcharts`,children:$9((0,G.jsx)(Jke,{}))})}),(0,G.jsx)(b,{path:`trash`,element:$9((0,G.jsx)($ke,{}))}),(0,G.jsx)(b,{path:`library`,element:$9((0,G.jsx)(Zke,{}))}),(0,G.jsx)(b,{path:`teams/:id`,element:$9((0,G.jsx)(Yke,{}))}),(0,G.jsx)(b,{path:`team-workspaces`,element:$9((0,G.jsx)(Xke,{}))}),(0,G.jsx)(b,{path:`users`,element:$9((0,G.jsx)(Qke,{}))}),(0,G.jsx)(b,{index:!0,element:(0,G.jsx)(Fke,{})}),(0,G.jsx)(b,{path:`*`,element:(0,G.jsx)(Nke,{})})]})}),(0,G.jsx)(DC,{}),(0,G.jsx)(kC,{open:l,onOpenChange:u})]})}function tAe(){return(0,G.jsx)(eAe,{})}typeof window<`u`&&`__TAURI_INTERNALS__`in window&&document.body.setAttribute(`data-tauri`,`true`);var nAe=window.fetch;window.fetch=async(...e)=>{let t=await nAe(...e),n=typeof e[0]==`string`?e[0]:e[0]instanceof Request?e[0].url:typeof e[0]==`object`&&`href`in e[0]?e[0].href:``,r=n.includes(`/api/login`)||n.includes(`/api/logout`)||n.includes(`/api/me`);n.includes(`supabase.co`);let i=vi(),a=(n.startsWith(`/api/`)||i&&n.startsWith(i))&&!n.includes(`supabase.co`),o=sessionStorage.getItem(`auth_mode`)===`guest`;return t.status===401&&a&&!r&&navigator.onLine&&!o&&(bi(),window.dispatchEvent(new Event(`auth:unauthorized`))),t},`serviceWorker`in navigator&&(window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||`__TAURI_INTERNALS__`in window?navigator.serviceWorker.getRegistrations().then(e=>{e.forEach(e=>e.unregister())}):window.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/sw.js`).catch(()=>{})})),(0,ga.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(W.StrictMode,{children:(0,G.jsx)(C,{children:(0,G.jsx)(se,{children:(0,G.jsx)(Ft,{children:(0,G.jsxs)(da,{children:[(0,G.jsx)(tAe,{}),(0,G.jsx)(ns,{position:`top-center`})]})})})})}));export{es as $,$a as $t,mw as A,Sa as An,Co as At,tg as B,po as Bt,_8 as C,ka as Cn,Ao as Ct,hE as D,Ta as Dn,Eo as Dt,zD as E,Ea as En,Do as Et,Qh as F,vo as Ft,vh as G,so as Gt,Kh as H,uo as Ht,eg as I,_o as It,xh as J,io as Jt,yh as K,oo as Kt,rg as L,go as Lt,gw as M,xo as Mt,_w as N,bo as Nt,lT as O,wa as On,To as Ot,Kne as P,yo as Pt,ts as Q,eo as Qt,ng as R,ho as Rt,E8 as S,Aa as Sn,jo as St,LD as T,Da as Tn,Oo as Tt,Vh as U,lo as Ut,Nne as V,fo as Vt,zh as W,co as Wt,ph as X,no as Xt,_h as Y,ro as Yt,ws as Z,to as Zt,nDe as _,Fa as _n,Io as _t,sDe as a,qa as an,Jo as at,O8 as b,Ma as bn,No as bt,B8 as c,Wa as cn,Go as ct,R8 as d,Va as dn,Ho as dt,Qa as en,$o as et,I8 as f,Ba as fn,Vo as ft,rDe as g,Ia as gn,Lo as gt,F8 as h,La as hn,Ro as ht,I5 as i,Ja as in,Yo as it,vw as j,xa as jn,So as jt,Xw as k,Ca as kn,wo as kt,iDe as l,Ua as ln,Wo as lt,P8 as m,Ra as mn,zo as mt,ike as n,Xa as nn,Zo as nt,V8 as o,Ka as on,qo as ot,L8 as p,za as pn,Bo as pt,bh as q,ao as qt,L7 as r,Ya as rn,Xo as rt,z8 as s,Ga as sn,Ko as st,n9 as t,Za as tn,Qo as tt,aDe as u,Ha as un,Uo as ut,tDe as v,Pa as vn,Fo as vt,ID as w,Oa as wn,ko as wt,qEe as x,ja as xn,Mo as xt,N8 as y,Na as yn,Po as yt,$h as z,mo as zt};
|