d1s 0.2.8 → 0.2.9
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/.next/.next/BUILD_ID +1 -1
- package/dist/.next/.next/app-build-manifest.json +33 -26
- package/dist/.next/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/.next/build-manifest.json +2 -2
- package/dist/.next/.next/cache/.rscinfo +1 -1
- package/dist/.next/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/dist/.next/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/.next/next-server.js.nft.json +1 -1
- package/dist/.next/.next/prerender-manifest.json +1 -1
- package/dist/.next/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/_not-found.html +1 -1
- package/dist/.next/.next/server/app/_not-found.rsc +4 -4
- package/dist/.next/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route.js +28 -3
- package/dist/.next/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js +26 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-data/confirm/route.js +1 -0
- package/dist/.next/.next/server/app/api/pull-data/confirm/route.js.nft.json +1 -0
- package/dist/.next/.next/server/app/api/pull-data/confirm/route_client-reference-manifest.js +1 -0
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js +26 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js +26 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js +28 -3
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js +28 -3
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/query/route.js +27 -2
- package/dist/.next/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/update/route.js +2 -2
- package/dist/.next/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/index.html +3 -3
- package/dist/.next/.next/server/app/index.rsc +5 -5
- package/dist/.next/.next/server/app/page.js +11 -11
- package/dist/.next/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app-paths-manifest.json +2 -1
- package/dist/.next/.next/server/chunks/226.js +30 -0
- package/dist/.next/.next/server/chunks/336.js +1 -1
- package/dist/.next/.next/server/pages/404.html +1 -1
- package/dist/.next/.next/server/pages/500.html +1 -1
- package/dist/.next/.next/server/pages-manifest.json +1 -1
- package/dist/.next/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/.next/static/7XBqETNmhSxMXhw8iUpEa/_buildManifest.js +1 -0
- package/dist/.next/.next/static/chunks/{958-98887928efebfdf7.js → 176-9146975ef8699719.js} +1 -1
- package/dist/.next/.next/static/chunks/{735-c9144179c6bd7d06.js → 735-b885dfec6353171d.js} +1 -1
- package/dist/.next/.next/static/chunks/app/api/cloudflare/route-b77846f372b01f38.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/databases/route-407794f8145d9a0b.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/migrations/sync/route-9f480f5590369a8f.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/migrations/sync-files/route-92010db279b4dd8e.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-data/confirm/route-a02fe6d3cdd0a535.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-remote/confirm/route-f401a03507d1da50.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-remote/preview/route-3c53814b5cb8b6b0.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/push-remote/confirm/route-8f359249e907c63b.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/push-remote/preview/route-b51bf94f39c17a9d.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/query/route-87bae2d4aebaf859.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/tables/[name]/route-d20ca163b9c03e7c.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/tables/route-0f46f911562abcdf.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/update/route-14edc1917760bce0.js +1 -0
- package/dist/.next/.next/static/chunks/app/page-5990cb23b8bd27c4.js +1 -0
- package/dist/.next/.next/static/css/674bee6608c638e4.css +3 -0
- package/dist/.next/.next/trace +3 -3
- package/dist/.next/.next/types/app/api/pull-data/confirm/route.ts +347 -0
- package/dist/.next/BUILD_ID +1 -1
- package/dist/.next/app-build-manifest.json +35 -21
- package/dist/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/build-manifest.json +2 -2
- package/dist/.next/cache/.rscinfo +1 -1
- package/dist/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/next-server.js.nft.json +1 -1
- package/dist/.next/prerender-manifest.json +1 -1
- package/dist/.next/server/app/_not-found/page.js +1 -1
- package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/_not-found.html +1 -1
- package/dist/.next/server/app/_not-found.rsc +4 -4
- package/dist/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync/route.js +28 -3
- package/dist/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js +26 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-data/confirm/route.js +1 -0
- package/dist/.next/server/app/api/pull-data/confirm/route.js.nft.json +1 -0
- package/dist/.next/server/app/api/pull-data/confirm/route_client-reference-manifest.js +1 -0
- package/dist/.next/server/app/api/pull-remote/confirm/route.js +26 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js +26 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route.js +28 -3
- package/dist/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route.js +28 -3
- package/dist/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/query/route.js +27 -2
- package/dist/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/[name]/route.js +3 -3
- package/dist/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/update/route.js +5 -0
- package/dist/.next/server/app/api/update/route.js.nft.json +1 -0
- package/dist/.next/server/app/api/update/route_client-reference-manifest.js +1 -0
- package/dist/.next/server/app/index.html +3 -3
- package/dist/.next/server/app/index.rsc +5 -5
- package/dist/.next/server/app/page.js +13 -11
- package/dist/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app-paths-manifest.json +5 -3
- package/dist/.next/server/chunks/226.js +30 -0
- package/dist/.next/server/chunks/336.js +1 -1
- package/dist/.next/server/chunks/391.js +23 -0
- package/dist/.next/server/chunks/452.js +1 -0
- package/dist/.next/server/chunks/627.js +3 -3
- package/dist/.next/server/chunks/638.js +3 -3
- package/dist/.next/server/chunks/992.js +3 -3
- package/dist/.next/server/pages/404.html +1 -1
- package/dist/.next/server/pages/500.html +1 -1
- package/dist/.next/server/pages/_app.js +1 -1
- package/dist/.next/server/pages/_document.js +1 -1
- package/dist/.next/server/pages/_error.js +1 -1
- package/dist/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/static/MoZBULXFiTFzrY1JVK_Df/_buildManifest.js +1 -0
- package/dist/.next/static/chunks/176-9146975ef8699719.js +1 -0
- package/dist/.next/static/chunks/{735-c9144179c6bd7d06.js → 735-b885dfec6353171d.js} +1 -1
- package/dist/.next/static/chunks/app/api/cloudflare/route-b77846f372b01f38.js +1 -0
- package/dist/.next/static/chunks/app/api/databases/route-407794f8145d9a0b.js +1 -0
- package/dist/.next/static/chunks/app/api/migrations/sync/route-9f480f5590369a8f.js +1 -0
- package/dist/.next/static/chunks/app/api/migrations/sync-files/route-92010db279b4dd8e.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-data/confirm/route-a02fe6d3cdd0a535.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-remote/confirm/route-f401a03507d1da50.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-remote/preview/route-3c53814b5cb8b6b0.js +1 -0
- package/dist/.next/static/chunks/app/api/push-remote/confirm/route-8f359249e907c63b.js +1 -0
- package/dist/.next/static/chunks/app/api/push-remote/preview/route-b51bf94f39c17a9d.js +1 -0
- package/dist/.next/static/chunks/app/api/query/route-87bae2d4aebaf859.js +1 -0
- package/dist/.next/static/chunks/app/api/tables/[name]/route-d20ca163b9c03e7c.js +1 -0
- package/dist/.next/static/chunks/app/api/tables/route-0f46f911562abcdf.js +1 -0
- package/dist/.next/static/chunks/app/api/update/route-14edc1917760bce0.js +1 -0
- package/dist/.next/static/chunks/app/page-5990cb23b8bd27c4.js +1 -0
- package/dist/.next/static/css/674bee6608c638e4.css +3 -0
- package/dist/.next/trace +17 -14
- package/dist/.next/types/app/api/pull-data/confirm/route.ts +347 -0
- package/dist/.next/types/app/api/update/route.ts +347 -0
- package/dist/app/api/pull-data/confirm/route.js +230 -0
- package/dist/app/api/update/route.js +36 -0
- package/dist/app/app/api/pull-data/confirm/route.js +230 -0
- package/dist/app/app/api/update/route.js +30 -5
- package/dist/app/app/page.jsx +21 -17
- package/dist/app/page.jsx +24 -14
- package/dist/d1-studio.js +8 -1
- package/dist/lib/logger.js +35 -5
- package/dist/lib/sql-operations.js +77 -0
- package/package.json +1 -1
- package/scripts/studio.js +8 -1
- package/src/app/api/pull-data/confirm/route.js +230 -0
- package/src/app/api/update/route.js +30 -5
- package/src/app/page.jsx +21 -17
- package/src/components/environment-handler.jsx +70 -16
- package/src/components/environment-select.jsx +6 -3
- package/src/components/pull-preview-toast.jsx +90 -63
- package/src/components/sidebar.jsx +25 -24
- package/src/components/update-banner.jsx +29 -31
- package/src/context/database-context.js +4 -4
- package/src/lib/logger.js +35 -5
- package/src/lib/sql-operations.js +77 -0
- package/dist/.next/.next/cache/webpack/client-development/0.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/1.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/2.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/3.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/4.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/index.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/client-development/index.pack.gz.old +0 -0
- package/dist/.next/.next/cache/webpack/client-production/10.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/11.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/12.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/13.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/14.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/4.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/5.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/6.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/7.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/8.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/9.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-development/0.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/1.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/2.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/3.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/4.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/index.pack.gz +0 -0
- package/dist/.next/.next/cache/webpack/server-development/index.pack.gz.old +0 -0
- package/dist/.next/.next/cache/webpack/server-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/10.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/11.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/12.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/13.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/4.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/5.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/6.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/7.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/8.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/9.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/dist/.next/.next/server/chunks/686.js +0 -23
- package/dist/.next/.next/server/chunks/801.js +0 -55
- package/dist/.next/.next/static/IWRJZhjf8U8mjzz4h0VNE/_buildManifest.js +0 -1
- package/dist/.next/.next/static/JrwgdSDcipr0Zh7k19Cj_/_buildManifest.js +0 -1
- package/dist/.next/.next/static/chunks/422-6fa3c14fc64ad67b.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/cloudflare/route-3458d78022185d7f.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/cloudflare/route-5133155a604f2719.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/databases/route-63a31080b565794e.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/databases/route-64255424877a9f72.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync/route-03766b3afcf043ba.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync/route-d97667565b4a59b6.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync-files/route-02fa291c8000dadf.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync-files/route-7089bcbfeb6b5260.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/confirm/route-7e05bb8920127abe.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/confirm/route-9143e6e4c3f05162.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/preview/route-0fa15f783e8a306c.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/preview/route-c963d143a51aed66.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/confirm/route-072132c0a6cb3df3.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/confirm/route-96691f1880e4ed14.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/preview/route-a798679c67374552.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/preview/route-ca6bf35aa72661ee.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/query/route-1466f6b7ffd8b6c0.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/query/route-e90d0030a5083e20.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/[name]/route-1efe63e73b480e58.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/[name]/route-898d3f85fc8544c4.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/route-3772b4f480c4b4a4.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/route-91650359fc3735cb.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/update/route-504d663df9124f97.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-2c28a255a4ecd8d4.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-3db7feef57019055.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-79049bfa6cc07e11.js +0 -1
- package/dist/.next/.next/static/css/4957328384ed5c42.css +0 -3
- package/dist/.next/.next/static/css/cf41da7a0d47f779.css +0 -3
- package/dist/.next/.next/static/gc8l1G6KXOeLLOM7VJip6/_buildManifest.js +0 -1
- package/dist/.next/.next/static/gc8l1G6KXOeLLOM7VJip6/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/kYsJoni86CJWDuTkc1xU6/_buildManifest.js +0 -1
- package/dist/.next/.next/static/kYsJoni86CJWDuTkc1xU6/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/scC5qwQC9H7rR1groM0Q-/_buildManifest.js +0 -1
- package/dist/.next/.next/static/scC5qwQC9H7rR1groM0Q-/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/tEHOI_-t-iqfJClNzuo9m/_buildManifest.js +0 -1
- package/dist/.next/.next/static/tEHOI_-t-iqfJClNzuo9m/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/vin2VQs5pM_dH2e2_I7AN/_buildManifest.js +0 -1
- package/dist/.next/.next/static/vin2VQs5pM_dH2e2_I7AN/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/wHKwQhaxin5_i06GFVDHb/_buildManifest.js +0 -1
- package/dist/.next/.next/static/wHKwQhaxin5_i06GFVDHb/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/xW4MspD8XibrhXDi_q2IO/_buildManifest.js +0 -1
- package/dist/.next/.next/static/xW4MspD8XibrhXDi_q2IO/_ssgManifest.js +0 -1
- package/dist/.next/server/chunks/686.js +0 -23
- package/dist/.next/server/chunks/801.js +0 -55
- package/dist/.next/static/ZwNOdZJ0LOtE0AJMNWwzY/_buildManifest.js +0 -1
- package/dist/.next/static/ZwNOdZJ0LOtE0AJMNWwzY/_ssgManifest.js +0 -1
- package/dist/.next/static/chunks/422-6fa3c14fc64ad67b.js +0 -1
- package/dist/.next/static/chunks/app/api/cloudflare/route-3458d78022185d7f.js +0 -1
- package/dist/.next/static/chunks/app/api/databases/route-64255424877a9f72.js +0 -1
- package/dist/.next/static/chunks/app/api/migrations/sync/route-03766b3afcf043ba.js +0 -1
- package/dist/.next/static/chunks/app/api/migrations/sync-files/route-02fa291c8000dadf.js +0 -1
- package/dist/.next/static/chunks/app/api/pull-remote/confirm/route-7e05bb8920127abe.js +0 -1
- package/dist/.next/static/chunks/app/api/pull-remote/preview/route-0fa15f783e8a306c.js +0 -1
- package/dist/.next/static/chunks/app/api/push-remote/confirm/route-96691f1880e4ed14.js +0 -1
- package/dist/.next/static/chunks/app/api/push-remote/preview/route-a798679c67374552.js +0 -1
- package/dist/.next/static/chunks/app/api/query/route-e90d0030a5083e20.js +0 -1
- package/dist/.next/static/chunks/app/api/tables/[name]/route-1efe63e73b480e58.js +0 -1
- package/dist/.next/static/chunks/app/api/tables/route-3772b4f480c4b4a4.js +0 -1
- package/dist/.next/static/chunks/app/page-79049bfa6cc07e11.js +0 -1
- package/dist/.next/static/css/cf41da7a0d47f779.css +0 -3
- /package/dist/.next/.next/static/{IWRJZhjf8U8mjzz4h0VNE → 7XBqETNmhSxMXhw8iUpEa}/_ssgManifest.js +0 -0
- /package/dist/.next/{.next/static/JrwgdSDcipr0Zh7k19Cj_ → static/MoZBULXFiTFzrY1JVK_Df}/_ssgManifest.js +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{9017:(e,t,a)=>{Promise.resolve().then(a.bind(a,5612))},5612:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>tl});var s=a(5155),l=a(2115),n=a(2398),r=a(7443),i=a(1680),o=a(2591),c=a(2783),d=a(4031);let u=l.forwardRef((e,t)=>{let{className:a,type:l,...n}=e;return(0,s.jsx)("input",{type:l,className:(0,d.cn)("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),ref:t,...n})});u.displayName="Input";var m=a(1027);let h=(0,m.F)("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),x=l.forwardRef((e,t)=>{let{className:a,variant:l,...n}=e;return(0,s.jsx)("div",{ref:t,role:"alert",className:(0,d.cn)(h({variant:l}),a),...n})});x.displayName="Alert",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("h5",{ref:t,className:(0,d.cn)("mb-1 font-medium leading-none tracking-tight",a),...l})}).displayName="AlertTitle";let f=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("div",{ref:t,className:(0,d.cn)("text-sm [&_p]:leading-relaxed",a),...l})});f.displayName="AlertDescription";var p=a(33),g=a(6217),v=a(689);let N=g.bL;g.l9;let j=g.ZL;g.bm;let b=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.hJ,{ref:t,className:(0,d.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...l})});b.displayName=g.hJ.displayName;let w=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(j,{children:[(0,s.jsx)(b,{}),(0,s.jsxs)(g.UC,{ref:t,className:(0,d.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",a),...n,children:[l,(0,s.jsxs)(g.bm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,s.jsx)(v.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});w.displayName=g.UC.displayName;let y=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,d.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...a})};y.displayName="DialogHeader";let C=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,d.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...a})};C.displayName="DialogFooter";let S=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.hE,{ref:t,className:(0,d.cn)("text-lg font-semibold leading-none tracking-tight",a),...l})});S.displayName=g.hE.displayName;let E=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.VY,{ref:t,className:(0,d.cn)("text-sm text-muted-foreground",a),...l})});E.displayName=g.VY.displayName;var R=a(2317);let T=(0,m.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),A=l.forwardRef((e,t)=>{let{className:a,variant:l,size:n,asChild:r=!1,...i}=e,o=r?R.DX:"button";return(0,s.jsx)(o,{className:(0,d.cn)(T({variant:l,size:n,className:a})),ref:t,...i})});function k(e){let{open:t,onClose:a,onSubmit:n}=e,[r,i]=(0,l.useState)(""),[o,d]=(0,l.useState)(""),[m,h]=(0,l.useState)(""),[p,g]=(0,l.useState)(!1),v=async e=>{e.preventDefault(),h(""),g(!0);try{await n({accountId:r,apiToken:o}),localStorage.setItem("cf_credentials",JSON.stringify({accountId:r,apiToken:o})),a()}catch(e){h(e.message)}finally{g(!1)}};return(0,s.jsx)(N,{open:t,onOpenChange:a,children:(0,s.jsxs)(w,{className:"sm:max-w-md",children:[(0,s.jsxs)(y,{children:[(0,s.jsx)(S,{children:"Connect to Cloudflare"}),(0,s.jsx)(E,{children:"Enter your Cloudflare credentials to push your database to production."})]}),(0,s.jsxs)("form",{onSubmit:v,className:"space-y-4 mt-4",children:[m&&(0,s.jsx)(x,{variant:"destructive",children:(0,s.jsx)(f,{children:m})}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("label",{className:"text-sm font-medium",children:"Account ID"}),(0,s.jsx)(u,{placeholder:"Your Cloudflare Account ID",value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("label",{className:"text-sm font-medium",children:"API Token"}),(0,s.jsx)(u,{type:"password",placeholder:"Your D1 Database API Token",value:o,onChange:e=>d(e.target.value),required:!0})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,s.jsx)(A,{type:"button",variant:"outline",onClick:a,children:"Cancel"}),(0,s.jsxs)(A,{type:"submit",disabled:p,children:[p&&(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Connect"]})]})]})]})})}A.displayName="Button";var _=a(6528),O=a(1868);let L=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(O.bL,{ref:t,className:(0,d.cn)("relative overflow-hidden",a),...n,children:[(0,s.jsx)(O.LM,{className:"h-full w-full rounded-[inherit]",children:l}),(0,s.jsx)(I,{}),(0,s.jsx)(O.OK,{})]})});L.displayName=O.bL.displayName;let I=l.forwardRef((e,t)=>{let{className:a,orientation:l="vertical",...n}=e;return(0,s.jsx)(O.VM,{ref:t,orientation:l,className:(0,d.cn)("flex touch-none select-none transition-colors","vertical"===l&&"h-full w-2.5 border-l border-l-transparent p-[1px]","horizontal"===l&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",a),...n,children:(0,s.jsx)(O.lr,{className:"relative flex-1 rounded-full bg-border"})})});I.displayName=O.VM.displayName;let U=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("div",{className:"relative w-full overflow-auto",children:(0,s.jsx)("table",{ref:t,className:(0,d.cn)("w-full caption-bottom text-sm",a),...l})})});U.displayName="Table";let P=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("thead",{ref:t,className:(0,d.cn)("[&_tr]:border-b",a),...l})});P.displayName="TableHeader";let F=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tbody",{ref:t,className:(0,d.cn)("[&_tr:last-child]:border-0",a),...l})});F.displayName="TableBody",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tfoot",{ref:t,className:(0,d.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...l})}).displayName="TableFooter";let D=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tr",{ref:t,className:(0,d.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",a),...l})});D.displayName="TableRow";let M=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("th",{ref:t,className:(0,d.cn)("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...l})});M.displayName="TableHead";let z=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("td",{ref:t,className:(0,d.cn)("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...l})});z.displayName="TableCell",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("caption",{ref:t,className:(0,d.cn)("mt-4 text-sm text-muted-foreground",a),...l})}).displayName="TableCaption";let Q=function(e){let{preview:t=[],onConfirm:a,onCancel:n,isConfirming:r,error:i,isLoading:o,success:u}=e,[m,h]=(0,l.useState)(!0);if(o)return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4 shadow-lg bg-background",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(c.A,{className:"h-5 w-5 text-neutral-600 shrink-0 mt-0.5 animate-spin"}),(0,s.jsx)("div",{className:"flex-1 space-y-3",children:(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"font-medium text-neutral-800",children:"Preparing Push Migration"}),(0,s.jsx)("p",{className:"text-sm text-neutral-600",children:"Checking local migrations..."})]})})]})})});if(!(null==t?void 0:t.length))return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4",children:(0,s.jsx)("p",{className:"text-sm font-medium",children:"No migrations to preview"})})});let x=t.filter(e=>"will be applied"===e.action).length,f=t.filter(e=>"skipped"===e.action).length;t.filter(e=>"applied"===e.action).length;let p=e=>{switch(e){case"will be applied":return"\uD83D\uDD52️";case"applied":case"skipped":return"✅";case"failed":return"❌";default:return""}};return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:(0,d.cn)("rounded-lg border p-4 shadow-lg",i?"bg-destructive/15":"bg-background"),children:(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h5",{className:"font-medium text-neutral-900",children:"Push Migration Preview"}),(0,s.jsx)("button",{onClick:n,className:"text-neutral-500 hover:text-neutral-900 p-1 rounded-md hover:bg-neutral-100",children:(0,s.jsx)(v.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("p",{className:"text-sm text-neutral-700",children:[x," migration(s) \uD83D\uDD52️ pending, ",f," to ✅ skip"]}),i?(0,s.jsx)("p",{className:"text-sm text-destructive font-medium mt-1",children:i.message}):u&&(0,s.jsx)("p",{className:"text-sm text-green-700 font-medium mt-1",children:u})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{onClick:()=>h(!m),className:"text-sm font-medium hover:underline",children:m?"Hide Details":"Show Details"}),m&&(0,s.jsx)(L,{className:"h-[480px] mt-2 rounded border border-neutral-200",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{children:"Migration"}),(0,s.jsx)(M,{className:"text-center w-24",children:"Status"})]})}),(0,s.jsx)(F,{children:t.map((e,t)=>(0,s.jsxs)(D,{children:[(0,s.jsx)(z,{className:"font-mono text-xs",children:e.name}),(0,s.jsx)(z,{className:"text-center align-middle",children:p(e.action)})]},t))})]})})]}),(0,s.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,s.jsx)(A,{onClick:a,disabled:r||0===x,className:"flex-1",children:r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirming..."]}):"Confirm Push"}),(0,s.jsx)(A,{variant:"outline",onClick:n,disabled:r,className:"flex-1",children:"Cancel"})]})]})})})};var V=a(1983);let K=function(e){let{preview:t=[],onConfirm:a,onCancel:n,isConfirming:r,error:i,isLoading:o}=e;console.log("PullPreviewToast rendered with:",{previewLength:t.length,isConfirming:r,error:i,isLoading:o}),(0,l.useEffect)(()=>(console.log("PullPreviewToast mounted/updated"),()=>console.log("PullPreviewToast unmounted")),[]);let[u,m]=(0,l.useState)(!1);if(o)return console.log("Rendering loading state"),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4 shadow-lg bg-background",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(c.A,{className:"h-5 w-5 text-neutral-600 shrink-0 mt-0.5 animate-spin"}),(0,s.jsx)("div",{className:"flex-1 space-y-3",children:(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"font-medium text-neutral-800",children:"Preparing Pull Migration"}),(0,s.jsx)("p",{className:"text-sm text-neutral-600",children:"Checking remote migrations..."})]})})]})})});if(!(null==t?void 0:t.length))return console.log("No preview data available"),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border bg-destructive/15 p-4",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(V.A,{className:"h-5 w-5 text-destructive"}),(0,s.jsx)("p",{className:"text-sm font-medium text-destructive",children:"No preview data available"})]})})});let h=t.filter(e=>(e.migration||e.name||"").endsWith(".sql")),x=h.length;return console.log("Migration stats:",{totalMigrations:x}),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:(0,d.cn)("rounded-lg border p-4 shadow-lg",i?"bg-destructive/15":"bg-background"),children:(0,s.jsx)("div",{className:"flex items-start gap-3",children:(0,s.jsxs)("div",{className:"flex-1 space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("h5",{className:(0,d.cn)("font-medium",i?"text-destructive":"text-neutral-900"),children:i?"Pull Migration Error":"Pull Migration Preview"}),(0,s.jsx)("p",{className:(0,d.cn)("text-sm",i?"text-destructive/80":"text-neutral-700"),children:i?i.message:"".concat(x," migration(s) will be applied")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{onClick:()=>m(!u),className:"text-sm font-medium hover:underline",children:u?"Hide Details":"Show Details"}),u&&(0,s.jsx)(L,{className:"h-[480px] mt-2 rounded border border-neutral-200",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{className:"w-[30px]"}),(0,s.jsx)(M,{className:"pl-0",children:"Migration"})]})}),(0,s.jsx)(F,{children:h.map((e,t)=>(0,s.jsxs)(D,{children:[(0,s.jsx)(z,{className:"w-[30px] pr-1 pl-2",children:(0,s.jsx)(V.A,{className:"h-4 w-4"})}),(0,s.jsx)(z,{className:"font-mono text-xs pr-5 pl-0.5",children:e.migration||e.name})]},t))})]})})]}),(0,s.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,s.jsx)(A,{onClick:a,disabled:r,className:"flex-1",children:r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirming..."]}):"Confirm Pull"}),(0,s.jsx)(A,{variant:"outline",onClick:n,disabled:r,className:"flex-1",children:"Cancel"})]})]})})})})};var q=a(3409),J=a(2645),Y=a(2488),X=a(7193);let H=q.bL;q.YJ;let B=q.WT,W=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(q.l9,{ref:t,className:(0,d.cn)("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",a),...n,children:[l,(0,s.jsx)(q.In,{asChild:!0,children:(0,s.jsx)(J.A,{className:"h-4 w-4 opacity-50"})})]})});W.displayName=q.l9.displayName;let G=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.PP,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",a),...l,children:(0,s.jsx)(Y.A,{className:"h-4 w-4"})})});G.displayName=q.PP.displayName;let Z=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.wn,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",a),...l,children:(0,s.jsx)(J.A,{className:"h-4 w-4"})})});Z.displayName=q.wn.displayName;let $=l.forwardRef((e,t)=>{let{className:a,children:l,position:n="popper",...r}=e;return(0,s.jsx)(q.ZL,{children:(0,s.jsxs)(q.UC,{ref:t,className:(0,d.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===n&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",a),position:n,...r,children:[(0,s.jsx)(G,{}),(0,s.jsx)(q.LM,{className:(0,d.cn)("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:l}),(0,s.jsx)(Z,{})]})})});$.displayName=q.UC.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.JU,{ref:t,className:(0,d.cn)("px-2 py-1.5 text-sm font-semibold",a),...l})}).displayName=q.JU.displayName;let ee=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(q.q7,{ref:t,className:(0,d.cn)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...n,children:[(0,s.jsx)("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(q.VF,{children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})}),(0,s.jsx)(q.p4,{children:l})]})});ee.displayName=q.q7.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.wv,{ref:t,className:(0,d.cn)("-mx-1 my-1 h-px bg-muted",a),...l})}).displayName=q.wv.displayName;var et=a(2303),ea=a(319),es=a(5942);function el(e){let{value:t,onValueChange:a,isLoading:l,disabled:n,showPreview:r}=e;return(0,s.jsxs)(H,{value:t,onValueChange:a,disabled:n||l||r,children:[(0,s.jsx)(W,{className:"w-[104px] bg-white border-neutral-200 font-medium",children:(0,s.jsx)("div",{className:"flex items-center gap-1 text-sm",children:l||r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,s.jsx)("span",{className:"text-muted-foreground font-medium",children:"pull"===t?"Pulling...":"Pushing..."})]}):(0,s.jsx)(B,{placeholder:"Environment"})})}),(0,s.jsxs)($,{children:[(0,s.jsx)(ee,{value:"local",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(et.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Local"})]})}),(0,s.jsx)(ee,{value:"pull",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ea.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Pull remote"})]})}),(0,s.jsx)(ee,{value:"production",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(es.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Push remote"})]})})]})]})}function en(e){var t;let{className:a,currentView:d,onNavigate:m,onTableSelect:h}=e,{tables:g,refreshTables:v,isLoading:N,error:j}=(0,p.t)(),[b,w]=(0,l.useState)([]),[y,C]=(0,l.useState)(""),[S,E]=(0,l.useState)("local"),[R,T]=(0,l.useState)(!1),[A,O]=(0,l.useState)(null),[L,I]=(0,l.useState)(!1),{isConnecting:U,isPushing:P,showPreview:F,connectToCloudflare:D,pushToRemote:M,pullFromRemote:z,pullToRemotePreview:V,validateStoredCredentials:q,PreviewUI:J}=function(){var e,t;let[a,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),[m,h]=(0,l.useState)(null),[x,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),{toast:N}=(0,_.dj)(),{refreshTables:j}=(0,p.t)(),b=()=>{c(!1),u(null),h(null),f(null),v(null)},w=async()=>{let e=localStorage.getItem("cf_credentials");if(!e)return null;try{let t=JSON.parse(e),a=await fetch("/api/cloudflare",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw Error("Invalid stored credentials");let s=await a.json();return{...t,databaseId:s.database.id}}catch(e){return console.error("Failed to validate stored credentials:",e),localStorage.removeItem("cf_credentials"),null}},y=async()=>{try{f("push"),c(!0),i(!0),h(null),v(null),u({preview:[]});let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/push-remote/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to generate preview")}u(s.details.details)}catch(e){console.error("Push to remote preview failed:",e),h(e),N({title:"Preview Failed",description:e.message||"Failed to generate preview",variant:"destructive"})}finally{i(!1)}},C=async()=>{try{i(!0),h(null),v(null);let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/push-remote/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to confirm push")}u(e=>({...e,preview:e.preview.map(e=>({...e,action:"will be applied"===e.action?"applied":e.action}))})),v("Applied ".concat(s.details.applied," migration(s), skipped ").concat(s.details.skipped,"."))}catch(e){console.error("Push to remote confirm failed:",e),h(e)}finally{i(!1)}},S=async()=>{try{f("pull"),c(!0),i(!0),h(null),v(null),u({preview:[]});let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/pull-remote/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to generate pull preview")}u(s.details)}catch(e){console.error("Pull to remote preview failed:",e),h(e),N({title:"Preview Failed",description:e.message||"Failed to generate pull preview",variant:"destructive"})}finally{i(!1)}},E=async()=>{try{i(!0),h(null);let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/pull-remote/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to confirm pull")}b(),N({title:"Migration Success",description:"Pull migrations applied successfully."}),await j()}catch(e){console.error("Pull to remote confirm failed:",e),h(e),N({title:"Migration Failed",description:e.message||"Failed to pull migrations from remote",variant:"destructive"})}finally{i(!1)}};async function R(e){try{n(!0);let t=await fetch("/api/cloudflare",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),a=await t.json();if(!t.ok)throw Error(a.error||"Failed to connect to Cloudflare");localStorage.setItem("cf_credentials",JSON.stringify({...e,databaseId:a.database.id})),N({title:"Connected to Cloudflare",description:"Connected to database: ".concat(a.database.name),variant:"default"})}catch(e){throw N({title:"Connection Failed",description:e.message||"Failed to connect to Cloudflare",variant:"destructive"}),e}finally{n(!1)}}let T=o&&("pull"===x?(0,s.jsx)(K,{preview:(null==d?void 0:d.preview)||[],onConfirm:E,onCancel:b,isConfirming:r,error:m,isLoading:r&&!(null==d?void 0:null===(e=d.preview)||void 0===e?void 0:e.length)}):(0,s.jsx)(Q,{preview:(null==d?void 0:d.preview)||[],onConfirm:C,onCancel:b,isConfirming:r,error:m,success:g,isLoading:r&&!(null==d?void 0:null===(t=d.preview)||void 0===t?void 0:t.length)}));return{isConnecting:a,isPushing:r,showPreview:o,previewError:m,pushToRemote:y,pullToRemotePreview:S,confirmPull:E,connectToCloudflare:R,validateStoredCredentials:w,PreviewUI:T}}(),Y=(0,l.useMemo)(()=>{let e=[...(null==g?void 0:g.filter(e=>e.toLowerCase().includes(y.toLowerCase())))||[]].sort((e,t)=>e.localeCompare(t)),t=e.indexOf("d1_migrations");return -1!==t&&(e.splice(t,1),e.unshift("d1_migrations")),e},[g,y]),X=async e=>{try{I(!0),O(e),h(e)}catch(e){console.error("Error selecting table:",e)}finally{I(!1)}},H=async e=>{if(console.log("Environment change triggered:",e),E(e),"production"===e)try{if(!await q()){T(!0);return}await M()}catch(e){console.error("Environment change failed:",e),E("local")}else if("pull"===e)try{if(!await q()){T(!0);return}await V()}catch(e){console.error("Pull from remote failed:",e),E("local")}else E(e)};return(0,l.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/databases"),t=await e.json();if(!e.ok)throw Error(t.error||"Failed to fetch databases");w(t.databases||[])}catch(e){console.error("Error fetching databases:",e)}})(),v()},[v]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("aside",{className:"".concat(a," w-64 fixed top-0 left-0 h-full bg-neutral-50 p-4"),children:[(0,s.jsxs)("div",{className:"flex flex-col h-full font-sans",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,s.jsx)(n.A,{className:"h-5 w-5"}),(0,s.jsx)("span",{className:"font-mono font-bold text-sm",children:"d1-studio"})]}),(0,s.jsx)("div",{className:"mb-6",children:(0,s.jsxs)("button",{className:"w-full flex items-center gap-x-1 border rounded-md text-sm font-medium transition-colors px-2 py-2\n ".concat("sql-editor"===d?"bg-neutral-900 text-white":"bg-white hover:bg-neutral-100"),onClick:()=>m("sql-editor"),disabled:L,children:[(0,s.jsx)(r.A,{className:"h-[16px] w-[16px]"}),"SQL editor"]})}),j&&(0,s.jsxs)(x,{variant:"destructive",className:"mb-4",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsx)(f,{className:"text-sm ml-2",children:j})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-muted-foreground mb-1",children:"Database name"}),(0,s.jsx)("div",{className:"font-semibold text-sm",children:(null===(t=b[0])||void 0===t?void 0:t.database_name)||"No database found"})]}),(0,s.jsx)(el,{value:S,onValueChange:H,isLoading:P,disabled:U,showPreview:F})]}),(0,s.jsxs)("div",{className:"relative mb-6 bg-white",children:[(0,s.jsx)(o.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-neutral-500"}),(0,s.jsx)(u,{placeholder:"Search tables",value:y,onChange:e=>C(e.target.value),className:"pl-7"})]}),(0,s.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-1 flex-none",children:[(0,s.jsxs)("h3",{className:"text-sm font-medium text-muted-foreground",children:["Tables ",(null==g?void 0:g.length)?"(".concat(g.length,")"):""]}),N&&(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),(0,s.jsx)("div",{className:"overflow-y-auto flex-1",children:(0,s.jsxs)("div",{className:"pr-2 pb-4",children:[" ",!N&&0===Y.length&&(0,s.jsx)("div",{className:"text-sm font-medium text-muted-foreground px-2 py-2",children:y?"No matching tables found":j?"Error loading tables":"No tables available"}),Y.map(e=>(0,s.jsx)("button",{className:"w-full text-left text-sm font-medium rounded-md transition-colors px-2 py-2\n ".concat("table-view"===d&&A===e?"bg-[#F0F0F0] text-neutral-900 font-semibold":"text-neutral-700 hover:bg-[#F2F2F2]","\n ").concat(L&&"opacity-50 cursor-not-allowed"),onClick:()=>X(e),disabled:L,children:e},e))]})})]})]}),(0,s.jsx)(k,{open:R,onClose:()=>{T(!1),E("local")},onSubmit:D})]}),J]})}var er=a(707),ei=a(1170),eo=a(3320),ec=a(5377);function ed(e){let{results:t}=e;return t&&Array.isArray(t)?(0,s.jsxs)("div",{className:"text-xs font-medium text-neutral-900 flex items-center gap-2 mb-2",children:[t.length," ",1===t.length?"row":"rows"," returned"]}):null}function eu(e){var t;let{error:a}=e;console.debug("SQLErrorDisplay - Received error prop:",a);let l=a&&"string"==typeof a.message?a:{message:"An unknown error occurred",details:{}};return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-neutral-700 text-sm",children:l.message}),(null===(t=l.details)||void 0===t?void 0:t.stderr)&&(0,s.jsx)("pre",{className:"mt-2 p-2 text-xs text-red-500 whitespace-pre-wrap",children:l.details.stderr})]})}function em(e){let{query:t,results:a}=e;if(!(null==a?void 0:a.length))return(0,s.jsx)("div",{className:"text-sm text-neutral-500",children:"No results to display."});let l=null==t?void 0:t.trim().toLowerCase().startsWith("pragma table_info"),n=l?["Column Name","Type","Not Null","Default Value","Primary Key"]:Object.keys(a[0]),r=l?a.map(e=>({"Column Name":e.name,Type:e.type,"Not Null":1===e.notnull?"YES":"NO","Default Value":e.dflt_value||"(null)","Primary Key":1===e.pk?"YES":"NO"})):a;return(0,s.jsxs)("div",{className:"flex flex-col h-full",children:[(0,s.jsx)(ed,{results:r}),(0,s.jsx)("div",{className:"flex-1 overflow-auto border rounded-lg",children:(0,s.jsx)("div",{className:"min-w-full",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsx)(D,{className:"bg-muted/50",children:n.map(e=>(0,s.jsx)(M,{className:"font-mono text-xs font-medium text-muted-foreground",children:e},e))})}),(0,s.jsx)(F,{children:r.map((e,t)=>(0,s.jsx)(D,{className:"hover:bg-muted/50",children:n.map(a=>{let l=e[a],n=null===l?"(null)":String(l);return(0,s.jsx)(z,{className:"font-monospace text-xs whitespace-nowrap",children:n},"".concat(t,"-").concat(a))})},t))})]})})})]})}var eh=a(4471),ex=a(5325),ef=a(1703);let ep=eh.bL,eg=eh.l9;eh.YJ,eh.ZL,eh.Pb,eh.z6,l.forwardRef((e,t)=>{let{className:a,inset:l,children:n,...r}=e;return(0,s.jsxs)(eh.ZP,{ref:t,className:(0,d.cn)("flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",l&&"pl-8",a),...r,children:[n,(0,s.jsx)(ex.A,{className:"ml-auto"})]})}).displayName=eh.ZP.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eh.G5,{ref:t,className:(0,d.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...l})}).displayName=eh.G5.displayName;let ev=l.forwardRef((e,t)=>{let{className:a,sideOffset:l=4,...n}=e;return(0,s.jsx)(eh.ZL,{children:(0,s.jsx)(eh.UC,{ref:t,sideOffset:l,className:(0,d.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n})})});ev.displayName=eh.UC.displayName;let eN=l.forwardRef((e,t)=>{let{className:a,inset:l,...n}=e;return(0,s.jsx)(eh.q7,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",l&&"pl-8",a),...n})});eN.displayName=eh.q7.displayName,l.forwardRef((e,t)=>{let{className:a,children:l,checked:n,...r}=e;return(0,s.jsxs)(eh.H_,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(eh.VF,{children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})}),l]})}).displayName=eh.H_.displayName,l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(eh.hN,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(eh.VF,{children:(0,s.jsx)(ef.A,{className:"h-2 w-2 fill-current"})})}),l]})}).displayName=eh.hN.displayName,l.forwardRef((e,t)=>{let{className:a,inset:l,...n}=e;return(0,s.jsx)(eh.JU,{ref:t,className:(0,d.cn)("px-2 py-1.5 text-sm font-semibold",l&&"pl-8",a),...n})}).displayName=eh.JU.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eh.wv,{ref:t,className:(0,d.cn)("-mx-1 my-1 h-px bg-muted",a),...l})}).displayName=eh.wv.displayName;let ej={SYNTAX_ERROR:"SYNTAX_ERROR",EXECUTION_ERROR:"EXECUTION_ERROR",TABLE_NOT_FOUND:"TABLE_NOT_FOUND",TABLE_EXISTS:"TABLE_EXISTS",FOREIGN_KEY_ERROR:"FOREIGN_KEY_ERROR",UNIQUE_CONSTRAINT_ERROR:"UNIQUE_CONSTRAINT_ERROR",NOT_NULL_CONSTRAINT_ERROR:"NOT_NULL_CONSTRAINT_ERROR",CHECK_CONSTRAINT_ERROR:"CHECK_CONSTRAINT_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR"};function eb(e){if(console.debug("parseSQLError - Received error:",e),!e)return console.debug("parseSQLError - error is null or undefined."),{type:ej.UNKNOWN_ERROR,message:"An unknown error occurred",details:{}};let t="",a=null,s=null,l=e.cmd||e.details&&e.details.command;if(l){let e=l.match(RegExp('--command="(.+?)"',"s"));e&&console.debug("parseSQLError - Extracted original query:",s=e[1].replace(/\\n/g,"\n"))}let n=e.stderr||e.details&&e.details.stderr;if(n){let r=n.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"");if(console.debug("parseSQLError - Cleaned stderr:",r),r.includes("env: node: No such file or directory"))return console.debug("parseSQLError - Detected 'env: node: No such file or directory' error."),{type:ej.EXECUTION_ERROR,message:e.message||"Execution error: env: node: No such file or directory",details:{originalQuery:s,stderr:r}};let i=r.match(/near "([^"]+)": syntax error at offset (\d+)/);if(i){let[e,l,n]=i;return a=parseInt(n,10),t='Syntax error near "'.concat(l,'" at position ').concat(a),console.debug("parseSQLError - Syntax error detected:",{near:l,offset:a}),{type:ej.SYNTAX_ERROR,message:t,details:{originalQuery:s,errorLocation:{offset:a,near:l},stderr:r}}}if(r.includes("UNIQUE constraint failed")){let[e,t,a]=r.match(/UNIQUE constraint failed: (\w+)\.(\w+)/)||[];return console.debug("parseSQLError - UNIQUE constraint error detected:",{table:t,column:a}),{type:ej.UNIQUE_CONSTRAINT_ERROR,message:"Unique constraint violation updating ".concat(t,".").concat(a),details:{originalQuery:s,stderr:r}}}if(r.includes("NOT NULL constraint failed")){let[e,t,a]=r.match(/NOT NULL constraint failed: (\w+)\.(\w+)/)||[];return console.debug("parseSQLError - NOT NULL constraint error detected:",{table:t,column:a}),{type:ej.NOT_NULL_CONSTRAINT_ERROR,message:"NOT NULL constraint violation updating ".concat(t,".").concat(a),details:{originalQuery:s,stderr:r}}}if(r.includes("CHECK constraint failed")){let[e,t]=r.match(/CHECK constraint failed: (\w+)/)||[];return console.debug("parseSQLError - CHECK constraint error detected:",{constraintName:t}),{type:ej.CHECK_CONSTRAINT_ERROR,message:"Check constraint violation updating ".concat(t),details:{originalQuery:s,stderr:r}}}if(r.includes("FOREIGN KEY constraint failed")){console.debug("parseSQLError - FOREIGN KEY constraint error detected.");let e=/--command="([^"]+)"/.exec(l||""),t=e?e[1]:null,a={};if(t){let e=/UPDATE\s+(\w+)\s+SET\s+(\w+)\s*=/.exec(t);e&&(a={table:e[1],column:e[2]})}let s=a.table?"Foreign key constraint violation updating ".concat(a.table,".").concat(a.column):"Foreign key constraint violation";return{type:ej.FOREIGN_KEY_ERROR,message:s,details:{...a,originalQuery:t,stderr:r}}}if(r.includes("no such table")){let[e,t]=r.match(/no such table: (\w+)/)||[];return console.debug("parseSQLError - Table not found error detected:",{table:t}),{type:ej.TABLE_NOT_FOUND,message:"Table not found: ".concat(t),details:{originalQuery:s,stderr:r}}}if(r.includes("already exists")){let[e,t]=r.match(/table (\w+) already exists/)||[];return console.debug("parseSQLError - Table exists error detected:",{table:t}),{type:ej.TABLE_EXISTS,message:"Table already exists: ".concat(t),details:{originalQuery:s,stderr:r}}}return console.debug("parseSQLError - No specific error match found. Using fallback for execution error."),{type:ej.EXECUTION_ERROR,message:e.message||"Failed to execute SQL command",details:{originalQuery:s,stderr:r}}}return console.debug("parseSQLError - No stderr available; using default error handling."),{type:ej.UNKNOWN_ERROR,message:e.message||"An unknown error occurred",details:{}}}let ew={"Show Tables":"SELECT name\n FROM sqlite_master \n WHERE type='table' \n AND name NOT LIKE 'sqlite_%';","Table Schema":"-- Table Schema\n-- Replace table_name with your table name\nPRAGMA table_info(table_name);","Table Indexes":"-- Table Indexes\n-- Replace table_name with your table name\nSELECT \n m.name as table_name,\n i.name as index_name,\n i.sql as index_definition\nFROM sqlite_master m\nJOIN sqlite_master i ON m.name = i.tbl_name\nWHERE m.type = 'table'\nAND i.type = 'index'\nAND m.name = 'table_name';","Foreign Keys":"-- Foreign Key Information\n-- Replace table_name with your table name\nPRAGMA foreign_key_list(table_name);","Table Data":"-- Table Data\n-- Replace table_name with your table name\nSELECT * FROM table_name LIMIT 100;","Row Count":"-- Row Count\n-- Replace table_name with your table name\nSELECT COUNT(*) as total_rows FROM table_name;","Column Stats":"-- Column Statistics\n-- Replace table_name and column_name with your values\nSELECT \n COUNT(*) as total_rows,\n COUNT(column_name) as non_null_count,\n COUNT(DISTINCT column_name) as unique_values,\n MIN(column_name) as min_value,\n MAX(column_name) as max_value\nFROM table_name;","Create Table":"CREATE TABLE IF NOT EXISTS new_table (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL,\n email TEXT UNIQUE,\n status TEXT CHECK(status IN ('active', 'inactive')) DEFAULT 'active',\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\n-- Create indexes\nCREATE INDEX idx_new_table_name ON new_table(name);\nCREATE UNIQUE INDEX idx_new_table_email ON new_table(email);","Create View":"-- Create a view\nCREATE VIEW view_name AS\nSELECT column1, column2\nFROM table_name\nWHERE condition;"},ey={"Schema Information":["Show Tables","Table Schema","Table Indexes","Foreign Keys"],"Data Queries":["Table Data","Row Count","Column Stats"],"Schema Modification":["Create Table","Create View"]};function eC(e){let{onSelectQuery:t}=e;return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsxs)(A,{variant:"outline",size:"sm",children:["Query Templates",(0,s.jsx)(J.A,{className:"ml-2 h-4 w-4"})]})}),(0,s.jsx)(ev,{align:"start",className:"w-72",children:Object.entries(ey).map(e=>{let[a,n]=e;return(0,s.jsxs)(l.Fragment,{children:[(0,s.jsx)("div",{className:"px-2 py-1.5 text-sm font-semibold text-neutral-900 font-sans",children:a}),n.map(e=>(0,s.jsx)(eN,{onClick:()=>t(e),className:"font-sans text-neutral-800",children:e},e))]},a)})})]})}function eS(){let{executeQuery:e,refreshTables:t}=(0,p.t)(),[a,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(300),[u,m]=(0,l.useState)(!1),h=(0,l.useRef)(null),x=(0,l.useRef)(null);(0,l.useEffect)(()=>{x.current&&(x.current.style.height="".concat(o,"px"))},[o]);let f=(0,l.useCallback)(e=>{e.preventDefault();let t=e.pageY,a=e=>{d(Math.min(Math.max(o+(e.pageY-t),100),.8*window.innerHeight))},s=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",s)};document.addEventListener("mousemove",a),document.addEventListener("mouseup",s)},[o]),g=async()=>{if(!h.current)return;let a=h.current.getValue().trim().replace(/;+$/,"");if(!a){n({success:!1,error:{message:"Query cannot be empty."}});return}try{var s,l,r,o;i(!0),n(null);let c=await e(a);/^(CREATE|DROP|ALTER)\s+TABLE/i.test(a)&&await t();let d=[];if(c.results){if(Array.isArray(c.results)){if(c.results.length>0&&(null===(s=c.results[0])||void 0===s?void 0:s.columns)&&(null===(l=c.results[0])||void 0===l?void 0:l.values)){let e=c.results[0];d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}else d=1===c.results.length&&c.results[0].results&&Array.isArray(c.results[0].results)?c.results[0].results:c.results}else if(c.results.columns&&c.results.values){let e=c.results;d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}}else if(c.result&&c.result.results){if(Array.isArray(c.result.results)){if(c.result.results.length>0&&(null===(r=c.result.results[0])||void 0===r?void 0:r.columns)&&(null===(o=c.result.results[0])||void 0===o?void 0:o.values)){let e=c.result.results[0];d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}else d=1===c.result.results.length&&c.result.results[0].results&&Array.isArray(c.result.results[0].results)?c.result.results[0].results:c.result.results}else if(c.result.results.columns&&c.result.results.values){let e=c.result.results;d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}}n({success:!0,results:d})}catch(e){n({success:!1,error:eb(e)||{message:"An unknown error occurred",details:{}}})}finally{i(!1)}};return(0,s.jsxs)("div",{className:"h-full flex flex-col bg-white text-neutral-900 font-sans",children:[(0,s.jsx)("div",{className:"px-4 py-2 bg-neutral-100 border-b flex items-center gap-4",children:(0,s.jsx)(eC,{onSelectQuery:e=>{if(h.current){let t=Object.keys(ew).find(t=>t.toLowerCase()===e.toLowerCase());if(t){let e=ew[t];h.current.setValue(e),h.current.focus()}else console.warn("Query template not found for: ".concat(e))}}})}),(0,s.jsx)("div",{ref:x,className:"relative pt-2 overflow-hidden",style:{height:"".concat(o,"px"),minHeight:"100px"},children:(0,s.jsx)(er.Ay,{height:"100%",language:"sql",options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",automaticLayout:!0,lineNumbers:"on",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"},onMount:e=>{h.current=e,e.addCommand(monaco.KeyMod.CtrlCmd|monaco.KeyCode.Enter,()=>{g()})}})}),(0,s.jsx)("div",{className:"relative h-0.5 cursor-row-resize bg-neutral-200 group ".concat(u?"bg-neutral-300":"hover:bg-neutral-300"),onMouseDown:e=>{m(!0),f(e)},onMouseUp:()=>m(!1),children:(0,s.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-neutral-900 rounded-sm px-0.5 \n ".concat(u?"visible":"invisible group-hover:visible"),children:(0,s.jsx)(ei.A,{className:"h-3 w-3 text-white"})})}),(0,s.jsx)("div",{className:"px-4 py-3 bg-neutral-100 border-b font-sans",children:(0,s.jsxs)("div",{className:"flex justify-between items-center",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"Results"}),(0,s.jsxs)(A,{size:"sm",onClick:g,disabled:r,className:"flex items-center gap-1 text-sm font-medium",children:["Run",r?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(eo.A,{className:"h-4 w-4"}),(0,s.jsx)(ec.A,{className:"h-4 w-4"})]})]})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-auto p-4 bg-white",children:(()=>{var e;if(r)return(0,s.jsxs)("div",{className:"flex items-center text-sm text-neutral-700",children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin mr-2 font-sans"}),"Running your query..."]});if(!a)return(0,s.jsx)("div",{className:"text-sm text-neutral-500 font-sans",children:"Run the query to see the results."});if(!a.success)return console.debug("SQLEditor - Rendering error:",a.error),(0,s.jsx)(eu,{error:a.error});let t=a.results;return t&&0!==t.length?(0,s.jsx)(em,{query:(null===(e=h.current)||void 0===e?void 0:e.getValue())||"",results:t}):(0,s.jsx)("div",{className:"text-sm text-neutral-900 font-sans",children:"Success. No results to display."})})()})]})}var eE=a(6352);let eR=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eE.bL,{ref:t,className:(0,d.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",a),...l,children:(0,s.jsx)(eE.C1,{className:(0,d.cn)("flex items-center justify-center text-current"),children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})})});eR.displayName=eE.bL.displayName;var eT=a(138),eA=a(1598),ek=a(2884),e_=a(9710);let eO=e_.Kq,eL=e_.bL,eI=e_.l9,eU=l.forwardRef((e,t)=>{let{className:a,sideOffset:l=4,...n}=e;return(0,s.jsx)(e_.ZL,{children:(0,s.jsx)(e_.UC,{ref:t,sideOffset:l,className:(0,d.cn)("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n})})});eU.displayName=e_.UC.displayName;var eP=a(6235);let eF=(0,l.memo)(e=>{let{onRefresh:t,disabled:a}=e,[n,r]=(0,l.useState)(!1),i=async()=>{if(!n&&!a){r(!0);try{await t()}catch(e){console.error("Refresh failed:",e)}finally{setTimeout(()=>{r(!1)},500)}}};return(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",onClick:i,disabled:n||a,className:"h-8",children:n?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(eP.A,{className:"h-4 w-4"})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Refresh table data"})})]})})});eF.displayName="RefreshButton";var eD=a(7973);let eM=(0,l.memo)(e=>{let{tableName:t,onSync:a}=e,[n,r]=(0,l.useState)(!1),{toast:i}=(0,_.dj)();if("d1_migrations"!==t)return null;let o=async()=>{try{r(!0);let e=await fetch("/api/migrations/sync-files",{method:"POST"}),t=await e.json();if(!e.ok)throw Error(t.error||"Failed to sync migrations");let{added:s=[],removed:l=[]}=t.details||{};i({title:"Migrations Synced",description:"Added: ".concat(s.length,", Removed: ").concat(l.length)}),a&&await a()}catch(e){console.error("Error syncing migrations:",e),i({variant:"destructive",title:"Sync Failed",description:e.message})}finally{r(!1)}};return(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",onClick:o,disabled:n,className:"h-8",children:n?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(eD.A,{className:"h-4 w-4"})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Sync migration files with d1_migrations table"})})]})})});eM.displayName="SyncMigrationsButton";var ez=a(358),eQ=a(8742),eV=a(6697);let eK=(0,l.memo)(e=>{let{tableName:t,onDownloadStart:a,onDownloadComplete:n,disabled:r}=e,[i,o]=(0,l.useState)(!1),{toast:d}=(0,_.dj)(),u=(e,t)=>{try{let a=new Blob([e],{type:"application/octet-stream"}),s=window.URL.createObjectURL(a),l=document.createElement("a");l.href=s,l.download=t,document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)}catch(e){throw console.error("Error during file download:",e),e}},m=async e=>{if(!r)try{o(!0),null==a||a();let s=await fetch("/api/tables/".concat(t)),l=await s.json();if(!s.ok)throw Error(l.error||"Failed to fetch data");let{data:r,schema:i}=l;if(!(null==r?void 0:r.length)){d({title:"No Data",description:"The table is empty.",variant:"destructive"});return}let c=new Date().toISOString().split("T")[0],m="".concat(t,"_").concat(c,".").concat(e);switch(e){case"json":{let e=JSON.stringify(r,null,2);u(e,m);break}case"csv":{let e=Object.keys(r[0]),t=[e.join(","),...r.map(t=>e.map(e=>{let a=t[e];if(null==a)return"";if("string"==typeof a){let e=a.replace(/"/g,'""');return'"'.concat(e,'"')}return a}).join(","))].join("\n");u(t,m);break}case"sql":{let e="CREATE TABLE IF NOT EXISTS ".concat(t," (\n")+i.map(e=>{let t=[];return e.pk&&t.push("PRIMARY KEY"),e.notnull||t.push("NOT NULL")," ".concat(e.name," ").concat(e.type).concat(t.length?" ".concat(t.join(" ")):"")}).join(",\n")+"\n);\n\n",a=r.map(e=>{let a=Object.keys(e),s=a.map(t=>{let a=e[t];return null===a?"NULL":"string"==typeof a?"'".concat(a.replace(/'/g,"''"),"'"):a});return"INSERT INTO ".concat(t," (").concat(a.join(", "),")\nVALUES (").concat(s.join(", "),");")}).join("\n");u(e+a,m)}}d({title:"Download Complete",description:"".concat(r.length," rows exported as ").concat(e.toUpperCase(),".")}),null==n||n()}catch(e){console.error("Download error:",e),d({variant:"destructive",title:"Download Failed",description:e.message})}finally{o(!1)}};return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",className:"h-8",disabled:i||r,children:i?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(ea.A,{className:"h-4 w-4"})})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Download table data"})})]})}),(0,s.jsxs)(ev,{align:"end",children:[(0,s.jsxs)(eN,{onClick:()=>m("json"),disabled:r,children:[(0,s.jsx)(ez.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download JSON"})]}),(0,s.jsxs)(eN,{onClick:()=>m("csv"),disabled:r,children:[(0,s.jsx)(eQ.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download CSV"})]}),(0,s.jsxs)(eN,{onClick:()=>m("sql"),disabled:r,children:[(0,s.jsx)(eV.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download SQL"})]})]})]})});eK.displayName="DownloadButton";var eq=a(9045);let eJ=function(e){let{schema:t=[],visibleColumns:a=[],onColumnToggle:n}=e,[r,i]=(0,l.useState)("");(0,l.useEffect)(()=>{if(!t||0===t.length)return;let e=t.map(e=>e.name);0===a.length&&e.forEach(e=>n(e))},[t,a.length,n]);let o=t.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())),c=o.map(e=>e.name),d=c.length>0&&c.every(e=>a.includes(e)),m=e=>{n(e)};return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsxs)(A,{size:"sm",variant:"outline",className:"font-semibold",children:[(0,s.jsx)(eq.A,{className:"h-4 w-4"}),"Columns (",a.length,")"]})}),(0,s.jsxs)(ev,{align:"end",className:"w-64 font-sans",children:[(0,s.jsx)("div",{className:"p-2",children:(0,s.jsx)(u,{placeholder:"Search columns...",value:r,onChange:e=>i(e.target.value),className:"h-8"})}),(0,s.jsxs)("div",{className:"flex items-center space-x-2 px-2 py-1.5 hover:bg-accent rounded-md",children:[(0,s.jsx)(eR,{id:"select-all-columns",checked:d,onCheckedChange:e=>{e?o.forEach(e=>{a.includes(e.name)||n(e.name)}):o.forEach(e=>{a.includes(e.name)&&n(e.name)})},className:"shrink-0"}),(0,s.jsxs)("label",{htmlFor:"select-all-columns",className:"flex-1 cursor-pointer text-sm font-medium",children:["Select All ",r&&"(Filtered)"]})]}),(0,s.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:o.map(e=>(0,s.jsxs)("div",{className:"flex items-start space-x-2 px-2 py-1.5 hover:bg-accent rounded-md",children:[(0,s.jsx)(eR,{id:"column-".concat(e.name),checked:a.includes(e.name),onCheckedChange:()=>m(e.name),className:"mt-1"}),(0,s.jsxs)("label",{htmlFor:"column-".concat(e.name),className:"flex-1 cursor-pointer",children:[(0,s.jsx)("div",{className:"text-sm font-medium",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground",children:e.type.toLowerCase()})]})]},e.name))})]})]})},eY=(0,l.memo)(e=>{let{onAdd:t,onDelete:a,selectedCount:l,disabled:n,newRecordsCount:r,schema:i,visibleColumns:o,onColumnToggle:c}=e;return(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)("span",{children:(0,s.jsxs)(A,{size:"sm",variant:"outline",className:"font-semibold opacity-50 cursor-not-allowed",disabled:!0,children:[(0,s.jsx)(eT.A,{className:"h-4 w-4"}),"Filters"]})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Filters are not available yet. Coming soon!"})})]})}),(0,s.jsx)(eJ,{schema:i,visibleColumns:o,onColumnToggle:c}),(0,s.jsx)("div",{className:"h-4 border-r mx-2"}),(0,s.jsx)(A,{size:"sm",variant:"default",className:"font-semibold",onClick:t,children:"Add record"}),l>0&&(0,s.jsxs)(A,{size:"sm",className:"font-semibold",onClick:a,variant:"destructive",disabled:n||r>0,children:["Delete ",l," ",1===l?"record":"records"]})]})}),eX=(0,l.memo)(e=>{let{totalRows:t}=e;return(0,s.jsxs)("span",{className:"text-sm text-neutral-600",children:[t," ",1===t?"row":"rows"]})}),eH=(0,l.memo)(e=>{let{currentPage:t,totalPages:a,onPageChange:l,disabled:n,newRecordsCount:r}=e;return(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(A,{variant:"ghost",size:"icon",onClick:()=>{console.log("Pagination: navigating to previous page",t-1),l(t-1)},disabled:1===t||n||r>0,className:"h-8",children:(0,s.jsx)(eA.A,{className:"h-4 w-4"})}),(0,s.jsxs)("span",{className:"text-sm",children:["Page ",t," of ",a]}),(0,s.jsx)(A,{variant:"ghost",size:"icon",onClick:()=>{console.log("Pagination: navigating to next page",t+1),l(t+1)},disabled:t===a||n||r>0,className:"h-8",children:(0,s.jsx)(ek.A,{className:"h-4 w-4"})})]})}),eB=(0,l.memo)(e=>{let{value:t,onValueChange:a,disabled:l,newRecordsCount:n}=e;return(0,s.jsxs)(H,{value:t.toString(),onValueChange:a,disabled:l||n>0,children:[(0,s.jsx)(W,{className:"w-20 h-8",children:(0,s.jsx)(B,{})}),(0,s.jsxs)($,{children:[(0,s.jsx)(ee,{value:"50",children:"50"}),(0,s.jsx)(ee,{value:"100",children:"100"}),(0,s.jsx)(ee,{value:"250",children:"250"})]})]})}),eW=(0,l.memo)(e=>{let{onSave:t,onDiscard:a,totalChanges:l,isSaving:n}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(A,{size:"sm",variant:"ghost",className:"font-semibold",onClick:a,disabled:n,children:"Discard changes"}),(0,s.jsx)(A,{size:"sm",className:"font-semibold bg-green-600 hover:bg-green-700",variant:"default",onClick:t,disabled:n,children:n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):"Save ".concat(l," ").concat(1===l?"change":"changes")})]})}),eG=e=>{let{selectedCount:t=0,onAdd:a,onDelete:l,onRefresh:n,totalRows:r=0,currentPage:i=1,totalPages:o=1,onPageChange:c,rowsPerPage:d=50,onRowsPerPageChange:u,tableName:m,onDownloadStart:h,onDownloadComplete:x,disabled:f=!1,editCount:p=0,newRecordsCount:g=0,onSaveChanges:v,onDiscardChanges:N,isSaving:j=!1,schema:b,visibleColumns:w,onColumnToggle:y}=e,C=p+g;return(0,s.jsx)("div",{className:"flex items-center justify-between p-3 border-b bg-background font-sans",children:(0,s.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,s.jsx)(eY,{onAdd:a,onDelete:l,selectedCount:t,disabled:f||j,newRecordsCount:g,schema:b,visibleColumns:w,onColumnToggle:y}),(0,s.jsx)("div",{className:"flex items-center gap-4",children:C>0?(0,s.jsx)(eW,{onSave:v,onDiscard:N,totalChanges:C,isSaving:j}):(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(eX,{totalRows:r}),(0,s.jsx)(eH,{currentPage:i,totalPages:o,onPageChange:c,disabled:f,newRecordsCount:g}),(0,s.jsx)(eB,{value:d,onValueChange:e=>{u(parseInt(e,10)),c(1)},disabled:f,newRecordsCount:g}),(0,s.jsx)(eF,{onRefresh:n,disabled:f}),(0,s.jsx)(eM,{tableName:m,onSync:n,disabled:f}),(0,s.jsx)(eK,{tableName:m,onDownloadStart:h,onDownloadComplete:x,disabled:f})]})})]})})};eG.displayName="TableToolbar";let eZ=(0,l.memo)(eG);function e$(e){let{value:t,row:a,column:n,schema:r,onChange:i,onStartEdit:o,isEditing:c}=e,d="string"==typeof t?t.replace(/^'|'$/g,""):t,[m,h]=(0,l.useState)(d),[x,f]=(0,l.useState)("auto"),p=(0,l.useRef)(null),g=(0,l.useRef)(null),v=r.find(e=>e.name===n),N=(0,l.useMemo)(()=>(null==v?void 0:v.check)||null,[v]),j=(0,l.useMemo)(()=>{var e;let t=(null==v?void 0:null===(e=v.type)||void 0===e?void 0:e.toLowerCase())||"";return"boolean"===t||"bool"===t||"integer"===t&&n.toLowerCase().startsWith("is_")},[v,n]);(0,l.useEffect)(()=>{h(d)},[d]),(0,l.useEffect)(()=>{if(p.current&&!c){let e=p.current.offsetWidth;f("".concat(e,"px"))}},[c]),(0,l.useEffect)(()=>{c&&g.current&&(g.current.focus(),g.current.select())},[c]),null==v||v.pk;let b=(0,l.useCallback)(e=>{let t=j?"true"===e?1:"false"===e?0:e:e;h(e),null==i||i(t)},[i,j]),w=(0,l.useCallback)(()=>{!c&&o&&o(d)},[c,o,d]),y="border-x border-neutral-200 px-3 py-2.5 text-xs font-mono whitespace-nowrap",C=(0,l.useMemo)(()=>null==d?"null":j?1===d||"1"===d||"true"===d?"true":"false":d.toString(),[d,j]);return c?j?(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)("div",{className:"w-full h-full",children:(0,s.jsxs)(H,{value:C,onValueChange:b,defaultOpen:c,children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select value"})}),(0,s.jsxs)($,{className:"min-w-[8rem]",children:[(0,s.jsx)(ee,{value:"true",children:"true"}),(0,s.jsx)(ee,{value:"false",children:"false"})]})]})})}):(null==N?void 0:N.length)>0?(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)("div",{className:"w-full h-full",children:(0,s.jsxs)(H,{value:null!=m?m:N[0],onValueChange:b,defaultOpen:c,children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select ".concat(n)})}),(0,s.jsx)($,{className:"min-w-[8rem]",children:N.map(e=>(0,s.jsx)(ee,{value:e,children:e},e))})]})})}):(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)(u,{ref:g,value:null!=m?m:"",onChange:e=>b(e.target.value),className:"w-full min-w-0 rounded-none border-0 bg-orange-50 text-orange-900"})}):(0,s.jsx)(z,{ref:p,className:"".concat(y," cursor-pointer hover:bg-muted/50"),onClick:w,children:C})}var e0=a(5524);function e1(e){return"string"==typeof e?e.replace(/^'|'$/g,""):e}function e4(e){let{schema:t,onRemove:a,onChange:n,showCheckbox:r=!1,initialData:i={}}=e,[o,c]=(0,l.useState)(()=>t.reduce((e,t)=>{var a;let s=null!==(a=i[t.name])&&void 0!==a?a:null;return null===(s=e1(s))&&(t.dflt_value?s=e1(t.dflt_value):"INTEGER"===t.type.toUpperCase()?s="":"TEXT"===t.type.toUpperCase()&&(s="")),e[t.name]=s,e},{})),d=(e,t)=>{let a={...o,[e]:t};c(a),null==n||n(a)},m=e=>{var t;let a=(null===(t=e.type)||void 0===t?void 0:t.toLowerCase())||"";return"boolean"===a||"bool"===a||"integer"===a&&e.name.toLowerCase().startsWith("is_")};return(0,s.jsxs)(D,{className:"bg-orange-50/50",children:[(0,s.jsx)(z,{className:"w-10 p-0",children:(0,s.jsx)("div",{className:"pl-1 flex items-center",children:r?(0,s.jsx)(eR,{disabled:!0}):(0,s.jsx)(A,{variant:"ghost",size:"icon",className:"h-8 w-8 text-orange-700 hover:text-orange-800",onClick:a,children:(0,s.jsx)(e0.A,{className:"h-4 w-4"})})})}),t.map(e=>{var t,a;let l=1===e.pk,n=e.check||null;if(m(e)){let t="false";if(null!==e.dflt_value&&void 0!==e.dflt_value){let a=e.dflt_value.toString().toLowerCase();t="1"===a||"true"===a||"'true'"===a||'"true"'===a?"true":"false"}let a=null!==o[e.name]&&void 0!==o[e.name]?1===o[e.name]||!0===o[e.name]||"true"===o[e.name]?"true":"false":t;return(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)("div",{className:"w-full",children:(0,s.jsxs)(H,{value:a,onValueChange:t=>d(e.name,"true"===t?1:0),children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",title:"Default: ".concat(t),children:(0,s.jsx)(B,{placeholder:"Select ".concat(e.name)})}),(0,s.jsxs)($,{className:"min-w-[8rem]",children:[(0,s.jsx)(ee,{value:"true",children:"true"}),(0,s.jsx)(ee,{value:"false",children:"false"})]})]})})},e.name)}return(null==n?void 0:n.length)>0?(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)("div",{className:"w-full",children:(0,s.jsxs)(H,{value:null!==(t=o[e.name])&&void 0!==t?t:n[0],onValueChange:t=>d(e.name,t),children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select ".concat(e.name)})}),(0,s.jsx)($,{className:"min-w-[8rem]",children:n.map(e=>(0,s.jsx)(ee,{value:e,children:e},e))})]})})},e.name):(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)(u,{value:null!==(a=o[e.name])&&void 0!==a?a:"",onChange:t=>d(e.name,t.target.value),className:"w-full min-w-0 rounded-none border-0 px-2 bg-orange-50 text-orange-900",placeholder:l?"Auto-generated":"Enter ".concat(e.name)})},e.name)})]})}let e2=function(e){let{isOpen:t,onClose:a,onConfirm:l,selectedCount:n,tableName:r,isDeleting:o,error:c}=e;return(0,s.jsx)(N,{open:t,onOpenChange:a,children:(0,s.jsxs)(w,{className:"sm:max-w-md font-sans",children:[(0,s.jsxs)(y,{children:[(0,s.jsxs)(S,{className:"mb-2",children:["Delete ",n," ",1===n?"Record":"Records","?"]}),(0,s.jsxs)(E,{className:"text-neutral-600 font-medium",children:["You're about to delete ",n," ",1===n?"record":"records"," from ",(0,s.jsx)("span",{className:"font-sans font-bold text-neutral-900",children:r}),"."]})]}),c&&(0,s.jsxs)(x,{variant:"destructive",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsx)(f,{children:c})]}),(0,s.jsxs)(C,{className:"flex gap-1 mt-2 sm:justify-end font-sans",children:[(0,s.jsx)(A,{variant:"outline",onClick:a,disabled:o,children:"Cancel"}),(0,s.jsx)(A,{variant:"destructive",onClick:l,disabled:o,children:o?"Deleting...":"Delete"})]})]})})};function e5(e){var t;let{isOpen:a,onClose:l,error:n}=e;if(!n||!a)return null;let{message:r,icon:o}=n?{message:n.message,icon:i.A}:{message:"An unknown error occurred.",icon:i.A};return(0,s.jsx)(N,{open:a,onOpenChange:l,children:(0,s.jsxs)(w,{className:"sm:max-w-md font-sans",children:[(0,s.jsx)(y,{children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(o,{className:"h-4 w-4 text-red-500"}),(0,s.jsx)(S,{children:"Error"})]})}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("p",{className:"bg-neutral-100 p-2 rounded-md text-neutral-900",children:r}),(null===(t=n.details)||void 0===t?void 0:t.suggestions)&&(0,s.jsxs)("div",{className:"text-sm space-y-1",children:[(0,s.jsx)("p",{className:"font-medium",children:"Suggestions:"}),(0,s.jsx)("ul",{className:"list-disc pl-4 space-y-1",children:n.details.suggestions.map((e,t)=>(0,s.jsx)("li",{children:e},t))})]})]}),(0,s.jsx)("div",{className:"flex justify-end gap-2 mt-4",children:(0,s.jsx)(A,{variant:"default",onClick:l,children:"Got it"})})]})})}let e3=e=>{let{children:t,width:a,onResize:n,className:r=""}=e,[i,o]=(0,l.useState)(!1),c=(0,l.useRef)(null),d=(0,l.useCallback)(e=>{var t;e.preventDefault(),o(!0);let a=e.clientX,s=(null===(t=c.current)||void 0===t?void 0:t.offsetWidth)||0,l=e=>{c.current&&n(Math.max(s+(e.clientX-a),100))},r=()=>{o(!1),document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",r)};document.addEventListener("mousemove",l),document.addEventListener("mouseup",r)},[n]);return(0,s.jsxs)("th",{ref:c,className:"relative ".concat(r," ").concat(i?"select-none":""),style:{width:"".concat(a,"px")},children:[t,(0,s.jsx)("div",{className:"absolute top-0 right-0 h-full w-1 cursor-col-resize group hover:bg-neutral-300",onMouseDown:d})]})},e9=e=>{let{columns:t,children:a,onColumnsResize:n,className:r=""}=e,[i,o]=(0,l.useState)(t.reduce((e,t)=>({...e,[t.key]:t.width||150}),{})),c=(0,l.useCallback)((e,t)=>{o(a=>{let s={...a,[e]:t};return null==n||n(s),s})},[n]);return(0,s.jsx)("div",{className:"w-full ".concat(r),children:l.Children.map(a,e=>l.isValidElement(e)?l.cloneElement(e,{onResize:c}):e)})};var e8=a(3998),e6=a(3303),e7=a(8729);function te(e){let{column:t,sortConfig:a,onSort:l,children:n}=e,r=a[t];return(0,s.jsx)("div",{className:"flex items-center w-full",children:(0,s.jsxs)(A,{variant:"ghost",size:"sm",className:"h-8 hover:bg-neutral-100 w-full justify-between",onClick:()=>{l(t,r?"asc"===r?"desc":null:"asc")},children:[(0,s.jsx)("span",{className:"flex items-center gap-1 font-mono",children:n}),(0,s.jsxs)("span",{className:"shrink-0",children:["asc"===r&&(0,s.jsx)(e8.A,{className:"h-4 w-4"}),"desc"===r&&(0,s.jsx)(e6.A,{className:"h-4 w-4"}),!r&&(0,s.jsx)(e7.A,{className:"h-4 w-4"})]})]})})}function tt(e){let{tableName:t}=e,{executeQuery:a,getCachedTable:n,updateTableCache:r,invalidateTable:o,switchTable:d,activeTable:u,updateTableData:m}=(0,p.t)(),{toast:h}=(0,_.dj)(),[g,v]=(0,l.useState)(()=>[]),[N,j]=(0,l.useState)([]),[b,w]=(0,l.useState)(0),[y,C]=(0,l.useState)(!0),[S,E]=(0,l.useState)(!1),[R,T]=(0,l.useState)(null),[A,k]=(0,l.useState)(new Map),[O,Q]=(0,l.useState)(new Set),[V,K]=(0,l.useState)([]),[q,J]=(0,l.useState)(1),[Y,X]=(0,l.useState)(50),[H,B]=(0,l.useState)(1),[W,G]=(0,l.useState)(new Set),Z=(0,l.useRef)(null),[$,ee]=(0,l.useState)(!1),[et,ea]=(0,l.useState)(!1),[es,el]=(0,l.useState)(null),[en,er]=(0,l.useState)(!1),[ei,eo]=(0,l.useState)(null),[ec,ed]=(0,l.useState)({}),[eu,em]=(0,l.useState)({}),[eh,ex]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(t){let e=localStorage.getItem("table-widths-".concat(t));e&&em(JSON.parse(e));let a=localStorage.getItem("table-columns-".concat(t));if(a)try{ex(JSON.parse(a))}catch(e){ex([])}}},[t]);let ef=(0,l.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!t)return;let a=n(t,q,Y);if(a&&!e){v(a.data),j(a.schema),w(a.meta.total),B(a.meta.totalPages);return}C(!0),T(null),G(new Set);try{let a=await d(t,{page:q,limit:Y,forceFetch:e});return a.meta.page=q,v(Array.isArray(a.data)?a.data:[]),j(a.schema||[]),w(a.meta.total),B(a.meta.totalPages),!0}catch(e){throw console.error("Error loading table data:",e),T(e.message||String(e)),h({variant:"destructive",title:"Error",description:"Failed to load table: ".concat(e.message)}),e}finally{C(!1)}},[t,q,Y,n,d,h,eh.length]),ep=(0,l.useCallback)(e=>{ex(a=>{let s=a.includes(e)?a.filter(t=>t!==e):[...a,e];return localStorage.setItem("table-columns-".concat(t),JSON.stringify(s)),s})},[t]),eg=(0,l.useCallback)((e,a)=>{em(s=>{let l={...s,[e]:a};return localStorage.setItem("table-widths-".concat(t),JSON.stringify(l)),l})},[t]),ev=(0,l.useCallback)(async()=>{try{G(new Set),o(t),await ef(!0),h({title:"Success",description:"Table data refreshed"})}catch(e){console.error("Refresh failed:",e),h({variant:"destructive",title:"Refresh Failed",description:e.message})}},[ef,o,t,h]),eN=(0,l.useCallback)((e,a)=>{ed(t=>({...t,[e]:a}));let s=a&&g.length?[...g].sort((t,s)=>{let l=t[e],n=s[e];if(null==l&&null==n)return 0;if(null==l)return 1;if(null==n)return -1;if("number"==typeof l&&"number"==typeof n)return"asc"===a?l-n:n-l;let r=String(l).toLowerCase(),i=String(n).toLowerCase();return"asc"===a?r.localeCompare(i):i.localeCompare(r)}):g;v(s);let l=n(t);l&&r(t,s,l.schema,{...l.meta,currentPage:q,limit:Y},q,Y)},[g,t,n,r]),ej=(0,l.useCallback)((e,t,a)=>{let s="".concat(e,"-").concat(t);k(e=>new Map(e).set(s,{value:a,originalValue:a})),Q(t=>new Set(t).add(e))},[]),ew=(0,l.useCallback)((e,t,a)=>{var s,l;let n="".concat(e,"-").concat(t),r=g[e],i=null!==(l=null===(s=A.get(n))||void 0===s?void 0:s.originalValue)&&void 0!==l?l:r[t];if(a===i){let t=new Map(A);if(t.delete(n),k(t),!Array.from(t.keys()).some(t=>t.startsWith("".concat(e,"-")))){let t=new Set(O);t.delete(e),Q(t)}}else k(e=>new Map(e).set(n,{value:a,originalValue:i})),Q(t=>new Set(t).add(e))},[g,A,O]),ey=(0,l.useCallback)(()=>{K(e=>[...e,{}])},[]),eC=(0,l.useCallback)(e=>{K(t=>t.filter((t,a)=>a!==e))},[]),eS=(0,l.useCallback)((e,t)=>{K(a=>{let s=[...a];return s[e]=t,s})},[]),eE=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];E(!0);try{if(V.length>0){let e=0,s=N.filter(e=>"datetime"===e.type.toLowerCase()).map(e=>e.name);for(let l of V){let n=Object.keys(l).filter(e=>null!==l[e]&&""!==l[e]&&"null"!==l[e]);if(s.forEach(e=>{n.includes(e)||n.push(e)}),0===n.length)continue;let r=n.map(e=>{if(s.includes(e))return"CURRENT_TIMESTAMP";let t=l[e];return null===t||""===t||"null"===t?"NULL":"'".concat(t.toString().replace(/'/g,"''"),"'")}),i="INSERT INTO ".concat(t," (").concat(n.join(", "),") VALUES (").concat(r.join(", "),");");await a(i),e++}if(e>0){let a=await m(t);v(a.data),w(a.meta.total),B(Math.ceil(a.meta.total/Y)),h({title:"Success",description:"Added ".concat(e," ").concat(1===e?"record":"records")})}K([])}if(A.size>0&&(e||!ei)){var s;let e=null===(s=N.find(e=>1===e.pk))||void 0===s?void 0:s.name;if(!e)throw Error("No primary key found in table schema");let l=new Map;A.forEach((t,a)=>{let[s,n]=a.split("-"),r=g[s];l.has(r[e])||l.set(r[e],new Map),l.get(r[e]).set(n,t.value)});let n=0;for(let[s,r]of l){let l=Array.from(r.entries()).map(e=>{let[t,a]=e;return null===a||""===a||"null"===a?"".concat(t," = NULL"):"CURRENT_TIMESTAMP"===a?"".concat(t," = CURRENT_TIMESTAMP"):"".concat(t," = '").concat(a.toString().replace(/'/g,"''"),"'")}).join(", "),i="\n UPDATE ".concat(t,"\n SET ").concat(l,"\n WHERE ").concat(e," = ").concat(s,";\n ");await a(i),n++}if(n>0){let e=await m(t);v(e.data),w(e.meta.total),B(Math.ceil(e.meta.total/Y)),h({title:"Success",description:"Updated ".concat(n," ").concat(1===n?"record":"records")})}}k(new Map),Q(new Set),eo(null)}catch(e){eo({...eb(e),stderr:e.stderr,stdout:e.stdout}),er(!0)}finally{E(!1)}},eT=(0,l.useCallback)(async()=>{if(ea(!0),el(null),t){ea(!0),el(null);try{var e;let s=null===(e=N.find(e=>1===e.pk))||void 0===e?void 0:e.name;if(!s)throw Error("No primary key found in table schema");let l=Array.from(W).map(e=>g[e][s]);if(0===l.length)return;let i="DELETE FROM ".concat(t," WHERE ").concat(s," IN (").concat(l.join(","),");");await a(i);let o=new Set(l),c=g.filter(e=>!o.has(e[s]));v(c),w(e=>e-l.length),B(Math.ceil((b-l.length)/Y));let d=n(t);d&&r(t,c,d.schema,{...d.meta,total:d.meta.total-l.length}),q>1&&g.length===l.length&&(J(e=>e-1),await ef()),ee(!1),G(new Set),h({title:"Success",description:"Successfully deleted ".concat(l.length," ").concat(1===l.length?"record":"records")})}catch(e){console.error("Delete operation failed:",e),el(e.message||String(e))}finally{ea(!1)}}},[t,W,g,N,a,m,ef,q,Y,b,h,n,r]);(0,l.useEffect)(()=>{if(!t)return;k(new Map),Q(new Set),K([]),T(null),G(new Set),J(1);let e=n(t,1,Y);e?(v(e.data),j(e.schema),w(e.meta.total),B(e.meta.totalPages),ex(a=>{if(a.length)return a;let s=e.schema.map(e=>e.name);return localStorage.setItem("table-columns-".concat(t),JSON.stringify(s)),s})):ef(!1)},[t,Y]),(0,l.useEffect)(()=>{if(u===t){let e=n(t);e&&(v(e.data),j(e.schema),w(e.meta.total),B(e.meta.totalPages))}},[u,t,n]),(0,l.useEffect)(()=>{if(t&&!y){var e;let a=n(t,q,Y);a&&q===(null===(e=a.meta)||void 0===e?void 0:e.currentPage)||ef(!1)}},[t,q,Y,y,ef,n]),(0,l.useEffect)(()=>{Z.current&&(Z.current.indeterminate=W.size>0&&W.size<g.length)},[W.size,g.length]);let eA=(0,l.useCallback)(e=>{G(e?new Set(g.map((e,t)=>t)):new Set)},[g]),ek=(0,l.useCallback)((e,t)=>{G(a=>{let s=new Set(a);return t?s.add(e):s.delete(e),s})},[]);(0,l.useCallback)(e=>{em(e),localStorage.setItem("table-widths-".concat(t),JSON.stringify(e))},[t]);let e_=N.filter(e=>eh.includes(e.name)),eO=A.size>0||V.length>0;return R?(0,s.jsx)("div",{className:"p-4",children:(0,s.jsxs)(x,{variant:"destructive",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsxs)(f,{children:["Failed to load table: ",R]})]})}):(0,s.jsxs)("div",{className:"h-full flex flex-col",children:[(0,s.jsx)(eZ,{selectedCount:W.size,totalRows:b,currentPage:q,totalPages:H,rowsPerPage:Y,onPageChange:J,onRowsPerPageChange:X,onAdd:ey,onDelete:()=>ee(!0),onRefresh:ev,tableName:t,disabled:eO,editCount:A.size,newRecordsCount:V.length,isSaving:S,onSaveChanges:eE,onDiscardChanges:()=>{k(new Map),Q(new Set),K([]),eo(null),h({description:"Changes discarded"})},schema:N,visibleColumns:eh,onColumnToggle:ep}),(0,s.jsx)(e9,{columns:N,onColumnsResize:eg,children:(0,s.jsx)("div",{className:"relative flex-1 overflow-hidden bg-background font-mono",children:(0,s.jsx)(L,{className:"w-full h-screen",children:(0,s.jsxs)("div",{className:"relative w-max min-w-fit pb-4",children:[(0,s.jsxs)(U,{children:[!y&&(0,s.jsx)(P,{className:"bg-neutral-100 sticky top-0 z-30",children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{className:"w-10 p-0 border-r border-neutral-200",children:(0,s.jsx)("div",{className:"py-0.5 px-3 flex items-center",children:(0,s.jsx)(eR,{ref:Z,checked:W.size===g.length&&g.length>0,onCheckedChange:eA,disabled:eO})})}),e_.map(e=>{var t;return(0,s.jsx)(e3,{width:eu[e.name]||150,onResize:t=>eg(e.name,t),className:"py-0.5 whitespace-nowrap border-r border-neutral-200",children:(0,s.jsxs)(te,{column:e.name,sortConfig:ec,onSort:eN,children:[(0,s.jsx)("span",{className:"text-xs font-bold text-foreground",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:null===(t=e.type)||void 0===t?void 0:t.toLowerCase()})]})},e.name)})]})}),(0,s.jsxs)(F,{children:[y&&(0,s.jsx)(D,{className:"hover:bg-transparent",children:(0,s.jsx)(z,{colSpan:e_.length+1,className:"h-[calc(100vh-200px)]",children:(0,s.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,s.jsx)(c.A,{className:"h-6 w-6 animate-spin text-primary"})})})}),!y&&(0,s.jsxs)(s.Fragment,{children:[V.map((e,t)=>(0,s.jsx)(e4,{schema:e_,onRemove:()=>eC(t),onChange:e=>eS(t,e)},"new-".concat(t))),0===g.length&&0===V.length?(0,s.jsx)(D,{className:"hover:bg-transparent",children:(0,s.jsx)(z,{colSpan:e_.length+1,className:"h-[calc(100vh-200px)] text-center text-muted-foreground",children:"Table is empty"})}):g.map((e,t)=>(0,s.jsxs)(D,{className:"".concat(W.has(t)?"bg-muted/50":""),children:[(0,s.jsx)(z,{className:"p-0",children:(0,s.jsx)("div",{className:"px-3 py-2.5 flex items-center",children:(0,s.jsx)(eR,{checked:W.has(t),onCheckedChange:e=>ek(t,e),disabled:eO})})}),e_.map(a=>{let l="".concat(t,"-").concat(a.name),n=A.get(l);return(0,s.jsx)(e$,{value:n?n.value:e[a.name],row:e,column:a.name,schema:N,onChange:e=>ew(t,a.name,e),onStartEdit:e=>ej(t,a.name,e),isEditing:A.has(l),style:{width:"".concat(eu[a.name]||150,"px")}},a.name)})]},t))]})]})]}),(0,s.jsx)(I,{orientation:"horizontal"})]})})})}),(0,s.jsx)(e2,{isOpen:$,onClose:()=>{ee(!1),el(null)},onConfirm:eT,selectedCount:W.size,tableName:t,isDeleting:et,error:es}),(0,s.jsx)(e5,{isOpen:en,onClose:()=>er(!1),error:ei,onOpenInSQL:()=>{er(!1)},onUpdateAnyway:async()=>{er(!1),await eE(!0)},showSQLOption:(null==ei?void 0:ei.type)==="NULLABLE_PK"})]})}var ta=a(2651);function ts(){let[e,t]=(0,l.useState)(null),[a,n]=(0,l.useState)(!0);return((0,l.useEffect)(()=>{"true"===localStorage.getItem("updateBannerDismissed")&&n(!1)},[]),(0,l.useEffect)(()=>{ta.A.get("/api/update").then(e=>{let{data:a}=e;(null==a?void 0:a.update)&&(t(a.update),n(!0))}).catch(console.error)},[]),e&&a)?(0,s.jsxs)("div",{className:"bg-gray-200 w-full px-3 py-3 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"text-gray-800",children:[(0,s.jsx)("strong",{children:"Update available!"})," You are on version ",e.current,"; version ",e.latest," is available. Run"," ",(0,s.jsx)("code",{className:"bg-white text-sm px-1 py-0.5 rounded",children:"npm install -g d1s@latest"})," ","to update."]}),(0,s.jsx)("button",{onClick:()=>{localStorage.setItem("updateBannerDismissed","true"),n(!1)},className:"ml-4 text-gray-500 hover:text-gray-700","aria-label":"Close update banner",children:"\xd7"})]}):null}function tl(){let[e,t]=(0,l.useState)("sql-editor"),[a,n]=(0,l.useState)(null);return(0,s.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,s.jsx)(ts,{}),(0,s.jsx)(en,{className:"w-64 border-r",currentView:e,onNavigate:t,onTableSelect:e=>{n(e),t("table-view")}}),(0,s.jsxs)("main",{className:"ml-64 h-screen",children:["sql-editor"===e&&(0,s.jsx)(eS,{}),"table-view"===e&&a&&(0,s.jsx)(tt,{tableName:a})]})]})}}},e=>{var t=t=>e(e.s=t);e.O(0,[692,958,735,441,517,358],()=>t(9017)),_N_E=e.O()}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{9017:(e,t,a)=>{Promise.resolve().then(a.bind(a,5612))},5612:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>tl});var s=a(5155),l=a(2115),n=a(2398),r=a(7443),i=a(1680),o=a(2591),c=a(2783),d=a(4031);let u=l.forwardRef((e,t)=>{let{className:a,type:l,...n}=e;return(0,s.jsx)("input",{type:l,className:(0,d.cn)("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),ref:t,...n})});u.displayName="Input";var m=a(1027);let h=(0,m.F)("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),x=l.forwardRef((e,t)=>{let{className:a,variant:l,...n}=e;return(0,s.jsx)("div",{ref:t,role:"alert",className:(0,d.cn)(h({variant:l}),a),...n})});x.displayName="Alert",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("h5",{ref:t,className:(0,d.cn)("mb-1 font-medium leading-none tracking-tight",a),...l})}).displayName="AlertTitle";let f=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("div",{ref:t,className:(0,d.cn)("text-sm [&_p]:leading-relaxed",a),...l})});f.displayName="AlertDescription";var p=a(33),g=a(6217),v=a(689);let N=g.bL;g.l9;let j=g.ZL;g.bm;let b=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.hJ,{ref:t,className:(0,d.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...l})});b.displayName=g.hJ.displayName;let w=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(j,{children:[(0,s.jsx)(b,{}),(0,s.jsxs)(g.UC,{ref:t,className:(0,d.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",a),...n,children:[l,(0,s.jsxs)(g.bm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,s.jsx)(v.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});w.displayName=g.UC.displayName;let y=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,d.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...a})};y.displayName="DialogHeader";let C=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,d.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...a})};C.displayName="DialogFooter";let S=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.hE,{ref:t,className:(0,d.cn)("text-lg font-semibold leading-none tracking-tight",a),...l})});S.displayName=g.hE.displayName;let E=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(g.VY,{ref:t,className:(0,d.cn)("text-sm text-muted-foreground",a),...l})});E.displayName=g.VY.displayName;var R=a(2317);let T=(0,m.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),A=l.forwardRef((e,t)=>{let{className:a,variant:l,size:n,asChild:r=!1,...i}=e,o=r?R.DX:"button";return(0,s.jsx)(o,{className:(0,d.cn)(T({variant:l,size:n,className:a})),ref:t,...i})});function k(e){let{open:t,onClose:a,onSubmit:n}=e,[r,i]=(0,l.useState)(""),[o,d]=(0,l.useState)(""),[m,h]=(0,l.useState)(""),[p,g]=(0,l.useState)(!1),v=async e=>{e.preventDefault(),h(""),g(!0);try{await n({accountId:r,apiToken:o}),localStorage.setItem("cf_credentials",JSON.stringify({accountId:r,apiToken:o})),a()}catch(e){h(e.message)}finally{g(!1)}};return(0,s.jsx)(N,{open:t,onOpenChange:a,children:(0,s.jsxs)(w,{className:"sm:max-w-md",children:[(0,s.jsxs)(y,{children:[(0,s.jsx)(S,{children:"Connect to Cloudflare"}),(0,s.jsx)(E,{children:"Enter your Cloudflare credentials to push your database to production."})]}),(0,s.jsxs)("form",{onSubmit:v,className:"space-y-4 mt-4",children:[m&&(0,s.jsx)(x,{variant:"destructive",children:(0,s.jsx)(f,{children:m})}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("label",{className:"text-sm font-medium",children:"Account ID"}),(0,s.jsx)(u,{placeholder:"Your Cloudflare Account ID",value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("label",{className:"text-sm font-medium",children:"API Token"}),(0,s.jsx)(u,{type:"password",placeholder:"Your D1 Database API Token",value:o,onChange:e=>d(e.target.value),required:!0})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,s.jsx)(A,{type:"button",variant:"outline",onClick:a,children:"Cancel"}),(0,s.jsxs)(A,{type:"submit",disabled:p,children:[p&&(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Connect"]})]})]})]})})}A.displayName="Button";var _=a(6528),O=a(1868);let L=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(O.bL,{ref:t,className:(0,d.cn)("relative overflow-hidden",a),...n,children:[(0,s.jsx)(O.LM,{className:"h-full w-full rounded-[inherit]",children:l}),(0,s.jsx)(I,{}),(0,s.jsx)(O.OK,{})]})});L.displayName=O.bL.displayName;let I=l.forwardRef((e,t)=>{let{className:a,orientation:l="vertical",...n}=e;return(0,s.jsx)(O.VM,{ref:t,orientation:l,className:(0,d.cn)("flex touch-none select-none transition-colors","vertical"===l&&"h-full w-2.5 border-l border-l-transparent p-[1px]","horizontal"===l&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",a),...n,children:(0,s.jsx)(O.lr,{className:"relative flex-1 rounded-full bg-border"})})});I.displayName=O.VM.displayName;let U=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("div",{className:"relative w-full overflow-auto",children:(0,s.jsx)("table",{ref:t,className:(0,d.cn)("w-full caption-bottom text-sm",a),...l})})});U.displayName="Table";let P=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("thead",{ref:t,className:(0,d.cn)("[&_tr]:border-b",a),...l})});P.displayName="TableHeader";let F=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tbody",{ref:t,className:(0,d.cn)("[&_tr:last-child]:border-0",a),...l})});F.displayName="TableBody",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tfoot",{ref:t,className:(0,d.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...l})}).displayName="TableFooter";let D=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("tr",{ref:t,className:(0,d.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",a),...l})});D.displayName="TableRow";let M=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("th",{ref:t,className:(0,d.cn)("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...l})});M.displayName="TableHead";let z=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("td",{ref:t,className:(0,d.cn)("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...l})});z.displayName="TableCell",l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)("caption",{ref:t,className:(0,d.cn)("mt-4 text-sm text-muted-foreground",a),...l})}).displayName="TableCaption";let Q=function(e){let{preview:t=[],onConfirm:a,onCancel:n,isConfirming:r,error:i,isLoading:o,success:u}=e,[m,h]=(0,l.useState)(!0);if(o)return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4 shadow-lg bg-background",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(c.A,{className:"h-5 w-5 text-neutral-600 shrink-0 mt-0.5 animate-spin"}),(0,s.jsx)("div",{className:"flex-1 space-y-3",children:(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"font-medium text-neutral-800",children:"Preparing Push Migration"}),(0,s.jsx)("p",{className:"text-sm text-neutral-600",children:"Checking local migrations..."})]})})]})})});if(!(null==t?void 0:t.length))return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4",children:(0,s.jsx)("p",{className:"text-sm font-medium",children:"No migrations to preview"})})});let x=t.filter(e=>"will be applied"===e.action).length,f=t.filter(e=>"skipped"===e.action).length;t.filter(e=>"applied"===e.action).length;let p=e=>{switch(e){case"will be applied":return"\uD83D\uDD52️";case"applied":case"skipped":return"✅";case"failed":return"❌";default:return""}};return(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:(0,d.cn)("rounded-lg border p-4 shadow-lg",i?"bg-destructive/15":"bg-background"),children:(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h5",{className:"font-medium text-neutral-900",children:"Push Migration Preview"}),(0,s.jsx)("button",{onClick:n,className:"text-neutral-500 hover:text-neutral-900 p-1 rounded-md hover:bg-neutral-100",children:(0,s.jsx)(v.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("p",{className:"text-sm text-neutral-700",children:[x," migration(s) \uD83D\uDD52️ pending, ",f," to ✅ skip"]}),i?(0,s.jsx)("p",{className:"text-sm text-destructive font-medium mt-1",children:i.message}):u&&(0,s.jsx)("p",{className:"text-sm text-green-700 font-medium mt-1",children:u})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{onClick:()=>h(!m),className:"text-sm font-medium hover:underline",children:m?"Hide Details":"Show Details"}),m&&(0,s.jsx)(L,{className:"h-[480px] mt-2 rounded border border-neutral-200",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{children:"Migration"}),(0,s.jsx)(M,{className:"text-center w-24",children:"Status"})]})}),(0,s.jsx)(F,{children:t.map((e,t)=>(0,s.jsxs)(D,{children:[(0,s.jsx)(z,{className:"font-mono text-xs",children:e.name}),(0,s.jsx)(z,{className:"text-center align-middle",children:p(e.action)})]},t))})]})})]}),(0,s.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,s.jsx)(A,{onClick:a,disabled:r||0===x,className:"flex-1",children:r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirming..."]}):"Confirm Push"}),(0,s.jsx)(A,{variant:"outline",onClick:n,disabled:r,className:"flex-1",children:"Cancel"})]})]})})})};var V=a(1983);let K=function(e){let{preview:t=[],onConfirm:a,onCancel:n,isConfirming:r,error:i,isLoading:o}=e;console.log("PullPreviewToast rendered with:",{previewLength:t.length,isConfirming:r,error:i,isLoading:o}),(0,l.useEffect)(()=>(console.log("PullPreviewToast mounted/updated"),()=>console.log("PullPreviewToast unmounted")),[]);let[u,m]=(0,l.useState)(!1);if(o)return console.log("Rendering loading state"),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border p-4 shadow-lg bg-background",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(c.A,{className:"h-5 w-5 text-neutral-600 shrink-0 mt-0.5 animate-spin"}),(0,s.jsx)("div",{className:"flex-1 space-y-3",children:(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"font-medium text-neutral-800",children:"Preparing Pull Migration"}),(0,s.jsx)("p",{className:"text-sm text-neutral-600",children:"Checking remote migrations..."})]})})]})})});if(!(null==t?void 0:t.length))return console.log("No preview data available"),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 w-[600px]",children:(0,s.jsx)("div",{className:"rounded-lg border bg-destructive/15 p-4",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(V.A,{className:"h-5 w-5 text-destructive"}),(0,s.jsx)("p",{className:"text-sm font-medium text-destructive",children:"No preview data available"})]})})});let h=t.filter(e=>(e.migration||e.name||"").endsWith(".sql")),x=h.length;return console.log("Migration stats:",{totalMigrations:x}),(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 font-sans w-[600px]",children:(0,s.jsx)("div",{className:(0,d.cn)("rounded-lg border p-4 shadow-lg",i?"bg-destructive/15":"bg-background"),children:(0,s.jsx)("div",{className:"flex items-start gap-3",children:(0,s.jsxs)("div",{className:"flex-1 space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("h5",{className:(0,d.cn)("font-medium",i?"text-destructive":"text-neutral-900"),children:i?"Pull Migration Error":"Pull Migration Preview"}),(0,s.jsx)("p",{className:(0,d.cn)("text-sm",i?"text-destructive/80":"text-neutral-700"),children:i?i.message:"".concat(x," migration(s) will be applied")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{onClick:()=>m(!u),className:"text-sm font-medium hover:underline",children:u?"Hide Details":"Show Details"}),u&&(0,s.jsx)(L,{className:"h-[480px] mt-2 rounded border border-neutral-200",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{className:"w-[30px]"}),(0,s.jsx)(M,{className:"pl-0",children:"Migration"})]})}),(0,s.jsx)(F,{children:h.map((e,t)=>(0,s.jsxs)(D,{children:[(0,s.jsx)(z,{className:"w-[30px] pr-1 pl-2",children:(0,s.jsx)(V.A,{className:"h-4 w-4"})}),(0,s.jsx)(z,{className:"font-mono text-xs pr-5 pl-0.5",children:e.migration||e.name})]},t))})]})})]}),(0,s.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,s.jsx)(A,{onClick:a,disabled:r,className:"flex-1",children:r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirming..."]}):"Confirm Pull"}),(0,s.jsx)(A,{variant:"outline",onClick:n,disabled:r,className:"flex-1",children:"Cancel"})]})]})})})})};var q=a(3409),J=a(2645),Y=a(2488),X=a(7193);let H=q.bL;q.YJ;let B=q.WT,W=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(q.l9,{ref:t,className:(0,d.cn)("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",a),...n,children:[l,(0,s.jsx)(q.In,{asChild:!0,children:(0,s.jsx)(J.A,{className:"h-4 w-4 opacity-50"})})]})});W.displayName=q.l9.displayName;let G=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.PP,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",a),...l,children:(0,s.jsx)(Y.A,{className:"h-4 w-4"})})});G.displayName=q.PP.displayName;let Z=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.wn,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",a),...l,children:(0,s.jsx)(J.A,{className:"h-4 w-4"})})});Z.displayName=q.wn.displayName;let $=l.forwardRef((e,t)=>{let{className:a,children:l,position:n="popper",...r}=e;return(0,s.jsx)(q.ZL,{children:(0,s.jsxs)(q.UC,{ref:t,className:(0,d.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===n&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",a),position:n,...r,children:[(0,s.jsx)(G,{}),(0,s.jsx)(q.LM,{className:(0,d.cn)("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:l}),(0,s.jsx)(Z,{})]})})});$.displayName=q.UC.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.JU,{ref:t,className:(0,d.cn)("px-2 py-1.5 text-sm font-semibold",a),...l})}).displayName=q.JU.displayName;let ee=l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(q.q7,{ref:t,className:(0,d.cn)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...n,children:[(0,s.jsx)("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(q.VF,{children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})}),(0,s.jsx)(q.p4,{children:l})]})});ee.displayName=q.q7.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(q.wv,{ref:t,className:(0,d.cn)("-mx-1 my-1 h-px bg-muted",a),...l})}).displayName=q.wv.displayName;var et=a(2303),ea=a(319),es=a(5942);function el(e){let{value:t,onValueChange:a,isLoading:l,disabled:n,showPreview:r}=e;return(0,s.jsxs)(H,{value:t,onValueChange:a,disabled:n||l||r,children:[(0,s.jsx)(W,{className:"w-[104px] bg-white border-neutral-200 font-medium",children:(0,s.jsx)("div",{className:"flex items-center gap-1 text-sm",children:l||r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,s.jsx)("span",{className:"text-muted-foreground font-medium",children:"pull"===t?"Pulling...":"Pushing..."})]}):(0,s.jsx)(B,{placeholder:"Environment"})})}),(0,s.jsxs)($,{children:[(0,s.jsx)(ee,{value:"local",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(et.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Local"})]})}),(0,s.jsx)(ee,{value:"pull",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ea.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Pull remote"})]})}),(0,s.jsx)(ee,{value:"production",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(es.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:"Push remote"})]})})]})]})}function en(e){var t;let{className:a,currentView:d,onNavigate:m,onTableSelect:h}=e,{tables:g,refreshTables:v,isLoading:N,error:j}=(0,p.t)(),[b,w]=(0,l.useState)([]),[y,C]=(0,l.useState)(""),[S,E]=(0,l.useState)("local"),[R,T]=(0,l.useState)(!1),[A,O]=(0,l.useState)(null),[L,I]=(0,l.useState)(!1),{isConnecting:U,isPushing:P,showPreview:F,connectToCloudflare:D,pushToRemote:M,pullFromRemote:z,pullToRemotePreview:V,validateStoredCredentials:q,PreviewUI:J}=function(){var e,t;let[a,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),[m,h]=(0,l.useState)(null),[x,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),{toast:N}=(0,_.dj)(),{refreshTables:j}=(0,p.t)(),b=()=>{c(!1),u(null),h(null),f(null),v(null)},w=async()=>{let e=localStorage.getItem("cf_credentials");if(!e)return null;try{let t=JSON.parse(e),a=await fetch("/api/cloudflare",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw Error("Invalid stored credentials");let s=await a.json();return{...t,databaseId:s.database.id}}catch(e){return console.error("Failed to validate stored credentials:",e),localStorage.removeItem("cf_credentials"),null}},y=async()=>{try{f("push"),c(!0),i(!0),h(null),v(null),u({preview:[]});let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/push-remote/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to generate preview")}u(s.details.details)}catch(e){console.error("Push to remote preview failed:",e),h(e),N({title:"Preview Failed",description:e.message||"Failed to generate preview",variant:"destructive"})}finally{i(!1)}},C=async()=>{try{i(!0),h(null),v(null);let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/push-remote/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to confirm push")}u(e=>({...e,preview:e.preview.map(e=>({...e,action:"will be applied"===e.action?"applied":e.action}))})),v("Applied ".concat(s.details.applied," migration(s), skipped ").concat(s.details.skipped,"."))}catch(e){console.error("Push to remote confirm failed:",e),h(e)}finally{i(!1)}},S=async()=>{try{f("pull"),c(!0),i(!0),h(null),v(null),u({preview:[]});let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/pull-remote/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to generate pull preview")}u(s.details)}catch(e){console.error("Pull to remote preview failed:",e),h(e),N({title:"Preview Failed",description:e.message||"Failed to generate pull preview",variant:"destructive"})}finally{i(!1)}},E=async()=>{try{i(!0),h(null);let t=await w();if(!t)throw Error("No valid credentials found");let a=await fetch("/api/pull-remote/confirm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),s=await a.json();if(!s.success){var e;throw Error((null===(e=s.error)||void 0===e?void 0:e.message)||"Failed to confirm pull")}b(),N({title:"Migration Success",description:"Pull migrations applied successfully."}),await j()}catch(e){console.error("Pull to remote confirm failed:",e),h(e),N({title:"Migration Failed",description:e.message||"Failed to pull migrations from remote",variant:"destructive"})}finally{i(!1)}};async function R(e){try{n(!0);let t=await fetch("/api/cloudflare",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),a=await t.json();if(!t.ok)throw Error(a.error||"Failed to connect to Cloudflare");localStorage.setItem("cf_credentials",JSON.stringify({...e,databaseId:a.database.id})),N({title:"Connected to Cloudflare",description:"Connected to database: ".concat(a.database.name),variant:"default"})}catch(e){throw N({title:"Connection Failed",description:e.message||"Failed to connect to Cloudflare",variant:"destructive"}),e}finally{n(!1)}}let T=o&&("pull"===x?(0,s.jsx)(K,{preview:(null==d?void 0:d.preview)||[],onConfirm:E,onCancel:b,isConfirming:r,error:m,isLoading:r&&!(null==d?void 0:null===(e=d.preview)||void 0===e?void 0:e.length)}):(0,s.jsx)(Q,{preview:(null==d?void 0:d.preview)||[],onConfirm:C,onCancel:b,isConfirming:r,error:m,success:g,isLoading:r&&!(null==d?void 0:null===(t=d.preview)||void 0===t?void 0:t.length)}));return{isConnecting:a,isPushing:r,showPreview:o,previewError:m,pushToRemote:y,pullToRemotePreview:S,confirmPull:E,connectToCloudflare:R,validateStoredCredentials:w,PreviewUI:T}}(),Y=(0,l.useMemo)(()=>{let e=[...(null==g?void 0:g.filter(e=>e.toLowerCase().includes(y.toLowerCase())))||[]].sort((e,t)=>e.localeCompare(t)),t=e.indexOf("d1_migrations");return -1!==t&&(e.splice(t,1),e.unshift("d1_migrations")),e},[g,y]),X=async e=>{try{I(!0),O(e),h(e)}catch(e){console.error("Error selecting table:",e)}finally{I(!1)}},H=async e=>{if(console.log("Environment change triggered:",e),E(e),"production"===e)try{if(!await q()){T(!0);return}await M()}catch(e){console.error("Environment change failed:",e),E("local")}else if("pull"===e)try{if(!await q()){T(!0);return}await V()}catch(e){console.error("Pull from remote failed:",e),E("local")}else E(e)};return(0,l.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/databases"),t=await e.json();if(!e.ok)throw Error(t.error||"Failed to fetch databases");w(t.databases||[])}catch(e){console.error("Error fetching databases:",e)}})(),v()},[v]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("aside",{className:"".concat(a," w-64 fixed top-0 left-0 h-full bg-neutral-50 p-4"),children:[(0,s.jsxs)("div",{className:"flex flex-col h-full font-sans",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,s.jsx)(n.A,{className:"h-5 w-5"}),(0,s.jsx)("span",{className:"font-mono font-bold text-sm",children:"d1-studio"})]}),(0,s.jsx)("div",{className:"mb-6",children:(0,s.jsxs)("button",{className:"w-full flex items-center gap-x-1 border rounded-md text-sm font-medium transition-colors px-2 py-2\n ".concat("sql-editor"===d?"bg-neutral-900 text-white":"bg-white hover:bg-neutral-100"),onClick:()=>m("sql-editor"),disabled:L,children:[(0,s.jsx)(r.A,{className:"h-[16px] w-[16px]"}),"SQL editor"]})}),j&&(0,s.jsxs)(x,{variant:"destructive",className:"mb-4",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsx)(f,{className:"text-sm ml-2",children:j})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-xs text-muted-foreground mb-1",children:"Database name"}),(0,s.jsx)("div",{className:"font-semibold text-sm",children:(null===(t=b[0])||void 0===t?void 0:t.database_name)||"No database found"})]}),(0,s.jsx)(el,{value:S,onValueChange:H,isLoading:P,disabled:U,showPreview:F})]}),(0,s.jsxs)("div",{className:"relative mb-6 bg-white",children:[(0,s.jsx)(o.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-neutral-500"}),(0,s.jsx)(u,{placeholder:"Search tables",value:y,onChange:e=>C(e.target.value),className:"pl-7"})]}),(0,s.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-1 flex-none",children:[(0,s.jsxs)("h3",{className:"text-sm font-medium text-muted-foreground",children:["Tables ",(null==g?void 0:g.length)?"(".concat(g.length,")"):""]}),N&&(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),(0,s.jsx)("div",{className:"overflow-y-auto flex-1",children:(0,s.jsxs)("div",{className:"pr-2 pb-4",children:[" ",!N&&0===Y.length&&(0,s.jsx)("div",{className:"text-sm font-medium text-muted-foreground px-2 py-2",children:y?"No matching tables found":j?"Error loading tables":"No tables available"}),Y.map(e=>(0,s.jsx)("button",{className:"w-full text-left text-sm font-medium rounded-md transition-colors px-2 py-2\n ".concat("table-view"===d&&A===e?"bg-[#F0F0F0] text-neutral-900 font-semibold":"text-neutral-700 hover:bg-[#F2F2F2]","\n ").concat(L&&"opacity-50 cursor-not-allowed"),onClick:()=>X(e),disabled:L,children:e},e))]})})]})]}),(0,s.jsx)(k,{open:R,onClose:()=>{T(!1),E("local")},onSubmit:D})]}),J]})}var er=a(707),ei=a(1170),eo=a(3320),ec=a(5377);function ed(e){let{results:t}=e;return t&&Array.isArray(t)?(0,s.jsxs)("div",{className:"text-xs font-medium text-neutral-900 flex items-center gap-2 mb-2",children:[t.length," ",1===t.length?"row":"rows"," returned"]}):null}function eu(e){var t;let{error:a}=e;console.debug("SQLErrorDisplay - Received error prop:",a);let l=a&&"string"==typeof a.message?a:{message:"An unknown error occurred",details:{}};return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-neutral-700 text-sm",children:l.message}),(null===(t=l.details)||void 0===t?void 0:t.stderr)&&(0,s.jsx)("pre",{className:"mt-2 p-2 text-xs text-red-500 whitespace-pre-wrap",children:l.details.stderr})]})}function em(e){let{query:t,results:a}=e;if(!(null==a?void 0:a.length))return(0,s.jsx)("div",{className:"text-sm text-neutral-500",children:"No results to display."});let l=null==t?void 0:t.trim().toLowerCase().startsWith("pragma table_info"),n=l?["Column Name","Type","Not Null","Default Value","Primary Key"]:Object.keys(a[0]),r=l?a.map(e=>({"Column Name":e.name,Type:e.type,"Not Null":1===e.notnull?"YES":"NO","Default Value":e.dflt_value||"(null)","Primary Key":1===e.pk?"YES":"NO"})):a;return(0,s.jsxs)("div",{className:"flex flex-col h-full",children:[(0,s.jsx)(ed,{results:r}),(0,s.jsx)("div",{className:"flex-1 overflow-auto border rounded-lg",children:(0,s.jsx)("div",{className:"min-w-full",children:(0,s.jsxs)(U,{children:[(0,s.jsx)(P,{children:(0,s.jsx)(D,{className:"bg-muted/50",children:n.map(e=>(0,s.jsx)(M,{className:"font-mono text-xs font-medium text-muted-foreground",children:e},e))})}),(0,s.jsx)(F,{children:r.map((e,t)=>(0,s.jsx)(D,{className:"hover:bg-muted/50",children:n.map(a=>{let l=e[a],n=null===l?"(null)":String(l);return(0,s.jsx)(z,{className:"font-monospace text-xs whitespace-nowrap",children:n},"".concat(t,"-").concat(a))})},t))})]})})})]})}var eh=a(4471),ex=a(5325),ef=a(1703);let ep=eh.bL,eg=eh.l9;eh.YJ,eh.ZL,eh.Pb,eh.z6,l.forwardRef((e,t)=>{let{className:a,inset:l,children:n,...r}=e;return(0,s.jsxs)(eh.ZP,{ref:t,className:(0,d.cn)("flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",l&&"pl-8",a),...r,children:[n,(0,s.jsx)(ex.A,{className:"ml-auto"})]})}).displayName=eh.ZP.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eh.G5,{ref:t,className:(0,d.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...l})}).displayName=eh.G5.displayName;let ev=l.forwardRef((e,t)=>{let{className:a,sideOffset:l=4,...n}=e;return(0,s.jsx)(eh.ZL,{children:(0,s.jsx)(eh.UC,{ref:t,sideOffset:l,className:(0,d.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n})})});ev.displayName=eh.UC.displayName;let eN=l.forwardRef((e,t)=>{let{className:a,inset:l,...n}=e;return(0,s.jsx)(eh.q7,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",l&&"pl-8",a),...n})});eN.displayName=eh.q7.displayName,l.forwardRef((e,t)=>{let{className:a,children:l,checked:n,...r}=e;return(0,s.jsxs)(eh.H_,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(eh.VF,{children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})}),l]})}).displayName=eh.H_.displayName,l.forwardRef((e,t)=>{let{className:a,children:l,...n}=e;return(0,s.jsxs)(eh.hN,{ref:t,className:(0,d.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(eh.VF,{children:(0,s.jsx)(ef.A,{className:"h-2 w-2 fill-current"})})}),l]})}).displayName=eh.hN.displayName,l.forwardRef((e,t)=>{let{className:a,inset:l,...n}=e;return(0,s.jsx)(eh.JU,{ref:t,className:(0,d.cn)("px-2 py-1.5 text-sm font-semibold",l&&"pl-8",a),...n})}).displayName=eh.JU.displayName,l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eh.wv,{ref:t,className:(0,d.cn)("-mx-1 my-1 h-px bg-muted",a),...l})}).displayName=eh.wv.displayName;let ej={SYNTAX_ERROR:"SYNTAX_ERROR",EXECUTION_ERROR:"EXECUTION_ERROR",TABLE_NOT_FOUND:"TABLE_NOT_FOUND",TABLE_EXISTS:"TABLE_EXISTS",FOREIGN_KEY_ERROR:"FOREIGN_KEY_ERROR",UNIQUE_CONSTRAINT_ERROR:"UNIQUE_CONSTRAINT_ERROR",NOT_NULL_CONSTRAINT_ERROR:"NOT_NULL_CONSTRAINT_ERROR",CHECK_CONSTRAINT_ERROR:"CHECK_CONSTRAINT_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR"};function eb(e){if(console.debug("parseSQLError - Received error:",e),!e)return console.debug("parseSQLError - error is null or undefined."),{type:ej.UNKNOWN_ERROR,message:"An unknown error occurred",details:{}};let t="",a=null,s=null,l=e.cmd||e.details&&e.details.command;if(l){let e=l.match(RegExp('--command="(.+?)"',"s"));e&&console.debug("parseSQLError - Extracted original query:",s=e[1].replace(/\\n/g,"\n"))}let n=e.stderr||e.details&&e.details.stderr;if(n){let r=n.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"");if(console.debug("parseSQLError - Cleaned stderr:",r),r.includes("env: node: No such file or directory"))return console.debug("parseSQLError - Detected 'env: node: No such file or directory' error."),{type:ej.EXECUTION_ERROR,message:e.message||"Execution error: env: node: No such file or directory",details:{originalQuery:s,stderr:r}};let i=r.match(/near "([^"]+)": syntax error at offset (\d+)/);if(i){let[e,l,n]=i;return a=parseInt(n,10),t='Syntax error near "'.concat(l,'" at position ').concat(a),console.debug("parseSQLError - Syntax error detected:",{near:l,offset:a}),{type:ej.SYNTAX_ERROR,message:t,details:{originalQuery:s,errorLocation:{offset:a,near:l},stderr:r}}}if(r.includes("UNIQUE constraint failed")){let[e,t,a]=r.match(/UNIQUE constraint failed: (\w+)\.(\w+)/)||[];return console.debug("parseSQLError - UNIQUE constraint error detected:",{table:t,column:a}),{type:ej.UNIQUE_CONSTRAINT_ERROR,message:"Unique constraint violation updating ".concat(t,".").concat(a),details:{originalQuery:s,stderr:r}}}if(r.includes("NOT NULL constraint failed")){let[e,t,a]=r.match(/NOT NULL constraint failed: (\w+)\.(\w+)/)||[];return console.debug("parseSQLError - NOT NULL constraint error detected:",{table:t,column:a}),{type:ej.NOT_NULL_CONSTRAINT_ERROR,message:"NOT NULL constraint violation updating ".concat(t,".").concat(a),details:{originalQuery:s,stderr:r}}}if(r.includes("CHECK constraint failed")){let[e,t]=r.match(/CHECK constraint failed: (\w+)/)||[];return console.debug("parseSQLError - CHECK constraint error detected:",{constraintName:t}),{type:ej.CHECK_CONSTRAINT_ERROR,message:"Check constraint violation updating ".concat(t),details:{originalQuery:s,stderr:r}}}if(r.includes("FOREIGN KEY constraint failed")){console.debug("parseSQLError - FOREIGN KEY constraint error detected.");let e=/--command="([^"]+)"/.exec(l||""),t=e?e[1]:null,a={};if(t){let e=/UPDATE\s+(\w+)\s+SET\s+(\w+)\s*=/.exec(t);e&&(a={table:e[1],column:e[2]})}let s=a.table?"Foreign key constraint violation updating ".concat(a.table,".").concat(a.column):"Foreign key constraint violation";return{type:ej.FOREIGN_KEY_ERROR,message:s,details:{...a,originalQuery:t,stderr:r}}}if(r.includes("no such table")){let[e,t]=r.match(/no such table: (\w+)/)||[];return console.debug("parseSQLError - Table not found error detected:",{table:t}),{type:ej.TABLE_NOT_FOUND,message:"Table not found: ".concat(t),details:{originalQuery:s,stderr:r}}}if(r.includes("already exists")){let[e,t]=r.match(/table (\w+) already exists/)||[];return console.debug("parseSQLError - Table exists error detected:",{table:t}),{type:ej.TABLE_EXISTS,message:"Table already exists: ".concat(t),details:{originalQuery:s,stderr:r}}}return console.debug("parseSQLError - No specific error match found. Using fallback for execution error."),{type:ej.EXECUTION_ERROR,message:e.message||"Failed to execute SQL command",details:{originalQuery:s,stderr:r}}}return console.debug("parseSQLError - No stderr available; using default error handling."),{type:ej.UNKNOWN_ERROR,message:e.message||"An unknown error occurred",details:{}}}let ew={"Show Tables":"SELECT name\n FROM sqlite_master \n WHERE type='table' \n AND name NOT LIKE 'sqlite_%';","Table Schema":"-- Table Schema\n-- Replace table_name with your table name\nPRAGMA table_info(table_name);","Table Indexes":"-- Table Indexes\n-- Replace table_name with your table name\nSELECT \n m.name as table_name,\n i.name as index_name,\n i.sql as index_definition\nFROM sqlite_master m\nJOIN sqlite_master i ON m.name = i.tbl_name\nWHERE m.type = 'table'\nAND i.type = 'index'\nAND m.name = 'table_name';","Foreign Keys":"-- Foreign Key Information\n-- Replace table_name with your table name\nPRAGMA foreign_key_list(table_name);","Table Data":"-- Table Data\n-- Replace table_name with your table name\nSELECT * FROM table_name LIMIT 100;","Row Count":"-- Row Count\n-- Replace table_name with your table name\nSELECT COUNT(*) as total_rows FROM table_name;","Column Stats":"-- Column Statistics\n-- Replace table_name and column_name with your values\nSELECT \n COUNT(*) as total_rows,\n COUNT(column_name) as non_null_count,\n COUNT(DISTINCT column_name) as unique_values,\n MIN(column_name) as min_value,\n MAX(column_name) as max_value\nFROM table_name;","Create Table":"CREATE TABLE IF NOT EXISTS new_table (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL,\n email TEXT UNIQUE,\n status TEXT CHECK(status IN ('active', 'inactive')) DEFAULT 'active',\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\n-- Create indexes\nCREATE INDEX idx_new_table_name ON new_table(name);\nCREATE UNIQUE INDEX idx_new_table_email ON new_table(email);","Create View":"-- Create a view\nCREATE VIEW view_name AS\nSELECT column1, column2\nFROM table_name\nWHERE condition;"},ey={"Schema Information":["Show Tables","Table Schema","Table Indexes","Foreign Keys"],"Data Queries":["Table Data","Row Count","Column Stats"],"Schema Modification":["Create Table","Create View"]};function eC(e){let{onSelectQuery:t}=e;return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsxs)(A,{variant:"outline",size:"sm",children:["Query Templates",(0,s.jsx)(J.A,{className:"ml-2 h-4 w-4"})]})}),(0,s.jsx)(ev,{align:"start",className:"w-72",children:Object.entries(ey).map(e=>{let[a,n]=e;return(0,s.jsxs)(l.Fragment,{children:[(0,s.jsx)("div",{className:"px-2 py-1.5 text-sm font-semibold text-neutral-900 font-sans",children:a}),n.map(e=>(0,s.jsx)(eN,{onClick:()=>t(e),className:"font-sans text-neutral-800",children:e},e))]},a)})})]})}function eS(){let{executeQuery:e,refreshTables:t}=(0,p.t)(),[a,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(300),[u,m]=(0,l.useState)(!1),h=(0,l.useRef)(null),x=(0,l.useRef)(null);(0,l.useEffect)(()=>{x.current&&(x.current.style.height="".concat(o,"px"))},[o]);let f=(0,l.useCallback)(e=>{e.preventDefault();let t=e.pageY,a=e=>{d(Math.min(Math.max(o+(e.pageY-t),100),.8*window.innerHeight))},s=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",s)};document.addEventListener("mousemove",a),document.addEventListener("mouseup",s)},[o]),g=async()=>{if(!h.current)return;let a=h.current.getValue().trim().replace(/;+$/,"");if(!a){n({success:!1,error:{message:"Query cannot be empty."}});return}try{var s,l,r,o;i(!0),n(null);let c=await e(a);/^(CREATE|DROP|ALTER)\s+TABLE/i.test(a)&&await t();let d=[];if(c.results){if(Array.isArray(c.results)){if(c.results.length>0&&(null===(s=c.results[0])||void 0===s?void 0:s.columns)&&(null===(l=c.results[0])||void 0===l?void 0:l.values)){let e=c.results[0];d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}else d=1===c.results.length&&c.results[0].results&&Array.isArray(c.results[0].results)?c.results[0].results:c.results}else if(c.results.columns&&c.results.values){let e=c.results;d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}}else if(c.result&&c.result.results){if(Array.isArray(c.result.results)){if(c.result.results.length>0&&(null===(r=c.result.results[0])||void 0===r?void 0:r.columns)&&(null===(o=c.result.results[0])||void 0===o?void 0:o.values)){let e=c.result.results[0];d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}else d=1===c.result.results.length&&c.result.results[0].results&&Array.isArray(c.result.results[0].results)?c.result.results[0].results:c.result.results}else if(c.result.results.columns&&c.result.results.values){let e=c.result.results;d=e.values.map(t=>e.columns.reduce((e,a,s)=>(e[a]=t[s],e),{}))}}n({success:!0,results:d})}catch(e){n({success:!1,error:eb(e)||{message:"An unknown error occurred",details:{}}})}finally{i(!1)}};return(0,s.jsxs)("div",{className:"h-full flex flex-col bg-white text-neutral-900 font-sans",children:[(0,s.jsx)("div",{className:"px-4 py-2 bg-neutral-100 border-b flex items-center gap-4",children:(0,s.jsx)(eC,{onSelectQuery:e=>{if(h.current){let t=Object.keys(ew).find(t=>t.toLowerCase()===e.toLowerCase());if(t){let e=ew[t];h.current.setValue(e),h.current.focus()}else console.warn("Query template not found for: ".concat(e))}}})}),(0,s.jsx)("div",{ref:x,className:"relative pt-2 overflow-hidden",style:{height:"".concat(o,"px"),minHeight:"100px"},children:(0,s.jsx)(er.Ay,{height:"100%",language:"sql",options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",automaticLayout:!0,lineNumbers:"on",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"},onMount:e=>{h.current=e,e.addCommand(monaco.KeyMod.CtrlCmd|monaco.KeyCode.Enter,()=>{g()})}})}),(0,s.jsx)("div",{className:"relative h-0.5 cursor-row-resize bg-neutral-200 group ".concat(u?"bg-neutral-300":"hover:bg-neutral-300"),onMouseDown:e=>{m(!0),f(e)},onMouseUp:()=>m(!1),children:(0,s.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-neutral-900 rounded-sm px-0.5 \n ".concat(u?"visible":"invisible group-hover:visible"),children:(0,s.jsx)(ei.A,{className:"h-3 w-3 text-white"})})}),(0,s.jsx)("div",{className:"px-4 py-3 bg-neutral-100 border-b font-sans",children:(0,s.jsxs)("div",{className:"flex justify-between items-center",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"Results"}),(0,s.jsxs)(A,{size:"sm",onClick:g,disabled:r,className:"flex items-center gap-1 text-sm font-medium",children:["Run",r?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(eo.A,{className:"h-4 w-4"}),(0,s.jsx)(ec.A,{className:"h-4 w-4"})]})]})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-auto p-4 bg-white",children:(()=>{var e;if(r)return(0,s.jsxs)("div",{className:"flex items-center text-sm text-neutral-700",children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin mr-2 font-sans"}),"Running your query..."]});if(!a)return(0,s.jsx)("div",{className:"text-sm text-neutral-500 font-sans",children:"Run the query to see the results."});if(!a.success)return console.debug("SQLEditor - Rendering error:",a.error),(0,s.jsx)(eu,{error:a.error});let t=a.results;return t&&0!==t.length?(0,s.jsx)(em,{query:(null===(e=h.current)||void 0===e?void 0:e.getValue())||"",results:t}):(0,s.jsx)("div",{className:"text-sm text-neutral-900 font-sans",children:"Success. No results to display."})})()})]})}var eE=a(6352);let eR=l.forwardRef((e,t)=>{let{className:a,...l}=e;return(0,s.jsx)(eE.bL,{ref:t,className:(0,d.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",a),...l,children:(0,s.jsx)(eE.C1,{className:(0,d.cn)("flex items-center justify-center text-current"),children:(0,s.jsx)(X.A,{className:"h-4 w-4"})})})});eR.displayName=eE.bL.displayName;var eT=a(138),eA=a(1598),ek=a(2884),e_=a(9710);let eO=e_.Kq,eL=e_.bL,eI=e_.l9,eU=l.forwardRef((e,t)=>{let{className:a,sideOffset:l=4,...n}=e;return(0,s.jsx)(e_.ZL,{children:(0,s.jsx)(e_.UC,{ref:t,sideOffset:l,className:(0,d.cn)("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n})})});eU.displayName=e_.UC.displayName;var eP=a(6235);let eF=(0,l.memo)(e=>{let{onRefresh:t,disabled:a}=e,[n,r]=(0,l.useState)(!1),i=async()=>{if(!n&&!a){r(!0);try{await t()}catch(e){console.error("Refresh failed:",e)}finally{setTimeout(()=>{r(!1)},500)}}};return(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",onClick:i,disabled:n||a,className:"h-8",children:n?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(eP.A,{className:"h-4 w-4"})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Refresh table data"})})]})})});eF.displayName="RefreshButton";var eD=a(7973);let eM=(0,l.memo)(e=>{let{tableName:t,onSync:a}=e,[n,r]=(0,l.useState)(!1),{toast:i}=(0,_.dj)();if("d1_migrations"!==t)return null;let o=async()=>{try{r(!0);let e=await fetch("/api/migrations/sync-files",{method:"POST"}),t=await e.json();if(!e.ok)throw Error(t.error||"Failed to sync migrations");let{added:s=[],removed:l=[]}=t.details||{};i({title:"Migrations Synced",description:"Added: ".concat(s.length,", Removed: ").concat(l.length)}),a&&await a()}catch(e){console.error("Error syncing migrations:",e),i({variant:"destructive",title:"Sync Failed",description:e.message})}finally{r(!1)}};return(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",onClick:o,disabled:n,className:"h-8",children:n?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(eD.A,{className:"h-4 w-4"})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Sync migration files with d1_migrations table"})})]})})});eM.displayName="SyncMigrationsButton";var ez=a(358),eQ=a(8742),eV=a(6697);let eK=(0,l.memo)(e=>{let{tableName:t,onDownloadStart:a,onDownloadComplete:n,disabled:r}=e,[i,o]=(0,l.useState)(!1),{toast:d}=(0,_.dj)(),u=(e,t)=>{try{let a=new Blob([e],{type:"application/octet-stream"}),s=window.URL.createObjectURL(a),l=document.createElement("a");l.href=s,l.download=t,document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)}catch(e){throw console.error("Error during file download:",e),e}},m=async e=>{if(!r)try{o(!0),null==a||a();let s=await fetch("/api/tables/".concat(t)),l=await s.json();if(!s.ok)throw Error(l.error||"Failed to fetch data");let{data:r,schema:i}=l;if(!(null==r?void 0:r.length)){d({title:"No Data",description:"The table is empty.",variant:"destructive"});return}let c=new Date().toISOString().split("T")[0],m="".concat(t,"_").concat(c,".").concat(e);switch(e){case"json":{let e=JSON.stringify(r,null,2);u(e,m);break}case"csv":{let e=Object.keys(r[0]),t=[e.join(","),...r.map(t=>e.map(e=>{let a=t[e];if(null==a)return"";if("string"==typeof a){let e=a.replace(/"/g,'""');return'"'.concat(e,'"')}return a}).join(","))].join("\n");u(t,m);break}case"sql":{let e="CREATE TABLE IF NOT EXISTS ".concat(t," (\n")+i.map(e=>{let t=[];return e.pk&&t.push("PRIMARY KEY"),e.notnull||t.push("NOT NULL")," ".concat(e.name," ").concat(e.type).concat(t.length?" ".concat(t.join(" ")):"")}).join(",\n")+"\n);\n\n",a=r.map(e=>{let a=Object.keys(e),s=a.map(t=>{let a=e[t];return null===a?"NULL":"string"==typeof a?"'".concat(a.replace(/'/g,"''"),"'"):a});return"INSERT INTO ".concat(t," (").concat(a.join(", "),")\nVALUES (").concat(s.join(", "),");")}).join("\n");u(e+a,m)}}d({title:"Download Complete",description:"".concat(r.length," rows exported as ").concat(e.toUpperCase(),".")}),null==n||n()}catch(e){console.error("Download error:",e),d({variant:"destructive",title:"Download Failed",description:e.message})}finally{o(!1)}};return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsx)(A,{variant:"outline",size:"icon",className:"h-8",disabled:i||r,children:i?(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(ea.A,{className:"h-4 w-4"})})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Download table data"})})]})}),(0,s.jsxs)(ev,{align:"end",children:[(0,s.jsxs)(eN,{onClick:()=>m("json"),disabled:r,children:[(0,s.jsx)(ez.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download JSON"})]}),(0,s.jsxs)(eN,{onClick:()=>m("csv"),disabled:r,children:[(0,s.jsx)(eQ.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download CSV"})]}),(0,s.jsxs)(eN,{onClick:()=>m("sql"),disabled:r,children:[(0,s.jsx)(eV.A,{className:"mr-2 h-4 w-4"}),(0,s.jsx)("span",{children:"Download SQL"})]})]})]})});eK.displayName="DownloadButton";var eq=a(9045);let eJ=function(e){let{schema:t=[],visibleColumns:a=[],onColumnToggle:n}=e,[r,i]=(0,l.useState)("");(0,l.useEffect)(()=>{if(!t||0===t.length)return;let e=t.map(e=>e.name);0===a.length&&e.forEach(e=>n(e))},[t,a.length,n]);let o=t.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())),c=o.map(e=>e.name),d=c.length>0&&c.every(e=>a.includes(e)),m=e=>{n(e)};return(0,s.jsxs)(ep,{children:[(0,s.jsx)(eg,{asChild:!0,children:(0,s.jsxs)(A,{size:"sm",variant:"outline",className:"font-semibold",children:[(0,s.jsx)(eq.A,{className:"h-4 w-4"}),"Columns (",a.length,")"]})}),(0,s.jsxs)(ev,{align:"end",className:"w-64 font-sans",children:[(0,s.jsx)("div",{className:"p-2",children:(0,s.jsx)(u,{placeholder:"Search columns...",value:r,onChange:e=>i(e.target.value),className:"h-8"})}),(0,s.jsxs)("div",{className:"flex items-center space-x-2 px-2 py-1.5 hover:bg-accent rounded-md",children:[(0,s.jsx)(eR,{id:"select-all-columns",checked:d,onCheckedChange:e=>{e?o.forEach(e=>{a.includes(e.name)||n(e.name)}):o.forEach(e=>{a.includes(e.name)&&n(e.name)})},className:"shrink-0"}),(0,s.jsxs)("label",{htmlFor:"select-all-columns",className:"flex-1 cursor-pointer text-sm font-medium",children:["Select All ",r&&"(Filtered)"]})]}),(0,s.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:o.map(e=>(0,s.jsxs)("div",{className:"flex items-start space-x-2 px-2 py-1.5 hover:bg-accent rounded-md",children:[(0,s.jsx)(eR,{id:"column-".concat(e.name),checked:a.includes(e.name),onCheckedChange:()=>m(e.name),className:"mt-1"}),(0,s.jsxs)("label",{htmlFor:"column-".concat(e.name),className:"flex-1 cursor-pointer",children:[(0,s.jsx)("div",{className:"text-sm font-medium",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground",children:e.type.toLowerCase()})]})]},e.name))})]})]})},eY=(0,l.memo)(e=>{let{onAdd:t,onDelete:a,selectedCount:l,disabled:n,newRecordsCount:r,schema:i,visibleColumns:o,onColumnToggle:c}=e;return(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(eO,{children:(0,s.jsxs)(eL,{children:[(0,s.jsx)(eI,{asChild:!0,children:(0,s.jsx)("span",{children:(0,s.jsxs)(A,{size:"sm",variant:"outline",className:"font-semibold opacity-50 cursor-not-allowed",disabled:!0,children:[(0,s.jsx)(eT.A,{className:"h-4 w-4"}),"Filters"]})})}),(0,s.jsx)(eU,{children:(0,s.jsx)("p",{children:"Filters are not available yet. Coming soon!"})})]})}),(0,s.jsx)(eJ,{schema:i,visibleColumns:o,onColumnToggle:c}),(0,s.jsx)("div",{className:"h-4 border-r mx-2"}),(0,s.jsx)(A,{size:"sm",variant:"default",className:"font-semibold",onClick:t,children:"Add record"}),l>0&&(0,s.jsxs)(A,{size:"sm",className:"font-semibold",onClick:a,variant:"destructive",disabled:n||r>0,children:["Delete ",l," ",1===l?"record":"records"]})]})}),eX=(0,l.memo)(e=>{let{totalRows:t}=e;return(0,s.jsxs)("span",{className:"text-sm text-neutral-600",children:[t," ",1===t?"row":"rows"]})}),eH=(0,l.memo)(e=>{let{currentPage:t,totalPages:a,onPageChange:l,disabled:n,newRecordsCount:r}=e;return(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(A,{variant:"ghost",size:"icon",onClick:()=>{console.log("Pagination: navigating to previous page",t-1),l(t-1)},disabled:1===t||n||r>0,className:"h-8",children:(0,s.jsx)(eA.A,{className:"h-4 w-4"})}),(0,s.jsxs)("span",{className:"text-sm",children:["Page ",t," of ",a]}),(0,s.jsx)(A,{variant:"ghost",size:"icon",onClick:()=>{console.log("Pagination: navigating to next page",t+1),l(t+1)},disabled:t===a||n||r>0,className:"h-8",children:(0,s.jsx)(ek.A,{className:"h-4 w-4"})})]})}),eB=(0,l.memo)(e=>{let{value:t,onValueChange:a,disabled:l,newRecordsCount:n}=e;return(0,s.jsxs)(H,{value:t.toString(),onValueChange:a,disabled:l||n>0,children:[(0,s.jsx)(W,{className:"w-20 h-8",children:(0,s.jsx)(B,{})}),(0,s.jsxs)($,{children:[(0,s.jsx)(ee,{value:"50",children:"50"}),(0,s.jsx)(ee,{value:"100",children:"100"}),(0,s.jsx)(ee,{value:"250",children:"250"})]})]})}),eW=(0,l.memo)(e=>{let{onSave:t,onDiscard:a,totalChanges:l,isSaving:n}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(A,{size:"sm",variant:"ghost",className:"font-semibold",onClick:a,disabled:n,children:"Discard changes"}),(0,s.jsx)(A,{size:"sm",className:"font-semibold bg-green-600 hover:bg-green-700",variant:"default",onClick:t,disabled:n,children:n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.A,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):"Save ".concat(l," ").concat(1===l?"change":"changes")})]})}),eG=e=>{let{selectedCount:t=0,onAdd:a,onDelete:l,onRefresh:n,totalRows:r=0,currentPage:i=1,totalPages:o=1,onPageChange:c,rowsPerPage:d=50,onRowsPerPageChange:u,tableName:m,onDownloadStart:h,onDownloadComplete:x,disabled:f=!1,editCount:p=0,newRecordsCount:g=0,onSaveChanges:v,onDiscardChanges:N,isSaving:j=!1,schema:b,visibleColumns:w,onColumnToggle:y}=e,C=p+g;return(0,s.jsx)("div",{className:"flex items-center justify-between p-3 border-b bg-background font-sans",children:(0,s.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,s.jsx)(eY,{onAdd:a,onDelete:l,selectedCount:t,disabled:f||j,newRecordsCount:g,schema:b,visibleColumns:w,onColumnToggle:y}),(0,s.jsx)("div",{className:"flex items-center gap-4",children:C>0?(0,s.jsx)(eW,{onSave:v,onDiscard:N,totalChanges:C,isSaving:j}):(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(eX,{totalRows:r}),(0,s.jsx)(eH,{currentPage:i,totalPages:o,onPageChange:c,disabled:f,newRecordsCount:g}),(0,s.jsx)(eB,{value:d,onValueChange:e=>{u(parseInt(e,10)),c(1)},disabled:f,newRecordsCount:g}),(0,s.jsx)(eF,{onRefresh:n,disabled:f}),(0,s.jsx)(eM,{tableName:m,onSync:n,disabled:f}),(0,s.jsx)(eK,{tableName:m,onDownloadStart:h,onDownloadComplete:x,disabled:f})]})})]})})};eG.displayName="TableToolbar";let eZ=(0,l.memo)(eG);function e$(e){let{value:t,row:a,column:n,schema:r,onChange:i,onStartEdit:o,isEditing:c}=e,d="string"==typeof t?t.replace(/^'|'$/g,""):t,[m,h]=(0,l.useState)(d),[x,f]=(0,l.useState)("auto"),p=(0,l.useRef)(null),g=(0,l.useRef)(null),v=r.find(e=>e.name===n),N=(0,l.useMemo)(()=>(null==v?void 0:v.check)||null,[v]),j=(0,l.useMemo)(()=>{var e;let t=(null==v?void 0:null===(e=v.type)||void 0===e?void 0:e.toLowerCase())||"";return"boolean"===t||"bool"===t||"integer"===t&&n.toLowerCase().startsWith("is_")},[v,n]);(0,l.useEffect)(()=>{h(d)},[d]),(0,l.useEffect)(()=>{if(p.current&&!c){let e=p.current.offsetWidth;f("".concat(e,"px"))}},[c]),(0,l.useEffect)(()=>{c&&g.current&&(g.current.focus(),g.current.select())},[c]),null==v||v.pk;let b=(0,l.useCallback)(e=>{let t=j?"true"===e?1:"false"===e?0:e:e;h(e),null==i||i(t)},[i,j]),w=(0,l.useCallback)(()=>{!c&&o&&o(d)},[c,o,d]),y="border-x border-neutral-200 px-3 py-2.5 text-xs font-mono whitespace-nowrap",C=(0,l.useMemo)(()=>null==d?"null":j?1===d||"1"===d||"true"===d?"true":"false":d.toString(),[d,j]);return c?j?(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)("div",{className:"w-full h-full",children:(0,s.jsxs)(H,{value:C,onValueChange:b,defaultOpen:c,children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select value"})}),(0,s.jsxs)($,{className:"min-w-[8rem]",children:[(0,s.jsx)(ee,{value:"true",children:"true"}),(0,s.jsx)(ee,{value:"false",children:"false"})]})]})})}):(null==N?void 0:N.length)>0?(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)("div",{className:"w-full h-full",children:(0,s.jsxs)(H,{value:null!=m?m:N[0],onValueChange:b,defaultOpen:c,children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select ".concat(n)})}),(0,s.jsx)($,{className:"min-w-[8rem]",children:N.map(e=>(0,s.jsx)(ee,{value:e,children:e},e))})]})})}):(0,s.jsx)(z,{className:"".concat(y," p-0"),style:{width:x},children:(0,s.jsx)(u,{ref:g,value:null!=m?m:"",onChange:e=>b(e.target.value),className:"w-full min-w-0 rounded-none border-0 bg-orange-50 text-orange-900"})}):(0,s.jsx)(z,{ref:p,className:"".concat(y," cursor-pointer hover:bg-muted/50"),onClick:w,children:C})}var e0=a(5524);function e1(e){return"string"==typeof e?e.replace(/^'|'$/g,""):e}function e4(e){let{schema:t,onRemove:a,onChange:n,showCheckbox:r=!1,initialData:i={}}=e,[o,c]=(0,l.useState)(()=>t.reduce((e,t)=>{var a;let s=null!==(a=i[t.name])&&void 0!==a?a:null;return null===(s=e1(s))&&(t.dflt_value?s=e1(t.dflt_value):"INTEGER"===t.type.toUpperCase()?s="":"TEXT"===t.type.toUpperCase()&&(s="")),e[t.name]=s,e},{})),d=(e,t)=>{let a={...o,[e]:t};c(a),null==n||n(a)},m=e=>{var t;let a=(null===(t=e.type)||void 0===t?void 0:t.toLowerCase())||"";return"boolean"===a||"bool"===a||"integer"===a&&e.name.toLowerCase().startsWith("is_")};return(0,s.jsxs)(D,{className:"bg-orange-50/50",children:[(0,s.jsx)(z,{className:"w-10 p-0",children:(0,s.jsx)("div",{className:"pl-1 flex items-center",children:r?(0,s.jsx)(eR,{disabled:!0}):(0,s.jsx)(A,{variant:"ghost",size:"icon",className:"h-8 w-8 text-orange-700 hover:text-orange-800",onClick:a,children:(0,s.jsx)(e0.A,{className:"h-4 w-4"})})})}),t.map(e=>{var t,a;let l=1===e.pk,n=e.check||null;if(m(e)){let t="false";if(null!==e.dflt_value&&void 0!==e.dflt_value){let a=e.dflt_value.toString().toLowerCase();t="1"===a||"true"===a||"'true'"===a||'"true"'===a?"true":"false"}let a=null!==o[e.name]&&void 0!==o[e.name]?1===o[e.name]||!0===o[e.name]||"true"===o[e.name]?"true":"false":t;return(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)("div",{className:"w-full",children:(0,s.jsxs)(H,{value:a,onValueChange:t=>d(e.name,"true"===t?1:0),children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",title:"Default: ".concat(t),children:(0,s.jsx)(B,{placeholder:"Select ".concat(e.name)})}),(0,s.jsxs)($,{className:"min-w-[8rem]",children:[(0,s.jsx)(ee,{value:"true",children:"true"}),(0,s.jsx)(ee,{value:"false",children:"false"})]})]})})},e.name)}return(null==n?void 0:n.length)>0?(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)("div",{className:"w-full",children:(0,s.jsxs)(H,{value:null!==(t=o[e.name])&&void 0!==t?t:n[0],onValueChange:t=>d(e.name,t),children:[(0,s.jsx)(W,{className:"w-full h-9 min-w-0 rounded-none border-0 bg-orange-50 text-orange-900",children:(0,s.jsx)(B,{placeholder:"Select ".concat(e.name)})}),(0,s.jsx)($,{className:"min-w-[8rem]",children:n.map(e=>(0,s.jsx)(ee,{value:e,children:e},e))})]})})},e.name):(0,s.jsx)(z,{className:"border-x border-neutral-200 p-0",children:(0,s.jsx)(u,{value:null!==(a=o[e.name])&&void 0!==a?a:"",onChange:t=>d(e.name,t.target.value),className:"w-full min-w-0 rounded-none border-0 px-2 bg-orange-50 text-orange-900",placeholder:l?"Auto-generated":"Enter ".concat(e.name)})},e.name)})]})}let e2=function(e){let{isOpen:t,onClose:a,onConfirm:l,selectedCount:n,tableName:r,isDeleting:o,error:c}=e;return(0,s.jsx)(N,{open:t,onOpenChange:a,children:(0,s.jsxs)(w,{className:"sm:max-w-md font-sans",children:[(0,s.jsxs)(y,{children:[(0,s.jsxs)(S,{className:"mb-2",children:["Delete ",n," ",1===n?"Record":"Records","?"]}),(0,s.jsxs)(E,{className:"text-neutral-600 font-medium",children:["You're about to delete ",n," ",1===n?"record":"records"," from ",(0,s.jsx)("span",{className:"font-sans font-bold text-neutral-900",children:r}),"."]})]}),c&&(0,s.jsxs)(x,{variant:"destructive",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsx)(f,{children:c})]}),(0,s.jsxs)(C,{className:"flex gap-1 mt-2 sm:justify-end font-sans",children:[(0,s.jsx)(A,{variant:"outline",onClick:a,disabled:o,children:"Cancel"}),(0,s.jsx)(A,{variant:"destructive",onClick:l,disabled:o,children:o?"Deleting...":"Delete"})]})]})})};function e5(e){var t;let{isOpen:a,onClose:l,error:n}=e;if(!n||!a)return null;let{message:r,icon:o}=n?{message:n.message,icon:i.A}:{message:"An unknown error occurred.",icon:i.A};return(0,s.jsx)(N,{open:a,onOpenChange:l,children:(0,s.jsxs)(w,{className:"sm:max-w-md font-sans",children:[(0,s.jsx)(y,{children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(o,{className:"h-4 w-4 text-red-500"}),(0,s.jsx)(S,{children:"Error"})]})}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("p",{className:"bg-neutral-100 p-2 rounded-md text-neutral-900",children:r}),(null===(t=n.details)||void 0===t?void 0:t.suggestions)&&(0,s.jsxs)("div",{className:"text-sm space-y-1",children:[(0,s.jsx)("p",{className:"font-medium",children:"Suggestions:"}),(0,s.jsx)("ul",{className:"list-disc pl-4 space-y-1",children:n.details.suggestions.map((e,t)=>(0,s.jsx)("li",{children:e},t))})]})]}),(0,s.jsx)("div",{className:"flex justify-end gap-2 mt-4",children:(0,s.jsx)(A,{variant:"default",onClick:l,children:"Got it"})})]})})}let e3=e=>{let{children:t,width:a,onResize:n,className:r=""}=e,[i,o]=(0,l.useState)(!1),c=(0,l.useRef)(null),d=(0,l.useCallback)(e=>{var t;e.preventDefault(),o(!0);let a=e.clientX,s=(null===(t=c.current)||void 0===t?void 0:t.offsetWidth)||0,l=e=>{c.current&&n(Math.max(s+(e.clientX-a),100))},r=()=>{o(!1),document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",r)};document.addEventListener("mousemove",l),document.addEventListener("mouseup",r)},[n]);return(0,s.jsxs)("th",{ref:c,className:"relative ".concat(r," ").concat(i?"select-none":""),style:{width:"".concat(a,"px")},children:[t,(0,s.jsx)("div",{className:"absolute top-0 right-0 h-full w-1 cursor-col-resize group hover:bg-neutral-300",onMouseDown:d})]})},e9=e=>{let{columns:t,children:a,onColumnsResize:n,className:r=""}=e,[i,o]=(0,l.useState)(t.reduce((e,t)=>({...e,[t.key]:t.width||150}),{})),c=(0,l.useCallback)((e,t)=>{o(a=>{let s={...a,[e]:t};return null==n||n(s),s})},[n]);return(0,s.jsx)("div",{className:"w-full ".concat(r),children:l.Children.map(a,e=>l.isValidElement(e)?l.cloneElement(e,{onResize:c}):e)})};var e8=a(3998),e6=a(3303),e7=a(8729);function te(e){let{column:t,sortConfig:a,onSort:l,children:n}=e,r=a[t];return(0,s.jsx)("div",{className:"flex items-center w-full",children:(0,s.jsxs)(A,{variant:"ghost",size:"sm",className:"h-8 hover:bg-neutral-100 w-full justify-between",onClick:()=>{l(t,r?"asc"===r?"desc":null:"asc")},children:[(0,s.jsx)("span",{className:"flex items-center gap-1 font-mono",children:n}),(0,s.jsxs)("span",{className:"shrink-0",children:["asc"===r&&(0,s.jsx)(e8.A,{className:"h-4 w-4"}),"desc"===r&&(0,s.jsx)(e6.A,{className:"h-4 w-4"}),!r&&(0,s.jsx)(e7.A,{className:"h-4 w-4"})]})]})})}function tt(e){let{tableName:t}=e,{executeQuery:a,getCachedTable:n,updateTableCache:r,invalidateTable:o,switchTable:d,activeTable:u,updateTableData:m}=(0,p.t)(),{toast:h}=(0,_.dj)(),[g,v]=(0,l.useState)(()=>[]),[N,j]=(0,l.useState)([]),[b,w]=(0,l.useState)(0),[y,C]=(0,l.useState)(!0),[S,E]=(0,l.useState)(!1),[R,T]=(0,l.useState)(null),[A,k]=(0,l.useState)(new Map),[O,Q]=(0,l.useState)(new Set),[V,K]=(0,l.useState)([]),[q,J]=(0,l.useState)(1),[Y,X]=(0,l.useState)(50),[H,B]=(0,l.useState)(1),[W,G]=(0,l.useState)(new Set),Z=(0,l.useRef)(null),[$,ee]=(0,l.useState)(!1),[et,ea]=(0,l.useState)(!1),[es,el]=(0,l.useState)(null),[en,er]=(0,l.useState)(!1),[ei,eo]=(0,l.useState)(null),[ec,ed]=(0,l.useState)({}),[eu,em]=(0,l.useState)({}),[eh,ex]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(t){let e=localStorage.getItem("table-widths-".concat(t));e&&em(JSON.parse(e));let a=localStorage.getItem("table-columns-".concat(t));if(a)try{ex(JSON.parse(a))}catch(e){ex([])}}},[t]);let ef=(0,l.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!t)return;let a=n(t,q,Y);if(a&&!e){v(a.data),j(a.schema),w(a.meta.total),B(a.meta.totalPages);return}C(!0),T(null),G(new Set);try{let a=await d(t,{page:q,limit:Y,forceFetch:e});return a.meta.page=q,v(Array.isArray(a.data)?a.data:[]),j(a.schema||[]),w(a.meta.total),B(a.meta.totalPages),!0}catch(e){throw console.error("Error loading table data:",e),T(e.message||String(e)),h({variant:"destructive",title:"Error",description:"Failed to load table: ".concat(e.message)}),e}finally{C(!1)}},[t,q,Y,n,d,h,eh.length]),ep=(0,l.useCallback)(e=>{ex(a=>{let s=a.includes(e)?a.filter(t=>t!==e):[...a,e];return localStorage.setItem("table-columns-".concat(t),JSON.stringify(s)),s})},[t]),eg=(0,l.useCallback)((e,a)=>{em(s=>{let l={...s,[e]:a};return localStorage.setItem("table-widths-".concat(t),JSON.stringify(l)),l})},[t]),ev=(0,l.useCallback)(async()=>{try{G(new Set),o(t),await ef(!0),h({title:"Success",description:"Table data refreshed"})}catch(e){console.error("Refresh failed:",e),h({variant:"destructive",title:"Refresh Failed",description:e.message})}},[ef,o,t,h]),eN=(0,l.useCallback)((e,a)=>{ed(t=>({...t,[e]:a}));let s=a&&g.length?[...g].sort((t,s)=>{let l=t[e],n=s[e];if(null==l&&null==n)return 0;if(null==l)return 1;if(null==n)return -1;if("number"==typeof l&&"number"==typeof n)return"asc"===a?l-n:n-l;let r=String(l).toLowerCase(),i=String(n).toLowerCase();return"asc"===a?r.localeCompare(i):i.localeCompare(r)}):g;v(s);let l=n(t);l&&r(t,s,l.schema,{...l.meta,currentPage:q,limit:Y},q,Y)},[g,t,n,r]),ej=(0,l.useCallback)((e,t,a)=>{let s="".concat(e,"-").concat(t);k(e=>new Map(e).set(s,{value:a,originalValue:a})),Q(t=>new Set(t).add(e))},[]),ew=(0,l.useCallback)((e,t,a)=>{var s,l;let n="".concat(e,"-").concat(t),r=g[e],i=null!==(l=null===(s=A.get(n))||void 0===s?void 0:s.originalValue)&&void 0!==l?l:r[t];if(a===i){let t=new Map(A);if(t.delete(n),k(t),!Array.from(t.keys()).some(t=>t.startsWith("".concat(e,"-")))){let t=new Set(O);t.delete(e),Q(t)}}else k(e=>new Map(e).set(n,{value:a,originalValue:i})),Q(t=>new Set(t).add(e))},[g,A,O]),ey=(0,l.useCallback)(()=>{K(e=>[...e,{}])},[]),eC=(0,l.useCallback)(e=>{K(t=>t.filter((t,a)=>a!==e))},[]),eS=(0,l.useCallback)((e,t)=>{K(a=>{let s=[...a];return s[e]=t,s})},[]),eE=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];E(!0);try{if(V.length>0){let e=0,s=N.filter(e=>"datetime"===e.type.toLowerCase()).map(e=>e.name);for(let l of V){let n=Object.keys(l).filter(e=>null!==l[e]&&""!==l[e]&&"null"!==l[e]);if(s.forEach(e=>{n.includes(e)||n.push(e)}),0===n.length)continue;let r=n.map(e=>{if(s.includes(e))return"CURRENT_TIMESTAMP";let t=l[e];return null===t||""===t||"null"===t?"NULL":"'".concat(t.toString().replace(/'/g,"''"),"'")}),i="INSERT INTO ".concat(t," (").concat(n.join(", "),") VALUES (").concat(r.join(", "),");");await a(i),e++}if(e>0){let a=await m(t);v(a.data),w(a.meta.total),B(Math.ceil(a.meta.total/Y)),h({title:"Success",description:"Added ".concat(e," ").concat(1===e?"record":"records")})}K([])}if(A.size>0&&(e||!ei)){var s;let e=null===(s=N.find(e=>1===e.pk))||void 0===s?void 0:s.name;if(!e)throw Error("No primary key found in table schema");let l=new Map;A.forEach((t,a)=>{let[s,n]=a.split("-"),r=g[s];l.has(r[e])||l.set(r[e],new Map),l.get(r[e]).set(n,t.value)});let n=0;for(let[s,r]of l){let l=Array.from(r.entries()).map(e=>{let[t,a]=e;return null===a||""===a||"null"===a?"".concat(t," = NULL"):"CURRENT_TIMESTAMP"===a?"".concat(t," = CURRENT_TIMESTAMP"):"".concat(t," = '").concat(a.toString().replace(/'/g,"''"),"'")}).join(", "),i="\n UPDATE ".concat(t,"\n SET ").concat(l,"\n WHERE ").concat(e," = ").concat(s,";\n ");await a(i),n++}if(n>0){let e=await m(t);v(e.data),w(e.meta.total),B(Math.ceil(e.meta.total/Y)),h({title:"Success",description:"Updated ".concat(n," ").concat(1===n?"record":"records")})}}k(new Map),Q(new Set),eo(null)}catch(e){eo({...eb(e),stderr:e.stderr,stdout:e.stdout}),er(!0)}finally{E(!1)}},eT=(0,l.useCallback)(async()=>{if(ea(!0),el(null),t){ea(!0),el(null);try{var e;let s=null===(e=N.find(e=>1===e.pk))||void 0===e?void 0:e.name;if(!s)throw Error("No primary key found in table schema");let l=Array.from(W).map(e=>g[e][s]);if(0===l.length)return;let i="DELETE FROM ".concat(t," WHERE ").concat(s," IN (").concat(l.join(","),");");await a(i);let o=new Set(l),c=g.filter(e=>!o.has(e[s]));v(c),w(e=>e-l.length),B(Math.ceil((b-l.length)/Y));let d=n(t);d&&r(t,c,d.schema,{...d.meta,total:d.meta.total-l.length}),q>1&&g.length===l.length&&(J(e=>e-1),await ef()),ee(!1),G(new Set),h({title:"Success",description:"Successfully deleted ".concat(l.length," ").concat(1===l.length?"record":"records")})}catch(e){console.error("Delete operation failed:",e),el(e.message||String(e))}finally{ea(!1)}}},[t,W,g,N,a,m,ef,q,Y,b,h,n,r]);(0,l.useEffect)(()=>{if(!t)return;k(new Map),Q(new Set),K([]),T(null),G(new Set),J(1);let e=n(t,1,Y);e?(v(e.data),j(e.schema),w(e.meta.total),B(e.meta.totalPages),ex(a=>{if(a.length)return a;let s=e.schema.map(e=>e.name);return localStorage.setItem("table-columns-".concat(t),JSON.stringify(s)),s})):ef(!1)},[t,Y]),(0,l.useEffect)(()=>{if(u===t){let e=n(t);e&&(v(e.data),j(e.schema),w(e.meta.total),B(e.meta.totalPages))}},[u,t,n]),(0,l.useEffect)(()=>{if(t&&!y){var e;let a=n(t,q,Y);a&&q===(null===(e=a.meta)||void 0===e?void 0:e.currentPage)||ef(!1)}},[t,q,Y,y,ef,n]),(0,l.useEffect)(()=>{Z.current&&(Z.current.indeterminate=W.size>0&&W.size<g.length)},[W.size,g.length]);let eA=(0,l.useCallback)(e=>{G(e?new Set(g.map((e,t)=>t)):new Set)},[g]),ek=(0,l.useCallback)((e,t)=>{G(a=>{let s=new Set(a);return t?s.add(e):s.delete(e),s})},[]);(0,l.useCallback)(e=>{em(e),localStorage.setItem("table-widths-".concat(t),JSON.stringify(e))},[t]);let e_=N.filter(e=>eh.includes(e.name)),eO=A.size>0||V.length>0;return R?(0,s.jsx)("div",{className:"p-4",children:(0,s.jsxs)(x,{variant:"destructive",children:[(0,s.jsx)(i.A,{className:"h-4 w-4"}),(0,s.jsxs)(f,{children:["Failed to load table: ",R]})]})}):(0,s.jsxs)("div",{className:"h-full flex flex-col",children:[(0,s.jsx)(eZ,{selectedCount:W.size,totalRows:b,currentPage:q,totalPages:H,rowsPerPage:Y,onPageChange:J,onRowsPerPageChange:X,onAdd:ey,onDelete:()=>ee(!0),onRefresh:ev,tableName:t,disabled:eO,editCount:A.size,newRecordsCount:V.length,isSaving:S,onSaveChanges:eE,onDiscardChanges:()=>{k(new Map),Q(new Set),K([]),eo(null),h({description:"Changes discarded"})},schema:N,visibleColumns:eh,onColumnToggle:ep}),(0,s.jsx)(e9,{columns:N,onColumnsResize:eg,children:(0,s.jsx)("div",{className:"relative flex-1 overflow-hidden bg-background font-mono",children:(0,s.jsx)(L,{className:"w-full h-screen",children:(0,s.jsxs)("div",{className:"relative w-max min-w-fit pb-4",children:[(0,s.jsxs)(U,{children:[!y&&(0,s.jsx)(P,{className:"bg-neutral-100 sticky top-0 z-30",children:(0,s.jsxs)(D,{children:[(0,s.jsx)(M,{className:"w-10 p-0 border-r border-neutral-200",children:(0,s.jsx)("div",{className:"py-0.5 px-3 flex items-center",children:(0,s.jsx)(eR,{ref:Z,checked:W.size===g.length&&g.length>0,onCheckedChange:eA,disabled:eO})})}),e_.map(e=>{var t;return(0,s.jsx)(e3,{width:eu[e.name]||150,onResize:t=>eg(e.name,t),className:"py-0.5 whitespace-nowrap border-r border-neutral-200",children:(0,s.jsxs)(te,{column:e.name,sortConfig:ec,onSort:eN,children:[(0,s.jsx)("span",{className:"text-xs font-bold text-foreground",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:null===(t=e.type)||void 0===t?void 0:t.toLowerCase()})]})},e.name)})]})}),(0,s.jsxs)(F,{children:[y&&(0,s.jsx)(D,{className:"hover:bg-transparent",children:(0,s.jsx)(z,{colSpan:e_.length+1,className:"h-[calc(100vh-200px)]",children:(0,s.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,s.jsx)(c.A,{className:"h-6 w-6 animate-spin text-primary"})})})}),!y&&(0,s.jsxs)(s.Fragment,{children:[V.map((e,t)=>(0,s.jsx)(e4,{schema:e_,onRemove:()=>eC(t),onChange:e=>eS(t,e)},"new-".concat(t))),0===g.length&&0===V.length?(0,s.jsx)(D,{className:"hover:bg-transparent",children:(0,s.jsx)(z,{colSpan:e_.length+1,className:"h-[calc(100vh-200px)] text-center text-muted-foreground",children:"Table is empty"})}):g.map((e,t)=>(0,s.jsxs)(D,{className:"".concat(W.has(t)?"bg-muted/50":""),children:[(0,s.jsx)(z,{className:"p-0",children:(0,s.jsx)("div",{className:"px-3 py-2.5 flex items-center",children:(0,s.jsx)(eR,{checked:W.has(t),onCheckedChange:e=>ek(t,e),disabled:eO})})}),e_.map(a=>{let l="".concat(t,"-").concat(a.name),n=A.get(l);return(0,s.jsx)(e$,{value:n?n.value:e[a.name],row:e,column:a.name,schema:N,onChange:e=>ew(t,a.name,e),onStartEdit:e=>ej(t,a.name,e),isEditing:A.has(l),style:{width:"".concat(eu[a.name]||150,"px")}},a.name)})]},t))]})]})]}),(0,s.jsx)(I,{orientation:"horizontal"})]})})})}),(0,s.jsx)(e2,{isOpen:$,onClose:()=>{ee(!1),el(null)},onConfirm:eT,selectedCount:W.size,tableName:t,isDeleting:et,error:es}),(0,s.jsx)(e5,{isOpen:en,onClose:()=>er(!1),error:ei,onOpenInSQL:()=>{er(!1)},onUpdateAnyway:async()=>{er(!1),await eE(!0)},showSQLOption:(null==ei?void 0:ei.type)==="NULLABLE_PK"})]})}var ta=a(2651);function ts(){let[e,t]=(0,l.useState)(null),[a,n]=(0,l.useState)(!0);return((0,l.useEffect)(()=>{"true"===localStorage.getItem("updateBannerDismissed")&&n(!1)},[]),(0,l.useEffect)(()=>{ta.A.get("/api/update").then(e=>{let{data:a}=e;(null==a?void 0:a.update)&&(t(a.update),n(!0))}).catch(console.error)},[]),e&&a)?(0,s.jsxs)("div",{className:"bg-gray-200 w-full px-3 py-3 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"text-gray-800",children:[(0,s.jsx)("strong",{children:"Update available!"})," You are on version ",e.current,"; version ",e.latest," is available. Run"," ",(0,s.jsx)("code",{className:"bg-white text-sm px-1 py-0.5 rounded",children:"npm install -g d1s@latest"})," ","to update."]}),(0,s.jsx)("button",{onClick:()=>{localStorage.setItem("updateBannerDismissed","true"),n(!1)},className:"ml-4 text-gray-500 hover:text-gray-700","aria-label":"Close update banner",children:"\xd7"})]}):null}function tl(){let[e,t]=(0,l.useState)("sql-editor"),[a,n]=(0,l.useState)(null);return(0,s.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,s.jsx)(ts,{}),(0,s.jsx)(en,{className:"w-64 border-r",currentView:e,onNavigate:t,onTableSelect:e=>{n(e),t("table-view")}}),(0,s.jsxs)("main",{className:"ml-64 h-screen",children:["sql-editor"===e&&(0,s.jsx)(eS,{}),"table-view"===e&&a&&(0,s.jsx)(tt,{tableName:a})]})]})}}},e=>{var t=t=>e(e.s=t);e.O(0,[692,958,735,441,517,358],()=>t(9017)),_N_E=e.O()}]);
|