nubot-lite 0.1.0 → 0.1.2
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/README.md +6 -5
- package/lib/api.mjs +6 -2
- package/lib/cloudflare.mjs +13 -12
- package/lib/commands/init.mjs +260 -251
- package/package.json +1 -1
- package/template/.claude/skills/nubot-lite/SKILL.md +7 -1
- package/template/panel/PANEL.md +1 -1
- package/template/panel/assets/AgendarDemoPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/{AgentDatasetsPage-D8vQhRWO.js → AgentDatasetsPage-wLtBtSB2.js} +2 -2
- package/template/panel/assets/AgentKnowledgeGroupsPage-BGHNFj-e.js +1 -0
- package/template/panel/assets/AgentListPage-F3ja9_o_.js +1 -0
- package/template/panel/assets/AgentQaTrainingPage-CojiU8_W.js +1 -0
- package/template/panel/assets/AiAgentWhatsappPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/BlogPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/BlogPostPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/CalculadoraTiempoRespuestaPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/{CampaignDetailPage-DFMctNEj.js → CampaignDetailPage-DUNnckvn.js} +1 -1
- package/template/panel/assets/CampaignsPage-CS60yZBd.js +1 -0
- package/template/panel/assets/ChannelSelector-C7R9zqrt.js +1 -0
- package/template/panel/assets/ChatbotParaWhatsappPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/ConfirmModal-B27OBQdm.js +1 -0
- package/template/panel/assets/ContactsPage-CvoDlFUN.js +14 -0
- package/template/panel/assets/CreateAgentPage-CbhikMY1.js +19 -0
- package/template/panel/assets/CreditLimitBanner-j72L7jgK.js +1 -0
- package/template/panel/assets/CrmParaWhatsappPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/DashboardPage-BGWkXY7W.js +1 -0
- package/template/panel/assets/{EmojiPicker-BToAe-MT.js → EmojiPicker-ByTMSXTj.js} +1 -1
- package/template/panel/assets/{EventTypesSettingsPage-DCedeQzM.js → EventTypesSettingsPage-CLpO1VBL.js} +1 -1
- package/template/panel/assets/GeneradorEnlacesPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/GeneradorQrWhatsappPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/{GeneralSettingsPage-B04ozcHb.js → GeneralSettingsPage-CY-5aGgL.js} +1 -1
- package/template/panel/assets/GoogleCalendarManagePage-oX7DuErV.js +1 -0
- package/template/panel/assets/{InvitationAcceptancePage-BPgtBFl5.js → InvitationAcceptancePage-BYllrAYs.js} +1 -1
- package/template/panel/assets/IrAlSitioPublico-Bn_BvTp1.js +1 -0
- package/template/panel/assets/LiteAiUsagePage-Dzm8jBL2.js +1 -0
- package/template/panel/assets/{LiteSetupPage-42rgAdnG.js → LiteSetupPage-CMSAur_e.js} +1 -1
- package/template/panel/assets/MarkdownRenderer-C3TD9KYa.js +3 -0
- package/template/panel/assets/MediaProcessingService-CG2DdSyN.js +1 -0
- package/template/panel/assets/NewCampaignPage-BfSEd075.js +1 -0
- package/template/panel/assets/OrdersConfigPage-BAKKaX0L.js +1 -0
- package/template/panel/assets/OrdersPage-CXiPOCXP.js +1 -0
- package/template/panel/assets/{PasswordStrengthIndicator-HZK_oU0W.js → PasswordStrengthIndicator-4h-Y0s2r.js} +1 -1
- package/template/panel/assets/PlantillaDetailPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/PlantillasIndexPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/PrivacyPolicy-Bn_BvTp1.js +1 -0
- package/template/panel/assets/{ProductManagementPage-DNM7DEgt.js → ProductManagementPage-CRkNTicv.js} +4 -4
- package/template/panel/assets/PublicFormPage-BxPxJ3Pq.js +1 -0
- package/template/panel/assets/QaForm-Px-cmakA.js +5 -0
- package/template/panel/assets/SelectPlanPage-Gyo5C1Hq.js +1 -0
- package/template/panel/assets/SignatureEditor-DIhmrXow.js +1 -0
- package/template/panel/assets/{TagSelector-ChoKzvjW.js → TagSelector-o6tVpRs9.js} +1 -1
- package/template/panel/assets/TagsSettingsPage-DT8MfW1H.js +2 -0
- package/template/panel/assets/TeamsPage-BuWuGxZo.js +1 -0
- package/template/panel/assets/WhatsappBusinessApiPage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/WhatsappMultiagentePage-Bn_BvTp1.js +1 -0
- package/template/panel/assets/{account-D2ltXC_U.js → account-G3WXxisG.js} +1 -1
- package/template/panel/assets/{admin-lEgqZTsa.js → admin-CSMlOMR8.js} +1 -1
- package/template/panel/assets/{agent.service-BcAkMU7j.js → agent.service-BE2rJG_o.js} +1 -1
- package/template/panel/assets/{alert-dialog-D8P69s-m.js → alert-dialog-gzZZoAiu.js} +2 -2
- package/template/panel/assets/{alert-DI3GBLi1.js → alert-seLKo73M.js} +1 -1
- package/template/panel/assets/api-keys-BF33GS2N.js +1 -0
- package/template/panel/assets/{archive-LUe5bKi5.js → archive-CxUKRJwu.js} +1 -1
- package/template/panel/assets/{arrow-left-BeDdBs_Q.js → arrow-left-CI7mH7bD.js} +1 -1
- package/template/panel/assets/{arrow-up-BiBq8Pvx.js → arrow-up-DJzXCc8_.js} +1 -1
- package/template/panel/assets/{arrow-up-down-CaG2BONN.js → arrow-up-down-DkSCsCjR.js} +1 -1
- package/template/panel/assets/audit-slljESxh.js +1 -0
- package/template/panel/assets/{authService-Cbm8LdlJ.js → authService-CtvlzCDa.js} +1 -1
- package/template/panel/assets/{avatar-CILB1zwS.js → avatar-BXhSKQGY.js} +1 -1
- package/template/panel/assets/{billing-IVLNopU2.js → billing-Cy2XUBeY.js} +1 -1
- package/template/panel/assets/{brain-B9z7jZ7A.js → brain-BmrjUpsb.js} +1 -1
- package/template/panel/assets/{calendar-CIHhMjNy.js → calendar-Bu0aDtW1.js} +1 -1
- package/template/panel/assets/{calendar-days-BwJfOz8M.js → calendar-days-CXtOZxOF.js} +1 -1
- package/template/panel/assets/{card-DcKsxjXK.js → card-DdbmSh-v.js} +1 -1
- package/template/panel/assets/{checkbox-pcbjC0d3.js → checkbox-CuJh5AMO.js} +1 -1
- package/template/panel/assets/{chevrons-up-down-DC-BWTrj.js → chevrons-up-down-DNNdNhV8.js} +1 -1
- package/template/panel/assets/{circle-check-big-DzPo5zZX.js → circle-check-big-BOZQ_2Kv.js} +1 -1
- package/template/panel/assets/{circle-x-BwMKIs8b.js → circle-x-decmm7ip.js} +1 -1
- package/template/panel/assets/cloud-B3m0_VpL.js +1 -0
- package/template/panel/assets/{code-BMAyHFJe.js → code-C-UH-ZD-.js} +1 -1
- package/template/panel/assets/{cog-M7j64wa2.js → cog-BS-_-U4F.js} +1 -1
- package/template/panel/assets/{collapsible-B22t1J-V.js → collapsible-Ce_8EeFJ.js} +1 -1
- package/template/panel/assets/{command-COdSmSIB.js → command-aHRTWaYV.js} +1 -1
- package/template/panel/assets/connectionsService-BJg4S1e9.js +1 -0
- package/template/panel/assets/contactsApi-DI5dcMLo.js +1 -0
- package/template/panel/assets/creditErrors-DSbswjsG.js +1 -0
- package/template/panel/assets/{database-C1qvt3Py.js → database-Brb7Omak.js} +1 -1
- package/template/panel/assets/{datapath-C12uI_pT.js → datapath-CHeKabeh.js} +1 -1
- package/template/panel/assets/{datetime-BuZosCVk.js → datetime-D72Uxhjs.js} +1 -1
- package/template/panel/assets/{download-CiVQHPeB.js → download-CyfdxFCW.js} +1 -1
- package/template/panel/assets/{ellipsis-CMEJnUfK.js → ellipsis-GLu0u4ze.js} +1 -1
- package/template/panel/assets/{ellipsis-vertical-DTqbEYYp.js → ellipsis-vertical-CskGwbgN.js} +1 -1
- package/template/panel/assets/email-inbox-kyJ2qML5.js +1 -0
- package/template/panel/assets/es-BDgg6unH.js +1 -0
- package/template/panel/assets/external-link-w7K66ae2.js +1 -0
- package/template/panel/assets/{eye-HfQCUjxJ.js → eye-CR5C6hVv.js} +1 -1
- package/template/panel/assets/{eye-off-v1Z_lKS0.js → eye-off-CBiJXw4j.js} +1 -1
- package/template/panel/assets/facebook-D0SQMea2.js +1 -0
- package/template/panel/assets/{file-DMzjdlTL.js → file-CTZ8-xmL.js} +1 -1
- package/template/panel/assets/file-braces-54MsOnzo.js +1 -0
- package/template/panel/assets/file-spreadsheet-DpekIaV8.js +1 -0
- package/template/panel/assets/{folder-D0GKakGp.js → folder-DxTHNhQ_.js} +1 -1
- package/template/panel/assets/{folder-open-DQFc4qTJ.js → folder-open-BM4rA96e.js} +1 -1
- package/template/panel/assets/format-BG1mN6C0.js +1 -0
- package/template/panel/assets/{grip-vertical-FN-eTC2C.js → grip-vertical-CS-dU0tJ.js} +1 -1
- package/template/panel/assets/{hash-BoTE56iw.js → hash-ByrjK6gt.js} +1 -1
- package/template/panel/assets/{help-center-B1MAIBWA.js → help-center-fmvvoAkD.js} +1 -1
- package/template/panel/assets/{history-DhHayxUg.js → history-97D1GT_9.js} +1 -1
- package/template/panel/assets/house-CXew5LB-.js +1 -0
- package/template/panel/assets/{index-DsyZ_FlA.js → index-43NA2pdZ.js} +23 -23
- package/template/panel/assets/index-BG59-Kyv.js +6 -0
- package/template/panel/assets/{index-DUnioqCT.js → index-BGvtgHY3.js} +1 -1
- package/template/panel/assets/index-BL76lyPt.js +2 -0
- package/template/panel/assets/index-BUA9lP4J.js +1 -0
- package/template/panel/assets/index-Bfvq4Q3v.js +1 -0
- package/template/panel/assets/index-CK793Wzl.css +1 -0
- package/template/panel/assets/{index-BTxe6gLJ.js → index-ChrvveQm.js} +1 -1
- package/template/panel/assets/index-CoJIvJ6y.js +1 -0
- package/template/panel/assets/{index-CMEeV9dO.js → index-CsV1u-Y7.js} +2 -2
- package/template/panel/assets/{index-BiSc3WD9.js → index-DIxON2Dm.js} +1 -1
- package/template/panel/assets/index-DtoSJTyl.js +1 -0
- package/template/panel/assets/index-FBuxpbGF.js +36 -0
- package/template/panel/assets/index-YR5X3nd4.js +1 -0
- package/template/panel/assets/{instagram-CC7iYt7V.js → instagram-Bm17x-Fs.js} +1 -1
- package/template/panel/assets/interactiveLimits-C7Sx7s9W.js +1 -0
- package/template/panel/assets/landing-CEUFhLJ9.js +1 -0
- package/template/panel/assets/{layout-grid-Cm6hfBWZ.js → layout-grid-DN-t2Wjd.js} +1 -1
- package/template/panel/assets/{list-BKc6EXnV.js → list-B0uLKf1b.js} +1 -1
- package/template/panel/assets/{map-pin-CPmcofD3.js → map-pin-COYHwobx.js} +1 -1
- package/template/panel/assets/{maximize-2-WdbM7Kdx.js → maximize-2-SbmXBBYe.js} +1 -1
- package/template/panel/assets/mediaLimits-CAYdWqeQ.js +1 -0
- package/template/panel/assets/mediaValidation-Bg0xHQrv.js +1 -0
- package/template/panel/assets/message-circle-tNSzOeOW.js +1 -0
- package/template/panel/assets/{message-square-Dfn16oHc.js → message-square-B1_OirdW.js} +1 -1
- package/template/panel/assets/{meta-templates-C7yEjSOI.js → meta-templates-hhDdxBOR.js} +1 -1
- package/template/panel/assets/metadataSchemasApi-BmJko2eC.js +1 -0
- package/template/panel/assets/{mic-CT4vyzLZ.js → mic-ClFq9hMZ.js} +1 -1
- package/template/panel/assets/minus-vh4a51Mn.js +1 -0
- package/template/panel/assets/{music-Cu8AQMFp.js → music-CgtkroYi.js} +1 -1
- package/template/panel/assets/{page-components-o2TF52HV.js → page-components-DXOKtt_M.js} +1 -1
- package/template/panel/assets/{pages-Cj5Qd1QO.js → pages-BcYbyh_-.js} +1 -1
- package/template/panel/assets/{pages-B7digtXi.js → pages-BuibyrnC.js} +1 -1
- package/template/panel/assets/{pages-Dw7dvmaS.js → pages-CGXCBdff.js} +1 -1
- package/template/panel/assets/paperclip-DVRbzE7C.js +1 -0
- package/template/panel/assets/{pen-line-DLnhkIuw.js → pen-line-Cr0YFjAs.js} +1 -1
- package/template/panel/assets/{pencil-Cx8u1N8t.js → pencil-aqjc7AWb.js} +1 -1
- package/template/panel/assets/{popover-MyuU-yAK.js → popover-cWIhNmod.js} +1 -1
- package/template/panel/assets/{power-CdR2OkIX.js → power-CVFzhVJx.js} +1 -1
- package/template/panel/assets/{product.service-CRLZOQsr.js → product.service-FClit10f.js} +1 -1
- package/template/panel/assets/products.types-nZIsk2w8.js +1 -0
- package/template/panel/assets/proxy-CvX2KM2u.js +1 -0
- package/template/panel/assets/{save-Dua2yhWl.js → save-mwkHDnDL.js} +1 -1
- package/template/panel/assets/scroll-area-CSCo4HHB.js +1 -0
- package/template/panel/assets/{select-DlB_BbfM.js → select-DCY_lg9j.js} +1 -1
- package/template/panel/assets/{send-Dxmdupsl.js → send-DBQH77K9.js} +1 -1
- package/template/panel/assets/{separator-CPT3uVRM.js → separator-DznqP68l.js} +1 -1
- package/template/panel/assets/{settings-2-C-c8ECWW.js → settings-2-PhKPMrsj.js} +1 -1
- package/template/panel/assets/shield-alert-Fv3j9Wbv.js +1 -0
- package/template/panel/assets/{skeleton-B0zh8s_y.js → skeleton-CN6xlRXP.js} +1 -1
- package/template/panel/assets/{slider-CY71MXOW.js → slider-D0QB_Lme.js} +1 -1
- package/template/panel/assets/{square-BuGqLxJB.js → square-Dm5VC71z.js} +1 -1
- package/template/panel/assets/{square-pen-CJajoyrm.js → square-pen-Dbn7xmc-.js} +1 -1
- package/template/panel/assets/{star-Cuegk1GF.js → star-BMD3HmS6.js} +1 -1
- package/template/panel/assets/stat-card-W7s_-fHW.js +1 -0
- package/template/panel/assets/storage.api-C0ZJBoSz.js +20 -0
- package/template/panel/assets/{switch-ODBa0fCT.js → switch-C7XmAU1c.js} +1 -1
- package/template/panel/assets/{table-CvSELOPi.js → table-7NGq0kRw.js} +1 -1
- package/template/panel/assets/{tabs-DqXhuAr6.js → tabs-BGCKrmVw.js} +1 -1
- package/template/panel/assets/{tags-By_tlh_r.js → tags-HU2fuPFH.js} +1 -1
- package/template/panel/assets/{target-DEuCdeUI.js → target-CG_g4_Fj.js} +1 -1
- package/template/panel/assets/{textarea-BYtcLsMD.js → textarea-B1anutjq.js} +1 -1
- package/template/panel/assets/{ticket-CWba7G1i.js → ticket-CHs1Xojr.js} +1 -1
- package/template/panel/assets/{trash-2-Du2vmQCH.js → trash-2-D_kmHMwn.js} +1 -1
- package/template/panel/assets/{trending-up-Ba4HSvuW.js → trending-up-BnHeLWFs.js} +1 -1
- package/template/panel/assets/{upload-C7TwpdyA.js → upload-CQg4_W5r.js} +1 -1
- package/template/panel/assets/{useAiAgentsQuery-Bm6aRHKj.js → useAiAgentsQuery-CXo6TmU6.js} +1 -1
- package/template/panel/assets/useFunnelStats-Bk8wTET5.js +1 -0
- package/template/panel/assets/useFunnelsQuery-vDrahaDr.js +1 -0
- package/template/panel/assets/{useInfiniteQuery-BXUM1Z9V.js → useInfiniteQuery-D0sFT2K2.js} +1 -1
- package/template/panel/assets/{useMutation-a5tIBvQY.js → useMutation-0ypmz8SO.js} +1 -1
- package/template/panel/assets/useOrgSyncedFetch-FSgwRhpR.js +1 -0
- package/template/panel/assets/usePipelineBoardQuery-BysscZXI.js +9 -0
- package/template/panel/assets/{useUploadConfig-BuiF0X-3.js → useUploadConfig-CvVmSc6S.js} +1 -1
- package/template/panel/assets/{user-DwCALzIG.js → user-l48WDfDH.js} +1 -1
- package/template/panel/assets/{user-plus-BiUjcHil.js → user-plus-CWaaUP-O.js} +1 -1
- package/template/panel/assets/{video-VfwKgB6z.js → video-CILE66CA.js} +1 -1
- package/template/panel/assets/{volume-2-C5DMdOVq.js → volume-2-DfFqN0dw.js} +1 -1
- package/template/panel/assets/wrench-Dcbk4scY.js +1 -0
- package/template/panel/index.html +2 -2
- package/template/panel/version.json +2 -2
- package/template/worker/migrations/0006_ai_usage.sql +33 -0
- package/template/worker/migrations/0007_channels.sql +18 -0
- package/template/worker/src/agent/pricing.ts +37 -0
- package/template/worker/src/agent/prompt.ts +137 -134
- package/template/worker/src/agent/run.ts +350 -243
- package/template/worker/src/agent/sandbox.ts +2 -2
- package/template/worker/src/agent/tools.ts +463 -463
- package/template/worker/src/channels/accounts.ts +177 -0
- package/template/worker/src/channels/zernio.ts +161 -148
- package/template/worker/src/inbox/contacts.ts +2 -0
- package/template/worker/src/inbox/store.ts +199 -187
- package/template/worker/src/index.ts +2 -0
- package/template/worker/src/nubot/account.ts +163 -178
- package/template/worker/src/nubot/ai-usage.ts +197 -0
- package/template/worker/src/nubot/channels.ts +159 -0
- package/template/worker/src/nubot/contacts.ts +387 -386
- package/template/worker/src/nubot/funnels.ts +672 -670
- package/template/worker/src/nubot/inbox.ts +623 -616
- package/template/worker/src/nubot/index.ts +127 -122
- package/template/worker/src/nubot/mappers.ts +12 -5
- package/template/worker/src/routes/channels.ts +13 -0
- package/template/worker/src/routes/system.ts +110 -100
- package/template/worker/src/webhooks/zernio.ts +154 -125
- package/template/panel/assets/AgendarDemoPage-DOiS40FL.js +0 -1
- package/template/panel/assets/AgentKnowledgeGroupsPage-DEPS1lsk.js +0 -1
- package/template/panel/assets/AgentListPage-DqY9rze5.js +0 -1
- package/template/panel/assets/AgentQaTrainingPage-Ecis7xoc.js +0 -1
- package/template/panel/assets/AiAgentWhatsappPage-DOiS40FL.js +0 -1
- package/template/panel/assets/AiMetricsPage-DEPS1lsk.js +0 -1
- package/template/panel/assets/BlogPage-DOiS40FL.js +0 -1
- package/template/panel/assets/BlogPostPage-DOiS40FL.js +0 -1
- package/template/panel/assets/CalculadoraTiempoRespuestaPage-DOiS40FL.js +0 -1
- package/template/panel/assets/CampaignsPage-CLRaXGlj.js +0 -1
- package/template/panel/assets/ChannelSelector-q9tTirNo.js +0 -1
- package/template/panel/assets/ChatbotParaWhatsappPage-DOiS40FL.js +0 -1
- package/template/panel/assets/ConfirmModal-W7VUI3Z_.js +0 -1
- package/template/panel/assets/ContactsPage-CsOFsOPw.js +0 -14
- package/template/panel/assets/CreateAgentPage-Ifxx6_UX.js +0 -19
- package/template/panel/assets/CreditLimitBanner-J49rSVEn.js +0 -1
- package/template/panel/assets/CrmParaWhatsappPage-DOiS40FL.js +0 -1
- package/template/panel/assets/DashboardPage-3Viy83dd.js +0 -1
- package/template/panel/assets/GeneradorEnlacesPage-DOiS40FL.js +0 -1
- package/template/panel/assets/GeneradorQrWhatsappPage-DOiS40FL.js +0 -1
- package/template/panel/assets/IrAlSitioPublico-DOiS40FL.js +0 -1
- package/template/panel/assets/MediaProcessingService-glHGiE_o.js +0 -1
- package/template/panel/assets/NewCampaignPage-Cw99m3W8.js +0 -1
- package/template/panel/assets/OrdersConfigPage-B6BfM3lf.js +0 -1
- package/template/panel/assets/OrdersPage-Du7CJjty.js +0 -1
- package/template/panel/assets/PlantillaDetailPage-DOiS40FL.js +0 -1
- package/template/panel/assets/PlantillasIndexPage-DOiS40FL.js +0 -1
- package/template/panel/assets/PrivacyPolicy-DOiS40FL.js +0 -1
- package/template/panel/assets/PublicFormPage-DDb4OXEM.js +0 -1
- package/template/panel/assets/QaForm-BDboHNKo.js +0 -5
- package/template/panel/assets/SelectPlanPage-DALaf8E5.js +0 -1
- package/template/panel/assets/TagsSettingsPage-DYCKveQq.js +0 -2
- package/template/panel/assets/TeamsPage-DPUcRdlh.js +0 -1
- package/template/panel/assets/WhatsappBusinessApiPage-DOiS40FL.js +0 -1
- package/template/panel/assets/WhatsappMultiagentePage-DOiS40FL.js +0 -1
- package/template/panel/assets/api-keys-B0UQNR5E.js +0 -1
- package/template/panel/assets/audit-BrdHcTNl.js +0 -1
- package/template/panel/assets/connections-Dqwd01UI.js +0 -1
- package/template/panel/assets/connectionsService-BsJf8pFz.js +0 -3
- package/template/panel/assets/contactsApi-B851NME_.js +0 -1
- package/template/panel/assets/creditErrors-CrpkwwUI.js +0 -1
- package/template/panel/assets/email-inbox-LbGeQCty.js +0 -1
- package/template/panel/assets/es-BG480iA5.js +0 -1
- package/template/panel/assets/facebook-RxMBweMB.js +0 -1
- package/template/panel/assets/index-B183O0S5.js +0 -1
- package/template/panel/assets/index-BJCPaymI.css +0 -1
- package/template/panel/assets/index-BtxJGfLL.js +0 -6
- package/template/panel/assets/index-Bz-ixwph.js +0 -1
- package/template/panel/assets/index-CjQSv8hF.js +0 -2
- package/template/panel/assets/index-D3vkHHjD.js +0 -9
- package/template/panel/assets/index-D4WhIkMN.js +0 -1
- package/template/panel/assets/interactiveLimits-CfLJ1O4_.js +0 -1
- package/template/panel/assets/landing-If3oVsS0.js +0 -1
- package/template/panel/assets/mediaValidation-BR-ZOj5w.js +0 -1
- package/template/panel/assets/minus-CyVEzdqL.js +0 -1
- package/template/panel/assets/products.types-46xSxBS8.js +0 -1
- package/template/panel/assets/scroll-area-CavEOIyz.js +0 -1
- package/template/panel/assets/shield-alert-04pSYngI.js +0 -1
- package/template/panel/assets/storage.api-CFU3KJNp.js +0 -20
- package/template/panel/assets/useFunnelStats-tvjpmWIC.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{c as $t,j as t,l as le,h as Os,au as an,P as Lt,t as ne,Q as wi,a3 as nn,bu as ji,B as ue,a4 as on,a5 as ki,a6 as ln,a7 as cn,z as sr,aa as dn,Z as Wr,X as Ft,o as be,a2 as Kt,C as Dt,y as ct,aB as br,av as dt,r as Ce,aC as ra,aG as un,ac as _i,a0 as Ar,T as et,v as tt,x as rt,g as ur,i as Ke,k as hn,af as jr,bv as mn,ag as kr,ah as _r,ai as Nr,G as fn,aj as Kr,D as Pr,n as yt,I as st,R as hr,$ as Fr,ak as Dr,F as sa,ae as it,H as ss,an as pn,ao as xn,ap as gn,aq as bn,ar as Gr,as as It,d as Ts,Y as Sr,q as Ni,a as Si,S as Ci,w as zi,aV as fs,ab as ps}from"./index-DsyZ_FlA.js";import{b as Y,m as Rr,k as Ei,R as Xe}from"./recharts-DrC5kNsx.js";import{P as Ii,a as Ai,b as Pi}from"./page-components-o2TF52HV.js";import{T as vn}from"./textarea-BYtcLsMD.js";import{S as at}from"./skeleton-B0zh8s_y.js";import{u as aa}from"./index-CCTahcpv.js";import{S as ar,a as nr,b as ir,c as or,d as kt,C as yn}from"./select-DlB_BbfM.js";import{C as Rs,a as Zs,b as Fi,c as Di}from"./card-DcKsxjXK.js";import{u as Oi,C as Hr,a as na}from"./index-BTxe6gLJ.js";import{T as Qr,a as Yr,b as lr,c as De,d as wn,e as ut}from"./table-CvSELOPi.js";import{p as we}from"./product.service-CRLZOQsr.js";import{read as Ti,utils as Ri}from"./xlsx-BvJTHLik.js";import{b as jn,a as kn,C as Zi,M as _n,S as Nn,F as $i}from"./products.types-46xSxBS8.js";import{h as Li,I as vr,m as Cs}from"./MediaProcessingService-glHGiE_o.js";import{g as Sn,c as Ui,s as Bi}from"./storage.api-CFU3KJNp.js";import{I as At,V as Cn}from"./video-VfwKgB6z.js";import{D as Ot}from"./database-C1qvt3Py.js";import{R as Mi}from"./index-DUnioqCT.js";import{A as Gt,b as Ht,c as Qt,d as Yt,e as Xt,f as Jt,g as er,h as tr}from"./alert-dialog-D8P69s-m.js";import{u as Ge}from"./useMutation-a5tIBvQY.js";import{a as as}from"./datetime-BuZosCVk.js";import{T as bt}from"./trash-2-Du2vmQCH.js";import{U as ia}from"./upload-C7TwpdyA.js";import{F as zn}from"./file-DMzjdlTL.js";import{M as En}from"./music-Cu8AQMFp.js";import{H as In}from"./hash-BoTE56iw.js";import{S as An}from"./save-Dua2yhWl.js";import{C as oa}from"./checkbox-pcbjC0d3.js";import{E as Pn}from"./ellipsis-CMEJnUfK.js";import{E as Fn}from"./eye-HfQCUjxJ.js";import{P as $s}from"./pencil-Cx8u1N8t.js";import{E as Cr}from"./eye-off-v1Z_lKS0.js";import{a as Vi,A as qi}from"./arrow-up-BiBq8Pvx.js";import{A as Wi}from"./arrow-up-down-CaG2BONN.js";import{C as Ki}from"./calendar-CIHhMjNy.js";import{M as Dn}from"./maximize-2-WdbM7Kdx.js";import{S as Gi}from"./slider-CY71MXOW.js";import{C as Hi,a as Qi,b as Yi}from"./collapsible-B22t1J-V.js";import{T as Xi,c as xs}from"./tabs-DqXhuAr6.js";import{u as Ji}from"./useDebounce-Bfcb_jpD.js";import{D as eo}from"./download-CiVQHPeB.js";import{L as to,S as ro}from"./star-Cuegk1GF.js";import{L as so}from"./list-BKc6EXnV.js";import"./index-KbFmSzBE.js";import"./index-CEYKqxbU.js";const ao=[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0",key:"5ilxe3"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0",key:"11zvb9"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7",key:"1iw5b2"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8",key:"c0bmvh"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69",key:"1ruxm7"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8",key:"qkgqxc"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69",key:"1mcia2"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7",key:"1fvljs"}]],no=$t("circle-dashed",ao);const io=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],cr=$t("dollar-sign",io);const oo=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]],lo=$t("file-spreadsheet",oo);const co=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],On=$t("image-off",co);const uo=[["path",{d:"m16 16 2 2 4-4",key:"gfu2re"}],["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}]],ho=$t("package-check",uo);const mo=[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],fo=$t("radio",mo);const po=[["circle",{cx:"15",cy:"12",r:"3",key:"1afu0r"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],Ls=$t("toggle-right",po),qr=Y.forwardRef(({className:e,value:r=0,max:s=100,...a},n)=>{const i=Math.min(Math.max(r/s*100,0),100);return t.jsx("div",{ref:n,role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":s,className:le("relative h-2 w-full overflow-hidden rounded-full bg-secondary",e),...a,children:t.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-out",style:{width:`${i}%`}})})});qr.displayName="Progress";function zr(e,r){if(e==null)return"—";const s=typeof e=="string"?parseFloat(e):e;if(isNaN(s))return"—";const a=(r||"USD").toUpperCase();return a==="COP"?`${s.toFixed(3)} COP`:`${a} ${s.toFixed(2)}`}function Zr(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var gs={exports:{}};var la;function xo(){return la||(la=1,(function(e,r){(function(s){e.exports=s()})(function(){return(function s(a,n,i){function o(p,_){if(!n[p]){if(!a[p]){var w=typeof Zr=="function"&&Zr;if(!_&&w)return w(p,!0);if(l)return l(p,!0);var g=new Error("Cannot find module '"+p+"'");throw g.code="MODULE_NOT_FOUND",g}var d=n[p]={exports:{}};a[p][0].call(d.exports,function(k){var u=a[p][1][k];return o(u||k)},d,d.exports,s,a,n,i)}return n[p].exports}for(var l=typeof Zr=="function"&&Zr,h=0;h<i.length;h++)o(i[h]);return o})({1:[function(s,a,n){var i=s("./utils"),o=s("./support"),l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.encode=function(h){for(var p,_,w,g,d,k,u,x=[],f=0,j=h.length,E=j,P=i.getTypeOf(h)!=="string";f<h.length;)E=j-f,w=P?(p=h[f++],_=f<j?h[f++]:0,f<j?h[f++]:0):(p=h.charCodeAt(f++),_=f<j?h.charCodeAt(f++):0,f<j?h.charCodeAt(f++):0),g=p>>2,d=(3&p)<<4|_>>4,k=1<E?(15&_)<<2|w>>6:64,u=2<E?63&w:64,x.push(l.charAt(g)+l.charAt(d)+l.charAt(k)+l.charAt(u));return x.join("")},n.decode=function(h){var p,_,w,g,d,k,u=0,x=0,f="data:";if(h.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var j,E=3*(h=h.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(h.charAt(h.length-1)===l.charAt(64)&&E--,h.charAt(h.length-2)===l.charAt(64)&&E--,E%1!=0)throw new Error("Invalid base64 input, bad content length.");for(j=o.uint8array?new Uint8Array(0|E):new Array(0|E);u<h.length;)p=l.indexOf(h.charAt(u++))<<2|(g=l.indexOf(h.charAt(u++)))>>4,_=(15&g)<<4|(d=l.indexOf(h.charAt(u++)))>>2,w=(3&d)<<6|(k=l.indexOf(h.charAt(u++))),j[x++]=p,d!==64&&(j[x++]=_),k!==64&&(j[x++]=w);return j}},{"./support":30,"./utils":32}],2:[function(s,a,n){var i=s("./external"),o=s("./stream/DataWorker"),l=s("./stream/Crc32Probe"),h=s("./stream/DataLengthProbe");function p(_,w,g,d,k){this.compressedSize=_,this.uncompressedSize=w,this.crc32=g,this.compression=d,this.compressedContent=k}p.prototype={getContentWorker:function(){var _=new o(i.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new h("data_length")),w=this;return _.on("end",function(){if(this.streamInfo.data_length!==w.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),_},getCompressedWorker:function(){return new o(i.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},p.createWorkerFrom=function(_,w,g){return _.pipe(new l).pipe(new h("uncompressedSize")).pipe(w.compressWorker(g)).pipe(new h("compressedSize")).withStreamInfo("compression",w)},a.exports=p},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(s,a,n){var i=s("./stream/GenericWorker");n.STORE={magic:"\0\0",compressWorker:function(){return new i("STORE compression")},uncompressWorker:function(){return new i("STORE decompression")}},n.DEFLATE=s("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(s,a,n){var i=s("./utils"),o=(function(){for(var l,h=[],p=0;p<256;p++){l=p;for(var _=0;_<8;_++)l=1&l?3988292384^l>>>1:l>>>1;h[p]=l}return h})();a.exports=function(l,h){return l!==void 0&&l.length?i.getTypeOf(l)!=="string"?(function(p,_,w,g){var d=o,k=g+w;p^=-1;for(var u=g;u<k;u++)p=p>>>8^d[255&(p^_[u])];return-1^p})(0|h,l,l.length,0):(function(p,_,w,g){var d=o,k=g+w;p^=-1;for(var u=g;u<k;u++)p=p>>>8^d[255&(p^_.charCodeAt(u))];return-1^p})(0|h,l,l.length,0):0}},{"./utils":32}],5:[function(s,a,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(s,a,n){var i=null;i=typeof Promise<"u"?Promise:s("lie"),a.exports={Promise:i}},{lie:37}],7:[function(s,a,n){var i=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",o=s("pako"),l=s("./utils"),h=s("./stream/GenericWorker"),p=i?"uint8array":"array";function _(w,g){h.call(this,"FlateWorker/"+w),this._pako=null,this._pakoAction=w,this._pakoOptions=g,this.meta={}}n.magic="\b\0",l.inherits(_,h),_.prototype.processChunk=function(w){this.meta=w.meta,this._pako===null&&this._createPako(),this._pako.push(l.transformTo(p,w.data),!1)},_.prototype.flush=function(){h.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},_.prototype.cleanUp=function(){h.prototype.cleanUp.call(this),this._pako=null},_.prototype._createPako=function(){this._pako=new o[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var w=this;this._pako.onData=function(g){w.push({data:g,meta:w.meta})}},n.compressWorker=function(w){return new _("Deflate",w)},n.uncompressWorker=function(){return new _("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(s,a,n){function i(d,k){var u,x="";for(u=0;u<k;u++)x+=String.fromCharCode(255&d),d>>>=8;return x}function o(d,k,u,x,f,j){var E,P,S=d.file,B=d.compression,U=j!==p.utf8encode,$=l.transformTo("string",j(S.name)),T=l.transformTo("string",p.utf8encode(S.name)),G=S.comment,se=l.transformTo("string",j(G)),v=l.transformTo("string",p.utf8encode(G)),R=T.length!==S.name.length,m=v.length!==G.length,V="",ie="",q="",ce=S.dir,F=S.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};k&&!u||(ee.crc32=d.crc32,ee.compressedSize=d.compressedSize,ee.uncompressedSize=d.uncompressedSize);var O=0;k&&(O|=8),U||!R&&!m||(O|=2048);var L=0,ae=0;ce&&(L|=16),f==="UNIX"?(ae=798,L|=(function(J,ve){var Se=J;return J||(Se=ve?16893:33204),(65535&Se)<<16})(S.unixPermissions,ce)):(ae=20,L|=(function(J){return 63&(J||0)})(S.dosPermissions)),E=F.getUTCHours(),E<<=6,E|=F.getUTCMinutes(),E<<=5,E|=F.getUTCSeconds()/2,P=F.getUTCFullYear()-1980,P<<=4,P|=F.getUTCMonth()+1,P<<=5,P|=F.getUTCDate(),R&&(ie=i(1,1)+i(_($),4)+T,V+="up"+i(ie.length,2)+ie),m&&(q=i(1,1)+i(_(se),4)+v,V+="uc"+i(q.length,2)+q);var te="";return te+=`
|
|
2
|
-
\0`,te+=i(O,2),te+=B.magic,te+=i(E,2),te+=i(P,2),te+=i(ee.crc32,4),te+=i(ee.compressedSize,4),te+=i(ee.uncompressedSize,4),te+=i($.length,2),te+=i(V.length,2),{fileRecord:w.LOCAL_FILE_HEADER+te+$+V,dirRecord:w.CENTRAL_FILE_HEADER+i(ae,2)+te+i(se.length,2)+"\0\0\0\0"+i(L,4)+i(x,4)+$+V+se}}var l=s("../utils"),h=s("../stream/GenericWorker"),p=s("../utf8"),_=s("../crc32"),w=s("../signature");function g(d,k,u,x){h.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=k,this.zipPlatform=u,this.encodeFileName=x,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}l.inherits(g,h),g.prototype.push=function(d){var k=d.meta.percent||0,u=this.entriesCount,x=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,h.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:u?(k+100*(u-x-1))/u:100}}))},g.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var k=this.streamFiles&&!d.file.dir;if(k){var u=o(d,k,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:u.fileRecord,meta:{percent:0}})}else this.accumulate=!0},g.prototype.closedSource=function(d){this.accumulate=!1;var k=this.streamFiles&&!d.file.dir,u=o(d,k,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(u.dirRecord),k)this.push({data:(function(x){return w.DATA_DESCRIPTOR+i(x.crc32,4)+i(x.compressedSize,4)+i(x.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:u.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},g.prototype.flush=function(){for(var d=this.bytesWritten,k=0;k<this.dirRecords.length;k++)this.push({data:this.dirRecords[k],meta:{percent:100}});var u=this.bytesWritten-d,x=(function(f,j,E,P,S){var B=l.transformTo("string",S(P));return w.CENTRAL_DIRECTORY_END+"\0\0\0\0"+i(f,2)+i(f,2)+i(j,4)+i(E,4)+i(B.length,2)+B})(this.dirRecords.length,u,d,this.zipComment,this.encodeFileName);this.push({data:x,meta:{percent:100}})},g.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},g.prototype.registerPrevious=function(d){this._sources.push(d);var k=this;return d.on("data",function(u){k.processChunk(u)}),d.on("end",function(){k.closedSource(k.previous.streamInfo),k._sources.length?k.prepareNextSource():k.end()}),d.on("error",function(u){k.error(u)}),this},g.prototype.resume=function(){return!!h.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},g.prototype.error=function(d){var k=this._sources;if(!h.prototype.error.call(this,d))return!1;for(var u=0;u<k.length;u++)try{k[u].error(d)}catch{}return!0},g.prototype.lock=function(){h.prototype.lock.call(this);for(var d=this._sources,k=0;k<d.length;k++)d[k].lock()},a.exports=g},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(s,a,n){var i=s("../compressions"),o=s("./ZipFileWorker");n.generateWorker=function(l,h,p){var _=new o(h.streamFiles,p,h.platform,h.encodeFileName),w=0;try{l.forEach(function(g,d){w++;var k=(function(j,E){var P=j||E,S=i[P];if(!S)throw new Error(P+" is not a valid compression method !");return S})(d.options.compression,h.compression),u=d.options.compressionOptions||h.compressionOptions||{},x=d.dir,f=d.date;d._compressWorker(k,u).withStreamInfo("file",{name:g,dir:x,date:f,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(_)}),_.entriesCount=w}catch(g){_.error(g)}return _}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(s,a,n){function i(){if(!(this instanceof i))return new i;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var o=new i;for(var l in this)typeof this[l]!="function"&&(o[l]=this[l]);return o}}(i.prototype=s("./object")).loadAsync=s("./load"),i.support=s("./support"),i.defaults=s("./defaults"),i.version="3.10.1",i.loadAsync=function(o,l){return new i().loadAsync(o,l)},i.external=s("./external"),a.exports=i},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(s,a,n){var i=s("./utils"),o=s("./external"),l=s("./utf8"),h=s("./zipEntries"),p=s("./stream/Crc32Probe"),_=s("./nodejsUtils");function w(g){return new o.Promise(function(d,k){var u=g.decompressed.getContentWorker().pipe(new p);u.on("error",function(x){k(x)}).on("end",function(){u.streamInfo.crc32!==g.decompressed.crc32?k(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}a.exports=function(g,d){var k=this;return d=i.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:l.utf8decode}),_.isNode&&_.isStream(g)?o.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):i.prepareContent("the loaded zip file",g,!0,d.optimizedBinaryString,d.base64).then(function(u){var x=new h(d);return x.load(u),x}).then(function(u){var x=[o.Promise.resolve(u)],f=u.files;if(d.checkCRC32)for(var j=0;j<f.length;j++)x.push(w(f[j]));return o.Promise.all(x)}).then(function(u){for(var x=u.shift(),f=x.files,j=0;j<f.length;j++){var E=f[j],P=E.fileNameStr,S=i.resolve(E.fileNameStr);k.file(S,E.decompressed,{binary:!0,optimizedBinaryString:!0,date:E.date,dir:E.dir,comment:E.fileCommentStr.length?E.fileCommentStr:null,unixPermissions:E.unixPermissions,dosPermissions:E.dosPermissions,createFolders:d.createFolders}),E.dir||(k.file(S).unsafeOriginalName=P)}return x.zipComment.length&&(k.comment=x.zipComment),k})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(s,a,n){var i=s("../utils"),o=s("../stream/GenericWorker");function l(h,p){o.call(this,"Nodejs stream input adapter for "+h),this._upstreamEnded=!1,this._bindStream(p)}i.inherits(l,o),l.prototype._bindStream=function(h){var p=this;(this._stream=h).pause(),h.on("data",function(_){p.push({data:_,meta:{percent:0}})}).on("error",function(_){p.isPaused?this.generatedError=_:p.error(_)}).on("end",function(){p.isPaused?p._upstreamEnded=!0:p.end()})},l.prototype.pause=function(){return!!o.prototype.pause.call(this)&&(this._stream.pause(),!0)},l.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},a.exports=l},{"../stream/GenericWorker":28,"../utils":32}],13:[function(s,a,n){var i=s("readable-stream").Readable;function o(l,h,p){i.call(this,h),this._helper=l;var _=this;l.on("data",function(w,g){_.push(w)||_._helper.pause(),p&&p(g)}).on("error",function(w){_.emit("error",w)}).on("end",function(){_.push(null)})}s("../utils").inherits(o,i),o.prototype._read=function(){this._helper.resume()},a.exports=o},{"../utils":32,"readable-stream":16}],14:[function(s,a,n){a.exports={isNode:typeof Buffer<"u",newBufferFrom:function(i,o){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(i,o);if(typeof i=="number")throw new Error('The "data" argument must not be a number');return new Buffer(i,o)},allocBuffer:function(i){if(Buffer.alloc)return Buffer.alloc(i);var o=new Buffer(i);return o.fill(0),o},isBuffer:function(i){return Buffer.isBuffer(i)},isStream:function(i){return i&&typeof i.on=="function"&&typeof i.pause=="function"&&typeof i.resume=="function"}}},{}],15:[function(s,a,n){function i(S,B,U){var $,T=l.getTypeOf(B),G=l.extend(U||{},_);G.date=G.date||new Date,G.compression!==null&&(G.compression=G.compression.toUpperCase()),typeof G.unixPermissions=="string"&&(G.unixPermissions=parseInt(G.unixPermissions,8)),G.unixPermissions&&16384&G.unixPermissions&&(G.dir=!0),G.dosPermissions&&16&G.dosPermissions&&(G.dir=!0),G.dir&&(S=f(S)),G.createFolders&&($=x(S))&&j.call(this,$,!0);var se=T==="string"&&G.binary===!1&&G.base64===!1;U&&U.binary!==void 0||(G.binary=!se),(B instanceof w&&B.uncompressedSize===0||G.dir||!B||B.length===0)&&(G.base64=!1,G.binary=!0,B="",G.compression="STORE",T="string");var v=null;v=B instanceof w||B instanceof h?B:k.isNode&&k.isStream(B)?new u(S,B):l.prepareContent(S,B,G.binary,G.optimizedBinaryString,G.base64);var R=new g(S,v,G);this.files[S]=R}var o=s("./utf8"),l=s("./utils"),h=s("./stream/GenericWorker"),p=s("./stream/StreamHelper"),_=s("./defaults"),w=s("./compressedObject"),g=s("./zipObject"),d=s("./generate"),k=s("./nodejsUtils"),u=s("./nodejs/NodejsStreamInputAdapter"),x=function(S){S.slice(-1)==="/"&&(S=S.substring(0,S.length-1));var B=S.lastIndexOf("/");return 0<B?S.substring(0,B):""},f=function(S){return S.slice(-1)!=="/"&&(S+="/"),S},j=function(S,B){return B=B!==void 0?B:_.createFolders,S=f(S),this.files[S]||i.call(this,S,null,{dir:!0,createFolders:B}),this.files[S]};function E(S){return Object.prototype.toString.call(S)==="[object RegExp]"}var P={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(S){var B,U,$;for(B in this.files)$=this.files[B],(U=B.slice(this.root.length,B.length))&&B.slice(0,this.root.length)===this.root&&S(U,$)},filter:function(S){var B=[];return this.forEach(function(U,$){S(U,$)&&B.push($)}),B},file:function(S,B,U){if(arguments.length!==1)return S=this.root+S,i.call(this,S,B,U),this;if(E(S)){var $=S;return this.filter(function(G,se){return!se.dir&&$.test(G)})}var T=this.files[this.root+S];return T&&!T.dir?T:null},folder:function(S){if(!S)return this;if(E(S))return this.filter(function(T,G){return G.dir&&S.test(T)});var B=this.root+S,U=j.call(this,B),$=this.clone();return $.root=U.name,$},remove:function(S){S=this.root+S;var B=this.files[S];if(B||(S.slice(-1)!=="/"&&(S+="/"),B=this.files[S]),B&&!B.dir)delete this.files[S];else for(var U=this.filter(function(T,G){return G.name.slice(0,S.length)===S}),$=0;$<U.length;$++)delete this.files[U[$].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(S){var B,U={};try{if((U=l.extend(S||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:o.utf8encode})).type=U.type.toLowerCase(),U.compression=U.compression.toUpperCase(),U.type==="binarystring"&&(U.type="string"),!U.type)throw new Error("No output type specified.");l.checkSupport(U.type),U.platform!=="darwin"&&U.platform!=="freebsd"&&U.platform!=="linux"&&U.platform!=="sunos"||(U.platform="UNIX"),U.platform==="win32"&&(U.platform="DOS");var $=U.comment||this.comment||"";B=d.generateWorker(this,U,$)}catch(T){(B=new h("error")).error(T)}return new p(B,U.type||"string",U.mimeType)},generateAsync:function(S,B){return this.generateInternalStream(S).accumulate(B)},generateNodeStream:function(S,B){return(S=S||{}).type||(S.type="nodebuffer"),this.generateInternalStream(S).toNodejsStream(B)}};a.exports=P},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(s,a,n){a.exports=s("stream")},{stream:void 0}],17:[function(s,a,n){var i=s("./DataReader");function o(l){i.call(this,l);for(var h=0;h<this.data.length;h++)l[h]=255&l[h]}s("../utils").inherits(o,i),o.prototype.byteAt=function(l){return this.data[this.zero+l]},o.prototype.lastIndexOfSignature=function(l){for(var h=l.charCodeAt(0),p=l.charCodeAt(1),_=l.charCodeAt(2),w=l.charCodeAt(3),g=this.length-4;0<=g;--g)if(this.data[g]===h&&this.data[g+1]===p&&this.data[g+2]===_&&this.data[g+3]===w)return g-this.zero;return-1},o.prototype.readAndCheckSignature=function(l){var h=l.charCodeAt(0),p=l.charCodeAt(1),_=l.charCodeAt(2),w=l.charCodeAt(3),g=this.readData(4);return h===g[0]&&p===g[1]&&_===g[2]&&w===g[3]},o.prototype.readData=function(l){if(this.checkOffset(l),l===0)return[];var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./DataReader":18}],18:[function(s,a,n){var i=s("../utils");function o(l){this.data=l,this.length=l.length,this.index=0,this.zero=0}o.prototype={checkOffset:function(l){this.checkIndex(this.index+l)},checkIndex:function(l){if(this.length<this.zero+l||l<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+l+"). Corrupted zip ?")},setIndex:function(l){this.checkIndex(l),this.index=l},skip:function(l){this.setIndex(this.index+l)},byteAt:function(){},readInt:function(l){var h,p=0;for(this.checkOffset(l),h=this.index+l-1;h>=this.index;h--)p=(p<<8)+this.byteAt(h);return this.index+=l,p},readString:function(l){return i.transformTo("string",this.readData(l))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var l=this.readInt(4);return new Date(Date.UTC(1980+(l>>25&127),(l>>21&15)-1,l>>16&31,l>>11&31,l>>5&63,(31&l)<<1))}},a.exports=o},{"../utils":32}],19:[function(s,a,n){var i=s("./Uint8ArrayReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.readData=function(l){this.checkOffset(l);var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(s,a,n){var i=s("./DataReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.byteAt=function(l){return this.data.charCodeAt(this.zero+l)},o.prototype.lastIndexOfSignature=function(l){return this.data.lastIndexOf(l)-this.zero},o.prototype.readAndCheckSignature=function(l){return l===this.readData(4)},o.prototype.readData=function(l){this.checkOffset(l);var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./DataReader":18}],21:[function(s,a,n){var i=s("./ArrayReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.readData=function(l){if(this.checkOffset(l),l===0)return new Uint8Array(0);var h=this.data.subarray(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./ArrayReader":17}],22:[function(s,a,n){var i=s("../utils"),o=s("../support"),l=s("./ArrayReader"),h=s("./StringReader"),p=s("./NodeBufferReader"),_=s("./Uint8ArrayReader");a.exports=function(w){var g=i.getTypeOf(w);return i.checkSupport(g),g!=="string"||o.uint8array?g==="nodebuffer"?new p(w):o.uint8array?new _(i.transformTo("uint8array",w)):new l(i.transformTo("array",w)):new h(w)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(s,a,n){n.LOCAL_FILE_HEADER="PK",n.CENTRAL_FILE_HEADER="PK",n.CENTRAL_DIRECTORY_END="PK",n.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",n.ZIP64_CENTRAL_DIRECTORY_END="PK",n.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(s,a,n){var i=s("./GenericWorker"),o=s("../utils");function l(h){i.call(this,"ConvertWorker to "+h),this.destType=h}o.inherits(l,i),l.prototype.processChunk=function(h){this.push({data:o.transformTo(this.destType,h.data),meta:h.meta})},a.exports=l},{"../utils":32,"./GenericWorker":28}],25:[function(s,a,n){var i=s("./GenericWorker"),o=s("../crc32");function l(){i.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}s("../utils").inherits(l,i),l.prototype.processChunk=function(h){this.streamInfo.crc32=o(h.data,this.streamInfo.crc32||0),this.push(h)},a.exports=l},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(s,a,n){var i=s("../utils"),o=s("./GenericWorker");function l(h){o.call(this,"DataLengthProbe for "+h),this.propName=h,this.withStreamInfo(h,0)}i.inherits(l,o),l.prototype.processChunk=function(h){if(h){var p=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=p+h.data.length}o.prototype.processChunk.call(this,h)},a.exports=l},{"../utils":32,"./GenericWorker":28}],27:[function(s,a,n){var i=s("../utils"),o=s("./GenericWorker");function l(h){o.call(this,"DataWorker");var p=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,h.then(function(_){p.dataIsReady=!0,p.data=_,p.max=_&&_.length||0,p.type=i.getTypeOf(_),p.isPaused||p._tickAndRepeat()},function(_){p.error(_)})}i.inherits(l,o),l.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this.data=null},l.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,i.delay(this._tickAndRepeat,[],this)),!0)},l.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(i.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},l.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var h=null,p=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":h=this.data.substring(this.index,p);break;case"uint8array":h=this.data.subarray(this.index,p);break;case"array":case"nodebuffer":h=this.data.slice(this.index,p)}return this.index=p,this.push({data:h,meta:{percent:this.max?this.index/this.max*100:0}})},a.exports=l},{"../utils":32,"./GenericWorker":28}],28:[function(s,a,n){function i(o){this.name=o||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}i.prototype={push:function(o){this.emit("data",o)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(o){this.emit("error",o)}return!0},error:function(o){return!this.isFinished&&(this.isPaused?this.generatedError=o:(this.isFinished=!0,this.emit("error",o),this.previous&&this.previous.error(o),this.cleanUp()),!0)},on:function(o,l){return this._listeners[o].push(l),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(o,l){if(this._listeners[o])for(var h=0;h<this._listeners[o].length;h++)this._listeners[o][h].call(this,l)},pipe:function(o){return o.registerPrevious(this)},registerPrevious:function(o){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=o.streamInfo,this.mergeStreamInfo(),this.previous=o;var l=this;return o.on("data",function(h){l.processChunk(h)}),o.on("end",function(){l.end()}),o.on("error",function(h){l.error(h)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var o=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),o=!0),this.previous&&this.previous.resume(),!o},flush:function(){},processChunk:function(o){this.push(o)},withStreamInfo:function(o,l){return this.extraStreamInfo[o]=l,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var o in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,o)&&(this.streamInfo[o]=this.extraStreamInfo[o])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var o="Worker "+this.name;return this.previous?this.previous+" -> "+o:o}},a.exports=i},{}],29:[function(s,a,n){var i=s("../utils"),o=s("./ConvertWorker"),l=s("./GenericWorker"),h=s("../base64"),p=s("../support"),_=s("../external"),w=null;if(p.nodestream)try{w=s("../nodejs/NodejsStreamOutputAdapter")}catch{}function g(k,u){return new _.Promise(function(x,f){var j=[],E=k._internalType,P=k._outputType,S=k._mimeType;k.on("data",function(B,U){j.push(B),u&&u(U)}).on("error",function(B){j=[],f(B)}).on("end",function(){try{var B=(function(U,$,T){switch(U){case"blob":return i.newBlob(i.transformTo("arraybuffer",$),T);case"base64":return h.encode($);default:return i.transformTo(U,$)}})(P,(function(U,$){var T,G=0,se=null,v=0;for(T=0;T<$.length;T++)v+=$[T].length;switch(U){case"string":return $.join("");case"array":return Array.prototype.concat.apply([],$);case"uint8array":for(se=new Uint8Array(v),T=0;T<$.length;T++)se.set($[T],G),G+=$[T].length;return se;case"nodebuffer":return Buffer.concat($);default:throw new Error("concat : unsupported type '"+U+"'")}})(E,j),S);x(B)}catch(U){f(U)}j=[]}).resume()})}function d(k,u,x){var f=u;switch(u){case"blob":case"arraybuffer":f="uint8array";break;case"base64":f="string"}try{this._internalType=f,this._outputType=u,this._mimeType=x,i.checkSupport(f),this._worker=k.pipe(new o(f)),k.lock()}catch(j){this._worker=new l("error"),this._worker.error(j)}}d.prototype={accumulate:function(k){return g(this,k)},on:function(k,u){var x=this;return k==="data"?this._worker.on(k,function(f){u.call(x,f.data,f.meta)}):this._worker.on(k,function(){i.delay(u,arguments,x)}),this},resume:function(){return i.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(k){if(i.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new w(this,{objectMode:this._outputType!=="nodebuffer"},k)}},a.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(s,a,n){if(n.base64=!0,n.array=!0,n.string=!0,n.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",n.nodebuffer=typeof Buffer<"u",n.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")n.blob=!1;else{var i=new ArrayBuffer(0);try{n.blob=new Blob([i],{type:"application/zip"}).size===0}catch{try{var o=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);o.append(i),n.blob=o.getBlob("application/zip").size===0}catch{n.blob=!1}}}try{n.nodestream=!!s("readable-stream").Readable}catch{n.nodestream=!1}},{"readable-stream":16}],31:[function(s,a,n){for(var i=s("./utils"),o=s("./support"),l=s("./nodejsUtils"),h=s("./stream/GenericWorker"),p=new Array(256),_=0;_<256;_++)p[_]=252<=_?6:248<=_?5:240<=_?4:224<=_?3:192<=_?2:1;p[254]=p[254]=1;function w(){h.call(this,"utf-8 decode"),this.leftOver=null}function g(){h.call(this,"utf-8 encode")}n.utf8encode=function(d){return o.nodebuffer?l.newBufferFrom(d,"utf-8"):(function(k){var u,x,f,j,E,P=k.length,S=0;for(j=0;j<P;j++)(64512&(x=k.charCodeAt(j)))==55296&&j+1<P&&(64512&(f=k.charCodeAt(j+1)))==56320&&(x=65536+(x-55296<<10)+(f-56320),j++),S+=x<128?1:x<2048?2:x<65536?3:4;for(u=o.uint8array?new Uint8Array(S):new Array(S),j=E=0;E<S;j++)(64512&(x=k.charCodeAt(j)))==55296&&j+1<P&&(64512&(f=k.charCodeAt(j+1)))==56320&&(x=65536+(x-55296<<10)+(f-56320),j++),x<128?u[E++]=x:(x<2048?u[E++]=192|x>>>6:(x<65536?u[E++]=224|x>>>12:(u[E++]=240|x>>>18,u[E++]=128|x>>>12&63),u[E++]=128|x>>>6&63),u[E++]=128|63&x);return u})(d)},n.utf8decode=function(d){return o.nodebuffer?i.transformTo("nodebuffer",d).toString("utf-8"):(function(k){var u,x,f,j,E=k.length,P=new Array(2*E);for(u=x=0;u<E;)if((f=k[u++])<128)P[x++]=f;else if(4<(j=p[f]))P[x++]=65533,u+=j-1;else{for(f&=j===2?31:j===3?15:7;1<j&&u<E;)f=f<<6|63&k[u++],j--;1<j?P[x++]=65533:f<65536?P[x++]=f:(f-=65536,P[x++]=55296|f>>10&1023,P[x++]=56320|1023&f)}return P.length!==x&&(P.subarray?P=P.subarray(0,x):P.length=x),i.applyFromCharCode(P)})(d=i.transformTo(o.uint8array?"uint8array":"array",d))},i.inherits(w,h),w.prototype.processChunk=function(d){var k=i.transformTo(o.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(o.uint8array){var u=k;(k=new Uint8Array(u.length+this.leftOver.length)).set(this.leftOver,0),k.set(u,this.leftOver.length)}else k=this.leftOver.concat(k);this.leftOver=null}var x=(function(j,E){var P;for((E=E||j.length)>j.length&&(E=j.length),P=E-1;0<=P&&(192&j[P])==128;)P--;return P<0||P===0?E:P+p[j[P]]>E?P:E})(k),f=k;x!==k.length&&(o.uint8array?(f=k.subarray(0,x),this.leftOver=k.subarray(x,k.length)):(f=k.slice(0,x),this.leftOver=k.slice(x,k.length))),this.push({data:n.utf8decode(f),meta:d.meta})},w.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:n.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},n.Utf8DecodeWorker=w,i.inherits(g,h),g.prototype.processChunk=function(d){this.push({data:n.utf8encode(d.data),meta:d.meta})},n.Utf8EncodeWorker=g},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(s,a,n){var i=s("./support"),o=s("./base64"),l=s("./nodejsUtils"),h=s("./external");function p(u){return u}function _(u,x){for(var f=0;f<u.length;++f)x[f]=255&u.charCodeAt(f);return x}s("setimmediate"),n.newBlob=function(u,x){n.checkSupport("blob");try{return new Blob([u],{type:x})}catch{try{var f=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return f.append(u),f.getBlob(x)}catch{throw new Error("Bug : can't construct the Blob.")}}};var w={stringifyByChunk:function(u,x,f){var j=[],E=0,P=u.length;if(P<=f)return String.fromCharCode.apply(null,u);for(;E<P;)x==="array"||x==="nodebuffer"?j.push(String.fromCharCode.apply(null,u.slice(E,Math.min(E+f,P)))):j.push(String.fromCharCode.apply(null,u.subarray(E,Math.min(E+f,P)))),E+=f;return j.join("")},stringifyByChar:function(u){for(var x="",f=0;f<u.length;f++)x+=String.fromCharCode(u[f]);return x},applyCanBeUsed:{uint8array:(function(){try{return i.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return i.nodebuffer&&String.fromCharCode.apply(null,l.allocBuffer(1)).length===1}catch{return!1}})()}};function g(u){var x=65536,f=n.getTypeOf(u),j=!0;if(f==="uint8array"?j=w.applyCanBeUsed.uint8array:f==="nodebuffer"&&(j=w.applyCanBeUsed.nodebuffer),j)for(;1<x;)try{return w.stringifyByChunk(u,f,x)}catch{x=Math.floor(x/2)}return w.stringifyByChar(u)}function d(u,x){for(var f=0;f<u.length;f++)x[f]=u[f];return x}n.applyFromCharCode=g;var k={};k.string={string:p,array:function(u){return _(u,new Array(u.length))},arraybuffer:function(u){return k.string.uint8array(u).buffer},uint8array:function(u){return _(u,new Uint8Array(u.length))},nodebuffer:function(u){return _(u,l.allocBuffer(u.length))}},k.array={string:g,array:p,arraybuffer:function(u){return new Uint8Array(u).buffer},uint8array:function(u){return new Uint8Array(u)},nodebuffer:function(u){return l.newBufferFrom(u)}},k.arraybuffer={string:function(u){return g(new Uint8Array(u))},array:function(u){return d(new Uint8Array(u),new Array(u.byteLength))},arraybuffer:p,uint8array:function(u){return new Uint8Array(u)},nodebuffer:function(u){return l.newBufferFrom(new Uint8Array(u))}},k.uint8array={string:g,array:function(u){return d(u,new Array(u.length))},arraybuffer:function(u){return u.buffer},uint8array:p,nodebuffer:function(u){return l.newBufferFrom(u)}},k.nodebuffer={string:g,array:function(u){return d(u,new Array(u.length))},arraybuffer:function(u){return k.nodebuffer.uint8array(u).buffer},uint8array:function(u){return d(u,new Uint8Array(u.length))},nodebuffer:p},n.transformTo=function(u,x){if(x=x||"",!u)return x;n.checkSupport(u);var f=n.getTypeOf(x);return k[f][u](x)},n.resolve=function(u){for(var x=u.split("/"),f=[],j=0;j<x.length;j++){var E=x[j];E==="."||E===""&&j!==0&&j!==x.length-1||(E===".."?f.pop():f.push(E))}return f.join("/")},n.getTypeOf=function(u){return typeof u=="string"?"string":Object.prototype.toString.call(u)==="[object Array]"?"array":i.nodebuffer&&l.isBuffer(u)?"nodebuffer":i.uint8array&&u instanceof Uint8Array?"uint8array":i.arraybuffer&&u instanceof ArrayBuffer?"arraybuffer":void 0},n.checkSupport=function(u){if(!i[u.toLowerCase()])throw new Error(u+" is not supported by this platform")},n.MAX_VALUE_16BITS=65535,n.MAX_VALUE_32BITS=-1,n.pretty=function(u){var x,f,j="";for(f=0;f<(u||"").length;f++)j+="\\x"+((x=u.charCodeAt(f))<16?"0":"")+x.toString(16).toUpperCase();return j},n.delay=function(u,x,f){setImmediate(function(){u.apply(f||null,x||[])})},n.inherits=function(u,x){function f(){}f.prototype=x.prototype,u.prototype=new f},n.extend=function(){var u,x,f={};for(u=0;u<arguments.length;u++)for(x in arguments[u])Object.prototype.hasOwnProperty.call(arguments[u],x)&&f[x]===void 0&&(f[x]=arguments[u][x]);return f},n.prepareContent=function(u,x,f,j,E){return h.Promise.resolve(x).then(function(P){return i.blob&&(P instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(P))!==-1)&&typeof FileReader<"u"?new h.Promise(function(S,B){var U=new FileReader;U.onload=function($){S($.target.result)},U.onerror=function($){B($.target.error)},U.readAsArrayBuffer(P)}):P}).then(function(P){var S=n.getTypeOf(P);return S?(S==="arraybuffer"?P=n.transformTo("uint8array",P):S==="string"&&(E?P=o.decode(P):f&&j!==!0&&(P=(function(B){return _(B,i.uint8array?new Uint8Array(B.length):new Array(B.length))})(P))),P):h.Promise.reject(new Error("Can't read the data of '"+u+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(s,a,n){var i=s("./reader/readerFor"),o=s("./utils"),l=s("./signature"),h=s("./zipEntry"),p=s("./support");function _(w){this.files=[],this.loadOptions=w}_.prototype={checkSignature:function(w){if(!this.reader.readAndCheckSignature(w)){this.reader.index-=4;var g=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+o.pretty(g)+", expected "+o.pretty(w)+")")}},isSignature:function(w,g){var d=this.reader.index;this.reader.setIndex(w);var k=this.reader.readString(4)===g;return this.reader.setIndex(d),k},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var w=this.reader.readData(this.zipCommentLength),g=p.uint8array?"uint8array":"array",d=o.transformTo(g,w);this.zipComment=this.loadOptions.decodeFileName(d)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var w,g,d,k=this.zip64EndOfCentralSize-44;0<k;)w=this.reader.readInt(2),g=this.reader.readInt(4),d=this.reader.readData(g),this.zip64ExtensibleData[w]={id:w,length:g,value:d}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var w,g;for(w=0;w<this.files.length;w++)g=this.files[w],this.reader.setIndex(g.localHeaderOffset),this.checkSignature(l.LOCAL_FILE_HEADER),g.readLocalPart(this.reader),g.handleUTF8(),g.processAttributes()},readCentralDir:function(){var w;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(l.CENTRAL_FILE_HEADER);)(w=new h({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(w);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var w=this.reader.lastIndexOfSignature(l.CENTRAL_DIRECTORY_END);if(w<0)throw this.isSignature(0,l.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(w);var g=w;if(this.checkSignature(l.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===o.MAX_VALUE_16BITS||this.diskWithCentralDirStart===o.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===o.MAX_VALUE_16BITS||this.centralDirRecords===o.MAX_VALUE_16BITS||this.centralDirSize===o.MAX_VALUE_32BITS||this.centralDirOffset===o.MAX_VALUE_32BITS){if(this.zip64=!0,(w=this.reader.lastIndexOfSignature(l.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(w),this.checkSignature(l.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,l.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(l.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(l.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var k=g-d;if(0<k)this.isSignature(g,l.CENTRAL_FILE_HEADER)||(this.reader.zero=k);else if(k<0)throw new Error("Corrupted zip: missing "+Math.abs(k)+" bytes.")},prepareReader:function(w){this.reader=i(w)},load:function(w){this.prepareReader(w),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},a.exports=_},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(s,a,n){var i=s("./reader/readerFor"),o=s("./utils"),l=s("./compressedObject"),h=s("./crc32"),p=s("./utf8"),_=s("./compressions"),w=s("./support");function g(d,k){this.options=d,this.loadOptions=k}g.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var k,u;if(d.skip(22),this.fileNameLength=d.readInt(2),u=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(u),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((k=(function(x){for(var f in _)if(Object.prototype.hasOwnProperty.call(_,f)&&_[f].magic===x)return _[f];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+o.pretty(this.compressionMethod)+" unknown (inner file : "+o.transformTo("string",this.fileName)+")");this.decompressed=new l(this.compressedSize,this.uncompressedSize,this.crc32,k,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var k=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(k),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=i(this.extraFields[1].value);this.uncompressedSize===o.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===o.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===o.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===o.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var k,u,x,f=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<f;)k=d.readInt(2),u=d.readInt(2),x=d.readData(u),this.extraFields[k]={id:k,length:u,value:x};d.setIndex(f)},handleUTF8:function(){var d=w.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=p.utf8decode(this.fileName),this.fileCommentStr=p.utf8decode(this.fileComment);else{var k=this.findExtraFieldUnicodePath();if(k!==null)this.fileNameStr=k;else{var u=o.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(u)}var x=this.findExtraFieldUnicodeComment();if(x!==null)this.fileCommentStr=x;else{var f=o.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(f)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var k=i(d.value);return k.readInt(1)!==1||h(this.fileName)!==k.readInt(4)?null:p.utf8decode(k.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var k=i(d.value);return k.readInt(1)!==1||h(this.fileComment)!==k.readInt(4)?null:p.utf8decode(k.readData(d.length-5))}return null}},a.exports=g},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(s,a,n){function i(k,u,x){this.name=k,this.dir=x.dir,this.date=x.date,this.comment=x.comment,this.unixPermissions=x.unixPermissions,this.dosPermissions=x.dosPermissions,this._data=u,this._dataBinary=x.binary,this.options={compression:x.compression,compressionOptions:x.compressionOptions}}var o=s("./stream/StreamHelper"),l=s("./stream/DataWorker"),h=s("./utf8"),p=s("./compressedObject"),_=s("./stream/GenericWorker");i.prototype={internalStream:function(k){var u=null,x="string";try{if(!k)throw new Error("No output type specified.");var f=(x=k.toLowerCase())==="string"||x==="text";x!=="binarystring"&&x!=="text"||(x="string"),u=this._decompressWorker();var j=!this._dataBinary;j&&!f&&(u=u.pipe(new h.Utf8EncodeWorker)),!j&&f&&(u=u.pipe(new h.Utf8DecodeWorker))}catch(E){(u=new _("error")).error(E)}return new o(u,x,"")},async:function(k,u){return this.internalStream(k).accumulate(u)},nodeStream:function(k,u){return this.internalStream(k||"nodebuffer").toNodejsStream(u)},_compressWorker:function(k,u){if(this._data instanceof p&&this._data.compression.magic===k.magic)return this._data.getCompressedWorker();var x=this._decompressWorker();return this._dataBinary||(x=x.pipe(new h.Utf8EncodeWorker)),p.createWorkerFrom(x,k,u)},_decompressWorker:function(){return this._data instanceof p?this._data.getContentWorker():this._data instanceof _?this._data:new l(this._data)}};for(var w=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],g=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<w.length;d++)i.prototype[w[d]]=g;a.exports=i},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(s,a,n){(function(i){var o,l,h=i.MutationObserver||i.WebKitMutationObserver;if(h){var p=0,_=new h(k),w=i.document.createTextNode("");_.observe(w,{characterData:!0}),o=function(){w.data=p=++p%2}}else if(i.setImmediate||i.MessageChannel===void 0)o="document"in i&&"onreadystatechange"in i.document.createElement("script")?function(){var u=i.document.createElement("script");u.onreadystatechange=function(){k(),u.onreadystatechange=null,u.parentNode.removeChild(u),u=null},i.document.documentElement.appendChild(u)}:function(){setTimeout(k,0)};else{var g=new i.MessageChannel;g.port1.onmessage=k,o=function(){g.port2.postMessage(0)}}var d=[];function k(){var u,x;l=!0;for(var f=d.length;f;){for(x=d,d=[],u=-1;++u<f;)x[u]();f=d.length}l=!1}a.exports=function(u){d.push(u)!==1||l||o()}}).call(this,typeof Rr<"u"?Rr:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(s,a,n){var i=s("immediate");function o(){}var l={},h=["REJECTED"],p=["FULFILLED"],_=["PENDING"];function w(f){if(typeof f!="function")throw new TypeError("resolver must be a function");this.state=_,this.queue=[],this.outcome=void 0,f!==o&&u(this,f)}function g(f,j,E){this.promise=f,typeof j=="function"&&(this.onFulfilled=j,this.callFulfilled=this.otherCallFulfilled),typeof E=="function"&&(this.onRejected=E,this.callRejected=this.otherCallRejected)}function d(f,j,E){i(function(){var P;try{P=j(E)}catch(S){return l.reject(f,S)}P===f?l.reject(f,new TypeError("Cannot resolve promise with itself")):l.resolve(f,P)})}function k(f){var j=f&&f.then;if(f&&(typeof f=="object"||typeof f=="function")&&typeof j=="function")return function(){j.apply(f,arguments)}}function u(f,j){var E=!1;function P(U){E||(E=!0,l.reject(f,U))}function S(U){E||(E=!0,l.resolve(f,U))}var B=x(function(){j(S,P)});B.status==="error"&&P(B.value)}function x(f,j){var E={};try{E.value=f(j),E.status="success"}catch(P){E.status="error",E.value=P}return E}(a.exports=w).prototype.finally=function(f){if(typeof f!="function")return this;var j=this.constructor;return this.then(function(E){return j.resolve(f()).then(function(){return E})},function(E){return j.resolve(f()).then(function(){throw E})})},w.prototype.catch=function(f){return this.then(null,f)},w.prototype.then=function(f,j){if(typeof f!="function"&&this.state===p||typeof j!="function"&&this.state===h)return this;var E=new this.constructor(o);return this.state!==_?d(E,this.state===p?f:j,this.outcome):this.queue.push(new g(E,f,j)),E},g.prototype.callFulfilled=function(f){l.resolve(this.promise,f)},g.prototype.otherCallFulfilled=function(f){d(this.promise,this.onFulfilled,f)},g.prototype.callRejected=function(f){l.reject(this.promise,f)},g.prototype.otherCallRejected=function(f){d(this.promise,this.onRejected,f)},l.resolve=function(f,j){var E=x(k,j);if(E.status==="error")return l.reject(f,E.value);var P=E.value;if(P)u(f,P);else{f.state=p,f.outcome=j;for(var S=-1,B=f.queue.length;++S<B;)f.queue[S].callFulfilled(j)}return f},l.reject=function(f,j){f.state=h,f.outcome=j;for(var E=-1,P=f.queue.length;++E<P;)f.queue[E].callRejected(j);return f},w.resolve=function(f){return f instanceof this?f:l.resolve(new this(o),f)},w.reject=function(f){var j=new this(o);return l.reject(j,f)},w.all=function(f){var j=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var E=f.length,P=!1;if(!E)return this.resolve([]);for(var S=new Array(E),B=0,U=-1,$=new this(o);++U<E;)T(f[U],U);return $;function T(G,se){j.resolve(G).then(function(v){S[se]=v,++B!==E||P||(P=!0,l.resolve($,S))},function(v){P||(P=!0,l.reject($,v))})}},w.race=function(f){var j=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var E=f.length,P=!1;if(!E)return this.resolve([]);for(var S=-1,B=new this(o);++S<E;)U=f[S],j.resolve(U).then(function($){P||(P=!0,l.resolve(B,$))},function($){P||(P=!0,l.reject(B,$))});var U;return B}},{immediate:36}],38:[function(s,a,n){var i={};(0,s("./lib/utils/common").assign)(i,s("./lib/deflate"),s("./lib/inflate"),s("./lib/zlib/constants")),a.exports=i},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(s,a,n){var i=s("./zlib/deflate"),o=s("./utils/common"),l=s("./utils/strings"),h=s("./zlib/messages"),p=s("./zlib/zstream"),_=Object.prototype.toString,w=0,g=-1,d=0,k=8;function u(f){if(!(this instanceof u))return new u(f);this.options=o.assign({level:g,method:k,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},f||{});var j=this.options;j.raw&&0<j.windowBits?j.windowBits=-j.windowBits:j.gzip&&0<j.windowBits&&j.windowBits<16&&(j.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new p,this.strm.avail_out=0;var E=i.deflateInit2(this.strm,j.level,j.method,j.windowBits,j.memLevel,j.strategy);if(E!==w)throw new Error(h[E]);if(j.header&&i.deflateSetHeader(this.strm,j.header),j.dictionary){var P;if(P=typeof j.dictionary=="string"?l.string2buf(j.dictionary):_.call(j.dictionary)==="[object ArrayBuffer]"?new Uint8Array(j.dictionary):j.dictionary,(E=i.deflateSetDictionary(this.strm,P))!==w)throw new Error(h[E]);this._dict_set=!0}}function x(f,j){var E=new u(j);if(E.push(f,!0),E.err)throw E.msg||h[E.err];return E.result}u.prototype.push=function(f,j){var E,P,S=this.strm,B=this.options.chunkSize;if(this.ended)return!1;P=j===~~j?j:j===!0?4:0,typeof f=="string"?S.input=l.string2buf(f):_.call(f)==="[object ArrayBuffer]"?S.input=new Uint8Array(f):S.input=f,S.next_in=0,S.avail_in=S.input.length;do{if(S.avail_out===0&&(S.output=new o.Buf8(B),S.next_out=0,S.avail_out=B),(E=i.deflate(S,P))!==1&&E!==w)return this.onEnd(E),!(this.ended=!0);S.avail_out!==0&&(S.avail_in!==0||P!==4&&P!==2)||(this.options.to==="string"?this.onData(l.buf2binstring(o.shrinkBuf(S.output,S.next_out))):this.onData(o.shrinkBuf(S.output,S.next_out)))}while((0<S.avail_in||S.avail_out===0)&&E!==1);return P===4?(E=i.deflateEnd(this.strm),this.onEnd(E),this.ended=!0,E===w):P!==2||(this.onEnd(w),!(S.avail_out=0))},u.prototype.onData=function(f){this.chunks.push(f)},u.prototype.onEnd=function(f){f===w&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=f,this.msg=this.strm.msg},n.Deflate=u,n.deflate=x,n.deflateRaw=function(f,j){return(j=j||{}).raw=!0,x(f,j)},n.gzip=function(f,j){return(j=j||{}).gzip=!0,x(f,j)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(s,a,n){var i=s("./zlib/inflate"),o=s("./utils/common"),l=s("./utils/strings"),h=s("./zlib/constants"),p=s("./zlib/messages"),_=s("./zlib/zstream"),w=s("./zlib/gzheader"),g=Object.prototype.toString;function d(u){if(!(this instanceof d))return new d(u);this.options=o.assign({chunkSize:16384,windowBits:0,to:""},u||{});var x=this.options;x.raw&&0<=x.windowBits&&x.windowBits<16&&(x.windowBits=-x.windowBits,x.windowBits===0&&(x.windowBits=-15)),!(0<=x.windowBits&&x.windowBits<16)||u&&u.windowBits||(x.windowBits+=32),15<x.windowBits&&x.windowBits<48&&(15&x.windowBits)==0&&(x.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new _,this.strm.avail_out=0;var f=i.inflateInit2(this.strm,x.windowBits);if(f!==h.Z_OK)throw new Error(p[f]);this.header=new w,i.inflateGetHeader(this.strm,this.header)}function k(u,x){var f=new d(x);if(f.push(u,!0),f.err)throw f.msg||p[f.err];return f.result}d.prototype.push=function(u,x){var f,j,E,P,S,B,U=this.strm,$=this.options.chunkSize,T=this.options.dictionary,G=!1;if(this.ended)return!1;j=x===~~x?x:x===!0?h.Z_FINISH:h.Z_NO_FLUSH,typeof u=="string"?U.input=l.binstring2buf(u):g.call(u)==="[object ArrayBuffer]"?U.input=new Uint8Array(u):U.input=u,U.next_in=0,U.avail_in=U.input.length;do{if(U.avail_out===0&&(U.output=new o.Buf8($),U.next_out=0,U.avail_out=$),(f=i.inflate(U,h.Z_NO_FLUSH))===h.Z_NEED_DICT&&T&&(B=typeof T=="string"?l.string2buf(T):g.call(T)==="[object ArrayBuffer]"?new Uint8Array(T):T,f=i.inflateSetDictionary(this.strm,B)),f===h.Z_BUF_ERROR&&G===!0&&(f=h.Z_OK,G=!1),f!==h.Z_STREAM_END&&f!==h.Z_OK)return this.onEnd(f),!(this.ended=!0);U.next_out&&(U.avail_out!==0&&f!==h.Z_STREAM_END&&(U.avail_in!==0||j!==h.Z_FINISH&&j!==h.Z_SYNC_FLUSH)||(this.options.to==="string"?(E=l.utf8border(U.output,U.next_out),P=U.next_out-E,S=l.buf2string(U.output,E),U.next_out=P,U.avail_out=$-P,P&&o.arraySet(U.output,U.output,E,P,0),this.onData(S)):this.onData(o.shrinkBuf(U.output,U.next_out)))),U.avail_in===0&&U.avail_out===0&&(G=!0)}while((0<U.avail_in||U.avail_out===0)&&f!==h.Z_STREAM_END);return f===h.Z_STREAM_END&&(j=h.Z_FINISH),j===h.Z_FINISH?(f=i.inflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===h.Z_OK):j!==h.Z_SYNC_FLUSH||(this.onEnd(h.Z_OK),!(U.avail_out=0))},d.prototype.onData=function(u){this.chunks.push(u)},d.prototype.onEnd=function(u){u===h.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=u,this.msg=this.strm.msg},n.Inflate=d,n.inflate=k,n.inflateRaw=function(u,x){return(x=x||{}).raw=!0,k(u,x)},n.ungzip=k},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(s,a,n){var i=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";n.assign=function(h){for(var p=Array.prototype.slice.call(arguments,1);p.length;){var _=p.shift();if(_){if(typeof _!="object")throw new TypeError(_+"must be non-object");for(var w in _)_.hasOwnProperty(w)&&(h[w]=_[w])}}return h},n.shrinkBuf=function(h,p){return h.length===p?h:h.subarray?h.subarray(0,p):(h.length=p,h)};var o={arraySet:function(h,p,_,w,g){if(p.subarray&&h.subarray)h.set(p.subarray(_,_+w),g);else for(var d=0;d<w;d++)h[g+d]=p[_+d]},flattenChunks:function(h){var p,_,w,g,d,k;for(p=w=0,_=h.length;p<_;p++)w+=h[p].length;for(k=new Uint8Array(w),p=g=0,_=h.length;p<_;p++)d=h[p],k.set(d,g),g+=d.length;return k}},l={arraySet:function(h,p,_,w,g){for(var d=0;d<w;d++)h[g+d]=p[_+d]},flattenChunks:function(h){return[].concat.apply([],h)}};n.setTyped=function(h){h?(n.Buf8=Uint8Array,n.Buf16=Uint16Array,n.Buf32=Int32Array,n.assign(n,o)):(n.Buf8=Array,n.Buf16=Array,n.Buf32=Array,n.assign(n,l))},n.setTyped(i)},{}],42:[function(s,a,n){var i=s("./common"),o=!0,l=!0;try{String.fromCharCode.apply(null,[0])}catch{o=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{l=!1}for(var h=new i.Buf8(256),p=0;p<256;p++)h[p]=252<=p?6:248<=p?5:240<=p?4:224<=p?3:192<=p?2:1;function _(w,g){if(g<65537&&(w.subarray&&l||!w.subarray&&o))return String.fromCharCode.apply(null,i.shrinkBuf(w,g));for(var d="",k=0;k<g;k++)d+=String.fromCharCode(w[k]);return d}h[254]=h[254]=1,n.string2buf=function(w){var g,d,k,u,x,f=w.length,j=0;for(u=0;u<f;u++)(64512&(d=w.charCodeAt(u)))==55296&&u+1<f&&(64512&(k=w.charCodeAt(u+1)))==56320&&(d=65536+(d-55296<<10)+(k-56320),u++),j+=d<128?1:d<2048?2:d<65536?3:4;for(g=new i.Buf8(j),u=x=0;x<j;u++)(64512&(d=w.charCodeAt(u)))==55296&&u+1<f&&(64512&(k=w.charCodeAt(u+1)))==56320&&(d=65536+(d-55296<<10)+(k-56320),u++),d<128?g[x++]=d:(d<2048?g[x++]=192|d>>>6:(d<65536?g[x++]=224|d>>>12:(g[x++]=240|d>>>18,g[x++]=128|d>>>12&63),g[x++]=128|d>>>6&63),g[x++]=128|63&d);return g},n.buf2binstring=function(w){return _(w,w.length)},n.binstring2buf=function(w){for(var g=new i.Buf8(w.length),d=0,k=g.length;d<k;d++)g[d]=w.charCodeAt(d);return g},n.buf2string=function(w,g){var d,k,u,x,f=g||w.length,j=new Array(2*f);for(d=k=0;d<f;)if((u=w[d++])<128)j[k++]=u;else if(4<(x=h[u]))j[k++]=65533,d+=x-1;else{for(u&=x===2?31:x===3?15:7;1<x&&d<f;)u=u<<6|63&w[d++],x--;1<x?j[k++]=65533:u<65536?j[k++]=u:(u-=65536,j[k++]=55296|u>>10&1023,j[k++]=56320|1023&u)}return _(j,k)},n.utf8border=function(w,g){var d;for((g=g||w.length)>w.length&&(g=w.length),d=g-1;0<=d&&(192&w[d])==128;)d--;return d<0||d===0?g:d+h[w[d]]>g?d:g}},{"./common":41}],43:[function(s,a,n){a.exports=function(i,o,l,h){for(var p=65535&i|0,_=i>>>16&65535|0,w=0;l!==0;){for(l-=w=2e3<l?2e3:l;_=_+(p=p+o[h++]|0)|0,--w;);p%=65521,_%=65521}return p|_<<16|0}},{}],44:[function(s,a,n){a.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(s,a,n){var i=(function(){for(var o,l=[],h=0;h<256;h++){o=h;for(var p=0;p<8;p++)o=1&o?3988292384^o>>>1:o>>>1;l[h]=o}return l})();a.exports=function(o,l,h,p){var _=i,w=p+h;o^=-1;for(var g=p;g<w;g++)o=o>>>8^_[255&(o^l[g])];return-1^o}},{}],46:[function(s,a,n){var i,o=s("../utils/common"),l=s("./trees"),h=s("./adler32"),p=s("./crc32"),_=s("./messages"),w=0,g=4,d=0,k=-2,u=-1,x=4,f=2,j=8,E=9,P=286,S=30,B=19,U=2*P+1,$=15,T=3,G=258,se=G+T+1,v=42,R=113,m=1,V=2,ie=3,q=4;function ce(c,K){return c.msg=_[K],K}function F(c){return(c<<1)-(4<c?9:0)}function ee(c){for(var K=c.length;0<=--K;)c[K]=0}function O(c){var K=c.state,M=K.pending;M>c.avail_out&&(M=c.avail_out),M!==0&&(o.arraySet(c.output,K.pending_buf,K.pending_out,M,c.next_out),c.next_out+=M,K.pending_out+=M,c.total_out+=M,c.avail_out-=M,K.pending-=M,K.pending===0&&(K.pending_out=0))}function L(c,K){l._tr_flush_block(c,0<=c.block_start?c.block_start:-1,c.strstart-c.block_start,K),c.block_start=c.strstart,O(c.strm)}function ae(c,K){c.pending_buf[c.pending++]=K}function te(c,K){c.pending_buf[c.pending++]=K>>>8&255,c.pending_buf[c.pending++]=255&K}function J(c,K){var M,C,N=c.max_chain_length,D=c.strstart,X=c.prev_length,y=c.nice_match,b=c.strstart>c.w_size-se?c.strstart-(c.w_size-se):0,A=c.window,I=c.w_mask,z=c.prev,Z=c.strstart+G,H=A[D+X-1],re=A[D+X];c.prev_length>=c.good_match&&(N>>=2),y>c.lookahead&&(y=c.lookahead);do if(A[(M=K)+X]===re&&A[M+X-1]===H&&A[M]===A[D]&&A[++M]===A[D+1]){D+=2,M++;do;while(A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&D<Z);if(C=G-(Z-D),D=Z-G,X<C){if(c.match_start=K,y<=(X=C))break;H=A[D+X-1],re=A[D+X]}}while((K=z[K&I])>b&&--N!=0);return X<=c.lookahead?X:c.lookahead}function ve(c){var K,M,C,N,D,X,y,b,A,I,z=c.w_size;do{if(N=c.window_size-c.lookahead-c.strstart,c.strstart>=z+(z-se)){for(o.arraySet(c.window,c.window,z,z,0),c.match_start-=z,c.strstart-=z,c.block_start-=z,K=M=c.hash_size;C=c.head[--K],c.head[K]=z<=C?C-z:0,--M;);for(K=M=z;C=c.prev[--K],c.prev[K]=z<=C?C-z:0,--M;);N+=z}if(c.strm.avail_in===0)break;if(X=c.strm,y=c.window,b=c.strstart+c.lookahead,A=N,I=void 0,I=X.avail_in,A<I&&(I=A),M=I===0?0:(X.avail_in-=I,o.arraySet(y,X.input,X.next_in,I,b),X.state.wrap===1?X.adler=h(X.adler,y,I,b):X.state.wrap===2&&(X.adler=p(X.adler,y,I,b)),X.next_in+=I,X.total_in+=I,I),c.lookahead+=M,c.lookahead+c.insert>=T)for(D=c.strstart-c.insert,c.ins_h=c.window[D],c.ins_h=(c.ins_h<<c.hash_shift^c.window[D+1])&c.hash_mask;c.insert&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[D+T-1])&c.hash_mask,c.prev[D&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=D,D++,c.insert--,!(c.lookahead+c.insert<T)););}while(c.lookahead<se&&c.strm.avail_in!==0)}function Se(c,K){for(var M,C;;){if(c.lookahead<se){if(ve(c),c.lookahead<se&&K===w)return m;if(c.lookahead===0)break}if(M=0,c.lookahead>=T&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),M!==0&&c.strstart-M<=c.w_size-se&&(c.match_length=J(c,M)),c.match_length>=T)if(C=l._tr_tally(c,c.strstart-c.match_start,c.match_length-T),c.lookahead-=c.match_length,c.match_length<=c.max_lazy_match&&c.lookahead>=T){for(c.match_length--;c.strstart++,c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart,--c.match_length!=0;);c.strstart++}else c.strstart+=c.match_length,c.match_length=0,c.ins_h=c.window[c.strstart],c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+1])&c.hash_mask;else C=l._tr_tally(c,0,c.window[c.strstart]),c.lookahead--,c.strstart++;if(C&&(L(c,!1),c.strm.avail_out===0))return m}return c.insert=c.strstart<T-1?c.strstart:T-1,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):c.last_lit&&(L(c,!1),c.strm.avail_out===0)?m:V}function fe(c,K){for(var M,C,N;;){if(c.lookahead<se){if(ve(c),c.lookahead<se&&K===w)return m;if(c.lookahead===0)break}if(M=0,c.lookahead>=T&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),c.prev_length=c.match_length,c.prev_match=c.match_start,c.match_length=T-1,M!==0&&c.prev_length<c.max_lazy_match&&c.strstart-M<=c.w_size-se&&(c.match_length=J(c,M),c.match_length<=5&&(c.strategy===1||c.match_length===T&&4096<c.strstart-c.match_start)&&(c.match_length=T-1)),c.prev_length>=T&&c.match_length<=c.prev_length){for(N=c.strstart+c.lookahead-T,C=l._tr_tally(c,c.strstart-1-c.prev_match,c.prev_length-T),c.lookahead-=c.prev_length-1,c.prev_length-=2;++c.strstart<=N&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),--c.prev_length!=0;);if(c.match_available=0,c.match_length=T-1,c.strstart++,C&&(L(c,!1),c.strm.avail_out===0))return m}else if(c.match_available){if((C=l._tr_tally(c,0,c.window[c.strstart-1]))&&L(c,!1),c.strstart++,c.lookahead--,c.strm.avail_out===0)return m}else c.match_available=1,c.strstart++,c.lookahead--}return c.match_available&&(C=l._tr_tally(c,0,c.window[c.strstart-1]),c.match_available=0),c.insert=c.strstart<T-1?c.strstart:T-1,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):c.last_lit&&(L(c,!1),c.strm.avail_out===0)?m:V}function me(c,K,M,C,N){this.good_length=c,this.max_lazy=K,this.nice_length=M,this.max_chain=C,this.func=N}function ke(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=j,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new o.Buf16(2*U),this.dyn_dtree=new o.Buf16(2*(2*S+1)),this.bl_tree=new o.Buf16(2*(2*B+1)),ee(this.dyn_ltree),ee(this.dyn_dtree),ee(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new o.Buf16($+1),this.heap=new o.Buf16(2*P+1),ee(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new o.Buf16(2*P+1),ee(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function ye(c){var K;return c&&c.state?(c.total_in=c.total_out=0,c.data_type=f,(K=c.state).pending=0,K.pending_out=0,K.wrap<0&&(K.wrap=-K.wrap),K.status=K.wrap?v:R,c.adler=K.wrap===2?0:1,K.last_flush=w,l._tr_init(K),d):ce(c,k)}function _e(c){var K=ye(c);return K===d&&(function(M){M.window_size=2*M.w_size,ee(M.head),M.max_lazy_match=i[M.level].max_lazy,M.good_match=i[M.level].good_length,M.nice_match=i[M.level].nice_length,M.max_chain_length=i[M.level].max_chain,M.strstart=0,M.block_start=0,M.lookahead=0,M.insert=0,M.match_length=M.prev_length=T-1,M.match_available=0,M.ins_h=0})(c.state),K}function Re(c,K,M,C,N,D){if(!c)return k;var X=1;if(K===u&&(K=6),C<0?(X=0,C=-C):15<C&&(X=2,C-=16),N<1||E<N||M!==j||C<8||15<C||K<0||9<K||D<0||x<D)return ce(c,k);C===8&&(C=9);var y=new ke;return(c.state=y).strm=c,y.wrap=X,y.gzhead=null,y.w_bits=C,y.w_size=1<<y.w_bits,y.w_mask=y.w_size-1,y.hash_bits=N+7,y.hash_size=1<<y.hash_bits,y.hash_mask=y.hash_size-1,y.hash_shift=~~((y.hash_bits+T-1)/T),y.window=new o.Buf8(2*y.w_size),y.head=new o.Buf16(y.hash_size),y.prev=new o.Buf16(y.w_size),y.lit_bufsize=1<<N+6,y.pending_buf_size=4*y.lit_bufsize,y.pending_buf=new o.Buf8(y.pending_buf_size),y.d_buf=1*y.lit_bufsize,y.l_buf=3*y.lit_bufsize,y.level=K,y.strategy=D,y.method=M,_e(c)}i=[new me(0,0,0,0,function(c,K){var M=65535;for(M>c.pending_buf_size-5&&(M=c.pending_buf_size-5);;){if(c.lookahead<=1){if(ve(c),c.lookahead===0&&K===w)return m;if(c.lookahead===0)break}c.strstart+=c.lookahead,c.lookahead=0;var C=c.block_start+M;if((c.strstart===0||c.strstart>=C)&&(c.lookahead=c.strstart-C,c.strstart=C,L(c,!1),c.strm.avail_out===0)||c.strstart-c.block_start>=c.w_size-se&&(L(c,!1),c.strm.avail_out===0))return m}return c.insert=0,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):(c.strstart>c.block_start&&(L(c,!1),c.strm.avail_out),m)}),new me(4,4,8,4,Se),new me(4,5,16,8,Se),new me(4,6,32,32,Se),new me(4,4,16,16,fe),new me(8,16,32,32,fe),new me(8,16,128,128,fe),new me(8,32,128,256,fe),new me(32,128,258,1024,fe),new me(32,258,258,4096,fe)],n.deflateInit=function(c,K){return Re(c,K,j,15,8,0)},n.deflateInit2=Re,n.deflateReset=_e,n.deflateResetKeep=ye,n.deflateSetHeader=function(c,K){return c&&c.state?c.state.wrap!==2?k:(c.state.gzhead=K,d):k},n.deflate=function(c,K){var M,C,N,D;if(!c||!c.state||5<K||K<0)return c?ce(c,k):k;if(C=c.state,!c.output||!c.input&&c.avail_in!==0||C.status===666&&K!==g)return ce(c,c.avail_out===0?-5:k);if(C.strm=c,M=C.last_flush,C.last_flush=K,C.status===v)if(C.wrap===2)c.adler=0,ae(C,31),ae(C,139),ae(C,8),C.gzhead?(ae(C,(C.gzhead.text?1:0)+(C.gzhead.hcrc?2:0)+(C.gzhead.extra?4:0)+(C.gzhead.name?8:0)+(C.gzhead.comment?16:0)),ae(C,255&C.gzhead.time),ae(C,C.gzhead.time>>8&255),ae(C,C.gzhead.time>>16&255),ae(C,C.gzhead.time>>24&255),ae(C,C.level===9?2:2<=C.strategy||C.level<2?4:0),ae(C,255&C.gzhead.os),C.gzhead.extra&&C.gzhead.extra.length&&(ae(C,255&C.gzhead.extra.length),ae(C,C.gzhead.extra.length>>8&255)),C.gzhead.hcrc&&(c.adler=p(c.adler,C.pending_buf,C.pending,0)),C.gzindex=0,C.status=69):(ae(C,0),ae(C,0),ae(C,0),ae(C,0),ae(C,0),ae(C,C.level===9?2:2<=C.strategy||C.level<2?4:0),ae(C,3),C.status=R);else{var X=j+(C.w_bits-8<<4)<<8;X|=(2<=C.strategy||C.level<2?0:C.level<6?1:C.level===6?2:3)<<6,C.strstart!==0&&(X|=32),X+=31-X%31,C.status=R,te(C,X),C.strstart!==0&&(te(C,c.adler>>>16),te(C,65535&c.adler)),c.adler=1}if(C.status===69)if(C.gzhead.extra){for(N=C.pending;C.gzindex<(65535&C.gzhead.extra.length)&&(C.pending!==C.pending_buf_size||(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending!==C.pending_buf_size));)ae(C,255&C.gzhead.extra[C.gzindex]),C.gzindex++;C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),C.gzindex===C.gzhead.extra.length&&(C.gzindex=0,C.status=73)}else C.status=73;if(C.status===73)if(C.gzhead.name){N=C.pending;do{if(C.pending===C.pending_buf_size&&(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending===C.pending_buf_size)){D=1;break}D=C.gzindex<C.gzhead.name.length?255&C.gzhead.name.charCodeAt(C.gzindex++):0,ae(C,D)}while(D!==0);C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),D===0&&(C.gzindex=0,C.status=91)}else C.status=91;if(C.status===91)if(C.gzhead.comment){N=C.pending;do{if(C.pending===C.pending_buf_size&&(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending===C.pending_buf_size)){D=1;break}D=C.gzindex<C.gzhead.comment.length?255&C.gzhead.comment.charCodeAt(C.gzindex++):0,ae(C,D)}while(D!==0);C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),D===0&&(C.status=103)}else C.status=103;if(C.status===103&&(C.gzhead.hcrc?(C.pending+2>C.pending_buf_size&&O(c),C.pending+2<=C.pending_buf_size&&(ae(C,255&c.adler),ae(C,c.adler>>8&255),c.adler=0,C.status=R)):C.status=R),C.pending!==0){if(O(c),c.avail_out===0)return C.last_flush=-1,d}else if(c.avail_in===0&&F(K)<=F(M)&&K!==g)return ce(c,-5);if(C.status===666&&c.avail_in!==0)return ce(c,-5);if(c.avail_in!==0||C.lookahead!==0||K!==w&&C.status!==666){var y=C.strategy===2?(function(b,A){for(var I;;){if(b.lookahead===0&&(ve(b),b.lookahead===0)){if(A===w)return m;break}if(b.match_length=0,I=l._tr_tally(b,0,b.window[b.strstart]),b.lookahead--,b.strstart++,I&&(L(b,!1),b.strm.avail_out===0))return m}return b.insert=0,A===g?(L(b,!0),b.strm.avail_out===0?ie:q):b.last_lit&&(L(b,!1),b.strm.avail_out===0)?m:V})(C,K):C.strategy===3?(function(b,A){for(var I,z,Z,H,re=b.window;;){if(b.lookahead<=G){if(ve(b),b.lookahead<=G&&A===w)return m;if(b.lookahead===0)break}if(b.match_length=0,b.lookahead>=T&&0<b.strstart&&(z=re[Z=b.strstart-1])===re[++Z]&&z===re[++Z]&&z===re[++Z]){H=b.strstart+G;do;while(z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&Z<H);b.match_length=G-(H-Z),b.match_length>b.lookahead&&(b.match_length=b.lookahead)}if(b.match_length>=T?(I=l._tr_tally(b,1,b.match_length-T),b.lookahead-=b.match_length,b.strstart+=b.match_length,b.match_length=0):(I=l._tr_tally(b,0,b.window[b.strstart]),b.lookahead--,b.strstart++),I&&(L(b,!1),b.strm.avail_out===0))return m}return b.insert=0,A===g?(L(b,!0),b.strm.avail_out===0?ie:q):b.last_lit&&(L(b,!1),b.strm.avail_out===0)?m:V})(C,K):i[C.level].func(C,K);if(y!==ie&&y!==q||(C.status=666),y===m||y===ie)return c.avail_out===0&&(C.last_flush=-1),d;if(y===V&&(K===1?l._tr_align(C):K!==5&&(l._tr_stored_block(C,0,0,!1),K===3&&(ee(C.head),C.lookahead===0&&(C.strstart=0,C.block_start=0,C.insert=0))),O(c),c.avail_out===0))return C.last_flush=-1,d}return K!==g?d:C.wrap<=0?1:(C.wrap===2?(ae(C,255&c.adler),ae(C,c.adler>>8&255),ae(C,c.adler>>16&255),ae(C,c.adler>>24&255),ae(C,255&c.total_in),ae(C,c.total_in>>8&255),ae(C,c.total_in>>16&255),ae(C,c.total_in>>24&255)):(te(C,c.adler>>>16),te(C,65535&c.adler)),O(c),0<C.wrap&&(C.wrap=-C.wrap),C.pending!==0?d:1)},n.deflateEnd=function(c){var K;return c&&c.state?(K=c.state.status)!==v&&K!==69&&K!==73&&K!==91&&K!==103&&K!==R&&K!==666?ce(c,k):(c.state=null,K===R?ce(c,-3):d):k},n.deflateSetDictionary=function(c,K){var M,C,N,D,X,y,b,A,I=K.length;if(!c||!c.state||(D=(M=c.state).wrap)===2||D===1&&M.status!==v||M.lookahead)return k;for(D===1&&(c.adler=h(c.adler,K,I,0)),M.wrap=0,I>=M.w_size&&(D===0&&(ee(M.head),M.strstart=0,M.block_start=0,M.insert=0),A=new o.Buf8(M.w_size),o.arraySet(A,K,I-M.w_size,M.w_size,0),K=A,I=M.w_size),X=c.avail_in,y=c.next_in,b=c.input,c.avail_in=I,c.next_in=0,c.input=K,ve(M);M.lookahead>=T;){for(C=M.strstart,N=M.lookahead-(T-1);M.ins_h=(M.ins_h<<M.hash_shift^M.window[C+T-1])&M.hash_mask,M.prev[C&M.w_mask]=M.head[M.ins_h],M.head[M.ins_h]=C,C++,--N;);M.strstart=C,M.lookahead=T-1,ve(M)}return M.strstart+=M.lookahead,M.block_start=M.strstart,M.insert=M.lookahead,M.lookahead=0,M.match_length=M.prev_length=T-1,M.match_available=0,c.next_in=y,c.input=b,c.avail_in=X,M.wrap=D,d},n.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(s,a,n){a.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(s,a,n){a.exports=function(i,o){var l,h,p,_,w,g,d,k,u,x,f,j,E,P,S,B,U,$,T,G,se,v,R,m,V;l=i.state,h=i.next_in,m=i.input,p=h+(i.avail_in-5),_=i.next_out,V=i.output,w=_-(o-i.avail_out),g=_+(i.avail_out-257),d=l.dmax,k=l.wsize,u=l.whave,x=l.wnext,f=l.window,j=l.hold,E=l.bits,P=l.lencode,S=l.distcode,B=(1<<l.lenbits)-1,U=(1<<l.distbits)-1;e:do{E<15&&(j+=m[h++]<<E,E+=8,j+=m[h++]<<E,E+=8),$=P[j&B];t:for(;;){if(j>>>=T=$>>>24,E-=T,(T=$>>>16&255)===0)V[_++]=65535&$;else{if(!(16&T)){if((64&T)==0){$=P[(65535&$)+(j&(1<<T)-1)];continue t}if(32&T){l.mode=12;break e}i.msg="invalid literal/length code",l.mode=30;break e}G=65535&$,(T&=15)&&(E<T&&(j+=m[h++]<<E,E+=8),G+=j&(1<<T)-1,j>>>=T,E-=T),E<15&&(j+=m[h++]<<E,E+=8,j+=m[h++]<<E,E+=8),$=S[j&U];r:for(;;){if(j>>>=T=$>>>24,E-=T,!(16&(T=$>>>16&255))){if((64&T)==0){$=S[(65535&$)+(j&(1<<T)-1)];continue r}i.msg="invalid distance code",l.mode=30;break e}if(se=65535&$,E<(T&=15)&&(j+=m[h++]<<E,(E+=8)<T&&(j+=m[h++]<<E,E+=8)),d<(se+=j&(1<<T)-1)){i.msg="invalid distance too far back",l.mode=30;break e}if(j>>>=T,E-=T,(T=_-w)<se){if(u<(T=se-T)&&l.sane){i.msg="invalid distance too far back",l.mode=30;break e}if(R=f,(v=0)===x){if(v+=k-T,T<G){for(G-=T;V[_++]=f[v++],--T;);v=_-se,R=V}}else if(x<T){if(v+=k+x-T,(T-=x)<G){for(G-=T;V[_++]=f[v++],--T;);if(v=0,x<G){for(G-=T=x;V[_++]=f[v++],--T;);v=_-se,R=V}}}else if(v+=x-T,T<G){for(G-=T;V[_++]=f[v++],--T;);v=_-se,R=V}for(;2<G;)V[_++]=R[v++],V[_++]=R[v++],V[_++]=R[v++],G-=3;G&&(V[_++]=R[v++],1<G&&(V[_++]=R[v++]))}else{for(v=_-se;V[_++]=V[v++],V[_++]=V[v++],V[_++]=V[v++],2<(G-=3););G&&(V[_++]=V[v++],1<G&&(V[_++]=V[v++]))}break}}break}}while(h<p&&_<g);h-=G=E>>3,j&=(1<<(E-=G<<3))-1,i.next_in=h,i.next_out=_,i.avail_in=h<p?p-h+5:5-(h-p),i.avail_out=_<g?g-_+257:257-(_-g),l.hold=j,l.bits=E}},{}],49:[function(s,a,n){var i=s("../utils/common"),o=s("./adler32"),l=s("./crc32"),h=s("./inffast"),p=s("./inftrees"),_=1,w=2,g=0,d=-2,k=1,u=852,x=592;function f(v){return(v>>>24&255)+(v>>>8&65280)+((65280&v)<<8)+((255&v)<<24)}function j(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new i.Buf16(320),this.work=new i.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function E(v){var R;return v&&v.state?(R=v.state,v.total_in=v.total_out=R.total=0,v.msg="",R.wrap&&(v.adler=1&R.wrap),R.mode=k,R.last=0,R.havedict=0,R.dmax=32768,R.head=null,R.hold=0,R.bits=0,R.lencode=R.lendyn=new i.Buf32(u),R.distcode=R.distdyn=new i.Buf32(x),R.sane=1,R.back=-1,g):d}function P(v){var R;return v&&v.state?((R=v.state).wsize=0,R.whave=0,R.wnext=0,E(v)):d}function S(v,R){var m,V;return v&&v.state?(V=v.state,R<0?(m=0,R=-R):(m=1+(R>>4),R<48&&(R&=15)),R&&(R<8||15<R)?d:(V.window!==null&&V.wbits!==R&&(V.window=null),V.wrap=m,V.wbits=R,P(v))):d}function B(v,R){var m,V;return v?(V=new j,(v.state=V).window=null,(m=S(v,R))!==g&&(v.state=null),m):d}var U,$,T=!0;function G(v){if(T){var R;for(U=new i.Buf32(512),$=new i.Buf32(32),R=0;R<144;)v.lens[R++]=8;for(;R<256;)v.lens[R++]=9;for(;R<280;)v.lens[R++]=7;for(;R<288;)v.lens[R++]=8;for(p(_,v.lens,0,288,U,0,v.work,{bits:9}),R=0;R<32;)v.lens[R++]=5;p(w,v.lens,0,32,$,0,v.work,{bits:5}),T=!1}v.lencode=U,v.lenbits=9,v.distcode=$,v.distbits=5}function se(v,R,m,V){var ie,q=v.state;return q.window===null&&(q.wsize=1<<q.wbits,q.wnext=0,q.whave=0,q.window=new i.Buf8(q.wsize)),V>=q.wsize?(i.arraySet(q.window,R,m-q.wsize,q.wsize,0),q.wnext=0,q.whave=q.wsize):(V<(ie=q.wsize-q.wnext)&&(ie=V),i.arraySet(q.window,R,m-V,ie,q.wnext),(V-=ie)?(i.arraySet(q.window,R,m-V,V,0),q.wnext=V,q.whave=q.wsize):(q.wnext+=ie,q.wnext===q.wsize&&(q.wnext=0),q.whave<q.wsize&&(q.whave+=ie))),0}n.inflateReset=P,n.inflateReset2=S,n.inflateResetKeep=E,n.inflateInit=function(v){return B(v,15)},n.inflateInit2=B,n.inflate=function(v,R){var m,V,ie,q,ce,F,ee,O,L,ae,te,J,ve,Se,fe,me,ke,ye,_e,Re,c,K,M,C,N=0,D=new i.Buf8(4),X=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!v||!v.state||!v.output||!v.input&&v.avail_in!==0)return d;(m=v.state).mode===12&&(m.mode=13),ce=v.next_out,ie=v.output,ee=v.avail_out,q=v.next_in,V=v.input,F=v.avail_in,O=m.hold,L=m.bits,ae=F,te=ee,K=g;e:for(;;)switch(m.mode){case k:if(m.wrap===0){m.mode=13;break}for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(2&m.wrap&&O===35615){D[m.check=0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0),L=O=0,m.mode=2;break}if(m.flags=0,m.head&&(m.head.done=!1),!(1&m.wrap)||(((255&O)<<8)+(O>>8))%31){v.msg="incorrect header check",m.mode=30;break}if((15&O)!=8){v.msg="unknown compression method",m.mode=30;break}if(L-=4,c=8+(15&(O>>>=4)),m.wbits===0)m.wbits=c;else if(c>m.wbits){v.msg="invalid window size",m.mode=30;break}m.dmax=1<<c,v.adler=m.check=1,m.mode=512&O?10:12,L=O=0;break;case 2:for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(m.flags=O,(255&m.flags)!=8){v.msg="unknown compression method",m.mode=30;break}if(57344&m.flags){v.msg="unknown header flags set",m.mode=30;break}m.head&&(m.head.text=O>>8&1),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0,m.mode=3;case 3:for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.head&&(m.head.time=O),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,D[2]=O>>>16&255,D[3]=O>>>24&255,m.check=l(m.check,D,4,0)),L=O=0,m.mode=4;case 4:for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.head&&(m.head.xflags=255&O,m.head.os=O>>8),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0,m.mode=5;case 5:if(1024&m.flags){for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.length=O,m.head&&(m.head.extra_len=O),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0}else m.head&&(m.head.extra=null);m.mode=6;case 6:if(1024&m.flags&&(F<(J=m.length)&&(J=F),J&&(m.head&&(c=m.head.extra_len-m.length,m.head.extra||(m.head.extra=new Array(m.head.extra_len)),i.arraySet(m.head.extra,V,q,J,c)),512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,m.length-=J),m.length))break e;m.length=0,m.mode=7;case 7:if(2048&m.flags){if(F===0)break e;for(J=0;c=V[q+J++],m.head&&c&&m.length<65536&&(m.head.name+=String.fromCharCode(c)),c&&J<F;);if(512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,c)break e}else m.head&&(m.head.name=null);m.length=0,m.mode=8;case 8:if(4096&m.flags){if(F===0)break e;for(J=0;c=V[q+J++],m.head&&c&&m.length<65536&&(m.head.comment+=String.fromCharCode(c)),c&&J<F;);if(512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,c)break e}else m.head&&(m.head.comment=null);m.mode=9;case 9:if(512&m.flags){for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O!==(65535&m.check)){v.msg="header crc mismatch",m.mode=30;break}L=O=0}m.head&&(m.head.hcrc=m.flags>>9&1,m.head.done=!0),v.adler=m.check=0,m.mode=12;break;case 10:for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}v.adler=m.check=f(O),L=O=0,m.mode=11;case 11:if(m.havedict===0)return v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,2;v.adler=m.check=1,m.mode=12;case 12:if(R===5||R===6)break e;case 13:if(m.last){O>>>=7&L,L-=7&L,m.mode=27;break}for(;L<3;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}switch(m.last=1&O,L-=1,3&(O>>>=1)){case 0:m.mode=14;break;case 1:if(G(m),m.mode=20,R!==6)break;O>>>=2,L-=2;break e;case 2:m.mode=17;break;case 3:v.msg="invalid block type",m.mode=30}O>>>=2,L-=2;break;case 14:for(O>>>=7&L,L-=7&L;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if((65535&O)!=(O>>>16^65535)){v.msg="invalid stored block lengths",m.mode=30;break}if(m.length=65535&O,L=O=0,m.mode=15,R===6)break e;case 15:m.mode=16;case 16:if(J=m.length){if(F<J&&(J=F),ee<J&&(J=ee),J===0)break e;i.arraySet(ie,V,q,J,ce),F-=J,q+=J,ee-=J,ce+=J,m.length-=J;break}m.mode=12;break;case 17:for(;L<14;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(m.nlen=257+(31&O),O>>>=5,L-=5,m.ndist=1+(31&O),O>>>=5,L-=5,m.ncode=4+(15&O),O>>>=4,L-=4,286<m.nlen||30<m.ndist){v.msg="too many length or distance symbols",m.mode=30;break}m.have=0,m.mode=18;case 18:for(;m.have<m.ncode;){for(;L<3;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.lens[X[m.have++]]=7&O,O>>>=3,L-=3}for(;m.have<19;)m.lens[X[m.have++]]=0;if(m.lencode=m.lendyn,m.lenbits=7,M={bits:m.lenbits},K=p(0,m.lens,0,19,m.lencode,0,m.work,M),m.lenbits=M.bits,K){v.msg="invalid code lengths set",m.mode=30;break}m.have=0,m.mode=19;case 19:for(;m.have<m.nlen+m.ndist;){for(;me=(N=m.lencode[O&(1<<m.lenbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(ke<16)O>>>=fe,L-=fe,m.lens[m.have++]=ke;else{if(ke===16){for(C=fe+2;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O>>>=fe,L-=fe,m.have===0){v.msg="invalid bit length repeat",m.mode=30;break}c=m.lens[m.have-1],J=3+(3&O),O>>>=2,L-=2}else if(ke===17){for(C=fe+3;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}L-=fe,c=0,J=3+(7&(O>>>=fe)),O>>>=3,L-=3}else{for(C=fe+7;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}L-=fe,c=0,J=11+(127&(O>>>=fe)),O>>>=7,L-=7}if(m.have+J>m.nlen+m.ndist){v.msg="invalid bit length repeat",m.mode=30;break}for(;J--;)m.lens[m.have++]=c}}if(m.mode===30)break;if(m.lens[256]===0){v.msg="invalid code -- missing end-of-block",m.mode=30;break}if(m.lenbits=9,M={bits:m.lenbits},K=p(_,m.lens,0,m.nlen,m.lencode,0,m.work,M),m.lenbits=M.bits,K){v.msg="invalid literal/lengths set",m.mode=30;break}if(m.distbits=6,m.distcode=m.distdyn,M={bits:m.distbits},K=p(w,m.lens,m.nlen,m.ndist,m.distcode,0,m.work,M),m.distbits=M.bits,K){v.msg="invalid distances set",m.mode=30;break}if(m.mode=20,R===6)break e;case 20:m.mode=21;case 21:if(6<=F&&258<=ee){v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,h(v,te),ce=v.next_out,ie=v.output,ee=v.avail_out,q=v.next_in,V=v.input,F=v.avail_in,O=m.hold,L=m.bits,m.mode===12&&(m.back=-1);break}for(m.back=0;me=(N=m.lencode[O&(1<<m.lenbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(me&&(240&me)==0){for(ye=fe,_e=me,Re=ke;me=(N=m.lencode[Re+((O&(1<<ye+_e)-1)>>ye)])>>>16&255,ke=65535&N,!(ye+(fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}O>>>=ye,L-=ye,m.back+=ye}if(O>>>=fe,L-=fe,m.back+=fe,m.length=ke,me===0){m.mode=26;break}if(32&me){m.back=-1,m.mode=12;break}if(64&me){v.msg="invalid literal/length code",m.mode=30;break}m.extra=15&me,m.mode=22;case 22:if(m.extra){for(C=m.extra;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.length+=O&(1<<m.extra)-1,O>>>=m.extra,L-=m.extra,m.back+=m.extra}m.was=m.length,m.mode=23;case 23:for(;me=(N=m.distcode[O&(1<<m.distbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if((240&me)==0){for(ye=fe,_e=me,Re=ke;me=(N=m.distcode[Re+((O&(1<<ye+_e)-1)>>ye)])>>>16&255,ke=65535&N,!(ye+(fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}O>>>=ye,L-=ye,m.back+=ye}if(O>>>=fe,L-=fe,m.back+=fe,64&me){v.msg="invalid distance code",m.mode=30;break}m.offset=ke,m.extra=15&me,m.mode=24;case 24:if(m.extra){for(C=m.extra;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.offset+=O&(1<<m.extra)-1,O>>>=m.extra,L-=m.extra,m.back+=m.extra}if(m.offset>m.dmax){v.msg="invalid distance too far back",m.mode=30;break}m.mode=25;case 25:if(ee===0)break e;if(J=te-ee,m.offset>J){if((J=m.offset-J)>m.whave&&m.sane){v.msg="invalid distance too far back",m.mode=30;break}ve=J>m.wnext?(J-=m.wnext,m.wsize-J):m.wnext-J,J>m.length&&(J=m.length),Se=m.window}else Se=ie,ve=ce-m.offset,J=m.length;for(ee<J&&(J=ee),ee-=J,m.length-=J;ie[ce++]=Se[ve++],--J;);m.length===0&&(m.mode=21);break;case 26:if(ee===0)break e;ie[ce++]=m.length,ee--,m.mode=21;break;case 27:if(m.wrap){for(;L<32;){if(F===0)break e;F--,O|=V[q++]<<L,L+=8}if(te-=ee,v.total_out+=te,m.total+=te,te&&(v.adler=m.check=m.flags?l(m.check,ie,te,ce-te):o(m.check,ie,te,ce-te)),te=ee,(m.flags?O:f(O))!==m.check){v.msg="incorrect data check",m.mode=30;break}L=O=0}m.mode=28;case 28:if(m.wrap&&m.flags){for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O!==(4294967295&m.total)){v.msg="incorrect length check",m.mode=30;break}L=O=0}m.mode=29;case 29:K=1;break e;case 30:K=-3;break e;case 31:return-4;case 32:default:return d}return v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,(m.wsize||te!==v.avail_out&&m.mode<30&&(m.mode<27||R!==4))&&se(v,v.output,v.next_out,te-v.avail_out)?(m.mode=31,-4):(ae-=v.avail_in,te-=v.avail_out,v.total_in+=ae,v.total_out+=te,m.total+=te,m.wrap&&te&&(v.adler=m.check=m.flags?l(m.check,ie,te,v.next_out-te):o(m.check,ie,te,v.next_out-te)),v.data_type=m.bits+(m.last?64:0)+(m.mode===12?128:0)+(m.mode===20||m.mode===15?256:0),(ae==0&&te===0||R===4)&&K===g&&(K=-5),K)},n.inflateEnd=function(v){if(!v||!v.state)return d;var R=v.state;return R.window&&(R.window=null),v.state=null,g},n.inflateGetHeader=function(v,R){var m;return v&&v.state?(2&(m=v.state).wrap)==0?d:((m.head=R).done=!1,g):d},n.inflateSetDictionary=function(v,R){var m,V=R.length;return v&&v.state?(m=v.state).wrap!==0&&m.mode!==11?d:m.mode===11&&o(1,R,V,0)!==m.check?-3:se(v,R,V,V)?(m.mode=31,-4):(m.havedict=1,g):d},n.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(s,a,n){var i=s("../utils/common"),o=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],l=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],h=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],p=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];a.exports=function(_,w,g,d,k,u,x,f){var j,E,P,S,B,U,$,T,G,se=f.bits,v=0,R=0,m=0,V=0,ie=0,q=0,ce=0,F=0,ee=0,O=0,L=null,ae=0,te=new i.Buf16(16),J=new i.Buf16(16),ve=null,Se=0;for(v=0;v<=15;v++)te[v]=0;for(R=0;R<d;R++)te[w[g+R]]++;for(ie=se,V=15;1<=V&&te[V]===0;V--);if(V<ie&&(ie=V),V===0)return k[u++]=20971520,k[u++]=20971520,f.bits=1,0;for(m=1;m<V&&te[m]===0;m++);for(ie<m&&(ie=m),v=F=1;v<=15;v++)if(F<<=1,(F-=te[v])<0)return-1;if(0<F&&(_===0||V!==1))return-1;for(J[1]=0,v=1;v<15;v++)J[v+1]=J[v]+te[v];for(R=0;R<d;R++)w[g+R]!==0&&(x[J[w[g+R]]++]=R);if(U=_===0?(L=ve=x,19):_===1?(L=o,ae-=257,ve=l,Se-=257,256):(L=h,ve=p,-1),v=m,B=u,ce=R=O=0,P=-1,S=(ee=1<<(q=ie))-1,_===1&&852<ee||_===2&&592<ee)return 1;for(;;){for($=v-ce,G=x[R]<U?(T=0,x[R]):x[R]>U?(T=ve[Se+x[R]],L[ae+x[R]]):(T=96,0),j=1<<v-ce,m=E=1<<q;k[B+(O>>ce)+(E-=j)]=$<<24|T<<16|G|0,E!==0;);for(j=1<<v-1;O&j;)j>>=1;if(j!==0?(O&=j-1,O+=j):O=0,R++,--te[v]==0){if(v===V)break;v=w[g+x[R]]}if(ie<v&&(O&S)!==P){for(ce===0&&(ce=ie),B+=m,F=1<<(q=v-ce);q+ce<V&&!((F-=te[q+ce])<=0);)q++,F<<=1;if(ee+=1<<q,_===1&&852<ee||_===2&&592<ee)return 1;k[P=O&S]=ie<<24|q<<16|B-u|0}}return O!==0&&(k[B+O]=v-ce<<24|64<<16|0),f.bits=ie,0}},{"../utils/common":41}],51:[function(s,a,n){a.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(s,a,n){var i=s("../utils/common"),o=0,l=1;function h(N){for(var D=N.length;0<=--D;)N[D]=0}var p=0,_=29,w=256,g=w+1+_,d=30,k=19,u=2*g+1,x=15,f=16,j=7,E=256,P=16,S=17,B=18,U=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],$=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],T=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],G=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],se=new Array(2*(g+2));h(se);var v=new Array(2*d);h(v);var R=new Array(512);h(R);var m=new Array(256);h(m);var V=new Array(_);h(V);var ie,q,ce,F=new Array(d);function ee(N,D,X,y,b){this.static_tree=N,this.extra_bits=D,this.extra_base=X,this.elems=y,this.max_length=b,this.has_stree=N&&N.length}function O(N,D){this.dyn_tree=N,this.max_code=0,this.stat_desc=D}function L(N){return N<256?R[N]:R[256+(N>>>7)]}function ae(N,D){N.pending_buf[N.pending++]=255&D,N.pending_buf[N.pending++]=D>>>8&255}function te(N,D,X){N.bi_valid>f-X?(N.bi_buf|=D<<N.bi_valid&65535,ae(N,N.bi_buf),N.bi_buf=D>>f-N.bi_valid,N.bi_valid+=X-f):(N.bi_buf|=D<<N.bi_valid&65535,N.bi_valid+=X)}function J(N,D,X){te(N,X[2*D],X[2*D+1])}function ve(N,D){for(var X=0;X|=1&N,N>>>=1,X<<=1,0<--D;);return X>>>1}function Se(N,D,X){var y,b,A=new Array(x+1),I=0;for(y=1;y<=x;y++)A[y]=I=I+X[y-1]<<1;for(b=0;b<=D;b++){var z=N[2*b+1];z!==0&&(N[2*b]=ve(A[z]++,z))}}function fe(N){var D;for(D=0;D<g;D++)N.dyn_ltree[2*D]=0;for(D=0;D<d;D++)N.dyn_dtree[2*D]=0;for(D=0;D<k;D++)N.bl_tree[2*D]=0;N.dyn_ltree[2*E]=1,N.opt_len=N.static_len=0,N.last_lit=N.matches=0}function me(N){8<N.bi_valid?ae(N,N.bi_buf):0<N.bi_valid&&(N.pending_buf[N.pending++]=N.bi_buf),N.bi_buf=0,N.bi_valid=0}function ke(N,D,X,y){var b=2*D,A=2*X;return N[b]<N[A]||N[b]===N[A]&&y[D]<=y[X]}function ye(N,D,X){for(var y=N.heap[X],b=X<<1;b<=N.heap_len&&(b<N.heap_len&&ke(D,N.heap[b+1],N.heap[b],N.depth)&&b++,!ke(D,y,N.heap[b],N.depth));)N.heap[X]=N.heap[b],X=b,b<<=1;N.heap[X]=y}function _e(N,D,X){var y,b,A,I,z=0;if(N.last_lit!==0)for(;y=N.pending_buf[N.d_buf+2*z]<<8|N.pending_buf[N.d_buf+2*z+1],b=N.pending_buf[N.l_buf+z],z++,y===0?J(N,b,D):(J(N,(A=m[b])+w+1,D),(I=U[A])!==0&&te(N,b-=V[A],I),J(N,A=L(--y),X),(I=$[A])!==0&&te(N,y-=F[A],I)),z<N.last_lit;);J(N,E,D)}function Re(N,D){var X,y,b,A=D.dyn_tree,I=D.stat_desc.static_tree,z=D.stat_desc.has_stree,Z=D.stat_desc.elems,H=-1;for(N.heap_len=0,N.heap_max=u,X=0;X<Z;X++)A[2*X]!==0?(N.heap[++N.heap_len]=H=X,N.depth[X]=0):A[2*X+1]=0;for(;N.heap_len<2;)A[2*(b=N.heap[++N.heap_len]=H<2?++H:0)]=1,N.depth[b]=0,N.opt_len--,z&&(N.static_len-=I[2*b+1]);for(D.max_code=H,X=N.heap_len>>1;1<=X;X--)ye(N,A,X);for(b=Z;X=N.heap[1],N.heap[1]=N.heap[N.heap_len--],ye(N,A,1),y=N.heap[1],N.heap[--N.heap_max]=X,N.heap[--N.heap_max]=y,A[2*b]=A[2*X]+A[2*y],N.depth[b]=(N.depth[X]>=N.depth[y]?N.depth[X]:N.depth[y])+1,A[2*X+1]=A[2*y+1]=b,N.heap[1]=b++,ye(N,A,1),2<=N.heap_len;);N.heap[--N.heap_max]=N.heap[1],(function(re,he){var ze,je,Fe,ge,xe,Ze,$e=he.dyn_tree,Ae=he.max_code,He=he.stat_desc.static_tree,Qe=he.stat_desc.has_stree,xt=he.stat_desc.extra_bits,mt=he.stat_desc.extra_base,Nt=he.stat_desc.max_length,St=0;for(ge=0;ge<=x;ge++)re.bl_count[ge]=0;for($e[2*re.heap[re.heap_max]+1]=0,ze=re.heap_max+1;ze<u;ze++)Nt<(ge=$e[2*$e[2*(je=re.heap[ze])+1]+1]+1)&&(ge=Nt,St++),$e[2*je+1]=ge,Ae<je||(re.bl_count[ge]++,xe=0,mt<=je&&(xe=xt[je-mt]),Ze=$e[2*je],re.opt_len+=Ze*(ge+xe),Qe&&(re.static_len+=Ze*(He[2*je+1]+xe)));if(St!==0){do{for(ge=Nt-1;re.bl_count[ge]===0;)ge--;re.bl_count[ge]--,re.bl_count[ge+1]+=2,re.bl_count[Nt]--,St-=2}while(0<St);for(ge=Nt;ge!==0;ge--)for(je=re.bl_count[ge];je!==0;)Ae<(Fe=re.heap[--ze])||($e[2*Fe+1]!==ge&&(re.opt_len+=(ge-$e[2*Fe+1])*$e[2*Fe],$e[2*Fe+1]=ge),je--)}})(N,D),Se(A,H,N.bl_count)}function c(N,D,X){var y,b,A=-1,I=D[1],z=0,Z=7,H=4;for(I===0&&(Z=138,H=3),D[2*(X+1)+1]=65535,y=0;y<=X;y++)b=I,I=D[2*(y+1)+1],++z<Z&&b===I||(z<H?N.bl_tree[2*b]+=z:b!==0?(b!==A&&N.bl_tree[2*b]++,N.bl_tree[2*P]++):z<=10?N.bl_tree[2*S]++:N.bl_tree[2*B]++,A=b,H=(z=0)===I?(Z=138,3):b===I?(Z=6,3):(Z=7,4))}function K(N,D,X){var y,b,A=-1,I=D[1],z=0,Z=7,H=4;for(I===0&&(Z=138,H=3),y=0;y<=X;y++)if(b=I,I=D[2*(y+1)+1],!(++z<Z&&b===I)){if(z<H)for(;J(N,b,N.bl_tree),--z!=0;);else b!==0?(b!==A&&(J(N,b,N.bl_tree),z--),J(N,P,N.bl_tree),te(N,z-3,2)):z<=10?(J(N,S,N.bl_tree),te(N,z-3,3)):(J(N,B,N.bl_tree),te(N,z-11,7));A=b,H=(z=0)===I?(Z=138,3):b===I?(Z=6,3):(Z=7,4)}}h(F);var M=!1;function C(N,D,X,y){te(N,(p<<1)+(y?1:0),3),(function(b,A,I,z){me(b),ae(b,I),ae(b,~I),i.arraySet(b.pending_buf,b.window,A,I,b.pending),b.pending+=I})(N,D,X)}n._tr_init=function(N){M||((function(){var D,X,y,b,A,I=new Array(x+1);for(b=y=0;b<_-1;b++)for(V[b]=y,D=0;D<1<<U[b];D++)m[y++]=b;for(m[y-1]=b,b=A=0;b<16;b++)for(F[b]=A,D=0;D<1<<$[b];D++)R[A++]=b;for(A>>=7;b<d;b++)for(F[b]=A<<7,D=0;D<1<<$[b]-7;D++)R[256+A++]=b;for(X=0;X<=x;X++)I[X]=0;for(D=0;D<=143;)se[2*D+1]=8,D++,I[8]++;for(;D<=255;)se[2*D+1]=9,D++,I[9]++;for(;D<=279;)se[2*D+1]=7,D++,I[7]++;for(;D<=287;)se[2*D+1]=8,D++,I[8]++;for(Se(se,g+1,I),D=0;D<d;D++)v[2*D+1]=5,v[2*D]=ve(D,5);ie=new ee(se,U,w+1,g,x),q=new ee(v,$,0,d,x),ce=new ee(new Array(0),T,0,k,j)})(),M=!0),N.l_desc=new O(N.dyn_ltree,ie),N.d_desc=new O(N.dyn_dtree,q),N.bl_desc=new O(N.bl_tree,ce),N.bi_buf=0,N.bi_valid=0,fe(N)},n._tr_stored_block=C,n._tr_flush_block=function(N,D,X,y){var b,A,I=0;0<N.level?(N.strm.data_type===2&&(N.strm.data_type=(function(z){var Z,H=4093624447;for(Z=0;Z<=31;Z++,H>>>=1)if(1&H&&z.dyn_ltree[2*Z]!==0)return o;if(z.dyn_ltree[18]!==0||z.dyn_ltree[20]!==0||z.dyn_ltree[26]!==0)return l;for(Z=32;Z<w;Z++)if(z.dyn_ltree[2*Z]!==0)return l;return o})(N)),Re(N,N.l_desc),Re(N,N.d_desc),I=(function(z){var Z;for(c(z,z.dyn_ltree,z.l_desc.max_code),c(z,z.dyn_dtree,z.d_desc.max_code),Re(z,z.bl_desc),Z=k-1;3<=Z&&z.bl_tree[2*G[Z]+1]===0;Z--);return z.opt_len+=3*(Z+1)+5+5+4,Z})(N),b=N.opt_len+3+7>>>3,(A=N.static_len+3+7>>>3)<=b&&(b=A)):b=A=X+5,X+4<=b&&D!==-1?C(N,D,X,y):N.strategy===4||A===b?(te(N,2+(y?1:0),3),_e(N,se,v)):(te(N,4+(y?1:0),3),(function(z,Z,H,re){var he;for(te(z,Z-257,5),te(z,H-1,5),te(z,re-4,4),he=0;he<re;he++)te(z,z.bl_tree[2*G[he]+1],3);K(z,z.dyn_ltree,Z-1),K(z,z.dyn_dtree,H-1)})(N,N.l_desc.max_code+1,N.d_desc.max_code+1,I+1),_e(N,N.dyn_ltree,N.dyn_dtree)),fe(N),y&&me(N)},n._tr_tally=function(N,D,X){return N.pending_buf[N.d_buf+2*N.last_lit]=D>>>8&255,N.pending_buf[N.d_buf+2*N.last_lit+1]=255&D,N.pending_buf[N.l_buf+N.last_lit]=255&X,N.last_lit++,D===0?N.dyn_ltree[2*X]++:(N.matches++,D--,N.dyn_ltree[2*(m[X]+w+1)]++,N.dyn_dtree[2*L(D)]++),N.last_lit===N.lit_bufsize-1},n._tr_align=function(N){te(N,2,3),J(N,E,se),(function(D){D.bi_valid===16?(ae(D,D.bi_buf),D.bi_buf=0,D.bi_valid=0):8<=D.bi_valid&&(D.pending_buf[D.pending++]=255&D.bi_buf,D.bi_buf>>=8,D.bi_valid-=8)})(N)}},{"../utils/common":41}],53:[function(s,a,n){a.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(s,a,n){(function(i){(function(o,l){if(!o.setImmediate){var h,p,_,w,g=1,d={},k=!1,u=o.document,x=Object.getPrototypeOf&&Object.getPrototypeOf(o);x=x&&x.setTimeout?x:o,h={}.toString.call(o.process)==="[object process]"?function(P){process.nextTick(function(){j(P)})}:(function(){if(o.postMessage&&!o.importScripts){var P=!0,S=o.onmessage;return o.onmessage=function(){P=!1},o.postMessage("","*"),o.onmessage=S,P}})()?(w="setImmediate$"+Math.random()+"$",o.addEventListener?o.addEventListener("message",E,!1):o.attachEvent("onmessage",E),function(P){o.postMessage(w+P,"*")}):o.MessageChannel?((_=new MessageChannel).port1.onmessage=function(P){j(P.data)},function(P){_.port2.postMessage(P)}):u&&"onreadystatechange"in u.createElement("script")?(p=u.documentElement,function(P){var S=u.createElement("script");S.onreadystatechange=function(){j(P),S.onreadystatechange=null,p.removeChild(S),S=null},p.appendChild(S)}):function(P){setTimeout(j,0,P)},x.setImmediate=function(P){typeof P!="function"&&(P=new Function(""+P));for(var S=new Array(arguments.length-1),B=0;B<S.length;B++)S[B]=arguments[B+1];var U={callback:P,args:S};return d[g]=U,h(g),g++},x.clearImmediate=f}function f(P){delete d[P]}function j(P){if(k)setTimeout(j,0,P);else{var S=d[P];if(S){k=!0;try{(function(B){var U=B.callback,$=B.args;switch($.length){case 0:U();break;case 1:U($[0]);break;case 2:U($[0],$[1]);break;case 3:U($[0],$[1],$[2]);break;default:U.apply(l,$)}})(S)}finally{f(P),k=!1}}}}function E(P){P.source===o&&typeof P.data=="string"&&P.data.indexOf(w)===0&&j(+P.data.slice(w.length))}})(typeof self>"u"?i===void 0?this:i:self)}).call(this,typeof Rr<"u"?Rr:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(gs)),gs.exports}var go=xo();const bo=Ei(go),ca=5e3,vo=new Set([".jpg",".jpeg",".png",".webp",".gif"]),yo="__MACOSX",Tn={name:["Nombre","name","Name","nombre","NOMBRE","producto","Producto"],description:["Descripción","Descripcion","description","Description","descripcion","DESCRIPCION"],price:["Precio","price","Price","precio","PRECIO"],currency:["Moneda","currency","Currency","moneda","MONEDA"],externalId:["SKU","sku","id","external_id","ExternalId","codigo","Código","Codigo"],externalCategory:["Categoría","Categoria","category","Category","categoria","CATEGORIA"],imageFilename:["Imagen","image","Image","image_url","imagen","IMAGEN","foto","Foto"]};async function wo(e){if(e.name.toLowerCase().endsWith(".xls")&&!e.name.toLowerCase().endsWith(".xlsx"))throw new Error("El formato .xls (Excel 97-2003) no es compatible. Por favor guarda el archivo como .xlsx");return e.name.toLowerCase().endsWith(".zip")||e.type==="application/zip"||e.type==="application/x-zip-compressed"?jo(e):ko(e)}function da(e){switch(e.toLowerCase().split(".").pop()){case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"webp":return"image/webp";case"gif":return"image/gif";default:return"application/octet-stream"}}async function jo(e){const r=await bo.loadAsync(e);let s=null;const a=new Map;if(r.forEach((o,l)=>{if(l.dir||o.startsWith(yo))return;const h=o.split("/").pop()?.toLowerCase()||"",p="."+h.split(".").pop();if(p===".xlsx")s||(s=l);else{if(p===".xls")throw new Error("El ZIP contiene un archivo .xls (Excel 97-2003) que no es compatible. Por favor convierte a .xlsx");vo.has(p)&&a.set(h,l)}}),!s)throw new Error("El ZIP debe contener un archivo Excel (.xlsx)");const n=await s.async("arraybuffer");return{rows:Rn(n),imageEntries:a,isZip:!0,fileName:e.name}}async function ko(e){const r=await e.arrayBuffer();return{rows:Rn(r),imageEntries:new Map,isZip:!1,fileName:e.name}}function Rn(e){const r=Ti(e,{type:"array"}),s=r.SheetNames[0];if(!s)throw new Error("El archivo Excel no contiene hojas");const a=r.Sheets[s],n=Ri.sheet_to_json(a);if(n.length===0)throw new Error("El archivo Excel no contiene filas de datos (solo encabezados)");if(n.length>ca)throw new Error(`El archivo excede el límite de ${ca} filas (tiene ${n.length})`);const i=n.map(_o);if(!i.some(l=>l.name!==void 0)&&i.length>0){const l=Object.values(Tn).flat(),h=Object.keys(n[0]);throw new Error(`No se reconocieron las columnas del Excel. Columnas encontradas: ${h.slice(0,5).join(", ")}${h.length>5?"...":""}. Esperadas: ${l.slice(0,6).join(", ")}...`)}return i}function _o(e){const r=_=>{const w=Tn[_];for(const g of w)if(e[g]!==void 0&&e[g]!==null&&e[g]!=="")return e[g]},s=r("name"),a=r("description"),n=r("price"),i=r("currency"),o=r("externalId"),l=r("externalCategory"),h=r("imageFilename"),p=n!==void 0?parseFloat(String(n)):void 0;return{name:s!=null?String(s).trim():void 0,description:a!=null?String(a).trim():void 0,price:p!==void 0&&!isNaN(p)?p:void 0,currency:i!=null?String(i).trim():void 0,externalId:o!=null?String(o).trim():void 0,externalCategory:l!=null?String(l).trim():void 0,imageFilename:h!=null?String(h).trim():void 0}}const No=new Set(jn.map(e=>e.value)),So="USD";async function Co(e,r,s){let a=0,n=0,i=0;const o=[],l=new Set,h=new Set,p=new Set;for(let g=0;g<e.length;g++){const d=e[g],k=g+2,u=[],x=[];(!d.name||d.name.trim()==="")&&u.push("Nombre es requerido"),d.name&&d.name.length>255&&u.push(`Nombre excede 255 caracteres (tiene ${d.name.length})`),d.description&&d.description.length>5e3&&u.push(`Descripción excede 5000 caracteres (tiene ${d.description.length})`);let f=!1;d.price===void 0||d.price===null||isNaN(d.price)?(u.push("Precio válido es requerido"),f=!0):d.price<0&&(u.push("Precio no puede ser negativo"),f=!0);const j=d.currency?.toUpperCase()||So;No.has(j)||u.push(`Moneda '${d.currency}' no soportada. Válidas: USD, EUR, PEN, COP, MXN, CLP, ARS, BRL`),d.externalId&&d.externalId.length>100&&u.push(`SKU excede 100 caracteres (tiene ${d.externalId.length})`),d.externalCategory&&d.externalCategory.length>100&&u.push(`Categoría excede 100 caracteres (tiene ${d.externalCategory.length})`),!f&&d.price===0&&x.push("Precio es 0 — el producto se importará como gratuito");let E,P;if(d.imageFilename&&s){const B=d.imageFilename.toLowerCase();l.add(B);const U=r.get(B);if(U){h.add(B);try{E=await U.async("blob"),P=URL.createObjectURL(E)}catch{x.push(`No se pudo leer '${d.imageFilename}' del ZIP — se importará sin imagen`)}}else p.add(B),x.push(`Imagen '${d.imageFilename}' no encontrada en el ZIP — se importará sin imagen`)}else d.imageFilename&&!s&&x.push("Las imágenes solo se procesan desde archivos ZIP. Se importará sin imagen");const S=u.length>0?"error":"valid";S==="valid"?(a++,x.length>0&&i++):n++,o.push({rowNumber:k,status:S,data:{...d,currency:j,price:d.price!==void 0&&!isNaN(d.price)?Math.round(d.price*100)/100:d.price},errors:u,warnings:x,imageBlob:E,imagePreviewUrl:P})}const _=r.size,w=_-h.size;return{totalRows:e.length,validRows:a,invalidRows:n,warningRows:i,items:o,imageStats:{referencedInExcel:l.size,foundInZip:h.size,missingFromZip:p.size,totalImagesInZip:_,unreferencedInZip:w}}}function bs(e){for(const r of e)r.imagePreviewUrl&&(URL.revokeObjectURL(r.imagePreviewUrl),r.imagePreviewUrl=void 0)}const ua=50*1024*1024,$r=5,ha={image:{maxBytes:10*1024*1024},video:{maxBytes:0},audio:{maxBytes:0},document:{maxBytes:0}},vs=[{key:"upload",label:"Archivo"},{key:"preview",label:"Revisar"},{key:"uploading",label:"Procesar"},{key:"success",label:"Listo"}],ys={status:"idle",progress:{current:0,total:0},results:new Map,summary:{existing:0,new:0,toOptimize:0}};function zo({onSuccess:e,catalogs:r=[],trigger:s}){const[a,n]=Y.useState(!1),[i,o]=Y.useState("upload"),[l,h]=Y.useState(null),[p,_]=Y.useState(!1),[w,g]=Y.useState(""),[d,k]=Y.useState(null),[u,x]=Y.useState(null),[f,j]=Y.useState("all"),[E,P]=Y.useState({current:0,total:0,percent:0}),[S,B]=Y.useState({uploaded:0,deduplicated:0,failed:0,failedRows:[]}),[U,$]=Y.useState(0),[T,G]=Y.useState([]),[se,v]=Y.useState("all"),[R,m]=Y.useState(""),[V,ie]=Y.useState(""),q=Y.useRef(!1),ce=Y.useRef(null),[F,ee]=Y.useState(ys),O=Y.useRef(null),L=Y.useRef(null),ae=Os(I=>I.currentOrganization),{channels:te,fetchChannels:J}=an(Lt(I=>({channels:I.channels,fetchChannels:I.fetchChannels})));Y.useEffect(()=>{ae?.id&&a&&J({withDeleted:!1})},[ae?.id,a,J]);const ve=Y.useMemo(()=>te.filter(I=>I.isActive&&!I.deletedAt&&!I.disconnectedFromMetaAt&&!I.deactivatedAt&&!I.archivedAt),[te]),Se=Y.useMemo(()=>{if(ve.length===0)return ha;let I=1/0;for(const z of ve){const Z=Sn(z.type),H=z.config?.mediaLimits?.outbound?.image?.maxBytes??Z.outbound.image.maxBytes??1/0;H<I&&(I=H)}return{image:{maxBytes:I===1/0?ha.image.maxBytes:I},video:{maxBytes:0},audio:{maxBytes:0},document:{maxBytes:0}}},[ve]);Y.useEffect(()=>()=>{u&&bs(u.items)},[u]);const fe=Y.useMemo(()=>{if(!u)return[];switch(f){case"errors":return u.items.filter(I=>I.status==="error");case"warnings":return u.items.filter(I=>I.status==="valid"&&I.warnings.length>0);case"valid":return u.items.filter(I=>I.status==="valid"&&I.warnings.length===0);default:return u.items}},[u,f]),me=Y.useMemo(()=>{switch(se){case"inserted":return T.filter(I=>I.dbStatus==="inserted");case"failed":return T.filter(I=>I.dbStatus==="failed");case"skipped":return T.filter(I=>I.dbStatus==="skipped");case"image_issues":return T.filter(I=>I.imageStatus==="failed"||I.imageStatus==="missing_in_zip");default:return T}},[T,se]),ke=aa({count:fe.length,getScrollElement:()=>O.current,estimateSize:()=>52,overscan:10}),ye=aa({count:me.length,getScrollElement:()=>L.current,estimateSize:()=>44,overscan:10}),_e=Y.useMemo(()=>{const I=T.filter(re=>re.dbStatus==="inserted").length,z=T.filter(re=>re.dbStatus==="failed").length,Z=T.filter(re=>re.dbStatus==="skipped").length,H=T.filter(re=>re.imageStatus==="failed"||re.imageStatus==="missing_in_zip").length;return{inserted:I,failed:z,skipped:Z,imageIssues:H,total:T.length}},[T]),Re=Y.useCallback(()=>{u&&bs(u.items),o("upload"),h(null),_(!1),g(""),k(null),x(null),j("all"),P({current:0,total:0,percent:0}),B({uploaded:0,deduplicated:0,failed:0,failedRows:[]}),$(0),G([]),v("all"),m(""),ie(""),ee(ys),q.current=!1,ce.current&&(ce.current.abort(),ce.current=null)},[u]),c=I=>{n(I),I||setTimeout(Re,300)},K=Y.useCallback((I,z)=>{if(z.length>0){z[0]?.errors?.[0]?.code==="file-too-large"?ne.error(`Archivo muy grande. Máximo: ${ua/(1024*1024)} MB`):ne.error("Formato no válido. Usa .xlsx o .zip");return}I.length>0&&h(I[0])},[]),{getRootProps:M,getInputProps:C,isDragActive:N}=Oi({onDrop:K,accept:{"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/zip":[".zip"],"application/x-zip-compressed":[".zip"]},maxFiles:1,maxSize:ua}),D=async()=>{if(l){_(!0),m("Leyendo archivo...");try{const I=await wo(l);k(I),m(`Validando ${I.rows.length} filas...`);const z=await Co(I.rows,I.imageEntries,I.isZip);x(z),j("all"),o("preview")}catch(I){ne.error(I.message||"Error al analizar el archivo")}finally{_(!1),m("")}}},X=Y.useCallback(async I=>{ee({status:"analyzing",progress:{current:0,total:I.length},results:new Map,summary:{existing:0,new:0,toOptimize:0}});const z=new Map;let Z=0,H=0,re=0,he=0;const ze=Se.image.maxBytes;for(let je=0;je<I.length;je+=$r){const Fe=I.slice(je,je+$r);await Promise.all(Fe.map(async ge=>{try{const xe=ge.data.imageFilename||"image.jpg",Ze=da(xe),$e=new File([ge.imageBlob],xe,{type:Ze}),Ae=$e.size,He=await Li.calculateHash($e),Qe=await wi.checkDuplicate(He),xt=Qe.exists&&!!Qe.gcsPath,mt=!xt&&ze>0&&Ae>ze;z.set(ge.rowNumber,{hash:He,isDuplicate:xt,gcsPath:Qe.gcsPath,willOptimize:mt,fileSizeBytes:Ae}),xt?Z++:(H++,mt&&re++)}catch{z.set(ge.rowNumber,{hash:"",isDuplicate:!1,willOptimize:!1,fileSizeBytes:0}),H++}finally{he++,ee(xe=>({...xe,progress:{current:he,total:I.length},results:new Map(z),summary:{existing:Z,new:H,toOptimize:re}}))}}))}ee(je=>({...je,status:"done"}))},[Se]);Y.useEffect(()=>{if(i==="preview"&&u){const I=u.items.filter(z=>z.status==="valid"&&z.imageBlob);I.length>0&&X(I)}},[i]);const y=async()=>{if(!u||!w){ne.error("Selecciona un catálogo para los productos importados");return}const I=u.items.filter(H=>H.status==="valid");if(I.length===0){ne.error("No hay productos válidos para importar");return}q.current=!1,o("uploading"),ie("images");const z={uploaded:0,deduplicated:0,failed:0,failedRows:[]},Z=new Map;for(const H of u.items)H.status!=="error"&&(H.data.imageFilename?!H.imageBlob&&H.warnings.some(re=>re.includes("no encontrada"))?Z.set(H.rowNumber,{status:"missing_in_zip"}):H.imageBlob||Z.set(H.rowNumber,{status:"none"}):Z.set(H.rowNumber,{status:"none"}));try{const H=I.filter(xe=>xe.imageBlob),re=H.length;P({current:0,total:re,percent:0});const he=new Map;if(re>0){let xe=0;for(let Ze=0;Ze<H.length&&!q.current;Ze+=$r){const $e=H.slice(Ze,Ze+$r);await Promise.all($e.map(async Ae=>{try{const He=Ae.data.imageFilename||"image.jpg",Qe=da(He),xt=new File([Ae.imageBlob],He,{type:Qe}),mt=await Cs.processFile(xt,{limits:Se});he.set(Ae.rowNumber,mt.gcsPath),mt.isDuplicate?(z.deduplicated++,Z.set(Ae.rowNumber,{status:"deduplicated"})):(z.uploaded++,Z.set(Ae.rowNumber,{status:"uploaded"}))}catch(He){z.failed++;const Qe=He.message||"Error desconocido";z.failedRows.push({rowNumber:Ae.rowNumber,name:Ae.data.name||"Sin nombre",error:Qe}),Z.set(Ae.rowNumber,{status:"failed",error:Qe})}finally{xe++,P({current:xe,total:re,percent:Math.round(xe/re*100)})}}))}}if(B({...z}),q.current){ne.info("Importación cancelada"),o("preview");return}const ze=I.map(xe=>({name:xe.data.name,description:xe.data.description||"",price:xe.data.price,currency:xe.data.currency||"USD",externalId:xe.data.externalId,externalCategory:xe.data.externalCategory,imageUrl:he.get(xe.rowNumber)||void 0}));ie("saving");const je=new AbortController;ce.current=je;const Fe=await we.bulkImportProducts(w,ze,je.signal);ce.current=null,$(Fe.inserted);const ge=[];for(const xe of u.items)xe.status==="error"&&ge.push({rowNumber:xe.rowNumber,name:xe.data.name||"Sin nombre",dbStatus:"skipped",imageStatus:"none"});I.forEach((xe,Ze)=>{const $e=Z.get(xe.rowNumber)||{status:"none"},Ae=Fe.results.find(Qe=>Qe.index===Ze);let He="skipped";Ae?.status==="inserted"?He="inserted":Ae?.status==="failed"&&(He="failed"),ge.push({rowNumber:xe.rowNumber,name:xe.data.name||"Sin nombre",dbStatus:He,imageStatus:$e.status,imageError:$e.error,dbError:Ae?.error,productId:Ae?.productId})}),ge.sort((xe,Ze)=>xe.rowNumber-Ze.rowNumber),G(ge),v("all"),o("success"),e()}catch(H){const re=H.response?.data?.message||H.message||"Error al importar productos";ne.error(Array.isArray(re)?re[0]:re),o("preview")}},b=async()=>{try{await we.downloadTemplate(),ne.success("Plantilla descargada")}catch{ne.error("Error al descargar plantilla")}},A=vs.findIndex(I=>I.key===i);return t.jsxs(nn,{open:a,onOpenChange:c,children:[t.jsx(ji,{asChild:!0,children:s??t.jsxs(ue,{variant:"outline",className:"gap-2",children:[t.jsx(Hr,{className:"h-4 w-4"}),"Importar"]})}),t.jsxs(on,{className:"sm:max-w-4xl max-h-[90vh] flex flex-col",children:[t.jsxs(ki,{children:[t.jsx(ln,{children:"Importación Masiva de Productos"}),t.jsx(cn,{className:"sr-only",children:"Wizard para importar productos desde un archivo Excel o ZIP"}),t.jsx("div",{className:"flex items-center gap-1 pt-2",children:vs.map((I,z)=>t.jsxs("div",{className:"flex items-center",children:[t.jsxs("div",{className:le("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium transition-colors",z<A&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",z===A&&"bg-primary/10 text-primary",z>A&&"bg-muted text-muted-foreground"),children:[z<A?t.jsx(sr,{className:"h-3.5 w-3.5"}):t.jsx("span",{className:le("w-4 h-4 rounded-full flex items-center justify-center text-[10px] font-bold",z===A?"bg-primary text-primary-foreground":"bg-muted-foreground/20 text-muted-foreground"),children:z+1}),I.label]}),z<vs.length-1&&t.jsx("div",{className:le("w-6 h-px mx-1",z<A?"bg-green-400":"bg-muted-foreground/20")})]},I.key))})]}),t.jsxs("div",{className:"flex-1 overflow-hidden py-3",children:[i==="upload"&&t.jsxs("div",{className:"h-full flex flex-col items-center justify-center space-y-4",children:[l?t.jsx(Rs,{className:"w-full max-w-lg",children:t.jsxs(Zs,{className:"p-6 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsx("div",{className:"p-2 bg-primary/10 rounded-md",children:t.jsx(Wr,{className:"h-8 w-8 text-primary"})}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium truncate max-w-[200px]",children:l.name}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:[(l.size/1024/1024).toFixed(2)," MB"]})]})]}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:I=>{I.stopPropagation(),h(null)},children:t.jsx(Ft,{className:"h-4 w-4"})})]})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{...M(),className:le("border-2 border-dashed rounded-lg p-10 text-center hover:bg-muted/50 cursor-pointer transition-colors w-full max-w-lg",N?"border-primary bg-primary/5":"border-muted-foreground/25"),children:[t.jsx("input",{...C()}),t.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[t.jsx("div",{className:"p-4 bg-primary/10 rounded-full",children:t.jsx(Hr,{className:"h-10 w-10 text-primary"})}),t.jsx("p",{className:"text-sm font-medium",children:"Arrastra tu archivo aquí o haz clic para seleccionar"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Formatos: .xlsx (Excel) o .zip (Excel + Imágenes) — Máx. 50 MB"})]})]}),t.jsx("div",{className:"w-full max-w-lg bg-blue-50/50 dark:bg-blue-950/10 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(dn,{className:"h-4 w-4 text-blue-600 mt-0.5 shrink-0"}),t.jsxs("div",{className:"space-y-1.5 text-xs",children:[t.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-200",children:"¿Cómo preparar tu archivo?"}),t.jsxs("div",{className:"text-blue-700 dark:text-blue-400 space-y-1",children:[t.jsxs("p",{children:[t.jsx("strong",{children:"Solo datos:"})," Sube un ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:".xlsx"})," con las columnas: Nombre, Precio, Descripción, Moneda, SKU, Categoría"]}),t.jsxs("p",{children:[t.jsx("strong",{children:"Con imágenes:"})," Crea un ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:".zip"})," que contenga el Excel + las imágenes. En la columna ",t.jsx("strong",{children:'"Imagen"'})," del Excel escribe el ",t.jsx("strong",{children:"nombre exacto del archivo"})," (ej: ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"polo.jpg"}),")"]})]}),t.jsxs("div",{className:"bg-blue-100/50 dark:bg-blue-900/30 rounded p-2 font-mono text-[11px]",children:[t.jsx("span",{className:"text-blue-500",children:"mi_catalogo.zip"}),t.jsx("br",{})," ├── productos.xlsx",t.jsx("br",{})," ├── polo.jpg",t.jsx("br",{})," ├── laptop.png",t.jsx("br",{})," └── cafe.webp"]})]})]})}),t.jsxs(ue,{variant:"link",size:"sm",onClick:b,className:"text-muted-foreground gap-2",children:[t.jsx(lo,{className:"h-4 w-4"}),"Descargar Plantilla Excel"]})]}),l&&t.jsxs("div",{className:"w-full max-w-lg space-y-1",children:[t.jsxs(ue,{onClick:D,disabled:p,className:"w-full",children:[p?t.jsx(be,{className:"animate-spin mr-2 h-4 w-4"}):t.jsx(Kt,{className:"mr-2 h-4 w-4"}),p?"Analizando...":"Analizar Archivo"]}),R&&t.jsx("p",{className:"text-xs text-center text-muted-foreground animate-pulse",children:R})]})]}),i==="preview"&&u&&t.jsxs("div",{className:"space-y-3 h-full flex flex-col",children:[t.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[t.jsx(Lr,{icon:t.jsx(sr,{className:"h-4 w-4 text-green-600"}),label:"Válidos",value:u.validRows,color:"green"}),t.jsx(Lr,{icon:t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),label:"Errores",value:u.invalidRows,color:"red"}),t.jsx(Lr,{icon:t.jsx(ct,{className:"h-4 w-4 text-amber-600"}),label:"Advertencias",value:u.warningRows,color:"amber",tooltip:"Productos válidos pero con observaciones (ej: imagen no encontrada)"}),t.jsx(Lr,{icon:t.jsx(Wr,{className:"h-4 w-4 text-blue-600"}),label:"Total",value:u.totalRows,color:"blue"})]}),d?.isZip&&u.imageStats.referencedInExcel>0&&t.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 dark:bg-slate-900/50 border rounded-lg px-3 py-2 text-xs",children:[t.jsx(At,{className:"h-4 w-4 text-slate-500 shrink-0"}),t.jsxs("span",{className:"text-slate-600 dark:text-slate-400",children:[t.jsx("strong",{children:u.imageStats.totalImagesInZip})," imágenes en ZIP"," · ",t.jsxs("span",{className:"text-green-600",children:[u.imageStats.foundInZip," vinculadas"]}),u.imageStats.missingFromZip>0&&t.jsxs(t.Fragment,{children:[" · ",t.jsxs("span",{className:"text-amber-600",children:[u.imageStats.missingFromZip," no encontradas"]})]}),u.imageStats.unreferencedInZip>0&&t.jsxs(t.Fragment,{children:[" · ",t.jsxs("span",{className:"text-slate-400",children:[u.imageStats.unreferencedInZip," sin usar"]})]})]})]}),F.status!=="idle"&&t.jsx("div",{className:"bg-violet-50 dark:bg-violet-900/10 border border-violet-200 dark:border-violet-800 rounded-lg px-3 py-2 text-xs",children:F.status==="analyzing"?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin text-violet-600 shrink-0"}),t.jsxs("span",{className:"text-violet-700 dark:text-violet-300",children:["Analizando imágenes... ",F.progress.current,"/",F.progress.total]}),t.jsx(qr,{value:F.progress.total>0?Math.round(F.progress.current/F.progress.total*100):0,className:"flex-1 h-1.5"})]}):t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsx(Kt,{className:"h-3.5 w-3.5 text-violet-600 shrink-0"}),t.jsx("span",{className:"text-violet-700 dark:text-violet-300 font-medium",children:"Análisis completo:"}),F.summary.existing>0&&t.jsxs("span",{className:"text-green-600 dark:text-green-400 flex items-center gap-0.5",children:[t.jsx(br,{className:"h-3 w-3"}),F.summary.existing," ya existen"]}),t.jsxs("span",{className:"text-blue-600 dark:text-blue-400 flex items-center gap-0.5",children:[t.jsx(vr,{className:"h-3 w-3"}),F.summary.new," nuevas"]}),F.summary.toOptimize>0&&t.jsxs("span",{className:"text-amber-600 dark:text-amber-400 flex items-center gap-0.5",children:[t.jsx(Kt,{className:"h-3 w-3"}),F.summary.toOptimize," se optimizarán"]})]})}),t.jsxs("div",{className:"flex items-center gap-3 bg-amber-50 dark:bg-amber-900/10 border border-amber-200 dark:border-amber-800 rounded-lg p-3",children:[t.jsx(dt,{className:"h-5 w-5 text-amber-600 shrink-0"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-amber-900 dark:text-amber-200",children:"Catálogo destino"}),t.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:r.length===0?"Primero debes crear un catálogo para asignar los productos":"Todos los productos se asignarán a este catálogo"})]}),r.length>0?t.jsxs(ar,{value:w,onValueChange:g,children:[t.jsx(nr,{className:"w-[200px] bg-white dark:bg-slate-900",children:t.jsx(ir,{placeholder:"Seleccionar..."})}),t.jsx(or,{children:r.map(I=>t.jsx(kt,{value:I.id,children:I.name},I.id))})]}):t.jsx(Ce,{variant:"outline",className:"text-amber-700 border-amber-300",children:"Sin catálogos"})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Mostrar:"}),[{key:"all",label:"Todos",count:u.totalRows},{key:"errors",label:"Errores",count:u.invalidRows},{key:"warnings",label:"Advertencias",count:u.warningRows},{key:"valid",label:"Sin problemas",count:u.validRows-u.warningRows}].map(I=>t.jsxs("button",{onClick:()=>j(I.key),className:le("px-2 py-0.5 rounded text-xs font-medium transition-colors",f===I.key?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80",I.count===0&&"opacity-50"),disabled:I.count===0,children:[I.label," (",I.count,")"]},I.key))]}),t.jsxs("div",{className:"border rounded-md flex-1 overflow-hidden",children:[t.jsx(Qr,{children:t.jsx(Yr,{children:t.jsxs(lr,{children:[t.jsx(De,{className:"w-[50px]",children:"Fila"}),t.jsx(De,{className:"w-[80px]",children:"Estado"}),t.jsx(De,{className:"w-[70px]",children:"Imagen"}),t.jsx(De,{children:"Nombre / SKU"}),t.jsx(De,{className:"w-[90px]",children:"Precio"}),t.jsx(De,{children:"Detalles"})]})})}),t.jsx("div",{ref:O,className:"h-[268px] overflow-auto",children:fe.length===0?t.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"No hay filas con este filtro"}):t.jsx("div",{style:{height:`${ke.getTotalSize()}px`,width:"100%",position:"relative"},children:ke.getVirtualItems().map(I=>{const z=fe[I.index],Z={position:"absolute",top:0,left:0,width:"100%",height:`${I.size}px`,transform:`translateY(${I.start}px)`};return t.jsxs("div",{style:Z,className:le("flex items-center border-b text-sm px-2",z.status==="error"&&"bg-red-50/50 dark:bg-red-950/10",z.status==="valid"&&z.warnings.length>0&&"bg-amber-50/30 dark:bg-amber-950/5"),children:[t.jsx("div",{className:"w-[50px] shrink-0 font-mono text-xs",children:z.rowNumber}),t.jsx("div",{className:"w-[80px] shrink-0",children:z.status==="error"?t.jsx(Ce,{variant:"destructive",className:"text-[10px]",children:"Error"}):z.warnings.length>0?t.jsx(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px]",children:"Aviso"}):t.jsx(Ce,{className:"bg-green-100 text-green-800 hover:bg-green-100 border-green-200 text-[10px]",children:"OK"})}),t.jsx("div",{className:"w-[70px] shrink-0",children:t.jsxs("div",{className:"flex items-center gap-1",children:[z.imagePreviewUrl?t.jsx("div",{className:"h-8 w-8 relative rounded overflow-hidden border shrink-0",children:t.jsx("img",{src:z.imagePreviewUrl,alt:"",className:"object-cover w-full h-full",loading:"lazy"})}):z.data.imageFilename?t.jsx("div",{className:"h-8 w-8 bg-amber-50 dark:bg-amber-900/20 flex items-center justify-center rounded border border-amber-200 shrink-0",children:t.jsx(On,{className:"h-3 w-3 text-amber-500"})}):t.jsx("span",{className:"text-muted-foreground text-xs",children:"—"}),F.results.has(z.rowNumber)&&(()=>{const H=F.results.get(z.rowNumber);return H.isDuplicate?t.jsx(Ce,{variant:"outline",className:"text-[8px] px-1 py-0 h-3.5 bg-green-50 text-green-600 border-green-200 whitespace-nowrap",children:"Existe"}):H.willOptimize?t.jsx(Ce,{variant:"outline",className:"text-[8px] px-1 py-0 h-3.5 bg-amber-50 text-amber-600 border-amber-200 whitespace-nowrap",children:"Optim."}):null})()]})}),t.jsxs("div",{className:"flex-1 min-w-0 pr-2",children:[t.jsx("div",{className:"font-medium text-sm truncate",children:z.data.name||t.jsx("span",{className:"text-red-500 italic",children:"Sin nombre"})}),z.data.externalId&&t.jsx("div",{className:"text-[11px] text-muted-foreground font-mono truncate",children:z.data.externalId})]}),t.jsx("div",{className:"w-[90px] shrink-0 font-mono text-xs text-right",children:zr(z.data.price,z.data.currency)}),t.jsxs("div",{className:"flex-1 min-w-0 text-[11px]",children:[z.errors.length>0&&t.jsxs("span",{className:"text-red-600 truncate block",children:[z.errors[0],z.errors.length>1&&` (+${z.errors.length-1})`]}),z.warnings.length>0&&t.jsxs("span",{className:"text-amber-600 truncate block",children:[z.warnings[0],z.warnings.length>1&&` (+${z.warnings.length-1})`]}),z.errors.length===0&&z.warnings.length===0&&t.jsx("span",{className:"text-muted-foreground truncate block",children:z.data.description})]})]},z.rowNumber)})})})]})]}),i==="uploading"&&t.jsxs("div",{className:"h-full flex flex-col items-center justify-center space-y-5",children:[t.jsx("div",{className:"w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center",children:t.jsx(be,{className:"h-8 w-8 text-primary animate-spin"})}),t.jsxs("div",{className:"space-y-3 text-center w-full max-w-md",children:[t.jsx("h3",{className:"text-lg font-semibold",children:V==="saving"?"Guardando en base de datos":"Procesando importación"}),V==="saving"?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Insertando ",u?.validRows||0," productos en el servidor..."]}),t.jsx(qr,{value:100,className:"h-2 animate-pulse"}),E.total>0&&t.jsxs("div",{className:"flex justify-center gap-4 text-xs text-muted-foreground",children:[S.uploaded>0&&t.jsxs("span",{className:"flex items-center gap-1 text-green-600",children:[t.jsx(vr,{className:"h-3 w-3"})," ",S.uploaded," subidas"]}),S.deduplicated>0&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-600",children:[t.jsx(br,{className:"h-3 w-3"})," ",S.deduplicated," reutilizadas"]})]})]}):E.total>0?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Imagen ",E.current," de ",E.total]}),t.jsx(qr,{value:E.percent,className:"h-2"}),t.jsxs("div",{className:"flex justify-center gap-4 text-xs text-muted-foreground",children:[S.uploaded>0&&t.jsxs("span",{className:"flex items-center gap-1 text-green-600",children:[t.jsx(vr,{className:"h-3 w-3"})," ",S.uploaded," subidas"]}),S.deduplicated>0&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-600",children:[t.jsx(br,{className:"h-3 w-3"})," ",S.deduplicated," reutilizadas"]}),S.failed>0&&t.jsxs("span",{className:"flex items-center gap-1 text-red-600",children:[t.jsx(Dt,{className:"h-3 w-3"})," ",S.failed," fallidas"]})]})]}):t.jsx("p",{className:"text-sm text-muted-foreground animate-pulse",children:"Preparando productos..."})]}),t.jsx(ue,{variant:"outline",size:"sm",onClick:()=>{q.current=!0,ce.current&&ce.current.abort()},children:"Cancelar"})]}),i==="success"&&t.jsxs("div",{className:"h-full flex flex-col space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-3 bg-green-50 dark:bg-green-950/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[t.jsx("div",{className:"w-10 h-10 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center shrink-0 animate-in zoom-in duration-500",children:t.jsx(ho,{className:"h-5 w-5 text-green-600"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm font-bold text-green-900 dark:text-green-200",children:"¡Importación Exitosa!"}),t.jsxs("p",{className:"text-xs text-green-700 dark:text-green-400",children:[U," productos creados en tu catálogo"]})]})]}),t.jsxs("div",{className:"grid grid-cols-5 gap-2",children:[t.jsx(fr,{icon:t.jsx(Ot,{className:"h-3.5 w-3.5 text-green-600"}),label:"Insertados",value:_e.inserted,color:"green"}),t.jsx(fr,{icon:t.jsx(vr,{className:"h-3.5 w-3.5 text-emerald-600"}),label:"Img subidas",value:S.uploaded,color:"emerald"}),t.jsx(fr,{icon:t.jsx(br,{className:"h-3.5 w-3.5 text-blue-600"}),label:"Img reutilizadas",value:S.deduplicated,color:"blue"}),t.jsx(fr,{icon:t.jsx(Dt,{className:"h-3.5 w-3.5 text-red-600"}),label:"Error DB",value:_e.failed,color:"red"}),t.jsx(fr,{icon:t.jsx(un,{className:"h-3.5 w-3.5 text-amber-600"}),label:"Omitidos",value:_e.skipped,color:"amber"})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Filtrar:"}),[{key:"all",label:"Todos",count:_e.total},{key:"inserted",label:"Insertados",count:_e.inserted},{key:"failed",label:"Error DB",count:_e.failed},{key:"skipped",label:"Omitidos",count:_e.skipped},{key:"image_issues",label:"Problemas imagen",count:_e.imageIssues}].map(I=>t.jsxs("button",{onClick:()=>v(I.key),className:le("px-2 py-0.5 rounded text-xs font-medium transition-colors",se===I.key?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80",I.count===0&&"opacity-50"),disabled:I.count===0,children:[I.label," (",I.count,")"]},I.key))]}),t.jsxs("div",{className:"border rounded-md flex-1 overflow-hidden",children:[t.jsx(Qr,{children:t.jsx(Yr,{children:t.jsxs(lr,{children:[t.jsx(De,{className:"w-[50px]",children:"Fila"}),t.jsx(De,{children:"Producto"}),t.jsx(De,{className:"w-[120px]",children:"Base de Datos"}),t.jsx(De,{className:"w-[150px]",children:"Imagen"}),t.jsx(De,{children:"Detalle"})]})})}),t.jsx("div",{ref:L,className:"h-[248px] overflow-auto",children:me.length===0?t.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"No hay filas con este filtro"}):t.jsx("div",{style:{height:`${ye.getTotalSize()}px`,width:"100%",position:"relative"},children:ye.getVirtualItems().map(I=>{const z=me[I.index],Z={position:"absolute",top:0,left:0,width:"100%",height:`${I.size}px`,transform:`translateY(${I.start}px)`};return t.jsxs("div",{style:Z,className:le("flex items-center border-b text-sm px-2",z.dbStatus==="skipped"&&"bg-red-50/50 dark:bg-red-950/10",z.imageStatus==="failed"&&z.dbStatus!=="skipped"&&"bg-amber-50/30 dark:bg-amber-950/5"),children:[t.jsx("div",{className:"w-[50px] shrink-0 font-mono text-xs",children:z.rowNumber}),t.jsx("div",{className:"flex-1 min-w-0 pr-2",children:t.jsx("span",{className:"text-sm font-medium truncate block",children:z.name})}),t.jsx("div",{className:"w-[120px] shrink-0",children:t.jsx(Eo,{status:z.dbStatus,error:z.dbError})}),t.jsx("div",{className:"w-[150px] shrink-0",children:t.jsx(Io,{status:z.imageStatus})}),t.jsxs("div",{className:"flex-1 min-w-0 text-[11px] text-muted-foreground",children:[z.dbStatus==="skipped"&&"Error de validación",z.imageStatus==="failed"&&z.imageError&&t.jsx("span",{className:"text-amber-600 truncate block",children:z.imageError}),z.imageStatus==="missing_in_zip"&&t.jsx("span",{className:"text-amber-600",children:"No en ZIP"}),z.dbStatus==="inserted"&&z.imageStatus!=="failed"&&z.imageStatus!=="missing_in_zip"&&t.jsx("span",{className:"text-green-600",children:"✓"})]})]},z.rowNumber)})})})]})]})]}),t.jsxs(_i,{children:[i==="upload"&&t.jsx(ue,{variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),i==="preview"&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{variant:"outline",onClick:()=>{u&&bs(u.items),o("upload"),h(null),k(null),x(null),ee(ys)},children:"Atrás"}),t.jsxs(ue,{onClick:y,disabled:u?.validRows===0||!w,children:["Confirmar Importación (",u?.validRows," productos)"]})]}),i==="success"&&t.jsxs(t.Fragment,{children:[t.jsxs(ue,{variant:"outline",onClick:Re,className:"gap-2",children:[t.jsx(Mi,{className:"h-3.5 w-3.5"}),"Importar Otro"]}),t.jsx(ue,{onClick:()=>n(!1),children:"Cerrar"})]})]})]})]})}function Lr({icon:e,label:r,value:s,color:a,tooltip:n}){const i={green:"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-800",red:"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-800",amber:"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800",blue:"bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-800"},o={green:"text-green-700 dark:text-green-400",red:"text-red-700 dark:text-red-400",amber:"text-amber-700 dark:text-amber-400",blue:"text-blue-700 dark:text-blue-400"},l=t.jsx(Rs,{className:i[a],children:t.jsxs(Zs,{className:"p-3 flex items-center gap-2",children:[e,t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-medium text-muted-foreground",children:r}),t.jsx("p",{className:le("text-xl font-bold",o[a]),children:s})]})]})});return n?t.jsx(Ar,{children:t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:l}),t.jsx(rt,{children:t.jsx("p",{className:"text-xs",children:n})})]})}):l}function fr({icon:e,label:r,value:s,color:a}){const n={green:"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-800",emerald:"bg-emerald-50 dark:bg-emerald-950/20 border-emerald-200 dark:border-emerald-800",blue:"bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-800",red:"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-800",amber:"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800"},i={green:"text-green-700 dark:text-green-400",emerald:"text-emerald-700 dark:text-emerald-400",blue:"text-blue-700 dark:text-blue-400",red:"text-red-700 dark:text-red-400",amber:"text-amber-700 dark:text-amber-400"};return t.jsxs("div",{className:le("rounded-lg border p-2 flex items-center gap-1.5",n[a]),children:[e,t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-medium text-muted-foreground truncate",children:r}),t.jsx("p",{className:le("text-lg font-bold leading-none",i[a]),children:s})]})]})}function Eo({status:e,error:r}){return e==="inserted"?t.jsxs(Ce,{className:"bg-green-100 text-green-800 hover:bg-green-100 border-green-200 text-[10px] gap-1",children:[t.jsx(Ot,{className:"h-3 w-3"}),"Insertado"]}):e==="failed"?t.jsx(Ar,{children:t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsxs(Ce,{variant:"destructive",className:"text-[10px] gap-1 cursor-help",children:[t.jsx(Dt,{className:"h-3 w-3"}),"Error DB"]})}),t.jsx(rt,{side:"top",className:"max-w-xs text-xs",children:r||"Error en transacción de base de datos"})]})}):t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(un,{className:"h-3 w-3"}),"Omitido"]})}function Io({status:e}){switch(e){case"uploaded":return t.jsxs(Ce,{className:"bg-emerald-100 text-emerald-800 hover:bg-emerald-100 border-emerald-200 text-[10px] gap-1",children:[t.jsx(vr,{className:"h-3 w-3"}),"Subida"]});case"deduplicated":return t.jsxs(Ce,{className:"bg-blue-100 text-blue-800 hover:bg-blue-100 border-blue-200 text-[10px] gap-1",children:[t.jsx(br,{className:"h-3 w-3"}),"Reutilizada"]});case"failed":return t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(Dt,{className:"h-3 w-3"}),"Fallida"]});case"missing_in_zip":return t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(On,{className:"h-3 w-3"}),"No en ZIP"]});case"none":return t.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted-foreground",children:[t.jsx(no,{className:"h-3 w-3"}),"Sin imagen"]})}}const pe={all:["products"],list:e=>[...pe.all,"list",e],detail:e=>[...pe.all,"detail",e],catalogs:()=>[...pe.all,"catalogs"],qdrantStatus:()=>[...pe.all,"qdrant-status"],qdrantOrphans:e=>[...pe.all,"qdrant-orphans",e],catalogFeedConfig:()=>[...pe.all,"catalog-feed","config"],shopifyConfig:()=>[...pe.all,"shopify","config"]};async function zs(e){try{const r=await we.getQdrantStatus(!0);e.setQueryData(pe.qdrantStatus(),r),e.invalidateQueries({queryKey:[...pe.all,"qdrant-orphans"]})}catch(r){console.warn("[Qdrant] Failed to refresh status cache:",r),e.invalidateQueries({queryKey:pe.qdrantStatus()})}}function Ao(e={}){return ur({queryKey:pe.list(e),queryFn:()=>we.getProducts(e),placeholderData:hn,staleTime:1e3*60})}function Po(){return ur({queryKey:pe.catalogs(),queryFn:()=>we.getCatalogs(),staleTime:1e3*60*5})}function Fo(){const e=Ke();return Ge({mutationFn:r=>we.createProduct(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto creado")},onError:r=>ne.error(r.message||"Error al crear producto")})}function Do(){const e=Ke();return Ge({mutationFn:({id:r,dto:s})=>we.updateProduct(r,s),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto actualizado")},onError:r=>ne.error(r.message||"Error al actualizar producto")})}function Oo(){const e=Ke();return Ge({mutationFn:r=>we.deleteProduct(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto eliminado permanentemente")},onError:r=>ne.error(r.message||"Error al eliminar producto")})}function To(){const e=Ke();return Ge({mutationFn:({id:r,isActive:s})=>we.toggleProductActive(r,s),onSuccess:(r,s)=>{e.invalidateQueries({queryKey:pe.all}),ne.success(s.isActive?"Producto activado":"Producto desactivado")},onError:r=>ne.error(r.message||"Error al cambiar estado")})}function Ro(){const e=Ke();return Ge({mutationFn:({ids:r,isActive:s})=>we.bulkToggleActive(r,s),onSuccess:({affected:r},s)=>{e.invalidateQueries({queryKey:pe.all});const a=s.isActive?"activado":"desactivado";ne.success(`${r} producto${r>1?"s":""} ${a}${r>1?"s":""}`)},onError:r=>ne.error(r.message||"Error en operación masiva")})}function Zo(){const e=Ke();return Ge({mutationFn:r=>we.bulkDelete(r),onSuccess:({affected:r})=>{e.invalidateQueries({queryKey:pe.all}),ne.success(`${r} producto${r>1?"s":""} eliminado${r>1?"s":""} permanentemente`)},onError:r=>ne.error(r.message||"Error al eliminar productos")})}function $o(){const e=Ke();return Ge({mutationFn:r=>we.createCatalog(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Catálogo creado")},onError:r=>ne.error(r.message||"Error al crear catálogo")})}function Lo(){const e=Ke();return Ge({mutationFn:({id:r,dto:s})=>we.updateCatalog(r,s),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),e.invalidateQueries({queryKey:pe.all}),ne.success("Catálogo actualizado")},onError:r=>ne.error(r.message||"Error al actualizar catálogo")})}function Uo(){const e=Ke();return Ge({mutationFn:r=>we.deleteCatalog(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),e.invalidateQueries({queryKey:pe.all}),ne.success("Catálogo eliminado")},onError:r=>ne.error(r.message||"Error al eliminar catálogo")})}function Bo(e=!0){return ur({queryKey:pe.qdrantStatus(),queryFn:()=>we.getQdrantStatus(),enabled:e,staleTime:1e3*60*5,refetchOnWindowFocus:!1,retry:1})}function Mo(){const e=Ke();return Ge({mutationFn:()=>we.getQdrantStatus(!0),onSuccess:r=>{e.setQueryData(pe.qdrantStatus(),r),e.invalidateQueries({queryKey:[...pe.all,"qdrant-orphans"]}),ne.success("Estado de consistencia actualizado")},onError:r=>ne.error(r.message||"Error al actualizar estado")})}function Vo(){const e=Ke();return Ge({mutationFn:()=>we.purgeQdrantOrphans(),onSuccess:async({deleted:r})=>{ne.success(`${r} registro${r!==1?"s":""} obsoleto${r!==1?"s":""} eliminado${r!==1?"s":""} del índice`),await zs(e)},onError:r=>ne.error(r.message||"Error al limpiar registros obsoletos")})}function qo(e,r=!0){return ur({queryKey:pe.qdrantOrphans(e),queryFn:()=>we.getQdrantOrphans(e,10),enabled:r,staleTime:1e3*60*5,refetchOnWindowFocus:!1,placeholderData:hn})}function Wo(){const e=Ke();return Ge({mutationFn:r=>we.syncMissingProducts(r),onSuccess:({queued:r})=>{ne.success(`${r} producto${r!==1?"s":""} enviado${r!==1?"s":""} a reindexar`),setTimeout(()=>zs(e),2500),setTimeout(()=>zs(e),6e3)},onError:r=>ne.error(r.message||"Error al reindexar productos")})}function Ko(){return Ge({mutationFn:e=>we.searchDebug(e),onError:e=>ne.error(e.message||"Error en búsqueda vectorial")})}function Go(e=!0){return ur({queryKey:pe.catalogFeedConfig(),queryFn:()=>we.getCatalogFeedConfig(),enabled:e,staleTime:1e3*30,refetchOnWindowFocus:!1})}function Ho(){const e=Ke();return Ge({mutationFn:r=>we.configureCatalogFeed(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Configuración guardada")},onError:r=>ne.error(r.message||"Error al guardar la configuración")})}function Qo(){const e=Ke();return Ge({mutationFn:()=>we.disableCatalogFeed(),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),ne.success("Sincronización desactivada")},onError:r=>ne.error(r.message||"Error al desactivar")})}function Yo(){const e=Ke();return Ge({mutationFn:()=>we.syncCatalogFeed(),onSuccess:r=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),e.invalidateQueries({queryKey:pe.all});const s=[];r.created&&s.push(`${r.created} nuevos`),r.updated&&s.push(`${r.updated} actualizados`),r.reactivated&&s.push(`${r.reactivated} reactivados`),r.deactivated&&s.push(`${r.deactivated} desactivados`),ne.success(s.length>0?`Sincronización completada: ${s.join(", ")}`:`Sincronización completada (${r.total} productos)`)},onError:r=>ne.error(r.message||"Error en la sincronización")})}function Xo(e=!0){return ur({queryKey:pe.shopifyConfig(),queryFn:()=>we.getShopifyConfig(),enabled:e,staleTime:1e3*30,refetchOnWindowFocus:!1})}function Jo(){const e=Ke();return Ge({mutationFn:r=>we.configureShopify(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Tienda Shopify conectada")},onError:r=>ne.error(r.message||"Error al conectar Shopify")})}function el(){const e=Ke();return Ge({mutationFn:()=>we.disableShopify(),onSuccess:()=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),ne.success("Integración de Shopify desactivada")},onError:r=>ne.error(r.message||"Error al desactivar")})}function tl(){const e=Ke();return Ge({mutationFn:()=>we.syncShopify(),onSuccess:r=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),e.invalidateQueries({queryKey:pe.all});const s=[];r.created&&s.push(`${r.created} nuevos`),r.updated&&s.push(`${r.updated} actualizados`),r.reactivated&&s.push(`${r.reactivated} reactivados`),r.deactivated&&s.push(`${r.deactivated} desactivados`),ne.success(s.length>0?`Sincronización completada: ${s.join(", ")}`:`Sincronización completada (${r.total} productos)`)},onError:r=>ne.error(r.message||"Error en la sincronización")})}function rl({trigger:e}){const[r,s]=Y.useState(!1),[a,n]=Y.useState(""),[i,o]=Y.useState(""),[l,h]=Y.useState(!1),p=Go(r),_=Ho(),w=Qo(),g=Yo(),d=p.data??null;Y.useEffect(()=>{d&&n(d.feedUrl)},[d]);const k=()=>{const S=a.trim(),B=i.trim();S&&(!d&&!B||_.mutate({feedUrl:S,catalogName:B||"Catálogo Externo"},{onSuccess:()=>o("")}))},u=()=>{g.mutate()},x=()=>{w.mutate(void 0,{onSuccess:()=>h(!1)})},f=_.isPending||g.isPending||w.isPending,j=d?.lastSyncStatus==="running"||g.isPending,E=a.trim().length>0&&(d!==null||i.trim().length>0),P=d!==null&&d.isActive&&!j;return t.jsxs(t.Fragment,{children:[t.jsxs(jr,{open:r,onOpenChange:s,children:[t.jsx(mn,{asChild:!0,children:e}),t.jsxs(kr,{side:"right",className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",children:[t.jsxs(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800",children:[t.jsxs(Nr,{className:"flex items-center gap-2 text-lg",children:[t.jsx(fn,{className:"h-5 w-5 text-primary"}),"Importar desde catálogo externo"]}),t.jsx(Kr,{children:"Sincroniza productos automáticamente desde un Meta Catalog Feed (JSON). Configura la URL una vez y la plataforma actualizará los productos cada noche."})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:p.isLoading?t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsx(be,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.jsxs(t.Fragment,{children:[d&&t.jsxs("div",{className:le("rounded-lg border p-3 text-sm",d.lastSyncStatus==="success"&&"bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-800",d.lastSyncStatus==="failed"&&"bg-red-50 dark:bg-red-950/30 border-red-200 dark:border-red-800",d.lastSyncStatus==="running"&&"bg-amber-50 dark:bg-amber-950/30 border-amber-200 dark:border-amber-800",d.lastSyncStatus==="idle"&&"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[d.lastSyncStatus==="success"&&t.jsx(sr,{className:"h-4 w-4 text-green-600"}),d.lastSyncStatus==="failed"&&t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),d.lastSyncStatus==="running"&&t.jsx(be,{className:"h-4 w-4 animate-spin text-amber-600"}),d.lastSyncStatus==="idle"&&t.jsx(Pr,{className:"h-4 w-4 text-slate-500"}),t.jsxs("span",{className:"font-semibold",children:[d.lastSyncStatus==="idle"&&"Sin ejecutar",d.lastSyncStatus==="running"&&"Sincronizando…",d.lastSyncStatus==="success"&&"Última sincronización OK",d.lastSyncStatus==="failed"&&"Última sincronización falló"]})]}),!d.isActive&&t.jsx(Ce,{variant:"outline",className:"text-xs",children:"Desactivada"})]}),d.lastSyncAt&&t.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:[as(d.lastSyncAt)," · ",d.lastSyncCount," producto",d.lastSyncCount!==1?"s":""," afectados"]}),d.lastSyncError&&t.jsx("p",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400 break-words",children:d.lastSyncError})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"feed-url",children:"URL del Meta Catalog Feed"}),t.jsx(st,{id:"feed-url",type:"url",placeholder:"https://www.datapath.ai/api/meta/catalog",value:a,onChange:S=>n(S.target.value),disabled:f}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Debe ser una URL pública (https) que devuelva JSON en formato Meta Catalog Feed."})]}),!d&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"catalog-name",children:"Nombre del catálogo destino"}),t.jsx(st,{id:"catalog-name",type:"text",placeholder:"Ej. Cursos Datapath",value:i,onChange:S=>o(S.target.value),maxLength:100,disabled:f}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Si ya existe un catálogo con ese nombre, se reutilizará. Si no, se creará uno nuevo."})]}),t.jsx("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 text-xs text-blue-900 dark:text-blue-200",children:'Los productos se sincronizan automáticamente cada noche a las 00:00 hora Lima. Puedes disparar una sincronización manual con el botón "Sincronizar ahora".'})]})}),t.jsxs("div",{className:"border-t border-slate-100 dark:border-slate-800 px-6 py-4 flex items-center justify-between gap-2",children:[t.jsx("div",{children:d&&t.jsxs(ue,{type:"button",variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30",onClick:()=>h(!0),disabled:f,children:[t.jsx(bt,{className:"h-3.5 w-3.5 mr-1.5"}),"Desactivar"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ue,{type:"button",variant:"outline",onClick:k,disabled:!E||f,children:_.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Guardando…"]}):"Guardar"}),t.jsx(ue,{type:"button",onClick:u,disabled:!P||f,className:"bg-primary hover:bg-primary/90",children:g.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Sincronizando…"]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-4 w-4 mr-1.5"}),"Sincronizar ahora"]})})]})]})]})]}),t.jsx(Gt,{open:l,onOpenChange:h,children:t.jsxs(Ht,{children:[t.jsxs(Qt,{children:[t.jsx(Yt,{children:"¿Desactivar la sincronización?"}),t.jsx(Xt,{children:"La sincronización automática se detendrá. Los productos ya importados se conservan tal cual; podrás reactivarla más adelante volviendo a guardar la URL."})]}),t.jsxs(Jt,{children:[t.jsx(er,{disabled:w.isPending,children:"Cancelar"}),t.jsx(tr,{onClick:x,disabled:w.isPending,className:"bg-red-600 hover:bg-red-700",children:w.isPending?t.jsx(be,{className:"h-4 w-4 animate-spin"}):"Desactivar"})]})]})})]})}function sl({trigger:e}){const[r,s]=Y.useState(!1),[a,n]=Y.useState(""),[i,o]=Y.useState(""),[l,h]=Y.useState(""),[p,_]=Y.useState(""),[w,g]=Y.useState(!1),d=Xo(r),k=Jo(),u=el(),x=tl(),f=d.data??null;Y.useEffect(()=>{f&&(n(f.shopDomain),o(f.clientId))},[f]);const j=()=>{const T=a.trim(),G=i.trim(),se=l.trim(),v=p.trim();T&&(!f&&(!G||!se||!v)||k.mutate({shopDomain:T,...G?{clientId:G}:{},...se?{clientSecret:se}:{},...v?{catalogName:v}:{}},{onSuccess:()=>{h(""),_("")}}))},E=()=>{x.mutate()},P=()=>{u.mutate(void 0,{onSuccess:()=>g(!1)})},S=k.isPending||x.isPending||u.isPending,B=f?.lastSyncStatus==="running"||x.isPending,U=a.trim().length>0&&(f!==null||i.trim().length>0&&l.trim().length>0&&p.trim().length>0),$=f!==null&&f.isActive&&!B;return t.jsxs(t.Fragment,{children:[t.jsxs(jr,{open:r,onOpenChange:s,children:[t.jsx(mn,{asChild:!0,children:e}),t.jsxs(kr,{side:"right",className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",children:[t.jsxs(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800",children:[t.jsxs(Nr,{className:"flex items-center gap-2 text-lg",children:[t.jsx(kn,{className:"h-5 w-5 text-primary"}),"Importar desde Shopify"]}),t.jsx(Kr,{children:"Conecta tu tienda Shopify una vez y la plataforma importará tus productos y los mantendrá actualizados cada noche."})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:d.isLoading?t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsx(be,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.jsxs(t.Fragment,{children:[f&&t.jsxs("div",{className:le("rounded-lg border p-3 text-sm",f.lastSyncStatus==="success"&&"bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-800",f.lastSyncStatus==="failed"&&"bg-red-50 dark:bg-red-950/30 border-red-200 dark:border-red-800",f.lastSyncStatus==="running"&&"bg-amber-50 dark:bg-amber-950/30 border-amber-200 dark:border-amber-800",f.lastSyncStatus==="idle"&&"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[f.lastSyncStatus==="success"&&t.jsx(sr,{className:"h-4 w-4 text-green-600"}),f.lastSyncStatus==="failed"&&t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),f.lastSyncStatus==="running"&&t.jsx(be,{className:"h-4 w-4 animate-spin text-amber-600"}),f.lastSyncStatus==="idle"&&t.jsx(Pr,{className:"h-4 w-4 text-slate-500"}),t.jsxs("span",{className:"font-semibold",children:[f.lastSyncStatus==="idle"&&"Sin ejecutar",f.lastSyncStatus==="running"&&"Sincronizando…",f.lastSyncStatus==="success"&&"Última sincronización OK",f.lastSyncStatus==="failed"&&"Última sincronización falló"]})]}),!f.isActive&&t.jsx(Ce,{variant:"outline",className:"text-xs",children:"Desactivada"})]}),f.lastSyncAt&&t.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:[as(f.lastSyncAt)," ·"," ",f.lastSyncCount," producto",f.lastSyncCount!==1?"s":""," afectados"]}),f.lastSyncError&&t.jsx("p",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400 break-words",children:f.lastSyncError})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-domain",children:"Dominio de la tienda"}),t.jsx(st,{id:"shopify-domain",type:"text",placeholder:"mitienda.myshopify.com",value:a,onChange:T=>n(T.target.value),disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"El dominio permanente de tu tienda (termina en .myshopify.com)."})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-client-id",children:"ID de cliente (Client ID)"}),t.jsx(st,{id:"shopify-client-id",type:"text",autoComplete:"off",placeholder:"f1657b1a5035fc8390…",value:i,onChange:T=>o(T.target.value),disabled:S})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-client-secret",children:"Secreto (Client secret)"}),t.jsx(st,{id:"shopify-client-secret",type:"password",autoComplete:"off",placeholder:f?"•••••••• (guardado — déjalo vacío para mantenerlo)":"Secreto de la app",value:l,onChange:T=>h(T.target.value),disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"En el dev dashboard de tu app: Configuración → Credenciales → copia el “ID de cliente” y el “Secreto”. La app debe estar instalada en tu tienda con el permiso read_products."})]}),!f&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-catalog-name",children:"Nombre del catálogo destino"}),t.jsx(st,{id:"shopify-catalog-name",type:"text",placeholder:"Ej. Tienda Shopify",value:p,onChange:T=>_(T.target.value),maxLength:100,disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Si ya existe un catálogo con ese nombre, se reutilizará. Si no, se creará uno nuevo."})]}),t.jsx("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 text-xs text-blue-900 dark:text-blue-200",children:"Los productos se sincronizan automáticamente cada noche a las 00:15 hora Lima. Puedes disparar una sincronización manual con el botón “Sincronizar ahora”."})]})}),t.jsxs("div",{className:"border-t border-slate-100 dark:border-slate-800 px-6 py-4 flex items-center justify-between gap-2",children:[t.jsx("div",{children:f&&t.jsxs(ue,{type:"button",variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30",onClick:()=>g(!0),disabled:S,children:[t.jsx(bt,{className:"h-3.5 w-3.5 mr-1.5"}),"Desactivar"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ue,{type:"button",variant:"outline",onClick:j,disabled:!U||S,children:k.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Guardando…"]}):f?"Guardar":"Conectar"}),t.jsx(ue,{type:"button",onClick:E,disabled:!$||S,className:"bg-primary hover:bg-primary/90",children:x.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Sincronizando…"]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-4 w-4 mr-1.5"}),"Sincronizar ahora"]})})]})]})]})]}),t.jsx(Gt,{open:w,onOpenChange:g,children:t.jsxs(Ht,{children:[t.jsxs(Qt,{children:[t.jsx(Yt,{children:"¿Desactivar la sincronización de Shopify?"}),t.jsx(Xt,{children:"La sincronización automática se detendrá. Los productos ya importados se conservan tal cual; podrás reactivarla más adelante volviendo a conectar la tienda."})]}),t.jsxs(Jt,{children:[t.jsx(er,{disabled:u.isPending,children:"Cancelar"}),t.jsx(tr,{onClick:P,disabled:u.isPending,className:"bg-red-600 hover:bg-red-700",children:u.isPending?t.jsx(be,{className:"h-4 w-4 animate-spin"}):"Desactivar"})]})]})})]})}var Or=e=>e.type==="checkbox",Pt=e=>e instanceof Date,nt=e=>e==null;const Zn=e=>typeof e=="object";var Me=e=>!nt(e)&&!Array.isArray(e)&&Zn(e)&&!Pt(e),al=e=>Me(e)&&e.target?Or(e.target)?e.target.checked:e.target.value:e,nl=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,il=(e,r)=>e.has(nl(r)),ol=e=>{const r=e.constructor&&e.constructor.prototype;return Me(r)&&r.hasOwnProperty("isPrototypeOf")},Us=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function We(e){if(e instanceof Date)return new Date(e);const r=typeof FileList<"u"&&e instanceof FileList;if(Us&&(e instanceof Blob||r))return e;const s=Array.isArray(e);if(!s&&!(Me(e)&&ol(e)))return e;const a=s?[]:Object.create(Object.getPrototypeOf(e));for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(a[n]=We(e[n]));return a}var ns=e=>/^\w*$/.test(e),Oe=e=>e===void 0,Bs=e=>Array.isArray(e)?e.filter(Boolean):[],Ms=e=>Bs(e.replace(/["|']|\]/g,"").split(/\.|\[/)),oe=(e,r,s)=>{if(!r||!Me(e))return s;const a=(ns(r)?[r]:Ms(r)).reduce((n,i)=>nt(n)?n:n[i],e);return Oe(a)||a===e?Oe(e[r])?s:e[r]:a},gt=e=>typeof e=="boolean",ft=e=>typeof e=="function",Ee=(e,r,s)=>{let a=-1;const n=ns(r)?[r]:Ms(r),i=n.length,o=i-1;for(;++a<i;){const l=n[a];let h=s;if(a!==o){const p=e[l];h=Me(p)||Array.isArray(p)?p:isNaN(+n[a+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;e[l]=h,e=e[l]}};const ma={BLUR:"blur",FOCUS_OUT:"focusout"},pt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},vt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},ll=Xe.createContext(null);ll.displayName="HookFormControlContext";var cl=(e,r,s,a=!0)=>{const n={defaultValues:r._defaultValues};for(const i in e)Object.defineProperty(n,i,{get:()=>{const o=i;return r._proxyFormState[o]!==pt.all&&(r._proxyFormState[o]=!a||pt.all),e[o]}});return n};const dl=typeof window<"u"?Xe.useLayoutEffect:Xe.useEffect;var lt=e=>typeof e=="string",ul=(e,r,s,a,n)=>lt(e)?(a&&r.watch.add(e),oe(s,e,n)):Array.isArray(e)?e.map(i=>(a&&r.watch.add(i),oe(s,i))):(a&&(r.watchAll=!0),s),Es=e=>nt(e)||!Zn(e);function jt(e,r,s=new WeakSet){if(Es(e)||Es(r))return Object.is(e,r);if(Pt(e)&&Pt(r))return Object.is(e.getTime(),r.getTime());const a=Object.keys(e),n=Object.keys(r);if(a.length!==n.length)return!1;if(s.has(e)||s.has(r))return!0;s.add(e),s.add(r);for(const i of a){const o=e[i];if(!n.includes(i))return!1;if(i!=="ref"){const l=r[i];if(Pt(o)&&Pt(l)||Me(o)&&Me(l)||Array.isArray(o)&&Array.isArray(l)?!jt(o,l,s):!Object.is(o,l))return!1}}return!0}const hl=Xe.createContext(null);hl.displayName="HookFormContext";var Vs=(e,r,s,a,n)=>r?{...s[e],types:{...s[e]&&s[e].types?s[e].types:{},[a]:n||!0}}:{},yr=e=>Array.isArray(e)?e:[e],fa=()=>{let e=[];return{get observers(){return e},next:n=>{for(const i of e)i.next&&i.next(n)},subscribe:n=>(e.push(n),{unsubscribe:()=>{e=e.filter(i=>i!==n)}}),unsubscribe:()=>{e=[]}}};function $n(e,r){const s={};for(const a in e)if(e.hasOwnProperty(a)){const n=e[a],i=r[a];if(n&&Me(n)&&i){const o=$n(n,i);Me(o)&&(s[a]=o)}else e[a]&&(s[a]=i)}return s}var Je=e=>Me(e)&&!Object.keys(e).length,qs=e=>e.type==="file",Xr=e=>{if(!Us)return!1;const r=e?e.ownerDocument:0;return e instanceof(r&&r.defaultView?r.defaultView.HTMLElement:HTMLElement)},Ln=e=>e.type==="select-multiple",Ws=e=>e.type==="radio",ml=e=>Ws(e)||Or(e),ws=e=>Xr(e)&&e.isConnected;function fl(e,r){const s=r.slice(0,-1).length;let a=0;for(;a<s;)e=Oe(e)?a++:e[r[a++]];return e}function pl(e){for(const r in e)if(e.hasOwnProperty(r)&&!Oe(e[r]))return!1;return!0}function Be(e,r){const s=Array.isArray(r)?r:ns(r)?[r]:Ms(r),a=s.length===1?e:fl(e,s),n=s.length-1,i=s[n];return a&&delete a[i],n!==0&&(Me(a)&&Je(a)||Array.isArray(a)&&pl(a))&&Be(e,s.slice(0,-1)),e}var xl=e=>{for(const r in e)if(ft(e[r]))return!0;return!1};function Un(e){return Array.isArray(e)||Me(e)&&!xl(e)}function Is(e,r={}){for(const s in e){const a=e[s];Un(a)?(r[s]=Array.isArray(a)?[]:{},Is(a,r[s])):Oe(a)||(r[s]=!0)}return r}function qt(e,r,s){s||(s=Is(r));for(const a in e){const n=e[a];if(Un(n))Oe(r)||Es(s[a])?s[a]=Is(n,Array.isArray(n)?[]:{}):qt(n,nt(r)?{}:r[a],s[a]);else{const i=r[a];s[a]=!jt(n,i)}}return s}const pa={value:!1,isValid:!1},xa={value:!0,isValid:!0};var Bn=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter(s=>s&&s.checked&&!s.disabled).map(s=>s.value);return{value:r,isValid:!!r.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Oe(e[0].attributes.value)?Oe(e[0].value)||e[0].value===""?xa:{value:e[0].value,isValid:!0}:xa:pa}return pa},Mn=(e,{valueAsNumber:r,valueAsDate:s,setValueAs:a})=>Oe(e)?e:r?e===""?NaN:e&&+e:s&<(e)?new Date(e):a?a(e):e;const ga={isValid:!1,value:null};var Vn=e=>Array.isArray(e)?e.reduce((r,s)=>s&&s.checked&&!s.disabled?{isValid:!0,value:s.value}:r,ga):ga;function ba(e){const r=e.ref;return qs(r)?r.files:Ws(r)?Vn(e.refs).value:Ln(r)?[...r.selectedOptions].map(({value:s})=>s):Or(r)?Bn(e.refs).value:Mn(Oe(r.value)?e.ref.value:r.value,e)}var gl=(e,r,s,a)=>{const n={};for(const i of e){const o=oe(r,i);o&&Ee(n,i,o._f)}return{criteriaMode:s,names:[...e],fields:n,shouldUseNativeValidation:a}},Jr=e=>e instanceof RegExp,pr=e=>Oe(e)?e:Jr(e)?e.source:Me(e)?Jr(e.value)?e.value.source:e.value:e,va=e=>({isOnSubmit:!e||e===pt.onSubmit,isOnBlur:e===pt.onBlur,isOnChange:e===pt.onChange,isOnAll:e===pt.all,isOnTouch:e===pt.onTouched});const ya="AsyncFunction";var bl=e=>!!e&&!!e.validate&&!!(ft(e.validate)&&e.validate.constructor.name===ya||Me(e.validate)&&Object.values(e.validate).find(r=>r.constructor.name===ya)),vl=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),wa=(e,r,s)=>!s&&(r.watchAll||r.watch.has(e)||[...r.watch].some(a=>e.startsWith(a)&&/^\.\w+/.test(e.slice(a.length))));const wr=(e,r,s,a)=>{for(const n of s||Object.keys(e)){const i=oe(e,n);if(i){const{_f:o,...l}=i;if(o){if(o.refs&&o.refs[0]&&r(o.refs[0],n)&&!a)return!0;if(o.ref&&r(o.ref,o.name)&&!a)return!0;if(wr(l,r))break}else if(Me(l)&&wr(l,r))break}}};function ja(e,r,s){const a=oe(e,s);if(a||ns(s))return{error:a,name:s};const n=s.split(".");for(;n.length;){const i=n.join("."),o=oe(r,i),l=oe(e,i);if(o&&!Array.isArray(o)&&s!==i)return{name:s};if(l&&l.type)return{name:i,error:l};if(l&&l.root&&l.root.type)return{name:`${i}.root`,error:l.root};n.pop()}return{name:s}}var yl=(e,r,s,a)=>{s(e);const{name:n,...i}=e;return Je(i)||Object.keys(i).length>=Object.keys(r).length||Object.keys(i).find(o=>r[o]===(!a||pt.all))},wl=(e,r,s)=>!e||!r||e===r||yr(e).some(a=>a&&(s?a===r:a.startsWith(r)||r.startsWith(a))),jl=(e,r,s,a,n)=>n.isOnAll?!1:!s&&n.isOnTouch?!(r||e):(s?a.isOnBlur:n.isOnBlur)?!e:(s?a.isOnChange:n.isOnChange)?e:!0,kl=(e,r)=>!Bs(oe(e,r)).length&&Be(e,r),_l=(e,r,s)=>{const a=yr(oe(e,s));return Ee(a,"root",r[s]),Ee(e,s,a),e};function ka(e,r,s="validate"){if(lt(e)||Array.isArray(e)&&e.every(lt)||gt(e)&&!e)return{type:s,message:lt(e)?e:"",ref:r}}var Vt=e=>Me(e)&&!Jr(e)?e:{value:e,message:""},_a=async(e,r,s,a,n,i)=>{const{ref:o,refs:l,required:h,maxLength:p,minLength:_,min:w,max:g,pattern:d,validate:k,name:u,valueAsNumber:x,mount:f}=e._f,j=oe(s,u);if(!f||r.has(u))return{};const E=l?l[0]:o,P=v=>{n&&E.reportValidity&&(E.setCustomValidity(gt(v)?"":v||""),E.reportValidity())},S={},B=Ws(o),U=Or(o),$=B||U,T=(x||qs(o))&&Oe(o.value)&&Oe(j)||Xr(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,G=Vs.bind(null,u,a,S),se=(v,R,m,V=vt.maxLength,ie=vt.minLength)=>{const q=v?R:m;S[u]={type:v?V:ie,message:q,ref:o,...G(v?V:ie,q)}};if(i?!Array.isArray(j)||!j.length:h&&(!$&&(T||nt(j))||gt(j)&&!j||U&&!Bn(l).isValid||B&&!Vn(l).isValid)){const{value:v,message:R}=lt(h)?{value:!!h,message:h}:Vt(h);if(v&&(S[u]={type:vt.required,message:R,ref:E,...G(vt.required,R)},!a))return P(R),S}if(!T&&(!nt(w)||!nt(g))){let v,R;const m=Vt(g),V=Vt(w);if(!nt(j)&&!isNaN(j)){const ie=o.valueAsNumber||j&&+j;nt(m.value)||(v=ie>m.value),nt(V.value)||(R=ie<V.value)}else{const ie=o.valueAsDate||new Date(j),q=ee=>new Date(new Date().toDateString()+" "+ee),ce=o.type=="time",F=o.type=="week";lt(m.value)&&j&&(v=ce?q(j)>q(m.value):F?j>m.value:ie>new Date(m.value)),lt(V.value)&&j&&(R=ce?q(j)<q(V.value):F?j<V.value:ie<new Date(V.value))}if((v||R)&&(se(!!v,m.message,V.message,vt.max,vt.min),!a))return P(S[u].message),S}if((p||_)&&!T&&(lt(j)||i&&Array.isArray(j))){const v=Vt(p),R=Vt(_),m=!nt(v.value)&&j.length>+v.value,V=!nt(R.value)&&j.length<+R.value;if((m||V)&&(se(m,v.message,R.message),!a))return P(S[u].message),S}if(d&&!T&<(j)){const{value:v,message:R}=Vt(d);if(Jr(v)&&!j.match(v)&&(S[u]={type:vt.pattern,message:R,ref:o,...G(vt.pattern,R)},!a))return P(R),S}if(k){if(ft(k)){const v=await k(j,s),R=ka(v,E);if(R&&(S[u]={...R,...G(vt.validate,R.message)},!a))return P(R.message),S}else if(Me(k)){let v={};for(const R in k){if(!Je(v)&&!a)break;const m=ka(await k[R](j,s),E,R);m&&(v={...m,...G(R,m.message)},P(m.message),a&&(S[u]=v))}if(!Je(v)&&(S[u]={ref:E,...v},!a))return S}}return P(!0),S};const Nl={mode:pt.onSubmit,reValidateMode:pt.onChange,shouldFocusError:!0};function Sl(e={}){let r={...Nl,...e},s={submitCount:0,isDirty:!1,isReady:!1,isLoading:ft(r.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:r.errors||{},disabled:r.disabled||!1},a={},n=Me(r.defaultValues)||Me(r.values)?We(r.defaultValues||r.values)||{}:{},i=r.shouldUnregister?{}:We(n),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},l={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},h,p=0;const _={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={..._};let g={...w};const d={array:fa(),state:fa()},k=r.criteriaMode===pt.all,u=y=>b=>{clearTimeout(p),p=setTimeout(y,b)},x=async y=>{if(!o.keepIsValid&&!r.disabled&&(w.isValid||g.isValid||y)){let b;r.resolver?(b=Je((await $()).errors),f()):b=await G(a,!0),b!==s.isValid&&d.state.next({isValid:b})}},f=(y,b)=>{!r.disabled&&(w.isValidating||w.validatingFields||g.isValidating||g.validatingFields)&&((y||Array.from(l.mount)).forEach(A=>{A&&(b?Ee(s.validatingFields,A,b):Be(s.validatingFields,A))}),d.state.next({validatingFields:s.validatingFields,isValidating:!Je(s.validatingFields)}))},j=(y,b=[],A,I,z=!0,Z=!0)=>{if(I&&A&&!r.disabled){if(o.action=!0,Z&&Array.isArray(oe(a,y))){const H=A(oe(a,y),I.argA,I.argB);z&&Ee(a,y,H)}if(Z&&Array.isArray(oe(s.errors,y))){const H=A(oe(s.errors,y),I.argA,I.argB);z&&Ee(s.errors,y,H),kl(s.errors,y)}if((w.touchedFields||g.touchedFields)&&Z&&Array.isArray(oe(s.touchedFields,y))){const H=A(oe(s.touchedFields,y),I.argA,I.argB);z&&Ee(s.touchedFields,y,H)}(w.dirtyFields||g.dirtyFields)&&(s.dirtyFields=qt(n,i)),d.state.next({name:y,isDirty:v(y,b),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else Ee(i,y,b)},E=(y,b)=>{Ee(s.errors,y,b),d.state.next({errors:s.errors})},P=y=>{s.errors=y,d.state.next({errors:s.errors,isValid:!1})},S=(y,b,A,I)=>{const z=oe(a,y);if(z){const Z=oe(i,y,Oe(A)?oe(n,y):A);Oe(Z)||I&&I.defaultChecked||b?Ee(i,y,b?Z:ba(z._f)):V(y,Z),o.mount&&!o.action&&x()}},B=(y,b,A,I,z)=>{let Z=!1,H=!1;const re={name:y};if(!r.disabled){if(!A||I){(w.isDirty||g.isDirty)&&(H=s.isDirty,s.isDirty=re.isDirty=v(),Z=H!==re.isDirty);const he=jt(oe(n,y),b);H=!!oe(s.dirtyFields,y),he?Be(s.dirtyFields,y):Ee(s.dirtyFields,y,!0),re.dirtyFields=s.dirtyFields,Z=Z||(w.dirtyFields||g.dirtyFields)&&H!==!he}if(A){const he=oe(s.touchedFields,y);he||(Ee(s.touchedFields,y,A),re.touchedFields=s.touchedFields,Z=Z||(w.touchedFields||g.touchedFields)&&he!==A)}Z&&z&&d.state.next(re)}return Z?re:{}},U=(y,b,A,I)=>{const z=oe(s.errors,y),Z=(w.isValid||g.isValid)&>(b)&&s.isValid!==b;if(r.delayError&&A?(h=u(()=>E(y,A)),h(r.delayError)):(clearTimeout(p),h=null,A?Ee(s.errors,y,A):Be(s.errors,y)),(A?!jt(z,A):z)||!Je(I)||Z){const H={...I,...Z&>(b)?{isValid:b}:{},errors:s.errors,name:y};s={...s,...H},d.state.next(H)}},$=async y=>(f(y,!0),await r.resolver(i,r.context,gl(y||l.mount,a,r.criteriaMode,r.shouldUseNativeValidation))),T=async y=>{const{errors:b}=await $(y);if(f(y),y)for(const A of y){const I=oe(b,A);I?Ee(s.errors,A,I):Be(s.errors,A)}else s.errors=b;return b},G=async(y,b,A={valid:!0})=>{for(const I in y){const z=y[I];if(z){const{_f:Z,...H}=z;if(Z){const re=l.array.has(Z.name),he=z._f&&bl(z._f);he&&w.validatingFields&&f([Z.name],!0);const ze=await _a(z,l.disabled,i,k,r.shouldUseNativeValidation&&!b,re);if(he&&w.validatingFields&&f([Z.name]),ze[Z.name]&&(A.valid=!1,b||e.shouldUseNativeValidation))break;!b&&(oe(ze,Z.name)?re?_l(s.errors,ze,Z.name):Ee(s.errors,Z.name,ze[Z.name]):Be(s.errors,Z.name))}!Je(H)&&await G(H,b,A)}}return A.valid},se=()=>{for(const y of l.unMount){const b=oe(a,y);b&&(b._f.refs?b._f.refs.every(A=>!ws(A)):!ws(b._f.ref))&&fe(y)}l.unMount=new Set},v=(y,b)=>!r.disabled&&(y&&b&&Ee(i,y,b),!jt(O(),n)),R=(y,b,A)=>ul(y,l,{...o.mount?i:Oe(b)?n:lt(y)?{[y]:b}:b},A,b),m=y=>Bs(oe(o.mount?i:n,y,r.shouldUnregister?oe(n,y,[]):[])),V=(y,b,A={})=>{const I=oe(a,y);let z=b;if(I){const Z=I._f;Z&&(!Z.disabled&&Ee(i,y,Mn(b,Z)),z=Xr(Z.ref)&&nt(b)?"":b,Ln(Z.ref)?[...Z.ref.options].forEach(H=>H.selected=z.includes(H.value)):Z.refs?Or(Z.ref)?Z.refs.forEach(H=>{(!H.defaultChecked||!H.disabled)&&(Array.isArray(z)?H.checked=!!z.find(re=>re===H.value):H.checked=z===H.value||!!z)}):Z.refs.forEach(H=>H.checked=H.value===z):qs(Z.ref)?Z.ref.value="":(Z.ref.value=z,Z.ref.type||d.state.next({name:y,values:We(i)})))}(A.shouldDirty||A.shouldTouch)&&B(y,z,A.shouldTouch,A.shouldDirty,!0),A.shouldValidate&&ee(y)},ie=(y,b,A)=>{for(const I in b){if(!b.hasOwnProperty(I))return;const z=b[I],Z=y+"."+I,H=oe(a,Z);(l.array.has(y)||Me(z)||H&&!H._f)&&!Pt(z)?ie(Z,z,A):V(Z,z,A)}},q=(y,b,A={})=>{const I=oe(a,y),z=l.array.has(y),Z=We(b);Ee(i,y,Z),z?(d.array.next({name:y,values:We(i)}),(w.isDirty||w.dirtyFields||g.isDirty||g.dirtyFields)&&A.shouldDirty&&d.state.next({name:y,dirtyFields:qt(n,i),isDirty:v(y,Z)})):I&&!I._f&&!nt(Z)?ie(y,Z,A):V(y,Z,A),wa(y,l)?d.state.next({...s,name:y,values:We(i)}):d.state.next({name:o.mount?y:void 0,values:We(i)})},ce=async y=>{o.mount=!0;const b=y.target;let A=b.name,I=!0;const z=oe(a,A),Z=he=>{I=Number.isNaN(he)||Pt(he)&&isNaN(he.getTime())||jt(he,oe(i,A,he))},H=va(r.mode),re=va(r.reValidateMode);if(z){let he,ze;const je=b.type?ba(z._f):al(y),Fe=y.type===ma.BLUR||y.type===ma.FOCUS_OUT,ge=!vl(z._f)&&!r.resolver&&!oe(s.errors,A)&&!z._f.deps||jl(Fe,oe(s.touchedFields,A),s.isSubmitted,re,H),xe=wa(A,l,Fe);Ee(i,A,je),Fe?(!b||!b.readOnly)&&(z._f.onBlur&&z._f.onBlur(y),h&&h(0)):z._f.onChange&&z._f.onChange(y);const Ze=B(A,je,Fe),$e=!Je(Ze)||xe;if(!Fe&&d.state.next({name:A,type:y.type,values:We(i)}),ge)return(w.isValid||g.isValid)&&(r.mode==="onBlur"?Fe&&x():Fe||x()),$e&&d.state.next({name:A,...xe?{}:Ze});if(!Fe&&xe&&d.state.next({...s}),r.resolver){const{errors:Ae}=await $([A]);if(f([A]),Z(je),I){const He=ja(s.errors,a,A),Qe=ja(Ae,a,He.name||A);he=Qe.error,A=Qe.name,ze=Je(Ae)}}else f([A],!0),he=(await _a(z,l.disabled,i,k,r.shouldUseNativeValidation))[A],f([A]),Z(je),I&&(he?ze=!1:(w.isValid||g.isValid)&&(ze=await G(a,!0)));I&&(z._f.deps&&(!Array.isArray(z._f.deps)||z._f.deps.length>0)&&ee(z._f.deps),U(A,ze,he,Ze))}},F=(y,b)=>{if(oe(s.errors,b)&&y.focus)return y.focus(),1},ee=async(y,b={})=>{let A,I;const z=yr(y);if(r.resolver){const Z=await T(Oe(y)?y:z);A=Je(Z),I=y?!z.some(H=>oe(Z,H)):A}else y?(I=(await Promise.all(z.map(async Z=>{const H=oe(a,Z);return await G(H&&H._f?{[Z]:H}:H)}))).every(Boolean),!(!I&&!s.isValid)&&x()):I=A=await G(a);return d.state.next({...!lt(y)||(w.isValid||g.isValid)&&A!==s.isValid?{}:{name:y},...r.resolver||!y?{isValid:A}:{},errors:s.errors}),b.shouldFocus&&!I&&wr(a,F,y?z:l.mount),I},O=(y,b)=>{let A={...o.mount?i:n};return b&&(A=$n(b.dirtyFields?s.dirtyFields:s.touchedFields,A)),Oe(y)?A:lt(y)?oe(A,y):y.map(I=>oe(A,I))},L=(y,b)=>({invalid:!!oe((b||s).errors,y),isDirty:!!oe((b||s).dirtyFields,y),error:oe((b||s).errors,y),isValidating:!!oe(s.validatingFields,y),isTouched:!!oe((b||s).touchedFields,y)}),ae=y=>{const b=y?yr(y):void 0;b?.forEach(A=>Be(s.errors,A)),b?b.forEach(A=>{d.state.next({name:A,errors:s.errors})}):d.state.next({errors:{}})},te=(y,b,A)=>{const I=(oe(a,y,{_f:{}})._f||{}).ref,z=oe(s.errors,y)||{},{ref:Z,message:H,type:re,...he}=z;Ee(s.errors,y,{...he,...b,ref:I}),d.state.next({name:y,errors:s.errors,isValid:!1}),A&&A.shouldFocus&&I&&I.focus&&I.focus()},J=(y,b)=>ft(y)?d.state.subscribe({next:A=>"values"in A&&y(R(void 0,b),A)}):R(y,b,!0),ve=y=>d.state.subscribe({next:b=>{wl(y.name,b.name,y.exact)&&yl(b,y.formState||w,N,y.reRenderRoot)&&y.callback({values:{...i},...s,...b,defaultValues:n})}}).unsubscribe,Se=y=>(o.mount=!0,g={...g,...y.formState},ve({...y,formState:{..._,...y.formState}})),fe=(y,b={})=>{for(const A of y?yr(y):l.mount)l.mount.delete(A),l.array.delete(A),b.keepValue||(Be(a,A),Be(i,A)),!b.keepError&&Be(s.errors,A),!b.keepDirty&&Be(s.dirtyFields,A),!b.keepTouched&&Be(s.touchedFields,A),!b.keepIsValidating&&Be(s.validatingFields,A),!r.shouldUnregister&&!b.keepDefaultValue&&Be(n,A);d.state.next({values:We(i)}),d.state.next({...s,...b.keepDirty?{isDirty:v()}:{}}),!b.keepIsValid&&x()},me=({disabled:y,name:b})=>{if(gt(y)&&o.mount||y||l.disabled.has(b)){const z=l.disabled.has(b)!==!!y;y?l.disabled.add(b):l.disabled.delete(b),z&&o.mount&&!o.action&&x()}},ke=(y,b={})=>{let A=oe(a,y);const I=gt(b.disabled)||gt(r.disabled);return Ee(a,y,{...A||{},_f:{...A&&A._f?A._f:{ref:{name:y}},name:y,mount:!0,...b}}),l.mount.add(y),A?me({disabled:gt(b.disabled)?b.disabled:r.disabled,name:y}):S(y,!0,b.value),{...I?{disabled:b.disabled||r.disabled}:{},...r.progressive?{required:!!b.required,min:pr(b.min),max:pr(b.max),minLength:pr(b.minLength),maxLength:pr(b.maxLength),pattern:pr(b.pattern)}:{},name:y,onChange:ce,onBlur:ce,ref:z=>{if(z){ke(y,b),A=oe(a,y);const Z=Oe(z.value)&&z.querySelectorAll&&z.querySelectorAll("input,select,textarea")[0]||z,H=ml(Z),re=A._f.refs||[];if(H?re.find(he=>he===Z):Z===A._f.ref)return;Ee(a,y,{_f:{...A._f,...H?{refs:[...re.filter(ws),Z,...Array.isArray(oe(n,y))?[{}]:[]],ref:{type:Z.type,name:y}}:{ref:Z}}}),S(y,!1,void 0,Z)}else A=oe(a,y,{}),A._f&&(A._f.mount=!1),(r.shouldUnregister||b.shouldUnregister)&&!(il(l.array,y)&&o.action)&&l.unMount.add(y)}}},ye=()=>r.shouldFocusError&&wr(a,F,l.mount),_e=y=>{gt(y)&&(d.state.next({disabled:y}),wr(a,(b,A)=>{const I=oe(a,A);I&&(b.disabled=I._f.disabled||y,Array.isArray(I._f.refs)&&I._f.refs.forEach(z=>{z.disabled=I._f.disabled||y}))},0,!1))},Re=(y,b)=>async A=>{let I;A&&(A.preventDefault&&A.preventDefault(),A.persist&&A.persist());let z=We(i);if(d.state.next({isSubmitting:!0}),r.resolver){const{errors:Z,values:H}=await $();f(),s.errors=Z,z=We(H)}else await G(a);if(l.disabled.size)for(const Z of l.disabled)Be(z,Z);if(Be(s.errors,"root"),Je(s.errors)){d.state.next({errors:{}});try{await y(z,A)}catch(Z){I=Z}}else b&&await b({...s.errors},A),ye(),setTimeout(ye);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Je(s.errors)&&!I,submitCount:s.submitCount+1,errors:s.errors}),I)throw I},c=(y,b={})=>{oe(a,y)&&(Oe(b.defaultValue)?q(y,We(oe(n,y))):(q(y,b.defaultValue),Ee(n,y,We(b.defaultValue))),b.keepTouched||Be(s.touchedFields,y),b.keepDirty||(Be(s.dirtyFields,y),s.isDirty=b.defaultValue?v(y,We(oe(n,y))):v()),b.keepError||(Be(s.errors,y),w.isValid&&x()),d.state.next({...s}))},K=(y,b={})=>{const A=y?We(y):n,I=We(A),z=Je(y),Z=z?n:I;if(b.keepDefaultValues||(n=A),!b.keepValues){if(b.keepDirtyValues){const H=new Set([...l.mount,...Object.keys(qt(n,i))]);for(const re of Array.from(H)){const he=oe(s.dirtyFields,re),ze=oe(i,re),je=oe(Z,re);he&&!Oe(ze)?Ee(Z,re,ze):!he&&!Oe(je)&&q(re,je)}}else{if(Us&&Oe(y))for(const H of l.mount){const re=oe(a,H);if(re&&re._f){const he=Array.isArray(re._f.refs)?re._f.refs[0]:re._f.ref;if(Xr(he)){const ze=he.closest("form");if(ze){ze.reset();break}}}}if(b.keepFieldsRef)for(const H of l.mount)q(H,oe(Z,H));else a={}}i=r.shouldUnregister?b.keepDefaultValues?We(n):{}:We(Z),d.array.next({values:{...Z}}),d.state.next({values:{...Z}})}l={mount:b.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!w.isValid||!!b.keepIsValid||!!b.keepDirtyValues||!r.shouldUnregister&&!Je(Z),o.watch=!!r.shouldUnregister,o.keepIsValid=!!b.keepIsValid,o.action=!1,b.keepErrors||(s.errors={}),d.state.next({submitCount:b.keepSubmitCount?s.submitCount:0,isDirty:z?!1:b.keepDirty?s.isDirty:!!(b.keepDefaultValues&&!jt(y,n)),isSubmitted:b.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:z?{}:b.keepDirtyValues?b.keepDefaultValues&&i?qt(n,i):s.dirtyFields:b.keepDefaultValues&&y?qt(n,y):b.keepDirty?s.dirtyFields:{},touchedFields:b.keepTouched?s.touchedFields:{},errors:b.keepErrors?s.errors:{},isSubmitSuccessful:b.keepIsSubmitSuccessful?s.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:n})},M=(y,b)=>K(ft(y)?y(i):y,{...r.resetOptions,...b}),C=(y,b={})=>{const A=oe(a,y),I=A&&A._f;if(I){const z=I.refs?I.refs[0]:I.ref;z.focus&&setTimeout(()=>{z.focus(),b.shouldSelect&&ft(z.select)&&z.select()})}},N=y=>{s={...s,...y}},X={control:{register:ke,unregister:fe,getFieldState:L,handleSubmit:Re,setError:te,_subscribe:ve,_runSchema:$,_updateIsValidating:f,_focusError:ye,_getWatch:R,_getDirty:v,_setValid:x,_setFieldArray:j,_setDisabledField:me,_setErrors:P,_getFieldArray:m,_reset:K,_resetDefaultValues:()=>ft(r.defaultValues)&&r.defaultValues().then(y=>{M(y,r.resetOptions),d.state.next({isLoading:!1})}),_removeUnmounted:se,_disableForm:_e,_subjects:d,_proxyFormState:w,get _fields(){return a},get _formValues(){return i},get _state(){return o},set _state(y){o=y},get _defaultValues(){return n},get _names(){return l},set _names(y){l=y},get _formState(){return s},get _options(){return r},set _options(y){r={...r,...y}}},subscribe:Se,trigger:ee,register:ke,handleSubmit:Re,watch:J,setValue:q,getValues:O,reset:M,resetField:c,clearErrors:ae,unregister:fe,setError:te,setFocus:C,getFieldState:L};return{...X,formControl:X}}function Cl(e={}){const r=Xe.useRef(void 0),s=Xe.useRef(void 0),[a,n]=Xe.useState({isDirty:!1,isValidating:!1,isLoading:ft(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:ft(e.defaultValues)?void 0:e.defaultValues});if(!r.current)if(e.formControl)r.current={...e.formControl,formState:a},e.defaultValues&&!ft(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:o,...l}=Sl(e);r.current={...l,formState:a}}const i=r.current.control;return i._options=e,dl(()=>{const o=i._subscribe({formState:i._proxyFormState,callback:()=>n({...i._formState}),reRenderRoot:!0});return n(l=>({...l,isReady:!0})),i._formState.isReady=!0,o},[i]),Xe.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),Xe.useEffect(()=>{e.mode&&(i._options.mode=e.mode),e.reValidateMode&&(i._options.reValidateMode=e.reValidateMode)},[i,e.mode,e.reValidateMode]),Xe.useEffect(()=>{e.errors&&(i._setErrors(e.errors),i._focusError())},[i,e.errors]),Xe.useEffect(()=>{e.shouldUnregister&&i._subjects.state.next({values:i._getWatch()})},[i,e.shouldUnregister]),Xe.useEffect(()=>{if(i._proxyFormState.isDirty){const o=i._getDirty();o!==a.isDirty&&i._subjects.state.next({isDirty:o})}},[i,a.isDirty]),Xe.useEffect(()=>{var o;e.values&&!jt(e.values,s.current)?(i._reset(e.values,{keepFieldsRef:!0,...i._options.resetOptions}),!((o=i._options.resetOptions)===null||o===void 0)&&o.keepIsValid||i._setValid(),s.current=e.values,n(l=>({...l}))):i._resetDefaultValues()},[i,e.values]),Xe.useEffect(()=>{i._state.mount||(i._setValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),r.current.formState=Xe.useMemo(()=>cl(a,i),[i,a]),r.current}const Na=(e,r,s)=>{if(e&&"reportValidity"in e){const a=oe(s,r);e.setCustomValidity(a&&a.message||""),e.reportValidity()}},As=(e,r)=>{for(const s in r.fields){const a=r.fields[s];a&&a.ref&&"reportValidity"in a.ref?Na(a.ref,s,e):a&&a.refs&&a.refs.forEach(n=>Na(n,s,e))}},Sa=(e,r)=>{r.shouldUseNativeValidation&&As(e,r);const s={};for(const a in e){const n=oe(r.fields,a),i=Object.assign(e[a]||{},{ref:n&&n.ref});if(zl(r.names||Object.keys(e),a)){const o=Object.assign({},oe(s,a));Ee(o,"root",i),Ee(s,a,o)}else Ee(s,a,i)}return s},zl=(e,r)=>{const s=Ca(r);return e.some(a=>Ca(a).match(`^${s}\\.\\d+`))};function Ca(e){return e.replace(/\]|\[/g,"")}function Q(e,r,s){function a(l,h){if(l._zod||Object.defineProperty(l,"_zod",{value:{def:h,constr:o,traits:new Set},enumerable:!1}),l._zod.traits.has(e))return;l._zod.traits.add(e),r(l,h);const p=o.prototype,_=Object.keys(p);for(let w=0;w<_.length;w++){const g=_[w];g in l||(l[g]=p[g].bind(l))}}const n=s?.Parent??Object;class i extends n{}Object.defineProperty(i,"name",{value:e});function o(l){var h;const p=s?.Parent?new i:this;a(p,l),(h=p._zod).deferred??(h.deferred=[]);for(const _ of p._zod.deferred)_();return p}return Object.defineProperty(o,"init",{value:a}),Object.defineProperty(o,Symbol.hasInstance,{value:l=>s?.Parent&&l instanceof s.Parent?!0:l?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}class rr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class qn extends Error{constructor(r){super(`Encountered unidirectional transform during encode: ${r}`),this.name="ZodEncodeError"}}const Wn={};function Tt(e){return Wn}function El(e){const r=Object.values(e).filter(a=>typeof a=="number");return Object.entries(e).filter(([a,n])=>r.indexOf(+a)===-1).map(([a,n])=>n)}function Ps(e,r){return typeof r=="bigint"?r.toString():r}function Ks(e){return{get value(){{const r=e();return Object.defineProperty(this,"value",{value:r}),r}}}}function Gs(e){return e==null}function Hs(e){const r=e.startsWith("^")?1:0,s=e.endsWith("$")?e.length-1:e.length;return e.slice(r,s)}function Il(e,r){const s=(e.toString().split(".")[1]||"").length,a=r.toString();let n=(a.split(".")[1]||"").length;if(n===0&&/\d?e-\d?/.test(a)){const h=a.match(/\d?e-(\d?)/);h?.[1]&&(n=Number.parseInt(h[1]))}const i=s>n?s:n,o=Number.parseInt(e.toFixed(i).replace(".","")),l=Number.parseInt(r.toFixed(i).replace(".",""));return o%l/10**i}const za=Symbol("evaluating");function Ie(e,r,s){let a;Object.defineProperty(e,r,{get(){if(a!==za)return a===void 0&&(a=za,a=s()),a},set(n){Object.defineProperty(e,r,{value:n})},configurable:!0})}function Ut(e,r,s){Object.defineProperty(e,r,{value:s,writable:!0,enumerable:!0,configurable:!0})}function Bt(...e){const r={};for(const s of e){const a=Object.getOwnPropertyDescriptors(s);Object.assign(r,a)}return Object.defineProperties({},r)}function Ea(e){return JSON.stringify(e)}function Al(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Kn="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function es(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Pl=Ks(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Er(e){if(es(e)===!1)return!1;const r=e.constructor;if(r===void 0||typeof r!="function")return!0;const s=r.prototype;return!(es(s)===!1||Object.prototype.hasOwnProperty.call(s,"isPrototypeOf")===!1)}function Gn(e){return Er(e)?{...e}:Array.isArray(e)?[...e]:e}const Fl=new Set(["string","number","symbol"]);function dr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _t(e,r,s){const a=new e._zod.constr(r??e._zod.def);return(!r||s?.parent)&&(a._zod.parent=e),a}function de(e){const r=e;if(!r)return{};if(typeof r=="string")return{error:()=>r};if(r?.message!==void 0){if(r?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");r.error=r.message}return delete r.message,typeof r.error=="string"?{...r,error:()=>r.error}:r}function Dl(e){return Object.keys(e).filter(r=>e[r]._zod.optin==="optional"&&e[r]._zod.optout==="optional")}const Ol={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Tl(e,r){const s=e._zod.def,a=Bt(e._zod.def,{get shape(){const n={};for(const i in r){if(!(i in s.shape))throw new Error(`Unrecognized key: "${i}"`);r[i]&&(n[i]=s.shape[i])}return Ut(this,"shape",n),n},checks:[]});return _t(e,a)}function Rl(e,r){const s=e._zod.def,a=Bt(e._zod.def,{get shape(){const n={...e._zod.def.shape};for(const i in r){if(!(i in s.shape))throw new Error(`Unrecognized key: "${i}"`);r[i]&&delete n[i]}return Ut(this,"shape",n),n},checks:[]});return _t(e,a)}function Zl(e,r){if(!Er(r))throw new Error("Invalid input to extend: expected a plain object");const s=e._zod.def.checks;if(s&&s.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const n=Bt(e._zod.def,{get shape(){const i={...e._zod.def.shape,...r};return Ut(this,"shape",i),i},checks:[]});return _t(e,n)}function $l(e,r){if(!Er(r))throw new Error("Invalid input to safeExtend: expected a plain object");const s={...e._zod.def,get shape(){const a={...e._zod.def.shape,...r};return Ut(this,"shape",a),a},checks:e._zod.def.checks};return _t(e,s)}function Ll(e,r){const s=Bt(e._zod.def,{get shape(){const a={...e._zod.def.shape,...r._zod.def.shape};return Ut(this,"shape",a),a},get catchall(){return r._zod.def.catchall},checks:[]});return _t(e,s)}function Ul(e,r,s){const a=Bt(r._zod.def,{get shape(){const n=r._zod.def.shape,i={...n};if(s)for(const o in s){if(!(o in n))throw new Error(`Unrecognized key: "${o}"`);s[o]&&(i[o]=e?new e({type:"optional",innerType:n[o]}):n[o])}else for(const o in n)i[o]=e?new e({type:"optional",innerType:n[o]}):n[o];return Ut(this,"shape",i),i},checks:[]});return _t(r,a)}function Bl(e,r,s){const a=Bt(r._zod.def,{get shape(){const n=r._zod.def.shape,i={...n};if(s)for(const o in s){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);s[o]&&(i[o]=new e({type:"nonoptional",innerType:n[o]}))}else for(const o in n)i[o]=new e({type:"nonoptional",innerType:n[o]});return Ut(this,"shape",i),i},checks:[]});return _t(r,a)}function Wt(e,r=0){if(e.aborted===!0)return!0;for(let s=r;s<e.issues.length;s++)if(e.issues[s]?.continue!==!0)return!0;return!1}function Hn(e,r){return r.map(s=>{var a;return(a=s).path??(a.path=[]),s.path.unshift(e),s})}function Ur(e){return typeof e=="string"?e:e?.message}function Rt(e,r,s){const a={...e,path:e.path??[]};if(!e.message){const n=Ur(e.inst?._zod.def?.error?.(e))??Ur(r?.error?.(e))??Ur(s.customError?.(e))??Ur(s.localeError?.(e))??"Invalid input";a.message=n}return delete a.inst,delete a.continue,r?.reportInput||delete a.input,a}function Qs(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Ir(...e){const[r,s,a]=e;return typeof r=="string"?{message:r,code:"custom",input:s,inst:a}:{...r}}const Qn=(e,r)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:r,enumerable:!1}),e.message=JSON.stringify(r,Ps,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ys=Q("$ZodError",Qn),is=Q("$ZodError",Qn,{Parent:Error});function Ml(e,r=s=>s.message){const s={},a=[];for(const n of e.issues)n.path.length>0?(s[n.path[0]]=s[n.path[0]]||[],s[n.path[0]].push(r(n))):a.push(r(n));return{formErrors:a,fieldErrors:s}}function Vl(e,r=s=>s.message){const s={_errors:[]},a=n=>{for(const i of n.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>a({issues:o}));else if(i.code==="invalid_key")a({issues:i.issues});else if(i.code==="invalid_element")a({issues:i.issues});else if(i.path.length===0)s._errors.push(r(i));else{let o=s,l=0;for(;l<i.path.length;){const h=i.path[l];l===i.path.length-1?(o[h]=o[h]||{_errors:[]},o[h]._errors.push(r(i))):o[h]=o[h]||{_errors:[]},o=o[h],l++}}};return a(e),s}const os=e=>(r,s,a,n)=>{const i=a?Object.assign(a,{async:!1}):{async:!1},o=r._zod.run({value:s,issues:[]},i);if(o instanceof Promise)throw new rr;if(o.issues.length){const l=new(n?.Err??e)(o.issues.map(h=>Rt(h,i,Tt())));throw Kn(l,n?.callee),l}return o.value},ql=os(is),ls=e=>async(r,s,a,n)=>{const i=a?Object.assign(a,{async:!0}):{async:!0};let o=r._zod.run({value:s,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const l=new(n?.Err??e)(o.issues.map(h=>Rt(h,i,Tt())));throw Kn(l,n?.callee),l}return o.value},Wl=ls(is),cs=e=>(r,s,a)=>{const n=a?{...a,async:!1}:{async:!1},i=r._zod.run({value:s,issues:[]},n);if(i instanceof Promise)throw new rr;return i.issues.length?{success:!1,error:new(e??Ys)(i.issues.map(o=>Rt(o,n,Tt())))}:{success:!0,data:i.value}},Kl=cs(is),ds=e=>async(r,s,a)=>{const n=a?Object.assign(a,{async:!0}):{async:!0};let i=r._zod.run({value:s,issues:[]},n);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(o=>Rt(o,n,Tt())))}:{success:!0,data:i.value}},Gl=ds(is),Hl=e=>(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return os(e)(r,s,n)},Ql=e=>(r,s,a)=>os(e)(r,s,a),Yl=e=>async(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return ls(e)(r,s,n)},Xl=e=>async(r,s,a)=>ls(e)(r,s,a),Jl=e=>(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return cs(e)(r,s,n)},ec=e=>(r,s,a)=>cs(e)(r,s,a),tc=e=>async(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return ds(e)(r,s,n)},rc=e=>async(r,s,a)=>ds(e)(r,s,a),sc=/^[cC][^\s-]{8,}$/,ac=/^[0-9a-z]+$/,nc=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ic=/^[0-9a-vA-V]{20}$/,oc=/^[A-Za-z0-9]{27}$/,lc=/^[a-zA-Z0-9_-]{21}$/,cc=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,dc=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ia=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,uc=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,hc="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function mc(){return new RegExp(hc,"u")}const fc=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,pc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,xc=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,gc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,bc=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Yn=/^[A-Za-z0-9_-]*$/,vc=/^\+(?:[0-9]){6,14}[0-9]$/,Xn="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",yc=new RegExp(`^${Xn}$`);function Jn(e){const r="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${r}`:e.precision===0?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${e.precision}}`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}function wc(e){return new RegExp(`^${Jn(e)}$`)}function jc(e){const r=Jn({precision:e.precision}),s=["Z"];e.local&&s.push(""),e.offset&&s.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const a=`${r}(?:${s.join("|")})`;return new RegExp(`^${Xn}T(?:${a})$`)}const kc=e=>{const r=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${r}$`)},_c=/^-?\d+$/,Nc=/^-?\d+(?:\.\d+)?/,Sc=/^[^A-Z]*$/,Cc=/^[^a-z]*$/,ot=Q("$ZodCheck",(e,r)=>{var s;e._zod??(e._zod={}),e._zod.def=r,(s=e._zod).onattach??(s.onattach=[])}),ei={number:"number",bigint:"bigint",object:"date"},ti=Q("$ZodCheckLessThan",(e,r)=>{ot.init(e,r);const s=ei[typeof r.value];e._zod.onattach.push(a=>{const n=a._zod.bag,i=(r.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;r.value<i&&(r.inclusive?n.maximum=r.value:n.exclusiveMaximum=r.value)}),e._zod.check=a=>{(r.inclusive?a.value<=r.value:a.value<r.value)||a.issues.push({origin:s,code:"too_big",maximum:r.value,input:a.value,inclusive:r.inclusive,inst:e,continue:!r.abort})}}),ri=Q("$ZodCheckGreaterThan",(e,r)=>{ot.init(e,r);const s=ei[typeof r.value];e._zod.onattach.push(a=>{const n=a._zod.bag,i=(r.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;r.value>i&&(r.inclusive?n.minimum=r.value:n.exclusiveMinimum=r.value)}),e._zod.check=a=>{(r.inclusive?a.value>=r.value:a.value>r.value)||a.issues.push({origin:s,code:"too_small",minimum:r.value,input:a.value,inclusive:r.inclusive,inst:e,continue:!r.abort})}}),zc=Q("$ZodCheckMultipleOf",(e,r)=>{ot.init(e,r),e._zod.onattach.push(s=>{var a;(a=s._zod.bag).multipleOf??(a.multipleOf=r.value)}),e._zod.check=s=>{if(typeof s.value!=typeof r.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof s.value=="bigint"?s.value%r.value===BigInt(0):Il(s.value,r.value)===0)||s.issues.push({origin:typeof s.value,code:"not_multiple_of",divisor:r.value,input:s.value,inst:e,continue:!r.abort})}}),Ec=Q("$ZodCheckNumberFormat",(e,r)=>{ot.init(e,r),r.format=r.format||"float64";const s=r.format?.includes("int"),a=s?"int":"number",[n,i]=Ol[r.format];e._zod.onattach.push(o=>{const l=o._zod.bag;l.format=r.format,l.minimum=n,l.maximum=i,s&&(l.pattern=_c)}),e._zod.check=o=>{const l=o.value;if(s){if(!Number.isInteger(l)){o.issues.push({expected:a,format:r.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?o.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,continue:!r.abort}):o.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,continue:!r.abort});return}}l<n&&o.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:e,continue:!r.abort}),l>i&&o.issues.push({origin:"number",input:l,code:"too_big",maximum:i,inst:e})}}),Ic=Q("$ZodCheckMaxLength",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag.maximum??Number.POSITIVE_INFINITY;r.maximum<n&&(a._zod.bag.maximum=r.maximum)}),e._zod.check=a=>{const n=a.value;if(n.length<=r.maximum)return;const o=Qs(n);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:n,inst:e,continue:!r.abort})}}),Ac=Q("$ZodCheckMinLength",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag.minimum??Number.NEGATIVE_INFINITY;r.minimum>n&&(a._zod.bag.minimum=r.minimum)}),e._zod.check=a=>{const n=a.value;if(n.length>=r.minimum)return;const o=Qs(n);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:n,inst:e,continue:!r.abort})}}),Pc=Q("$ZodCheckLengthEquals",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag;n.minimum=r.length,n.maximum=r.length,n.length=r.length}),e._zod.check=a=>{const n=a.value,i=n.length;if(i===r.length)return;const o=Qs(n),l=i>r.length;a.issues.push({origin:o,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:e,continue:!r.abort})}}),us=Q("$ZodCheckStringFormat",(e,r)=>{var s,a;ot.init(e,r),e._zod.onattach.push(n=>{const i=n._zod.bag;i.format=r.format,r.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(r.pattern))}),r.pattern?(s=e._zod).check??(s.check=n=>{r.pattern.lastIndex=0,!r.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:r.format,input:n.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:e,continue:!r.abort})}):(a=e._zod).check??(a.check=()=>{})}),Fc=Q("$ZodCheckRegex",(e,r)=>{us.init(e,r),e._zod.check=s=>{r.pattern.lastIndex=0,!r.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:"regex",input:s.value,pattern:r.pattern.toString(),inst:e,continue:!r.abort})}}),Dc=Q("$ZodCheckLowerCase",(e,r)=>{r.pattern??(r.pattern=Sc),us.init(e,r)}),Oc=Q("$ZodCheckUpperCase",(e,r)=>{r.pattern??(r.pattern=Cc),us.init(e,r)}),Tc=Q("$ZodCheckIncludes",(e,r)=>{ot.init(e,r);const s=dr(r.includes),a=new RegExp(typeof r.position=="number"?`^.{${r.position}}${s}`:s);r.pattern=a,e._zod.onattach.push(n=>{const i=n._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(a)}),e._zod.check=n=>{n.value.includes(r.includes,r.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:n.value,inst:e,continue:!r.abort})}}),Rc=Q("$ZodCheckStartsWith",(e,r)=>{ot.init(e,r);const s=new RegExp(`^${dr(r.prefix)}.*`);r.pattern??(r.pattern=s),e._zod.onattach.push(a=>{const n=a._zod.bag;n.patterns??(n.patterns=new Set),n.patterns.add(s)}),e._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:e,continue:!r.abort})}}),Zc=Q("$ZodCheckEndsWith",(e,r)=>{ot.init(e,r);const s=new RegExp(`.*${dr(r.suffix)}$`);r.pattern??(r.pattern=s),e._zod.onattach.push(a=>{const n=a._zod.bag;n.patterns??(n.patterns=new Set),n.patterns.add(s)}),e._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:e,continue:!r.abort})}}),$c=Q("$ZodCheckOverwrite",(e,r)=>{ot.init(e,r),e._zod.check=s=>{s.value=r.tx(s.value)}});class Lc{constructor(r=[]){this.content=[],this.indent=0,this&&(this.args=r)}indented(r){this.indent+=1,r(this),this.indent-=1}write(r){if(typeof r=="function"){r(this,{execution:"sync"}),r(this,{execution:"async"});return}const a=r.split(`
|
|
1
|
+
import{c as dr,j as t,l as le,h as Os,as as an,K as $t,t as ne,O as wi,a1 as nn,bD as ji,B as ue,a2 as on,a3 as ki,a4 as ln,a5 as cn,x as rr,a8 as dn,V as Wr,X as Ft,o as be,a0 as Wt,C as Dt,w as ct,az as br,at as dt,r as Ce,aA as ra,aE as un,aa as _i,Z as Ar,T as et,s as tt,v as rt,g as ur,i as Ke,k as hn,ad as jr,bE as mn,ae as kr,af as _r,ag as Nr,G as fn,ah as Kr,y as Pr,n as yt,I as st,R as hr,Y as Fr,ai as Dr,D as sa,ac as it,E as ss,al as pn,am as xn,an as gn,ao as bn,ap as Gr,aq as It,d as Ts,S as Sr,q as Ni,a as Si,P as Ci,au as zi,aK as fs,a9 as ps}from"./index-43NA2pdZ.js";import{b as Y,m as Rr,k as Ei,R as Xe}from"./recharts-DrC5kNsx.js";import{P as Ii,a as Ai,b as Pi}from"./page-components-DXOKtt_M.js";import{T as vn}from"./textarea-B1anutjq.js";import{S as at}from"./skeleton-CN6xlRXP.js";import{u as aa}from"./index-CCTahcpv.js";import{S as sr,a as ar,b as nr,c as ir,d as kt,C as yn}from"./select-DCY_lg9j.js";import{C as Rs,a as Zs,b as Fi,c as Di}from"./card-DdbmSh-v.js";import{u as Oi,C as Hr,a as na}from"./index-ChrvveQm.js";import{T as Qr,a as Yr,b as or,c as De,d as wn,e as ut}from"./table-7NGq0kRw.js";import{p as we}from"./product.service-FClit10f.js";import{read as Ti,utils as Ri}from"./xlsx-BvJTHLik.js";import{b as jn,a as kn,M as _n,S as Nn,F as Zi}from"./products.types-nZIsk2w8.js";import{h as $i,I as vr,m as Cs}from"./MediaProcessingService-CG2DdSyN.js";import{g as Sn,c as Li}from"./mediaLimits-CAYdWqeQ.js";import{F as Ui}from"./file-spreadsheet-DpekIaV8.js";import{I as At,V as Cn}from"./video-CILE66CA.js";import{D as Ot}from"./database-Brb7Omak.js";import{R as Bi}from"./index-BGvtgHY3.js";import{A as Kt,a as Gt,b as Ht,c as Qt,d as Yt,e as Xt,f as Jt,g as er}from"./alert-dialog-gzZZoAiu.js";import{u as Ge}from"./useMutation-0ypmz8SO.js";import{a as as}from"./datetime-D72Uxhjs.js";import{T as bt}from"./trash-2-D_kmHMwn.js";import{U as ia}from"./upload-CQg4_W5r.js";import{C as Mi}from"./cloud-B3m0_VpL.js";import{F as zn}from"./file-CTZ8-xmL.js";import{M as En}from"./music-CgtkroYi.js";import{H as In}from"./hash-ByrjK6gt.js";import{S as An}from"./save-mwkHDnDL.js";import{C as oa}from"./checkbox-CuJh5AMO.js";import{E as Pn}from"./ellipsis-GLu0u4ze.js";import{E as Fn}from"./eye-CR5C6hVv.js";import{P as $s}from"./pencil-aqjc7AWb.js";import{E as Cr}from"./eye-off-CBiJXw4j.js";import{a as Vi,A as qi}from"./arrow-up-DJzXCc8_.js";import{A as Wi}from"./arrow-up-down-DkSCsCjR.js";import{C as Ki}from"./calendar-Bu0aDtW1.js";import{M as Dn}from"./maximize-2-SbmXBBYe.js";import{S as Gi}from"./slider-D0QB_Lme.js";import{C as Hi,a as Qi,b as Yi}from"./collapsible-Ce_8EeFJ.js";import{s as Xi}from"./storage.api-C0ZJBoSz.js";import{T as Ji,c as xs}from"./tabs-BGCKrmVw.js";import{u as eo}from"./useDebounce-Bfcb_jpD.js";import{D as to}from"./download-CyfdxFCW.js";import{L as ro,S as so}from"./star-BMD3HmS6.js";import{L as ao}from"./list-B0uLKf1b.js";import"./index-KbFmSzBE.js";import"./index-CEYKqxbU.js";const no=[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0",key:"5ilxe3"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0",key:"11zvb9"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7",key:"1iw5b2"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8",key:"c0bmvh"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69",key:"1ruxm7"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8",key:"qkgqxc"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69",key:"1mcia2"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7",key:"1fvljs"}]],io=dr("circle-dashed",no);const oo=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],lr=dr("dollar-sign",oo);const lo=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],On=dr("image-off",lo);const co=[["path",{d:"m16 16 2 2 4-4",key:"gfu2re"}],["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}]],uo=dr("package-check",co);const ho=[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],mo=dr("radio",ho);const fo=[["circle",{cx:"15",cy:"12",r:"3",key:"1afu0r"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],Ls=dr("toggle-right",fo),qr=Y.forwardRef(({className:e,value:r=0,max:s=100,...a},n)=>{const i=Math.min(Math.max(r/s*100,0),100);return t.jsx("div",{ref:n,role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":s,className:le("relative h-2 w-full overflow-hidden rounded-full bg-secondary",e),...a,children:t.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-out",style:{width:`${i}%`}})})});qr.displayName="Progress";function zr(e,r){if(e==null)return"—";const s=typeof e=="string"?parseFloat(e):e;if(isNaN(s))return"—";const a=(r||"USD").toUpperCase();return a==="COP"?`${s.toFixed(3)} COP`:`${a} ${s.toFixed(2)}`}function Zr(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var gs={exports:{}};var la;function po(){return la||(la=1,(function(e,r){(function(s){e.exports=s()})(function(){return(function s(a,n,i){function o(p,_){if(!n[p]){if(!a[p]){var w=typeof Zr=="function"&&Zr;if(!_&&w)return w(p,!0);if(l)return l(p,!0);var g=new Error("Cannot find module '"+p+"'");throw g.code="MODULE_NOT_FOUND",g}var d=n[p]={exports:{}};a[p][0].call(d.exports,function(k){var u=a[p][1][k];return o(u||k)},d,d.exports,s,a,n,i)}return n[p].exports}for(var l=typeof Zr=="function"&&Zr,h=0;h<i.length;h++)o(i[h]);return o})({1:[function(s,a,n){var i=s("./utils"),o=s("./support"),l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.encode=function(h){for(var p,_,w,g,d,k,u,x=[],f=0,j=h.length,E=j,P=i.getTypeOf(h)!=="string";f<h.length;)E=j-f,w=P?(p=h[f++],_=f<j?h[f++]:0,f<j?h[f++]:0):(p=h.charCodeAt(f++),_=f<j?h.charCodeAt(f++):0,f<j?h.charCodeAt(f++):0),g=p>>2,d=(3&p)<<4|_>>4,k=1<E?(15&_)<<2|w>>6:64,u=2<E?63&w:64,x.push(l.charAt(g)+l.charAt(d)+l.charAt(k)+l.charAt(u));return x.join("")},n.decode=function(h){var p,_,w,g,d,k,u=0,x=0,f="data:";if(h.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var j,E=3*(h=h.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(h.charAt(h.length-1)===l.charAt(64)&&E--,h.charAt(h.length-2)===l.charAt(64)&&E--,E%1!=0)throw new Error("Invalid base64 input, bad content length.");for(j=o.uint8array?new Uint8Array(0|E):new Array(0|E);u<h.length;)p=l.indexOf(h.charAt(u++))<<2|(g=l.indexOf(h.charAt(u++)))>>4,_=(15&g)<<4|(d=l.indexOf(h.charAt(u++)))>>2,w=(3&d)<<6|(k=l.indexOf(h.charAt(u++))),j[x++]=p,d!==64&&(j[x++]=_),k!==64&&(j[x++]=w);return j}},{"./support":30,"./utils":32}],2:[function(s,a,n){var i=s("./external"),o=s("./stream/DataWorker"),l=s("./stream/Crc32Probe"),h=s("./stream/DataLengthProbe");function p(_,w,g,d,k){this.compressedSize=_,this.uncompressedSize=w,this.crc32=g,this.compression=d,this.compressedContent=k}p.prototype={getContentWorker:function(){var _=new o(i.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new h("data_length")),w=this;return _.on("end",function(){if(this.streamInfo.data_length!==w.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),_},getCompressedWorker:function(){return new o(i.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},p.createWorkerFrom=function(_,w,g){return _.pipe(new l).pipe(new h("uncompressedSize")).pipe(w.compressWorker(g)).pipe(new h("compressedSize")).withStreamInfo("compression",w)},a.exports=p},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(s,a,n){var i=s("./stream/GenericWorker");n.STORE={magic:"\0\0",compressWorker:function(){return new i("STORE compression")},uncompressWorker:function(){return new i("STORE decompression")}},n.DEFLATE=s("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(s,a,n){var i=s("./utils"),o=(function(){for(var l,h=[],p=0;p<256;p++){l=p;for(var _=0;_<8;_++)l=1&l?3988292384^l>>>1:l>>>1;h[p]=l}return h})();a.exports=function(l,h){return l!==void 0&&l.length?i.getTypeOf(l)!=="string"?(function(p,_,w,g){var d=o,k=g+w;p^=-1;for(var u=g;u<k;u++)p=p>>>8^d[255&(p^_[u])];return-1^p})(0|h,l,l.length,0):(function(p,_,w,g){var d=o,k=g+w;p^=-1;for(var u=g;u<k;u++)p=p>>>8^d[255&(p^_.charCodeAt(u))];return-1^p})(0|h,l,l.length,0):0}},{"./utils":32}],5:[function(s,a,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(s,a,n){var i=null;i=typeof Promise<"u"?Promise:s("lie"),a.exports={Promise:i}},{lie:37}],7:[function(s,a,n){var i=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",o=s("pako"),l=s("./utils"),h=s("./stream/GenericWorker"),p=i?"uint8array":"array";function _(w,g){h.call(this,"FlateWorker/"+w),this._pako=null,this._pakoAction=w,this._pakoOptions=g,this.meta={}}n.magic="\b\0",l.inherits(_,h),_.prototype.processChunk=function(w){this.meta=w.meta,this._pako===null&&this._createPako(),this._pako.push(l.transformTo(p,w.data),!1)},_.prototype.flush=function(){h.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},_.prototype.cleanUp=function(){h.prototype.cleanUp.call(this),this._pako=null},_.prototype._createPako=function(){this._pako=new o[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var w=this;this._pako.onData=function(g){w.push({data:g,meta:w.meta})}},n.compressWorker=function(w){return new _("Deflate",w)},n.uncompressWorker=function(){return new _("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(s,a,n){function i(d,k){var u,x="";for(u=0;u<k;u++)x+=String.fromCharCode(255&d),d>>>=8;return x}function o(d,k,u,x,f,j){var E,P,S=d.file,B=d.compression,U=j!==p.utf8encode,$=l.transformTo("string",j(S.name)),T=l.transformTo("string",p.utf8encode(S.name)),G=S.comment,se=l.transformTo("string",j(G)),v=l.transformTo("string",p.utf8encode(G)),R=T.length!==S.name.length,m=v.length!==G.length,V="",ie="",q="",ce=S.dir,F=S.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};k&&!u||(ee.crc32=d.crc32,ee.compressedSize=d.compressedSize,ee.uncompressedSize=d.uncompressedSize);var O=0;k&&(O|=8),U||!R&&!m||(O|=2048);var L=0,ae=0;ce&&(L|=16),f==="UNIX"?(ae=798,L|=(function(J,ve){var Se=J;return J||(Se=ve?16893:33204),(65535&Se)<<16})(S.unixPermissions,ce)):(ae=20,L|=(function(J){return 63&(J||0)})(S.dosPermissions)),E=F.getUTCHours(),E<<=6,E|=F.getUTCMinutes(),E<<=5,E|=F.getUTCSeconds()/2,P=F.getUTCFullYear()-1980,P<<=4,P|=F.getUTCMonth()+1,P<<=5,P|=F.getUTCDate(),R&&(ie=i(1,1)+i(_($),4)+T,V+="up"+i(ie.length,2)+ie),m&&(q=i(1,1)+i(_(se),4)+v,V+="uc"+i(q.length,2)+q);var te="";return te+=`
|
|
2
|
+
\0`,te+=i(O,2),te+=B.magic,te+=i(E,2),te+=i(P,2),te+=i(ee.crc32,4),te+=i(ee.compressedSize,4),te+=i(ee.uncompressedSize,4),te+=i($.length,2),te+=i(V.length,2),{fileRecord:w.LOCAL_FILE_HEADER+te+$+V,dirRecord:w.CENTRAL_FILE_HEADER+i(ae,2)+te+i(se.length,2)+"\0\0\0\0"+i(L,4)+i(x,4)+$+V+se}}var l=s("../utils"),h=s("../stream/GenericWorker"),p=s("../utf8"),_=s("../crc32"),w=s("../signature");function g(d,k,u,x){h.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=k,this.zipPlatform=u,this.encodeFileName=x,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}l.inherits(g,h),g.prototype.push=function(d){var k=d.meta.percent||0,u=this.entriesCount,x=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,h.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:u?(k+100*(u-x-1))/u:100}}))},g.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var k=this.streamFiles&&!d.file.dir;if(k){var u=o(d,k,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:u.fileRecord,meta:{percent:0}})}else this.accumulate=!0},g.prototype.closedSource=function(d){this.accumulate=!1;var k=this.streamFiles&&!d.file.dir,u=o(d,k,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(u.dirRecord),k)this.push({data:(function(x){return w.DATA_DESCRIPTOR+i(x.crc32,4)+i(x.compressedSize,4)+i(x.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:u.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},g.prototype.flush=function(){for(var d=this.bytesWritten,k=0;k<this.dirRecords.length;k++)this.push({data:this.dirRecords[k],meta:{percent:100}});var u=this.bytesWritten-d,x=(function(f,j,E,P,S){var B=l.transformTo("string",S(P));return w.CENTRAL_DIRECTORY_END+"\0\0\0\0"+i(f,2)+i(f,2)+i(j,4)+i(E,4)+i(B.length,2)+B})(this.dirRecords.length,u,d,this.zipComment,this.encodeFileName);this.push({data:x,meta:{percent:100}})},g.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},g.prototype.registerPrevious=function(d){this._sources.push(d);var k=this;return d.on("data",function(u){k.processChunk(u)}),d.on("end",function(){k.closedSource(k.previous.streamInfo),k._sources.length?k.prepareNextSource():k.end()}),d.on("error",function(u){k.error(u)}),this},g.prototype.resume=function(){return!!h.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},g.prototype.error=function(d){var k=this._sources;if(!h.prototype.error.call(this,d))return!1;for(var u=0;u<k.length;u++)try{k[u].error(d)}catch{}return!0},g.prototype.lock=function(){h.prototype.lock.call(this);for(var d=this._sources,k=0;k<d.length;k++)d[k].lock()},a.exports=g},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(s,a,n){var i=s("../compressions"),o=s("./ZipFileWorker");n.generateWorker=function(l,h,p){var _=new o(h.streamFiles,p,h.platform,h.encodeFileName),w=0;try{l.forEach(function(g,d){w++;var k=(function(j,E){var P=j||E,S=i[P];if(!S)throw new Error(P+" is not a valid compression method !");return S})(d.options.compression,h.compression),u=d.options.compressionOptions||h.compressionOptions||{},x=d.dir,f=d.date;d._compressWorker(k,u).withStreamInfo("file",{name:g,dir:x,date:f,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(_)}),_.entriesCount=w}catch(g){_.error(g)}return _}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(s,a,n){function i(){if(!(this instanceof i))return new i;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var o=new i;for(var l in this)typeof this[l]!="function"&&(o[l]=this[l]);return o}}(i.prototype=s("./object")).loadAsync=s("./load"),i.support=s("./support"),i.defaults=s("./defaults"),i.version="3.10.1",i.loadAsync=function(o,l){return new i().loadAsync(o,l)},i.external=s("./external"),a.exports=i},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(s,a,n){var i=s("./utils"),o=s("./external"),l=s("./utf8"),h=s("./zipEntries"),p=s("./stream/Crc32Probe"),_=s("./nodejsUtils");function w(g){return new o.Promise(function(d,k){var u=g.decompressed.getContentWorker().pipe(new p);u.on("error",function(x){k(x)}).on("end",function(){u.streamInfo.crc32!==g.decompressed.crc32?k(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}a.exports=function(g,d){var k=this;return d=i.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:l.utf8decode}),_.isNode&&_.isStream(g)?o.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):i.prepareContent("the loaded zip file",g,!0,d.optimizedBinaryString,d.base64).then(function(u){var x=new h(d);return x.load(u),x}).then(function(u){var x=[o.Promise.resolve(u)],f=u.files;if(d.checkCRC32)for(var j=0;j<f.length;j++)x.push(w(f[j]));return o.Promise.all(x)}).then(function(u){for(var x=u.shift(),f=x.files,j=0;j<f.length;j++){var E=f[j],P=E.fileNameStr,S=i.resolve(E.fileNameStr);k.file(S,E.decompressed,{binary:!0,optimizedBinaryString:!0,date:E.date,dir:E.dir,comment:E.fileCommentStr.length?E.fileCommentStr:null,unixPermissions:E.unixPermissions,dosPermissions:E.dosPermissions,createFolders:d.createFolders}),E.dir||(k.file(S).unsafeOriginalName=P)}return x.zipComment.length&&(k.comment=x.zipComment),k})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(s,a,n){var i=s("../utils"),o=s("../stream/GenericWorker");function l(h,p){o.call(this,"Nodejs stream input adapter for "+h),this._upstreamEnded=!1,this._bindStream(p)}i.inherits(l,o),l.prototype._bindStream=function(h){var p=this;(this._stream=h).pause(),h.on("data",function(_){p.push({data:_,meta:{percent:0}})}).on("error",function(_){p.isPaused?this.generatedError=_:p.error(_)}).on("end",function(){p.isPaused?p._upstreamEnded=!0:p.end()})},l.prototype.pause=function(){return!!o.prototype.pause.call(this)&&(this._stream.pause(),!0)},l.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},a.exports=l},{"../stream/GenericWorker":28,"../utils":32}],13:[function(s,a,n){var i=s("readable-stream").Readable;function o(l,h,p){i.call(this,h),this._helper=l;var _=this;l.on("data",function(w,g){_.push(w)||_._helper.pause(),p&&p(g)}).on("error",function(w){_.emit("error",w)}).on("end",function(){_.push(null)})}s("../utils").inherits(o,i),o.prototype._read=function(){this._helper.resume()},a.exports=o},{"../utils":32,"readable-stream":16}],14:[function(s,a,n){a.exports={isNode:typeof Buffer<"u",newBufferFrom:function(i,o){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(i,o);if(typeof i=="number")throw new Error('The "data" argument must not be a number');return new Buffer(i,o)},allocBuffer:function(i){if(Buffer.alloc)return Buffer.alloc(i);var o=new Buffer(i);return o.fill(0),o},isBuffer:function(i){return Buffer.isBuffer(i)},isStream:function(i){return i&&typeof i.on=="function"&&typeof i.pause=="function"&&typeof i.resume=="function"}}},{}],15:[function(s,a,n){function i(S,B,U){var $,T=l.getTypeOf(B),G=l.extend(U||{},_);G.date=G.date||new Date,G.compression!==null&&(G.compression=G.compression.toUpperCase()),typeof G.unixPermissions=="string"&&(G.unixPermissions=parseInt(G.unixPermissions,8)),G.unixPermissions&&16384&G.unixPermissions&&(G.dir=!0),G.dosPermissions&&16&G.dosPermissions&&(G.dir=!0),G.dir&&(S=f(S)),G.createFolders&&($=x(S))&&j.call(this,$,!0);var se=T==="string"&&G.binary===!1&&G.base64===!1;U&&U.binary!==void 0||(G.binary=!se),(B instanceof w&&B.uncompressedSize===0||G.dir||!B||B.length===0)&&(G.base64=!1,G.binary=!0,B="",G.compression="STORE",T="string");var v=null;v=B instanceof w||B instanceof h?B:k.isNode&&k.isStream(B)?new u(S,B):l.prepareContent(S,B,G.binary,G.optimizedBinaryString,G.base64);var R=new g(S,v,G);this.files[S]=R}var o=s("./utf8"),l=s("./utils"),h=s("./stream/GenericWorker"),p=s("./stream/StreamHelper"),_=s("./defaults"),w=s("./compressedObject"),g=s("./zipObject"),d=s("./generate"),k=s("./nodejsUtils"),u=s("./nodejs/NodejsStreamInputAdapter"),x=function(S){S.slice(-1)==="/"&&(S=S.substring(0,S.length-1));var B=S.lastIndexOf("/");return 0<B?S.substring(0,B):""},f=function(S){return S.slice(-1)!=="/"&&(S+="/"),S},j=function(S,B){return B=B!==void 0?B:_.createFolders,S=f(S),this.files[S]||i.call(this,S,null,{dir:!0,createFolders:B}),this.files[S]};function E(S){return Object.prototype.toString.call(S)==="[object RegExp]"}var P={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(S){var B,U,$;for(B in this.files)$=this.files[B],(U=B.slice(this.root.length,B.length))&&B.slice(0,this.root.length)===this.root&&S(U,$)},filter:function(S){var B=[];return this.forEach(function(U,$){S(U,$)&&B.push($)}),B},file:function(S,B,U){if(arguments.length!==1)return S=this.root+S,i.call(this,S,B,U),this;if(E(S)){var $=S;return this.filter(function(G,se){return!se.dir&&$.test(G)})}var T=this.files[this.root+S];return T&&!T.dir?T:null},folder:function(S){if(!S)return this;if(E(S))return this.filter(function(T,G){return G.dir&&S.test(T)});var B=this.root+S,U=j.call(this,B),$=this.clone();return $.root=U.name,$},remove:function(S){S=this.root+S;var B=this.files[S];if(B||(S.slice(-1)!=="/"&&(S+="/"),B=this.files[S]),B&&!B.dir)delete this.files[S];else for(var U=this.filter(function(T,G){return G.name.slice(0,S.length)===S}),$=0;$<U.length;$++)delete this.files[U[$].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(S){var B,U={};try{if((U=l.extend(S||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:o.utf8encode})).type=U.type.toLowerCase(),U.compression=U.compression.toUpperCase(),U.type==="binarystring"&&(U.type="string"),!U.type)throw new Error("No output type specified.");l.checkSupport(U.type),U.platform!=="darwin"&&U.platform!=="freebsd"&&U.platform!=="linux"&&U.platform!=="sunos"||(U.platform="UNIX"),U.platform==="win32"&&(U.platform="DOS");var $=U.comment||this.comment||"";B=d.generateWorker(this,U,$)}catch(T){(B=new h("error")).error(T)}return new p(B,U.type||"string",U.mimeType)},generateAsync:function(S,B){return this.generateInternalStream(S).accumulate(B)},generateNodeStream:function(S,B){return(S=S||{}).type||(S.type="nodebuffer"),this.generateInternalStream(S).toNodejsStream(B)}};a.exports=P},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(s,a,n){a.exports=s("stream")},{stream:void 0}],17:[function(s,a,n){var i=s("./DataReader");function o(l){i.call(this,l);for(var h=0;h<this.data.length;h++)l[h]=255&l[h]}s("../utils").inherits(o,i),o.prototype.byteAt=function(l){return this.data[this.zero+l]},o.prototype.lastIndexOfSignature=function(l){for(var h=l.charCodeAt(0),p=l.charCodeAt(1),_=l.charCodeAt(2),w=l.charCodeAt(3),g=this.length-4;0<=g;--g)if(this.data[g]===h&&this.data[g+1]===p&&this.data[g+2]===_&&this.data[g+3]===w)return g-this.zero;return-1},o.prototype.readAndCheckSignature=function(l){var h=l.charCodeAt(0),p=l.charCodeAt(1),_=l.charCodeAt(2),w=l.charCodeAt(3),g=this.readData(4);return h===g[0]&&p===g[1]&&_===g[2]&&w===g[3]},o.prototype.readData=function(l){if(this.checkOffset(l),l===0)return[];var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./DataReader":18}],18:[function(s,a,n){var i=s("../utils");function o(l){this.data=l,this.length=l.length,this.index=0,this.zero=0}o.prototype={checkOffset:function(l){this.checkIndex(this.index+l)},checkIndex:function(l){if(this.length<this.zero+l||l<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+l+"). Corrupted zip ?")},setIndex:function(l){this.checkIndex(l),this.index=l},skip:function(l){this.setIndex(this.index+l)},byteAt:function(){},readInt:function(l){var h,p=0;for(this.checkOffset(l),h=this.index+l-1;h>=this.index;h--)p=(p<<8)+this.byteAt(h);return this.index+=l,p},readString:function(l){return i.transformTo("string",this.readData(l))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var l=this.readInt(4);return new Date(Date.UTC(1980+(l>>25&127),(l>>21&15)-1,l>>16&31,l>>11&31,l>>5&63,(31&l)<<1))}},a.exports=o},{"../utils":32}],19:[function(s,a,n){var i=s("./Uint8ArrayReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.readData=function(l){this.checkOffset(l);var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(s,a,n){var i=s("./DataReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.byteAt=function(l){return this.data.charCodeAt(this.zero+l)},o.prototype.lastIndexOfSignature=function(l){return this.data.lastIndexOf(l)-this.zero},o.prototype.readAndCheckSignature=function(l){return l===this.readData(4)},o.prototype.readData=function(l){this.checkOffset(l);var h=this.data.slice(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./DataReader":18}],21:[function(s,a,n){var i=s("./ArrayReader");function o(l){i.call(this,l)}s("../utils").inherits(o,i),o.prototype.readData=function(l){if(this.checkOffset(l),l===0)return new Uint8Array(0);var h=this.data.subarray(this.zero+this.index,this.zero+this.index+l);return this.index+=l,h},a.exports=o},{"../utils":32,"./ArrayReader":17}],22:[function(s,a,n){var i=s("../utils"),o=s("../support"),l=s("./ArrayReader"),h=s("./StringReader"),p=s("./NodeBufferReader"),_=s("./Uint8ArrayReader");a.exports=function(w){var g=i.getTypeOf(w);return i.checkSupport(g),g!=="string"||o.uint8array?g==="nodebuffer"?new p(w):o.uint8array?new _(i.transformTo("uint8array",w)):new l(i.transformTo("array",w)):new h(w)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(s,a,n){n.LOCAL_FILE_HEADER="PK",n.CENTRAL_FILE_HEADER="PK",n.CENTRAL_DIRECTORY_END="PK",n.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",n.ZIP64_CENTRAL_DIRECTORY_END="PK",n.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(s,a,n){var i=s("./GenericWorker"),o=s("../utils");function l(h){i.call(this,"ConvertWorker to "+h),this.destType=h}o.inherits(l,i),l.prototype.processChunk=function(h){this.push({data:o.transformTo(this.destType,h.data),meta:h.meta})},a.exports=l},{"../utils":32,"./GenericWorker":28}],25:[function(s,a,n){var i=s("./GenericWorker"),o=s("../crc32");function l(){i.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}s("../utils").inherits(l,i),l.prototype.processChunk=function(h){this.streamInfo.crc32=o(h.data,this.streamInfo.crc32||0),this.push(h)},a.exports=l},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(s,a,n){var i=s("../utils"),o=s("./GenericWorker");function l(h){o.call(this,"DataLengthProbe for "+h),this.propName=h,this.withStreamInfo(h,0)}i.inherits(l,o),l.prototype.processChunk=function(h){if(h){var p=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=p+h.data.length}o.prototype.processChunk.call(this,h)},a.exports=l},{"../utils":32,"./GenericWorker":28}],27:[function(s,a,n){var i=s("../utils"),o=s("./GenericWorker");function l(h){o.call(this,"DataWorker");var p=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,h.then(function(_){p.dataIsReady=!0,p.data=_,p.max=_&&_.length||0,p.type=i.getTypeOf(_),p.isPaused||p._tickAndRepeat()},function(_){p.error(_)})}i.inherits(l,o),l.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this.data=null},l.prototype.resume=function(){return!!o.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,i.delay(this._tickAndRepeat,[],this)),!0)},l.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(i.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},l.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var h=null,p=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":h=this.data.substring(this.index,p);break;case"uint8array":h=this.data.subarray(this.index,p);break;case"array":case"nodebuffer":h=this.data.slice(this.index,p)}return this.index=p,this.push({data:h,meta:{percent:this.max?this.index/this.max*100:0}})},a.exports=l},{"../utils":32,"./GenericWorker":28}],28:[function(s,a,n){function i(o){this.name=o||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}i.prototype={push:function(o){this.emit("data",o)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(o){this.emit("error",o)}return!0},error:function(o){return!this.isFinished&&(this.isPaused?this.generatedError=o:(this.isFinished=!0,this.emit("error",o),this.previous&&this.previous.error(o),this.cleanUp()),!0)},on:function(o,l){return this._listeners[o].push(l),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(o,l){if(this._listeners[o])for(var h=0;h<this._listeners[o].length;h++)this._listeners[o][h].call(this,l)},pipe:function(o){return o.registerPrevious(this)},registerPrevious:function(o){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=o.streamInfo,this.mergeStreamInfo(),this.previous=o;var l=this;return o.on("data",function(h){l.processChunk(h)}),o.on("end",function(){l.end()}),o.on("error",function(h){l.error(h)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var o=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),o=!0),this.previous&&this.previous.resume(),!o},flush:function(){},processChunk:function(o){this.push(o)},withStreamInfo:function(o,l){return this.extraStreamInfo[o]=l,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var o in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,o)&&(this.streamInfo[o]=this.extraStreamInfo[o])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var o="Worker "+this.name;return this.previous?this.previous+" -> "+o:o}},a.exports=i},{}],29:[function(s,a,n){var i=s("../utils"),o=s("./ConvertWorker"),l=s("./GenericWorker"),h=s("../base64"),p=s("../support"),_=s("../external"),w=null;if(p.nodestream)try{w=s("../nodejs/NodejsStreamOutputAdapter")}catch{}function g(k,u){return new _.Promise(function(x,f){var j=[],E=k._internalType,P=k._outputType,S=k._mimeType;k.on("data",function(B,U){j.push(B),u&&u(U)}).on("error",function(B){j=[],f(B)}).on("end",function(){try{var B=(function(U,$,T){switch(U){case"blob":return i.newBlob(i.transformTo("arraybuffer",$),T);case"base64":return h.encode($);default:return i.transformTo(U,$)}})(P,(function(U,$){var T,G=0,se=null,v=0;for(T=0;T<$.length;T++)v+=$[T].length;switch(U){case"string":return $.join("");case"array":return Array.prototype.concat.apply([],$);case"uint8array":for(se=new Uint8Array(v),T=0;T<$.length;T++)se.set($[T],G),G+=$[T].length;return se;case"nodebuffer":return Buffer.concat($);default:throw new Error("concat : unsupported type '"+U+"'")}})(E,j),S);x(B)}catch(U){f(U)}j=[]}).resume()})}function d(k,u,x){var f=u;switch(u){case"blob":case"arraybuffer":f="uint8array";break;case"base64":f="string"}try{this._internalType=f,this._outputType=u,this._mimeType=x,i.checkSupport(f),this._worker=k.pipe(new o(f)),k.lock()}catch(j){this._worker=new l("error"),this._worker.error(j)}}d.prototype={accumulate:function(k){return g(this,k)},on:function(k,u){var x=this;return k==="data"?this._worker.on(k,function(f){u.call(x,f.data,f.meta)}):this._worker.on(k,function(){i.delay(u,arguments,x)}),this},resume:function(){return i.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(k){if(i.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new w(this,{objectMode:this._outputType!=="nodebuffer"},k)}},a.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(s,a,n){if(n.base64=!0,n.array=!0,n.string=!0,n.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",n.nodebuffer=typeof Buffer<"u",n.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")n.blob=!1;else{var i=new ArrayBuffer(0);try{n.blob=new Blob([i],{type:"application/zip"}).size===0}catch{try{var o=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);o.append(i),n.blob=o.getBlob("application/zip").size===0}catch{n.blob=!1}}}try{n.nodestream=!!s("readable-stream").Readable}catch{n.nodestream=!1}},{"readable-stream":16}],31:[function(s,a,n){for(var i=s("./utils"),o=s("./support"),l=s("./nodejsUtils"),h=s("./stream/GenericWorker"),p=new Array(256),_=0;_<256;_++)p[_]=252<=_?6:248<=_?5:240<=_?4:224<=_?3:192<=_?2:1;p[254]=p[254]=1;function w(){h.call(this,"utf-8 decode"),this.leftOver=null}function g(){h.call(this,"utf-8 encode")}n.utf8encode=function(d){return o.nodebuffer?l.newBufferFrom(d,"utf-8"):(function(k){var u,x,f,j,E,P=k.length,S=0;for(j=0;j<P;j++)(64512&(x=k.charCodeAt(j)))==55296&&j+1<P&&(64512&(f=k.charCodeAt(j+1)))==56320&&(x=65536+(x-55296<<10)+(f-56320),j++),S+=x<128?1:x<2048?2:x<65536?3:4;for(u=o.uint8array?new Uint8Array(S):new Array(S),j=E=0;E<S;j++)(64512&(x=k.charCodeAt(j)))==55296&&j+1<P&&(64512&(f=k.charCodeAt(j+1)))==56320&&(x=65536+(x-55296<<10)+(f-56320),j++),x<128?u[E++]=x:(x<2048?u[E++]=192|x>>>6:(x<65536?u[E++]=224|x>>>12:(u[E++]=240|x>>>18,u[E++]=128|x>>>12&63),u[E++]=128|x>>>6&63),u[E++]=128|63&x);return u})(d)},n.utf8decode=function(d){return o.nodebuffer?i.transformTo("nodebuffer",d).toString("utf-8"):(function(k){var u,x,f,j,E=k.length,P=new Array(2*E);for(u=x=0;u<E;)if((f=k[u++])<128)P[x++]=f;else if(4<(j=p[f]))P[x++]=65533,u+=j-1;else{for(f&=j===2?31:j===3?15:7;1<j&&u<E;)f=f<<6|63&k[u++],j--;1<j?P[x++]=65533:f<65536?P[x++]=f:(f-=65536,P[x++]=55296|f>>10&1023,P[x++]=56320|1023&f)}return P.length!==x&&(P.subarray?P=P.subarray(0,x):P.length=x),i.applyFromCharCode(P)})(d=i.transformTo(o.uint8array?"uint8array":"array",d))},i.inherits(w,h),w.prototype.processChunk=function(d){var k=i.transformTo(o.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(o.uint8array){var u=k;(k=new Uint8Array(u.length+this.leftOver.length)).set(this.leftOver,0),k.set(u,this.leftOver.length)}else k=this.leftOver.concat(k);this.leftOver=null}var x=(function(j,E){var P;for((E=E||j.length)>j.length&&(E=j.length),P=E-1;0<=P&&(192&j[P])==128;)P--;return P<0||P===0?E:P+p[j[P]]>E?P:E})(k),f=k;x!==k.length&&(o.uint8array?(f=k.subarray(0,x),this.leftOver=k.subarray(x,k.length)):(f=k.slice(0,x),this.leftOver=k.slice(x,k.length))),this.push({data:n.utf8decode(f),meta:d.meta})},w.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:n.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},n.Utf8DecodeWorker=w,i.inherits(g,h),g.prototype.processChunk=function(d){this.push({data:n.utf8encode(d.data),meta:d.meta})},n.Utf8EncodeWorker=g},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(s,a,n){var i=s("./support"),o=s("./base64"),l=s("./nodejsUtils"),h=s("./external");function p(u){return u}function _(u,x){for(var f=0;f<u.length;++f)x[f]=255&u.charCodeAt(f);return x}s("setimmediate"),n.newBlob=function(u,x){n.checkSupport("blob");try{return new Blob([u],{type:x})}catch{try{var f=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return f.append(u),f.getBlob(x)}catch{throw new Error("Bug : can't construct the Blob.")}}};var w={stringifyByChunk:function(u,x,f){var j=[],E=0,P=u.length;if(P<=f)return String.fromCharCode.apply(null,u);for(;E<P;)x==="array"||x==="nodebuffer"?j.push(String.fromCharCode.apply(null,u.slice(E,Math.min(E+f,P)))):j.push(String.fromCharCode.apply(null,u.subarray(E,Math.min(E+f,P)))),E+=f;return j.join("")},stringifyByChar:function(u){for(var x="",f=0;f<u.length;f++)x+=String.fromCharCode(u[f]);return x},applyCanBeUsed:{uint8array:(function(){try{return i.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return i.nodebuffer&&String.fromCharCode.apply(null,l.allocBuffer(1)).length===1}catch{return!1}})()}};function g(u){var x=65536,f=n.getTypeOf(u),j=!0;if(f==="uint8array"?j=w.applyCanBeUsed.uint8array:f==="nodebuffer"&&(j=w.applyCanBeUsed.nodebuffer),j)for(;1<x;)try{return w.stringifyByChunk(u,f,x)}catch{x=Math.floor(x/2)}return w.stringifyByChar(u)}function d(u,x){for(var f=0;f<u.length;f++)x[f]=u[f];return x}n.applyFromCharCode=g;var k={};k.string={string:p,array:function(u){return _(u,new Array(u.length))},arraybuffer:function(u){return k.string.uint8array(u).buffer},uint8array:function(u){return _(u,new Uint8Array(u.length))},nodebuffer:function(u){return _(u,l.allocBuffer(u.length))}},k.array={string:g,array:p,arraybuffer:function(u){return new Uint8Array(u).buffer},uint8array:function(u){return new Uint8Array(u)},nodebuffer:function(u){return l.newBufferFrom(u)}},k.arraybuffer={string:function(u){return g(new Uint8Array(u))},array:function(u){return d(new Uint8Array(u),new Array(u.byteLength))},arraybuffer:p,uint8array:function(u){return new Uint8Array(u)},nodebuffer:function(u){return l.newBufferFrom(new Uint8Array(u))}},k.uint8array={string:g,array:function(u){return d(u,new Array(u.length))},arraybuffer:function(u){return u.buffer},uint8array:p,nodebuffer:function(u){return l.newBufferFrom(u)}},k.nodebuffer={string:g,array:function(u){return d(u,new Array(u.length))},arraybuffer:function(u){return k.nodebuffer.uint8array(u).buffer},uint8array:function(u){return d(u,new Uint8Array(u.length))},nodebuffer:p},n.transformTo=function(u,x){if(x=x||"",!u)return x;n.checkSupport(u);var f=n.getTypeOf(x);return k[f][u](x)},n.resolve=function(u){for(var x=u.split("/"),f=[],j=0;j<x.length;j++){var E=x[j];E==="."||E===""&&j!==0&&j!==x.length-1||(E===".."?f.pop():f.push(E))}return f.join("/")},n.getTypeOf=function(u){return typeof u=="string"?"string":Object.prototype.toString.call(u)==="[object Array]"?"array":i.nodebuffer&&l.isBuffer(u)?"nodebuffer":i.uint8array&&u instanceof Uint8Array?"uint8array":i.arraybuffer&&u instanceof ArrayBuffer?"arraybuffer":void 0},n.checkSupport=function(u){if(!i[u.toLowerCase()])throw new Error(u+" is not supported by this platform")},n.MAX_VALUE_16BITS=65535,n.MAX_VALUE_32BITS=-1,n.pretty=function(u){var x,f,j="";for(f=0;f<(u||"").length;f++)j+="\\x"+((x=u.charCodeAt(f))<16?"0":"")+x.toString(16).toUpperCase();return j},n.delay=function(u,x,f){setImmediate(function(){u.apply(f||null,x||[])})},n.inherits=function(u,x){function f(){}f.prototype=x.prototype,u.prototype=new f},n.extend=function(){var u,x,f={};for(u=0;u<arguments.length;u++)for(x in arguments[u])Object.prototype.hasOwnProperty.call(arguments[u],x)&&f[x]===void 0&&(f[x]=arguments[u][x]);return f},n.prepareContent=function(u,x,f,j,E){return h.Promise.resolve(x).then(function(P){return i.blob&&(P instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(P))!==-1)&&typeof FileReader<"u"?new h.Promise(function(S,B){var U=new FileReader;U.onload=function($){S($.target.result)},U.onerror=function($){B($.target.error)},U.readAsArrayBuffer(P)}):P}).then(function(P){var S=n.getTypeOf(P);return S?(S==="arraybuffer"?P=n.transformTo("uint8array",P):S==="string"&&(E?P=o.decode(P):f&&j!==!0&&(P=(function(B){return _(B,i.uint8array?new Uint8Array(B.length):new Array(B.length))})(P))),P):h.Promise.reject(new Error("Can't read the data of '"+u+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(s,a,n){var i=s("./reader/readerFor"),o=s("./utils"),l=s("./signature"),h=s("./zipEntry"),p=s("./support");function _(w){this.files=[],this.loadOptions=w}_.prototype={checkSignature:function(w){if(!this.reader.readAndCheckSignature(w)){this.reader.index-=4;var g=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+o.pretty(g)+", expected "+o.pretty(w)+")")}},isSignature:function(w,g){var d=this.reader.index;this.reader.setIndex(w);var k=this.reader.readString(4)===g;return this.reader.setIndex(d),k},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var w=this.reader.readData(this.zipCommentLength),g=p.uint8array?"uint8array":"array",d=o.transformTo(g,w);this.zipComment=this.loadOptions.decodeFileName(d)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var w,g,d,k=this.zip64EndOfCentralSize-44;0<k;)w=this.reader.readInt(2),g=this.reader.readInt(4),d=this.reader.readData(g),this.zip64ExtensibleData[w]={id:w,length:g,value:d}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var w,g;for(w=0;w<this.files.length;w++)g=this.files[w],this.reader.setIndex(g.localHeaderOffset),this.checkSignature(l.LOCAL_FILE_HEADER),g.readLocalPart(this.reader),g.handleUTF8(),g.processAttributes()},readCentralDir:function(){var w;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(l.CENTRAL_FILE_HEADER);)(w=new h({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(w);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var w=this.reader.lastIndexOfSignature(l.CENTRAL_DIRECTORY_END);if(w<0)throw this.isSignature(0,l.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(w);var g=w;if(this.checkSignature(l.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===o.MAX_VALUE_16BITS||this.diskWithCentralDirStart===o.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===o.MAX_VALUE_16BITS||this.centralDirRecords===o.MAX_VALUE_16BITS||this.centralDirSize===o.MAX_VALUE_32BITS||this.centralDirOffset===o.MAX_VALUE_32BITS){if(this.zip64=!0,(w=this.reader.lastIndexOfSignature(l.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(w),this.checkSignature(l.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,l.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(l.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(l.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var k=g-d;if(0<k)this.isSignature(g,l.CENTRAL_FILE_HEADER)||(this.reader.zero=k);else if(k<0)throw new Error("Corrupted zip: missing "+Math.abs(k)+" bytes.")},prepareReader:function(w){this.reader=i(w)},load:function(w){this.prepareReader(w),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},a.exports=_},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(s,a,n){var i=s("./reader/readerFor"),o=s("./utils"),l=s("./compressedObject"),h=s("./crc32"),p=s("./utf8"),_=s("./compressions"),w=s("./support");function g(d,k){this.options=d,this.loadOptions=k}g.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var k,u;if(d.skip(22),this.fileNameLength=d.readInt(2),u=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(u),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((k=(function(x){for(var f in _)if(Object.prototype.hasOwnProperty.call(_,f)&&_[f].magic===x)return _[f];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+o.pretty(this.compressionMethod)+" unknown (inner file : "+o.transformTo("string",this.fileName)+")");this.decompressed=new l(this.compressedSize,this.uncompressedSize,this.crc32,k,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var k=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(k),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=i(this.extraFields[1].value);this.uncompressedSize===o.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===o.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===o.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===o.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var k,u,x,f=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<f;)k=d.readInt(2),u=d.readInt(2),x=d.readData(u),this.extraFields[k]={id:k,length:u,value:x};d.setIndex(f)},handleUTF8:function(){var d=w.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=p.utf8decode(this.fileName),this.fileCommentStr=p.utf8decode(this.fileComment);else{var k=this.findExtraFieldUnicodePath();if(k!==null)this.fileNameStr=k;else{var u=o.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(u)}var x=this.findExtraFieldUnicodeComment();if(x!==null)this.fileCommentStr=x;else{var f=o.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(f)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var k=i(d.value);return k.readInt(1)!==1||h(this.fileName)!==k.readInt(4)?null:p.utf8decode(k.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var k=i(d.value);return k.readInt(1)!==1||h(this.fileComment)!==k.readInt(4)?null:p.utf8decode(k.readData(d.length-5))}return null}},a.exports=g},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(s,a,n){function i(k,u,x){this.name=k,this.dir=x.dir,this.date=x.date,this.comment=x.comment,this.unixPermissions=x.unixPermissions,this.dosPermissions=x.dosPermissions,this._data=u,this._dataBinary=x.binary,this.options={compression:x.compression,compressionOptions:x.compressionOptions}}var o=s("./stream/StreamHelper"),l=s("./stream/DataWorker"),h=s("./utf8"),p=s("./compressedObject"),_=s("./stream/GenericWorker");i.prototype={internalStream:function(k){var u=null,x="string";try{if(!k)throw new Error("No output type specified.");var f=(x=k.toLowerCase())==="string"||x==="text";x!=="binarystring"&&x!=="text"||(x="string"),u=this._decompressWorker();var j=!this._dataBinary;j&&!f&&(u=u.pipe(new h.Utf8EncodeWorker)),!j&&f&&(u=u.pipe(new h.Utf8DecodeWorker))}catch(E){(u=new _("error")).error(E)}return new o(u,x,"")},async:function(k,u){return this.internalStream(k).accumulate(u)},nodeStream:function(k,u){return this.internalStream(k||"nodebuffer").toNodejsStream(u)},_compressWorker:function(k,u){if(this._data instanceof p&&this._data.compression.magic===k.magic)return this._data.getCompressedWorker();var x=this._decompressWorker();return this._dataBinary||(x=x.pipe(new h.Utf8EncodeWorker)),p.createWorkerFrom(x,k,u)},_decompressWorker:function(){return this._data instanceof p?this._data.getContentWorker():this._data instanceof _?this._data:new l(this._data)}};for(var w=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],g=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<w.length;d++)i.prototype[w[d]]=g;a.exports=i},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(s,a,n){(function(i){var o,l,h=i.MutationObserver||i.WebKitMutationObserver;if(h){var p=0,_=new h(k),w=i.document.createTextNode("");_.observe(w,{characterData:!0}),o=function(){w.data=p=++p%2}}else if(i.setImmediate||i.MessageChannel===void 0)o="document"in i&&"onreadystatechange"in i.document.createElement("script")?function(){var u=i.document.createElement("script");u.onreadystatechange=function(){k(),u.onreadystatechange=null,u.parentNode.removeChild(u),u=null},i.document.documentElement.appendChild(u)}:function(){setTimeout(k,0)};else{var g=new i.MessageChannel;g.port1.onmessage=k,o=function(){g.port2.postMessage(0)}}var d=[];function k(){var u,x;l=!0;for(var f=d.length;f;){for(x=d,d=[],u=-1;++u<f;)x[u]();f=d.length}l=!1}a.exports=function(u){d.push(u)!==1||l||o()}}).call(this,typeof Rr<"u"?Rr:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(s,a,n){var i=s("immediate");function o(){}var l={},h=["REJECTED"],p=["FULFILLED"],_=["PENDING"];function w(f){if(typeof f!="function")throw new TypeError("resolver must be a function");this.state=_,this.queue=[],this.outcome=void 0,f!==o&&u(this,f)}function g(f,j,E){this.promise=f,typeof j=="function"&&(this.onFulfilled=j,this.callFulfilled=this.otherCallFulfilled),typeof E=="function"&&(this.onRejected=E,this.callRejected=this.otherCallRejected)}function d(f,j,E){i(function(){var P;try{P=j(E)}catch(S){return l.reject(f,S)}P===f?l.reject(f,new TypeError("Cannot resolve promise with itself")):l.resolve(f,P)})}function k(f){var j=f&&f.then;if(f&&(typeof f=="object"||typeof f=="function")&&typeof j=="function")return function(){j.apply(f,arguments)}}function u(f,j){var E=!1;function P(U){E||(E=!0,l.reject(f,U))}function S(U){E||(E=!0,l.resolve(f,U))}var B=x(function(){j(S,P)});B.status==="error"&&P(B.value)}function x(f,j){var E={};try{E.value=f(j),E.status="success"}catch(P){E.status="error",E.value=P}return E}(a.exports=w).prototype.finally=function(f){if(typeof f!="function")return this;var j=this.constructor;return this.then(function(E){return j.resolve(f()).then(function(){return E})},function(E){return j.resolve(f()).then(function(){throw E})})},w.prototype.catch=function(f){return this.then(null,f)},w.prototype.then=function(f,j){if(typeof f!="function"&&this.state===p||typeof j!="function"&&this.state===h)return this;var E=new this.constructor(o);return this.state!==_?d(E,this.state===p?f:j,this.outcome):this.queue.push(new g(E,f,j)),E},g.prototype.callFulfilled=function(f){l.resolve(this.promise,f)},g.prototype.otherCallFulfilled=function(f){d(this.promise,this.onFulfilled,f)},g.prototype.callRejected=function(f){l.reject(this.promise,f)},g.prototype.otherCallRejected=function(f){d(this.promise,this.onRejected,f)},l.resolve=function(f,j){var E=x(k,j);if(E.status==="error")return l.reject(f,E.value);var P=E.value;if(P)u(f,P);else{f.state=p,f.outcome=j;for(var S=-1,B=f.queue.length;++S<B;)f.queue[S].callFulfilled(j)}return f},l.reject=function(f,j){f.state=h,f.outcome=j;for(var E=-1,P=f.queue.length;++E<P;)f.queue[E].callRejected(j);return f},w.resolve=function(f){return f instanceof this?f:l.resolve(new this(o),f)},w.reject=function(f){var j=new this(o);return l.reject(j,f)},w.all=function(f){var j=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var E=f.length,P=!1;if(!E)return this.resolve([]);for(var S=new Array(E),B=0,U=-1,$=new this(o);++U<E;)T(f[U],U);return $;function T(G,se){j.resolve(G).then(function(v){S[se]=v,++B!==E||P||(P=!0,l.resolve($,S))},function(v){P||(P=!0,l.reject($,v))})}},w.race=function(f){var j=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var E=f.length,P=!1;if(!E)return this.resolve([]);for(var S=-1,B=new this(o);++S<E;)U=f[S],j.resolve(U).then(function($){P||(P=!0,l.resolve(B,$))},function($){P||(P=!0,l.reject(B,$))});var U;return B}},{immediate:36}],38:[function(s,a,n){var i={};(0,s("./lib/utils/common").assign)(i,s("./lib/deflate"),s("./lib/inflate"),s("./lib/zlib/constants")),a.exports=i},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(s,a,n){var i=s("./zlib/deflate"),o=s("./utils/common"),l=s("./utils/strings"),h=s("./zlib/messages"),p=s("./zlib/zstream"),_=Object.prototype.toString,w=0,g=-1,d=0,k=8;function u(f){if(!(this instanceof u))return new u(f);this.options=o.assign({level:g,method:k,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},f||{});var j=this.options;j.raw&&0<j.windowBits?j.windowBits=-j.windowBits:j.gzip&&0<j.windowBits&&j.windowBits<16&&(j.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new p,this.strm.avail_out=0;var E=i.deflateInit2(this.strm,j.level,j.method,j.windowBits,j.memLevel,j.strategy);if(E!==w)throw new Error(h[E]);if(j.header&&i.deflateSetHeader(this.strm,j.header),j.dictionary){var P;if(P=typeof j.dictionary=="string"?l.string2buf(j.dictionary):_.call(j.dictionary)==="[object ArrayBuffer]"?new Uint8Array(j.dictionary):j.dictionary,(E=i.deflateSetDictionary(this.strm,P))!==w)throw new Error(h[E]);this._dict_set=!0}}function x(f,j){var E=new u(j);if(E.push(f,!0),E.err)throw E.msg||h[E.err];return E.result}u.prototype.push=function(f,j){var E,P,S=this.strm,B=this.options.chunkSize;if(this.ended)return!1;P=j===~~j?j:j===!0?4:0,typeof f=="string"?S.input=l.string2buf(f):_.call(f)==="[object ArrayBuffer]"?S.input=new Uint8Array(f):S.input=f,S.next_in=0,S.avail_in=S.input.length;do{if(S.avail_out===0&&(S.output=new o.Buf8(B),S.next_out=0,S.avail_out=B),(E=i.deflate(S,P))!==1&&E!==w)return this.onEnd(E),!(this.ended=!0);S.avail_out!==0&&(S.avail_in!==0||P!==4&&P!==2)||(this.options.to==="string"?this.onData(l.buf2binstring(o.shrinkBuf(S.output,S.next_out))):this.onData(o.shrinkBuf(S.output,S.next_out)))}while((0<S.avail_in||S.avail_out===0)&&E!==1);return P===4?(E=i.deflateEnd(this.strm),this.onEnd(E),this.ended=!0,E===w):P!==2||(this.onEnd(w),!(S.avail_out=0))},u.prototype.onData=function(f){this.chunks.push(f)},u.prototype.onEnd=function(f){f===w&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=f,this.msg=this.strm.msg},n.Deflate=u,n.deflate=x,n.deflateRaw=function(f,j){return(j=j||{}).raw=!0,x(f,j)},n.gzip=function(f,j){return(j=j||{}).gzip=!0,x(f,j)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(s,a,n){var i=s("./zlib/inflate"),o=s("./utils/common"),l=s("./utils/strings"),h=s("./zlib/constants"),p=s("./zlib/messages"),_=s("./zlib/zstream"),w=s("./zlib/gzheader"),g=Object.prototype.toString;function d(u){if(!(this instanceof d))return new d(u);this.options=o.assign({chunkSize:16384,windowBits:0,to:""},u||{});var x=this.options;x.raw&&0<=x.windowBits&&x.windowBits<16&&(x.windowBits=-x.windowBits,x.windowBits===0&&(x.windowBits=-15)),!(0<=x.windowBits&&x.windowBits<16)||u&&u.windowBits||(x.windowBits+=32),15<x.windowBits&&x.windowBits<48&&(15&x.windowBits)==0&&(x.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new _,this.strm.avail_out=0;var f=i.inflateInit2(this.strm,x.windowBits);if(f!==h.Z_OK)throw new Error(p[f]);this.header=new w,i.inflateGetHeader(this.strm,this.header)}function k(u,x){var f=new d(x);if(f.push(u,!0),f.err)throw f.msg||p[f.err];return f.result}d.prototype.push=function(u,x){var f,j,E,P,S,B,U=this.strm,$=this.options.chunkSize,T=this.options.dictionary,G=!1;if(this.ended)return!1;j=x===~~x?x:x===!0?h.Z_FINISH:h.Z_NO_FLUSH,typeof u=="string"?U.input=l.binstring2buf(u):g.call(u)==="[object ArrayBuffer]"?U.input=new Uint8Array(u):U.input=u,U.next_in=0,U.avail_in=U.input.length;do{if(U.avail_out===0&&(U.output=new o.Buf8($),U.next_out=0,U.avail_out=$),(f=i.inflate(U,h.Z_NO_FLUSH))===h.Z_NEED_DICT&&T&&(B=typeof T=="string"?l.string2buf(T):g.call(T)==="[object ArrayBuffer]"?new Uint8Array(T):T,f=i.inflateSetDictionary(this.strm,B)),f===h.Z_BUF_ERROR&&G===!0&&(f=h.Z_OK,G=!1),f!==h.Z_STREAM_END&&f!==h.Z_OK)return this.onEnd(f),!(this.ended=!0);U.next_out&&(U.avail_out!==0&&f!==h.Z_STREAM_END&&(U.avail_in!==0||j!==h.Z_FINISH&&j!==h.Z_SYNC_FLUSH)||(this.options.to==="string"?(E=l.utf8border(U.output,U.next_out),P=U.next_out-E,S=l.buf2string(U.output,E),U.next_out=P,U.avail_out=$-P,P&&o.arraySet(U.output,U.output,E,P,0),this.onData(S)):this.onData(o.shrinkBuf(U.output,U.next_out)))),U.avail_in===0&&U.avail_out===0&&(G=!0)}while((0<U.avail_in||U.avail_out===0)&&f!==h.Z_STREAM_END);return f===h.Z_STREAM_END&&(j=h.Z_FINISH),j===h.Z_FINISH?(f=i.inflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===h.Z_OK):j!==h.Z_SYNC_FLUSH||(this.onEnd(h.Z_OK),!(U.avail_out=0))},d.prototype.onData=function(u){this.chunks.push(u)},d.prototype.onEnd=function(u){u===h.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=u,this.msg=this.strm.msg},n.Inflate=d,n.inflate=k,n.inflateRaw=function(u,x){return(x=x||{}).raw=!0,k(u,x)},n.ungzip=k},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(s,a,n){var i=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";n.assign=function(h){for(var p=Array.prototype.slice.call(arguments,1);p.length;){var _=p.shift();if(_){if(typeof _!="object")throw new TypeError(_+"must be non-object");for(var w in _)_.hasOwnProperty(w)&&(h[w]=_[w])}}return h},n.shrinkBuf=function(h,p){return h.length===p?h:h.subarray?h.subarray(0,p):(h.length=p,h)};var o={arraySet:function(h,p,_,w,g){if(p.subarray&&h.subarray)h.set(p.subarray(_,_+w),g);else for(var d=0;d<w;d++)h[g+d]=p[_+d]},flattenChunks:function(h){var p,_,w,g,d,k;for(p=w=0,_=h.length;p<_;p++)w+=h[p].length;for(k=new Uint8Array(w),p=g=0,_=h.length;p<_;p++)d=h[p],k.set(d,g),g+=d.length;return k}},l={arraySet:function(h,p,_,w,g){for(var d=0;d<w;d++)h[g+d]=p[_+d]},flattenChunks:function(h){return[].concat.apply([],h)}};n.setTyped=function(h){h?(n.Buf8=Uint8Array,n.Buf16=Uint16Array,n.Buf32=Int32Array,n.assign(n,o)):(n.Buf8=Array,n.Buf16=Array,n.Buf32=Array,n.assign(n,l))},n.setTyped(i)},{}],42:[function(s,a,n){var i=s("./common"),o=!0,l=!0;try{String.fromCharCode.apply(null,[0])}catch{o=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{l=!1}for(var h=new i.Buf8(256),p=0;p<256;p++)h[p]=252<=p?6:248<=p?5:240<=p?4:224<=p?3:192<=p?2:1;function _(w,g){if(g<65537&&(w.subarray&&l||!w.subarray&&o))return String.fromCharCode.apply(null,i.shrinkBuf(w,g));for(var d="",k=0;k<g;k++)d+=String.fromCharCode(w[k]);return d}h[254]=h[254]=1,n.string2buf=function(w){var g,d,k,u,x,f=w.length,j=0;for(u=0;u<f;u++)(64512&(d=w.charCodeAt(u)))==55296&&u+1<f&&(64512&(k=w.charCodeAt(u+1)))==56320&&(d=65536+(d-55296<<10)+(k-56320),u++),j+=d<128?1:d<2048?2:d<65536?3:4;for(g=new i.Buf8(j),u=x=0;x<j;u++)(64512&(d=w.charCodeAt(u)))==55296&&u+1<f&&(64512&(k=w.charCodeAt(u+1)))==56320&&(d=65536+(d-55296<<10)+(k-56320),u++),d<128?g[x++]=d:(d<2048?g[x++]=192|d>>>6:(d<65536?g[x++]=224|d>>>12:(g[x++]=240|d>>>18,g[x++]=128|d>>>12&63),g[x++]=128|d>>>6&63),g[x++]=128|63&d);return g},n.buf2binstring=function(w){return _(w,w.length)},n.binstring2buf=function(w){for(var g=new i.Buf8(w.length),d=0,k=g.length;d<k;d++)g[d]=w.charCodeAt(d);return g},n.buf2string=function(w,g){var d,k,u,x,f=g||w.length,j=new Array(2*f);for(d=k=0;d<f;)if((u=w[d++])<128)j[k++]=u;else if(4<(x=h[u]))j[k++]=65533,d+=x-1;else{for(u&=x===2?31:x===3?15:7;1<x&&d<f;)u=u<<6|63&w[d++],x--;1<x?j[k++]=65533:u<65536?j[k++]=u:(u-=65536,j[k++]=55296|u>>10&1023,j[k++]=56320|1023&u)}return _(j,k)},n.utf8border=function(w,g){var d;for((g=g||w.length)>w.length&&(g=w.length),d=g-1;0<=d&&(192&w[d])==128;)d--;return d<0||d===0?g:d+h[w[d]]>g?d:g}},{"./common":41}],43:[function(s,a,n){a.exports=function(i,o,l,h){for(var p=65535&i|0,_=i>>>16&65535|0,w=0;l!==0;){for(l-=w=2e3<l?2e3:l;_=_+(p=p+o[h++]|0)|0,--w;);p%=65521,_%=65521}return p|_<<16|0}},{}],44:[function(s,a,n){a.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(s,a,n){var i=(function(){for(var o,l=[],h=0;h<256;h++){o=h;for(var p=0;p<8;p++)o=1&o?3988292384^o>>>1:o>>>1;l[h]=o}return l})();a.exports=function(o,l,h,p){var _=i,w=p+h;o^=-1;for(var g=p;g<w;g++)o=o>>>8^_[255&(o^l[g])];return-1^o}},{}],46:[function(s,a,n){var i,o=s("../utils/common"),l=s("./trees"),h=s("./adler32"),p=s("./crc32"),_=s("./messages"),w=0,g=4,d=0,k=-2,u=-1,x=4,f=2,j=8,E=9,P=286,S=30,B=19,U=2*P+1,$=15,T=3,G=258,se=G+T+1,v=42,R=113,m=1,V=2,ie=3,q=4;function ce(c,K){return c.msg=_[K],K}function F(c){return(c<<1)-(4<c?9:0)}function ee(c){for(var K=c.length;0<=--K;)c[K]=0}function O(c){var K=c.state,M=K.pending;M>c.avail_out&&(M=c.avail_out),M!==0&&(o.arraySet(c.output,K.pending_buf,K.pending_out,M,c.next_out),c.next_out+=M,K.pending_out+=M,c.total_out+=M,c.avail_out-=M,K.pending-=M,K.pending===0&&(K.pending_out=0))}function L(c,K){l._tr_flush_block(c,0<=c.block_start?c.block_start:-1,c.strstart-c.block_start,K),c.block_start=c.strstart,O(c.strm)}function ae(c,K){c.pending_buf[c.pending++]=K}function te(c,K){c.pending_buf[c.pending++]=K>>>8&255,c.pending_buf[c.pending++]=255&K}function J(c,K){var M,C,N=c.max_chain_length,D=c.strstart,X=c.prev_length,y=c.nice_match,b=c.strstart>c.w_size-se?c.strstart-(c.w_size-se):0,A=c.window,I=c.w_mask,z=c.prev,Z=c.strstart+G,H=A[D+X-1],re=A[D+X];c.prev_length>=c.good_match&&(N>>=2),y>c.lookahead&&(y=c.lookahead);do if(A[(M=K)+X]===re&&A[M+X-1]===H&&A[M]===A[D]&&A[++M]===A[D+1]){D+=2,M++;do;while(A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&A[++D]===A[++M]&&D<Z);if(C=G-(Z-D),D=Z-G,X<C){if(c.match_start=K,y<=(X=C))break;H=A[D+X-1],re=A[D+X]}}while((K=z[K&I])>b&&--N!=0);return X<=c.lookahead?X:c.lookahead}function ve(c){var K,M,C,N,D,X,y,b,A,I,z=c.w_size;do{if(N=c.window_size-c.lookahead-c.strstart,c.strstart>=z+(z-se)){for(o.arraySet(c.window,c.window,z,z,0),c.match_start-=z,c.strstart-=z,c.block_start-=z,K=M=c.hash_size;C=c.head[--K],c.head[K]=z<=C?C-z:0,--M;);for(K=M=z;C=c.prev[--K],c.prev[K]=z<=C?C-z:0,--M;);N+=z}if(c.strm.avail_in===0)break;if(X=c.strm,y=c.window,b=c.strstart+c.lookahead,A=N,I=void 0,I=X.avail_in,A<I&&(I=A),M=I===0?0:(X.avail_in-=I,o.arraySet(y,X.input,X.next_in,I,b),X.state.wrap===1?X.adler=h(X.adler,y,I,b):X.state.wrap===2&&(X.adler=p(X.adler,y,I,b)),X.next_in+=I,X.total_in+=I,I),c.lookahead+=M,c.lookahead+c.insert>=T)for(D=c.strstart-c.insert,c.ins_h=c.window[D],c.ins_h=(c.ins_h<<c.hash_shift^c.window[D+1])&c.hash_mask;c.insert&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[D+T-1])&c.hash_mask,c.prev[D&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=D,D++,c.insert--,!(c.lookahead+c.insert<T)););}while(c.lookahead<se&&c.strm.avail_in!==0)}function Se(c,K){for(var M,C;;){if(c.lookahead<se){if(ve(c),c.lookahead<se&&K===w)return m;if(c.lookahead===0)break}if(M=0,c.lookahead>=T&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),M!==0&&c.strstart-M<=c.w_size-se&&(c.match_length=J(c,M)),c.match_length>=T)if(C=l._tr_tally(c,c.strstart-c.match_start,c.match_length-T),c.lookahead-=c.match_length,c.match_length<=c.max_lazy_match&&c.lookahead>=T){for(c.match_length--;c.strstart++,c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart,--c.match_length!=0;);c.strstart++}else c.strstart+=c.match_length,c.match_length=0,c.ins_h=c.window[c.strstart],c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+1])&c.hash_mask;else C=l._tr_tally(c,0,c.window[c.strstart]),c.lookahead--,c.strstart++;if(C&&(L(c,!1),c.strm.avail_out===0))return m}return c.insert=c.strstart<T-1?c.strstart:T-1,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):c.last_lit&&(L(c,!1),c.strm.avail_out===0)?m:V}function fe(c,K){for(var M,C,N;;){if(c.lookahead<se){if(ve(c),c.lookahead<se&&K===w)return m;if(c.lookahead===0)break}if(M=0,c.lookahead>=T&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),c.prev_length=c.match_length,c.prev_match=c.match_start,c.match_length=T-1,M!==0&&c.prev_length<c.max_lazy_match&&c.strstart-M<=c.w_size-se&&(c.match_length=J(c,M),c.match_length<=5&&(c.strategy===1||c.match_length===T&&4096<c.strstart-c.match_start)&&(c.match_length=T-1)),c.prev_length>=T&&c.match_length<=c.prev_length){for(N=c.strstart+c.lookahead-T,C=l._tr_tally(c,c.strstart-1-c.prev_match,c.prev_length-T),c.lookahead-=c.prev_length-1,c.prev_length-=2;++c.strstart<=N&&(c.ins_h=(c.ins_h<<c.hash_shift^c.window[c.strstart+T-1])&c.hash_mask,M=c.prev[c.strstart&c.w_mask]=c.head[c.ins_h],c.head[c.ins_h]=c.strstart),--c.prev_length!=0;);if(c.match_available=0,c.match_length=T-1,c.strstart++,C&&(L(c,!1),c.strm.avail_out===0))return m}else if(c.match_available){if((C=l._tr_tally(c,0,c.window[c.strstart-1]))&&L(c,!1),c.strstart++,c.lookahead--,c.strm.avail_out===0)return m}else c.match_available=1,c.strstart++,c.lookahead--}return c.match_available&&(C=l._tr_tally(c,0,c.window[c.strstart-1]),c.match_available=0),c.insert=c.strstart<T-1?c.strstart:T-1,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):c.last_lit&&(L(c,!1),c.strm.avail_out===0)?m:V}function me(c,K,M,C,N){this.good_length=c,this.max_lazy=K,this.nice_length=M,this.max_chain=C,this.func=N}function ke(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=j,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new o.Buf16(2*U),this.dyn_dtree=new o.Buf16(2*(2*S+1)),this.bl_tree=new o.Buf16(2*(2*B+1)),ee(this.dyn_ltree),ee(this.dyn_dtree),ee(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new o.Buf16($+1),this.heap=new o.Buf16(2*P+1),ee(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new o.Buf16(2*P+1),ee(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function ye(c){var K;return c&&c.state?(c.total_in=c.total_out=0,c.data_type=f,(K=c.state).pending=0,K.pending_out=0,K.wrap<0&&(K.wrap=-K.wrap),K.status=K.wrap?v:R,c.adler=K.wrap===2?0:1,K.last_flush=w,l._tr_init(K),d):ce(c,k)}function _e(c){var K=ye(c);return K===d&&(function(M){M.window_size=2*M.w_size,ee(M.head),M.max_lazy_match=i[M.level].max_lazy,M.good_match=i[M.level].good_length,M.nice_match=i[M.level].nice_length,M.max_chain_length=i[M.level].max_chain,M.strstart=0,M.block_start=0,M.lookahead=0,M.insert=0,M.match_length=M.prev_length=T-1,M.match_available=0,M.ins_h=0})(c.state),K}function Re(c,K,M,C,N,D){if(!c)return k;var X=1;if(K===u&&(K=6),C<0?(X=0,C=-C):15<C&&(X=2,C-=16),N<1||E<N||M!==j||C<8||15<C||K<0||9<K||D<0||x<D)return ce(c,k);C===8&&(C=9);var y=new ke;return(c.state=y).strm=c,y.wrap=X,y.gzhead=null,y.w_bits=C,y.w_size=1<<y.w_bits,y.w_mask=y.w_size-1,y.hash_bits=N+7,y.hash_size=1<<y.hash_bits,y.hash_mask=y.hash_size-1,y.hash_shift=~~((y.hash_bits+T-1)/T),y.window=new o.Buf8(2*y.w_size),y.head=new o.Buf16(y.hash_size),y.prev=new o.Buf16(y.w_size),y.lit_bufsize=1<<N+6,y.pending_buf_size=4*y.lit_bufsize,y.pending_buf=new o.Buf8(y.pending_buf_size),y.d_buf=1*y.lit_bufsize,y.l_buf=3*y.lit_bufsize,y.level=K,y.strategy=D,y.method=M,_e(c)}i=[new me(0,0,0,0,function(c,K){var M=65535;for(M>c.pending_buf_size-5&&(M=c.pending_buf_size-5);;){if(c.lookahead<=1){if(ve(c),c.lookahead===0&&K===w)return m;if(c.lookahead===0)break}c.strstart+=c.lookahead,c.lookahead=0;var C=c.block_start+M;if((c.strstart===0||c.strstart>=C)&&(c.lookahead=c.strstart-C,c.strstart=C,L(c,!1),c.strm.avail_out===0)||c.strstart-c.block_start>=c.w_size-se&&(L(c,!1),c.strm.avail_out===0))return m}return c.insert=0,K===g?(L(c,!0),c.strm.avail_out===0?ie:q):(c.strstart>c.block_start&&(L(c,!1),c.strm.avail_out),m)}),new me(4,4,8,4,Se),new me(4,5,16,8,Se),new me(4,6,32,32,Se),new me(4,4,16,16,fe),new me(8,16,32,32,fe),new me(8,16,128,128,fe),new me(8,32,128,256,fe),new me(32,128,258,1024,fe),new me(32,258,258,4096,fe)],n.deflateInit=function(c,K){return Re(c,K,j,15,8,0)},n.deflateInit2=Re,n.deflateReset=_e,n.deflateResetKeep=ye,n.deflateSetHeader=function(c,K){return c&&c.state?c.state.wrap!==2?k:(c.state.gzhead=K,d):k},n.deflate=function(c,K){var M,C,N,D;if(!c||!c.state||5<K||K<0)return c?ce(c,k):k;if(C=c.state,!c.output||!c.input&&c.avail_in!==0||C.status===666&&K!==g)return ce(c,c.avail_out===0?-5:k);if(C.strm=c,M=C.last_flush,C.last_flush=K,C.status===v)if(C.wrap===2)c.adler=0,ae(C,31),ae(C,139),ae(C,8),C.gzhead?(ae(C,(C.gzhead.text?1:0)+(C.gzhead.hcrc?2:0)+(C.gzhead.extra?4:0)+(C.gzhead.name?8:0)+(C.gzhead.comment?16:0)),ae(C,255&C.gzhead.time),ae(C,C.gzhead.time>>8&255),ae(C,C.gzhead.time>>16&255),ae(C,C.gzhead.time>>24&255),ae(C,C.level===9?2:2<=C.strategy||C.level<2?4:0),ae(C,255&C.gzhead.os),C.gzhead.extra&&C.gzhead.extra.length&&(ae(C,255&C.gzhead.extra.length),ae(C,C.gzhead.extra.length>>8&255)),C.gzhead.hcrc&&(c.adler=p(c.adler,C.pending_buf,C.pending,0)),C.gzindex=0,C.status=69):(ae(C,0),ae(C,0),ae(C,0),ae(C,0),ae(C,0),ae(C,C.level===9?2:2<=C.strategy||C.level<2?4:0),ae(C,3),C.status=R);else{var X=j+(C.w_bits-8<<4)<<8;X|=(2<=C.strategy||C.level<2?0:C.level<6?1:C.level===6?2:3)<<6,C.strstart!==0&&(X|=32),X+=31-X%31,C.status=R,te(C,X),C.strstart!==0&&(te(C,c.adler>>>16),te(C,65535&c.adler)),c.adler=1}if(C.status===69)if(C.gzhead.extra){for(N=C.pending;C.gzindex<(65535&C.gzhead.extra.length)&&(C.pending!==C.pending_buf_size||(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending!==C.pending_buf_size));)ae(C,255&C.gzhead.extra[C.gzindex]),C.gzindex++;C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),C.gzindex===C.gzhead.extra.length&&(C.gzindex=0,C.status=73)}else C.status=73;if(C.status===73)if(C.gzhead.name){N=C.pending;do{if(C.pending===C.pending_buf_size&&(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending===C.pending_buf_size)){D=1;break}D=C.gzindex<C.gzhead.name.length?255&C.gzhead.name.charCodeAt(C.gzindex++):0,ae(C,D)}while(D!==0);C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),D===0&&(C.gzindex=0,C.status=91)}else C.status=91;if(C.status===91)if(C.gzhead.comment){N=C.pending;do{if(C.pending===C.pending_buf_size&&(C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),O(c),N=C.pending,C.pending===C.pending_buf_size)){D=1;break}D=C.gzindex<C.gzhead.comment.length?255&C.gzhead.comment.charCodeAt(C.gzindex++):0,ae(C,D)}while(D!==0);C.gzhead.hcrc&&C.pending>N&&(c.adler=p(c.adler,C.pending_buf,C.pending-N,N)),D===0&&(C.status=103)}else C.status=103;if(C.status===103&&(C.gzhead.hcrc?(C.pending+2>C.pending_buf_size&&O(c),C.pending+2<=C.pending_buf_size&&(ae(C,255&c.adler),ae(C,c.adler>>8&255),c.adler=0,C.status=R)):C.status=R),C.pending!==0){if(O(c),c.avail_out===0)return C.last_flush=-1,d}else if(c.avail_in===0&&F(K)<=F(M)&&K!==g)return ce(c,-5);if(C.status===666&&c.avail_in!==0)return ce(c,-5);if(c.avail_in!==0||C.lookahead!==0||K!==w&&C.status!==666){var y=C.strategy===2?(function(b,A){for(var I;;){if(b.lookahead===0&&(ve(b),b.lookahead===0)){if(A===w)return m;break}if(b.match_length=0,I=l._tr_tally(b,0,b.window[b.strstart]),b.lookahead--,b.strstart++,I&&(L(b,!1),b.strm.avail_out===0))return m}return b.insert=0,A===g?(L(b,!0),b.strm.avail_out===0?ie:q):b.last_lit&&(L(b,!1),b.strm.avail_out===0)?m:V})(C,K):C.strategy===3?(function(b,A){for(var I,z,Z,H,re=b.window;;){if(b.lookahead<=G){if(ve(b),b.lookahead<=G&&A===w)return m;if(b.lookahead===0)break}if(b.match_length=0,b.lookahead>=T&&0<b.strstart&&(z=re[Z=b.strstart-1])===re[++Z]&&z===re[++Z]&&z===re[++Z]){H=b.strstart+G;do;while(z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&z===re[++Z]&&Z<H);b.match_length=G-(H-Z),b.match_length>b.lookahead&&(b.match_length=b.lookahead)}if(b.match_length>=T?(I=l._tr_tally(b,1,b.match_length-T),b.lookahead-=b.match_length,b.strstart+=b.match_length,b.match_length=0):(I=l._tr_tally(b,0,b.window[b.strstart]),b.lookahead--,b.strstart++),I&&(L(b,!1),b.strm.avail_out===0))return m}return b.insert=0,A===g?(L(b,!0),b.strm.avail_out===0?ie:q):b.last_lit&&(L(b,!1),b.strm.avail_out===0)?m:V})(C,K):i[C.level].func(C,K);if(y!==ie&&y!==q||(C.status=666),y===m||y===ie)return c.avail_out===0&&(C.last_flush=-1),d;if(y===V&&(K===1?l._tr_align(C):K!==5&&(l._tr_stored_block(C,0,0,!1),K===3&&(ee(C.head),C.lookahead===0&&(C.strstart=0,C.block_start=0,C.insert=0))),O(c),c.avail_out===0))return C.last_flush=-1,d}return K!==g?d:C.wrap<=0?1:(C.wrap===2?(ae(C,255&c.adler),ae(C,c.adler>>8&255),ae(C,c.adler>>16&255),ae(C,c.adler>>24&255),ae(C,255&c.total_in),ae(C,c.total_in>>8&255),ae(C,c.total_in>>16&255),ae(C,c.total_in>>24&255)):(te(C,c.adler>>>16),te(C,65535&c.adler)),O(c),0<C.wrap&&(C.wrap=-C.wrap),C.pending!==0?d:1)},n.deflateEnd=function(c){var K;return c&&c.state?(K=c.state.status)!==v&&K!==69&&K!==73&&K!==91&&K!==103&&K!==R&&K!==666?ce(c,k):(c.state=null,K===R?ce(c,-3):d):k},n.deflateSetDictionary=function(c,K){var M,C,N,D,X,y,b,A,I=K.length;if(!c||!c.state||(D=(M=c.state).wrap)===2||D===1&&M.status!==v||M.lookahead)return k;for(D===1&&(c.adler=h(c.adler,K,I,0)),M.wrap=0,I>=M.w_size&&(D===0&&(ee(M.head),M.strstart=0,M.block_start=0,M.insert=0),A=new o.Buf8(M.w_size),o.arraySet(A,K,I-M.w_size,M.w_size,0),K=A,I=M.w_size),X=c.avail_in,y=c.next_in,b=c.input,c.avail_in=I,c.next_in=0,c.input=K,ve(M);M.lookahead>=T;){for(C=M.strstart,N=M.lookahead-(T-1);M.ins_h=(M.ins_h<<M.hash_shift^M.window[C+T-1])&M.hash_mask,M.prev[C&M.w_mask]=M.head[M.ins_h],M.head[M.ins_h]=C,C++,--N;);M.strstart=C,M.lookahead=T-1,ve(M)}return M.strstart+=M.lookahead,M.block_start=M.strstart,M.insert=M.lookahead,M.lookahead=0,M.match_length=M.prev_length=T-1,M.match_available=0,c.next_in=y,c.input=b,c.avail_in=X,M.wrap=D,d},n.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(s,a,n){a.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(s,a,n){a.exports=function(i,o){var l,h,p,_,w,g,d,k,u,x,f,j,E,P,S,B,U,$,T,G,se,v,R,m,V;l=i.state,h=i.next_in,m=i.input,p=h+(i.avail_in-5),_=i.next_out,V=i.output,w=_-(o-i.avail_out),g=_+(i.avail_out-257),d=l.dmax,k=l.wsize,u=l.whave,x=l.wnext,f=l.window,j=l.hold,E=l.bits,P=l.lencode,S=l.distcode,B=(1<<l.lenbits)-1,U=(1<<l.distbits)-1;e:do{E<15&&(j+=m[h++]<<E,E+=8,j+=m[h++]<<E,E+=8),$=P[j&B];t:for(;;){if(j>>>=T=$>>>24,E-=T,(T=$>>>16&255)===0)V[_++]=65535&$;else{if(!(16&T)){if((64&T)==0){$=P[(65535&$)+(j&(1<<T)-1)];continue t}if(32&T){l.mode=12;break e}i.msg="invalid literal/length code",l.mode=30;break e}G=65535&$,(T&=15)&&(E<T&&(j+=m[h++]<<E,E+=8),G+=j&(1<<T)-1,j>>>=T,E-=T),E<15&&(j+=m[h++]<<E,E+=8,j+=m[h++]<<E,E+=8),$=S[j&U];r:for(;;){if(j>>>=T=$>>>24,E-=T,!(16&(T=$>>>16&255))){if((64&T)==0){$=S[(65535&$)+(j&(1<<T)-1)];continue r}i.msg="invalid distance code",l.mode=30;break e}if(se=65535&$,E<(T&=15)&&(j+=m[h++]<<E,(E+=8)<T&&(j+=m[h++]<<E,E+=8)),d<(se+=j&(1<<T)-1)){i.msg="invalid distance too far back",l.mode=30;break e}if(j>>>=T,E-=T,(T=_-w)<se){if(u<(T=se-T)&&l.sane){i.msg="invalid distance too far back",l.mode=30;break e}if(R=f,(v=0)===x){if(v+=k-T,T<G){for(G-=T;V[_++]=f[v++],--T;);v=_-se,R=V}}else if(x<T){if(v+=k+x-T,(T-=x)<G){for(G-=T;V[_++]=f[v++],--T;);if(v=0,x<G){for(G-=T=x;V[_++]=f[v++],--T;);v=_-se,R=V}}}else if(v+=x-T,T<G){for(G-=T;V[_++]=f[v++],--T;);v=_-se,R=V}for(;2<G;)V[_++]=R[v++],V[_++]=R[v++],V[_++]=R[v++],G-=3;G&&(V[_++]=R[v++],1<G&&(V[_++]=R[v++]))}else{for(v=_-se;V[_++]=V[v++],V[_++]=V[v++],V[_++]=V[v++],2<(G-=3););G&&(V[_++]=V[v++],1<G&&(V[_++]=V[v++]))}break}}break}}while(h<p&&_<g);h-=G=E>>3,j&=(1<<(E-=G<<3))-1,i.next_in=h,i.next_out=_,i.avail_in=h<p?p-h+5:5-(h-p),i.avail_out=_<g?g-_+257:257-(_-g),l.hold=j,l.bits=E}},{}],49:[function(s,a,n){var i=s("../utils/common"),o=s("./adler32"),l=s("./crc32"),h=s("./inffast"),p=s("./inftrees"),_=1,w=2,g=0,d=-2,k=1,u=852,x=592;function f(v){return(v>>>24&255)+(v>>>8&65280)+((65280&v)<<8)+((255&v)<<24)}function j(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new i.Buf16(320),this.work=new i.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function E(v){var R;return v&&v.state?(R=v.state,v.total_in=v.total_out=R.total=0,v.msg="",R.wrap&&(v.adler=1&R.wrap),R.mode=k,R.last=0,R.havedict=0,R.dmax=32768,R.head=null,R.hold=0,R.bits=0,R.lencode=R.lendyn=new i.Buf32(u),R.distcode=R.distdyn=new i.Buf32(x),R.sane=1,R.back=-1,g):d}function P(v){var R;return v&&v.state?((R=v.state).wsize=0,R.whave=0,R.wnext=0,E(v)):d}function S(v,R){var m,V;return v&&v.state?(V=v.state,R<0?(m=0,R=-R):(m=1+(R>>4),R<48&&(R&=15)),R&&(R<8||15<R)?d:(V.window!==null&&V.wbits!==R&&(V.window=null),V.wrap=m,V.wbits=R,P(v))):d}function B(v,R){var m,V;return v?(V=new j,(v.state=V).window=null,(m=S(v,R))!==g&&(v.state=null),m):d}var U,$,T=!0;function G(v){if(T){var R;for(U=new i.Buf32(512),$=new i.Buf32(32),R=0;R<144;)v.lens[R++]=8;for(;R<256;)v.lens[R++]=9;for(;R<280;)v.lens[R++]=7;for(;R<288;)v.lens[R++]=8;for(p(_,v.lens,0,288,U,0,v.work,{bits:9}),R=0;R<32;)v.lens[R++]=5;p(w,v.lens,0,32,$,0,v.work,{bits:5}),T=!1}v.lencode=U,v.lenbits=9,v.distcode=$,v.distbits=5}function se(v,R,m,V){var ie,q=v.state;return q.window===null&&(q.wsize=1<<q.wbits,q.wnext=0,q.whave=0,q.window=new i.Buf8(q.wsize)),V>=q.wsize?(i.arraySet(q.window,R,m-q.wsize,q.wsize,0),q.wnext=0,q.whave=q.wsize):(V<(ie=q.wsize-q.wnext)&&(ie=V),i.arraySet(q.window,R,m-V,ie,q.wnext),(V-=ie)?(i.arraySet(q.window,R,m-V,V,0),q.wnext=V,q.whave=q.wsize):(q.wnext+=ie,q.wnext===q.wsize&&(q.wnext=0),q.whave<q.wsize&&(q.whave+=ie))),0}n.inflateReset=P,n.inflateReset2=S,n.inflateResetKeep=E,n.inflateInit=function(v){return B(v,15)},n.inflateInit2=B,n.inflate=function(v,R){var m,V,ie,q,ce,F,ee,O,L,ae,te,J,ve,Se,fe,me,ke,ye,_e,Re,c,K,M,C,N=0,D=new i.Buf8(4),X=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!v||!v.state||!v.output||!v.input&&v.avail_in!==0)return d;(m=v.state).mode===12&&(m.mode=13),ce=v.next_out,ie=v.output,ee=v.avail_out,q=v.next_in,V=v.input,F=v.avail_in,O=m.hold,L=m.bits,ae=F,te=ee,K=g;e:for(;;)switch(m.mode){case k:if(m.wrap===0){m.mode=13;break}for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(2&m.wrap&&O===35615){D[m.check=0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0),L=O=0,m.mode=2;break}if(m.flags=0,m.head&&(m.head.done=!1),!(1&m.wrap)||(((255&O)<<8)+(O>>8))%31){v.msg="incorrect header check",m.mode=30;break}if((15&O)!=8){v.msg="unknown compression method",m.mode=30;break}if(L-=4,c=8+(15&(O>>>=4)),m.wbits===0)m.wbits=c;else if(c>m.wbits){v.msg="invalid window size",m.mode=30;break}m.dmax=1<<c,v.adler=m.check=1,m.mode=512&O?10:12,L=O=0;break;case 2:for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(m.flags=O,(255&m.flags)!=8){v.msg="unknown compression method",m.mode=30;break}if(57344&m.flags){v.msg="unknown header flags set",m.mode=30;break}m.head&&(m.head.text=O>>8&1),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0,m.mode=3;case 3:for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.head&&(m.head.time=O),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,D[2]=O>>>16&255,D[3]=O>>>24&255,m.check=l(m.check,D,4,0)),L=O=0,m.mode=4;case 4:for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.head&&(m.head.xflags=255&O,m.head.os=O>>8),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0,m.mode=5;case 5:if(1024&m.flags){for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.length=O,m.head&&(m.head.extra_len=O),512&m.flags&&(D[0]=255&O,D[1]=O>>>8&255,m.check=l(m.check,D,2,0)),L=O=0}else m.head&&(m.head.extra=null);m.mode=6;case 6:if(1024&m.flags&&(F<(J=m.length)&&(J=F),J&&(m.head&&(c=m.head.extra_len-m.length,m.head.extra||(m.head.extra=new Array(m.head.extra_len)),i.arraySet(m.head.extra,V,q,J,c)),512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,m.length-=J),m.length))break e;m.length=0,m.mode=7;case 7:if(2048&m.flags){if(F===0)break e;for(J=0;c=V[q+J++],m.head&&c&&m.length<65536&&(m.head.name+=String.fromCharCode(c)),c&&J<F;);if(512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,c)break e}else m.head&&(m.head.name=null);m.length=0,m.mode=8;case 8:if(4096&m.flags){if(F===0)break e;for(J=0;c=V[q+J++],m.head&&c&&m.length<65536&&(m.head.comment+=String.fromCharCode(c)),c&&J<F;);if(512&m.flags&&(m.check=l(m.check,V,J,q)),F-=J,q+=J,c)break e}else m.head&&(m.head.comment=null);m.mode=9;case 9:if(512&m.flags){for(;L<16;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O!==(65535&m.check)){v.msg="header crc mismatch",m.mode=30;break}L=O=0}m.head&&(m.head.hcrc=m.flags>>9&1,m.head.done=!0),v.adler=m.check=0,m.mode=12;break;case 10:for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}v.adler=m.check=f(O),L=O=0,m.mode=11;case 11:if(m.havedict===0)return v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,2;v.adler=m.check=1,m.mode=12;case 12:if(R===5||R===6)break e;case 13:if(m.last){O>>>=7&L,L-=7&L,m.mode=27;break}for(;L<3;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}switch(m.last=1&O,L-=1,3&(O>>>=1)){case 0:m.mode=14;break;case 1:if(G(m),m.mode=20,R!==6)break;O>>>=2,L-=2;break e;case 2:m.mode=17;break;case 3:v.msg="invalid block type",m.mode=30}O>>>=2,L-=2;break;case 14:for(O>>>=7&L,L-=7&L;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if((65535&O)!=(O>>>16^65535)){v.msg="invalid stored block lengths",m.mode=30;break}if(m.length=65535&O,L=O=0,m.mode=15,R===6)break e;case 15:m.mode=16;case 16:if(J=m.length){if(F<J&&(J=F),ee<J&&(J=ee),J===0)break e;i.arraySet(ie,V,q,J,ce),F-=J,q+=J,ee-=J,ce+=J,m.length-=J;break}m.mode=12;break;case 17:for(;L<14;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(m.nlen=257+(31&O),O>>>=5,L-=5,m.ndist=1+(31&O),O>>>=5,L-=5,m.ncode=4+(15&O),O>>>=4,L-=4,286<m.nlen||30<m.ndist){v.msg="too many length or distance symbols",m.mode=30;break}m.have=0,m.mode=18;case 18:for(;m.have<m.ncode;){for(;L<3;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.lens[X[m.have++]]=7&O,O>>>=3,L-=3}for(;m.have<19;)m.lens[X[m.have++]]=0;if(m.lencode=m.lendyn,m.lenbits=7,M={bits:m.lenbits},K=p(0,m.lens,0,19,m.lencode,0,m.work,M),m.lenbits=M.bits,K){v.msg="invalid code lengths set",m.mode=30;break}m.have=0,m.mode=19;case 19:for(;m.have<m.nlen+m.ndist;){for(;me=(N=m.lencode[O&(1<<m.lenbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(ke<16)O>>>=fe,L-=fe,m.lens[m.have++]=ke;else{if(ke===16){for(C=fe+2;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O>>>=fe,L-=fe,m.have===0){v.msg="invalid bit length repeat",m.mode=30;break}c=m.lens[m.have-1],J=3+(3&O),O>>>=2,L-=2}else if(ke===17){for(C=fe+3;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}L-=fe,c=0,J=3+(7&(O>>>=fe)),O>>>=3,L-=3}else{for(C=fe+7;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}L-=fe,c=0,J=11+(127&(O>>>=fe)),O>>>=7,L-=7}if(m.have+J>m.nlen+m.ndist){v.msg="invalid bit length repeat",m.mode=30;break}for(;J--;)m.lens[m.have++]=c}}if(m.mode===30)break;if(m.lens[256]===0){v.msg="invalid code -- missing end-of-block",m.mode=30;break}if(m.lenbits=9,M={bits:m.lenbits},K=p(_,m.lens,0,m.nlen,m.lencode,0,m.work,M),m.lenbits=M.bits,K){v.msg="invalid literal/lengths set",m.mode=30;break}if(m.distbits=6,m.distcode=m.distdyn,M={bits:m.distbits},K=p(w,m.lens,m.nlen,m.ndist,m.distcode,0,m.work,M),m.distbits=M.bits,K){v.msg="invalid distances set",m.mode=30;break}if(m.mode=20,R===6)break e;case 20:m.mode=21;case 21:if(6<=F&&258<=ee){v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,h(v,te),ce=v.next_out,ie=v.output,ee=v.avail_out,q=v.next_in,V=v.input,F=v.avail_in,O=m.hold,L=m.bits,m.mode===12&&(m.back=-1);break}for(m.back=0;me=(N=m.lencode[O&(1<<m.lenbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(me&&(240&me)==0){for(ye=fe,_e=me,Re=ke;me=(N=m.lencode[Re+((O&(1<<ye+_e)-1)>>ye)])>>>16&255,ke=65535&N,!(ye+(fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}O>>>=ye,L-=ye,m.back+=ye}if(O>>>=fe,L-=fe,m.back+=fe,m.length=ke,me===0){m.mode=26;break}if(32&me){m.back=-1,m.mode=12;break}if(64&me){v.msg="invalid literal/length code",m.mode=30;break}m.extra=15&me,m.mode=22;case 22:if(m.extra){for(C=m.extra;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.length+=O&(1<<m.extra)-1,O>>>=m.extra,L-=m.extra,m.back+=m.extra}m.was=m.length,m.mode=23;case 23:for(;me=(N=m.distcode[O&(1<<m.distbits)-1])>>>16&255,ke=65535&N,!((fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if((240&me)==0){for(ye=fe,_e=me,Re=ke;me=(N=m.distcode[Re+((O&(1<<ye+_e)-1)>>ye)])>>>16&255,ke=65535&N,!(ye+(fe=N>>>24)<=L);){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}O>>>=ye,L-=ye,m.back+=ye}if(O>>>=fe,L-=fe,m.back+=fe,64&me){v.msg="invalid distance code",m.mode=30;break}m.offset=ke,m.extra=15&me,m.mode=24;case 24:if(m.extra){for(C=m.extra;L<C;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}m.offset+=O&(1<<m.extra)-1,O>>>=m.extra,L-=m.extra,m.back+=m.extra}if(m.offset>m.dmax){v.msg="invalid distance too far back",m.mode=30;break}m.mode=25;case 25:if(ee===0)break e;if(J=te-ee,m.offset>J){if((J=m.offset-J)>m.whave&&m.sane){v.msg="invalid distance too far back",m.mode=30;break}ve=J>m.wnext?(J-=m.wnext,m.wsize-J):m.wnext-J,J>m.length&&(J=m.length),Se=m.window}else Se=ie,ve=ce-m.offset,J=m.length;for(ee<J&&(J=ee),ee-=J,m.length-=J;ie[ce++]=Se[ve++],--J;);m.length===0&&(m.mode=21);break;case 26:if(ee===0)break e;ie[ce++]=m.length,ee--,m.mode=21;break;case 27:if(m.wrap){for(;L<32;){if(F===0)break e;F--,O|=V[q++]<<L,L+=8}if(te-=ee,v.total_out+=te,m.total+=te,te&&(v.adler=m.check=m.flags?l(m.check,ie,te,ce-te):o(m.check,ie,te,ce-te)),te=ee,(m.flags?O:f(O))!==m.check){v.msg="incorrect data check",m.mode=30;break}L=O=0}m.mode=28;case 28:if(m.wrap&&m.flags){for(;L<32;){if(F===0)break e;F--,O+=V[q++]<<L,L+=8}if(O!==(4294967295&m.total)){v.msg="incorrect length check",m.mode=30;break}L=O=0}m.mode=29;case 29:K=1;break e;case 30:K=-3;break e;case 31:return-4;case 32:default:return d}return v.next_out=ce,v.avail_out=ee,v.next_in=q,v.avail_in=F,m.hold=O,m.bits=L,(m.wsize||te!==v.avail_out&&m.mode<30&&(m.mode<27||R!==4))&&se(v,v.output,v.next_out,te-v.avail_out)?(m.mode=31,-4):(ae-=v.avail_in,te-=v.avail_out,v.total_in+=ae,v.total_out+=te,m.total+=te,m.wrap&&te&&(v.adler=m.check=m.flags?l(m.check,ie,te,v.next_out-te):o(m.check,ie,te,v.next_out-te)),v.data_type=m.bits+(m.last?64:0)+(m.mode===12?128:0)+(m.mode===20||m.mode===15?256:0),(ae==0&&te===0||R===4)&&K===g&&(K=-5),K)},n.inflateEnd=function(v){if(!v||!v.state)return d;var R=v.state;return R.window&&(R.window=null),v.state=null,g},n.inflateGetHeader=function(v,R){var m;return v&&v.state?(2&(m=v.state).wrap)==0?d:((m.head=R).done=!1,g):d},n.inflateSetDictionary=function(v,R){var m,V=R.length;return v&&v.state?(m=v.state).wrap!==0&&m.mode!==11?d:m.mode===11&&o(1,R,V,0)!==m.check?-3:se(v,R,V,V)?(m.mode=31,-4):(m.havedict=1,g):d},n.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(s,a,n){var i=s("../utils/common"),o=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],l=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],h=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],p=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];a.exports=function(_,w,g,d,k,u,x,f){var j,E,P,S,B,U,$,T,G,se=f.bits,v=0,R=0,m=0,V=0,ie=0,q=0,ce=0,F=0,ee=0,O=0,L=null,ae=0,te=new i.Buf16(16),J=new i.Buf16(16),ve=null,Se=0;for(v=0;v<=15;v++)te[v]=0;for(R=0;R<d;R++)te[w[g+R]]++;for(ie=se,V=15;1<=V&&te[V]===0;V--);if(V<ie&&(ie=V),V===0)return k[u++]=20971520,k[u++]=20971520,f.bits=1,0;for(m=1;m<V&&te[m]===0;m++);for(ie<m&&(ie=m),v=F=1;v<=15;v++)if(F<<=1,(F-=te[v])<0)return-1;if(0<F&&(_===0||V!==1))return-1;for(J[1]=0,v=1;v<15;v++)J[v+1]=J[v]+te[v];for(R=0;R<d;R++)w[g+R]!==0&&(x[J[w[g+R]]++]=R);if(U=_===0?(L=ve=x,19):_===1?(L=o,ae-=257,ve=l,Se-=257,256):(L=h,ve=p,-1),v=m,B=u,ce=R=O=0,P=-1,S=(ee=1<<(q=ie))-1,_===1&&852<ee||_===2&&592<ee)return 1;for(;;){for($=v-ce,G=x[R]<U?(T=0,x[R]):x[R]>U?(T=ve[Se+x[R]],L[ae+x[R]]):(T=96,0),j=1<<v-ce,m=E=1<<q;k[B+(O>>ce)+(E-=j)]=$<<24|T<<16|G|0,E!==0;);for(j=1<<v-1;O&j;)j>>=1;if(j!==0?(O&=j-1,O+=j):O=0,R++,--te[v]==0){if(v===V)break;v=w[g+x[R]]}if(ie<v&&(O&S)!==P){for(ce===0&&(ce=ie),B+=m,F=1<<(q=v-ce);q+ce<V&&!((F-=te[q+ce])<=0);)q++,F<<=1;if(ee+=1<<q,_===1&&852<ee||_===2&&592<ee)return 1;k[P=O&S]=ie<<24|q<<16|B-u|0}}return O!==0&&(k[B+O]=v-ce<<24|64<<16|0),f.bits=ie,0}},{"../utils/common":41}],51:[function(s,a,n){a.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(s,a,n){var i=s("../utils/common"),o=0,l=1;function h(N){for(var D=N.length;0<=--D;)N[D]=0}var p=0,_=29,w=256,g=w+1+_,d=30,k=19,u=2*g+1,x=15,f=16,j=7,E=256,P=16,S=17,B=18,U=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],$=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],T=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],G=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],se=new Array(2*(g+2));h(se);var v=new Array(2*d);h(v);var R=new Array(512);h(R);var m=new Array(256);h(m);var V=new Array(_);h(V);var ie,q,ce,F=new Array(d);function ee(N,D,X,y,b){this.static_tree=N,this.extra_bits=D,this.extra_base=X,this.elems=y,this.max_length=b,this.has_stree=N&&N.length}function O(N,D){this.dyn_tree=N,this.max_code=0,this.stat_desc=D}function L(N){return N<256?R[N]:R[256+(N>>>7)]}function ae(N,D){N.pending_buf[N.pending++]=255&D,N.pending_buf[N.pending++]=D>>>8&255}function te(N,D,X){N.bi_valid>f-X?(N.bi_buf|=D<<N.bi_valid&65535,ae(N,N.bi_buf),N.bi_buf=D>>f-N.bi_valid,N.bi_valid+=X-f):(N.bi_buf|=D<<N.bi_valid&65535,N.bi_valid+=X)}function J(N,D,X){te(N,X[2*D],X[2*D+1])}function ve(N,D){for(var X=0;X|=1&N,N>>>=1,X<<=1,0<--D;);return X>>>1}function Se(N,D,X){var y,b,A=new Array(x+1),I=0;for(y=1;y<=x;y++)A[y]=I=I+X[y-1]<<1;for(b=0;b<=D;b++){var z=N[2*b+1];z!==0&&(N[2*b]=ve(A[z]++,z))}}function fe(N){var D;for(D=0;D<g;D++)N.dyn_ltree[2*D]=0;for(D=0;D<d;D++)N.dyn_dtree[2*D]=0;for(D=0;D<k;D++)N.bl_tree[2*D]=0;N.dyn_ltree[2*E]=1,N.opt_len=N.static_len=0,N.last_lit=N.matches=0}function me(N){8<N.bi_valid?ae(N,N.bi_buf):0<N.bi_valid&&(N.pending_buf[N.pending++]=N.bi_buf),N.bi_buf=0,N.bi_valid=0}function ke(N,D,X,y){var b=2*D,A=2*X;return N[b]<N[A]||N[b]===N[A]&&y[D]<=y[X]}function ye(N,D,X){for(var y=N.heap[X],b=X<<1;b<=N.heap_len&&(b<N.heap_len&&ke(D,N.heap[b+1],N.heap[b],N.depth)&&b++,!ke(D,y,N.heap[b],N.depth));)N.heap[X]=N.heap[b],X=b,b<<=1;N.heap[X]=y}function _e(N,D,X){var y,b,A,I,z=0;if(N.last_lit!==0)for(;y=N.pending_buf[N.d_buf+2*z]<<8|N.pending_buf[N.d_buf+2*z+1],b=N.pending_buf[N.l_buf+z],z++,y===0?J(N,b,D):(J(N,(A=m[b])+w+1,D),(I=U[A])!==0&&te(N,b-=V[A],I),J(N,A=L(--y),X),(I=$[A])!==0&&te(N,y-=F[A],I)),z<N.last_lit;);J(N,E,D)}function Re(N,D){var X,y,b,A=D.dyn_tree,I=D.stat_desc.static_tree,z=D.stat_desc.has_stree,Z=D.stat_desc.elems,H=-1;for(N.heap_len=0,N.heap_max=u,X=0;X<Z;X++)A[2*X]!==0?(N.heap[++N.heap_len]=H=X,N.depth[X]=0):A[2*X+1]=0;for(;N.heap_len<2;)A[2*(b=N.heap[++N.heap_len]=H<2?++H:0)]=1,N.depth[b]=0,N.opt_len--,z&&(N.static_len-=I[2*b+1]);for(D.max_code=H,X=N.heap_len>>1;1<=X;X--)ye(N,A,X);for(b=Z;X=N.heap[1],N.heap[1]=N.heap[N.heap_len--],ye(N,A,1),y=N.heap[1],N.heap[--N.heap_max]=X,N.heap[--N.heap_max]=y,A[2*b]=A[2*X]+A[2*y],N.depth[b]=(N.depth[X]>=N.depth[y]?N.depth[X]:N.depth[y])+1,A[2*X+1]=A[2*y+1]=b,N.heap[1]=b++,ye(N,A,1),2<=N.heap_len;);N.heap[--N.heap_max]=N.heap[1],(function(re,he){var ze,je,Fe,ge,xe,Ze,$e=he.dyn_tree,Ae=he.max_code,He=he.stat_desc.static_tree,Qe=he.stat_desc.has_stree,xt=he.stat_desc.extra_bits,mt=he.stat_desc.extra_base,Nt=he.stat_desc.max_length,St=0;for(ge=0;ge<=x;ge++)re.bl_count[ge]=0;for($e[2*re.heap[re.heap_max]+1]=0,ze=re.heap_max+1;ze<u;ze++)Nt<(ge=$e[2*$e[2*(je=re.heap[ze])+1]+1]+1)&&(ge=Nt,St++),$e[2*je+1]=ge,Ae<je||(re.bl_count[ge]++,xe=0,mt<=je&&(xe=xt[je-mt]),Ze=$e[2*je],re.opt_len+=Ze*(ge+xe),Qe&&(re.static_len+=Ze*(He[2*je+1]+xe)));if(St!==0){do{for(ge=Nt-1;re.bl_count[ge]===0;)ge--;re.bl_count[ge]--,re.bl_count[ge+1]+=2,re.bl_count[Nt]--,St-=2}while(0<St);for(ge=Nt;ge!==0;ge--)for(je=re.bl_count[ge];je!==0;)Ae<(Fe=re.heap[--ze])||($e[2*Fe+1]!==ge&&(re.opt_len+=(ge-$e[2*Fe+1])*$e[2*Fe],$e[2*Fe+1]=ge),je--)}})(N,D),Se(A,H,N.bl_count)}function c(N,D,X){var y,b,A=-1,I=D[1],z=0,Z=7,H=4;for(I===0&&(Z=138,H=3),D[2*(X+1)+1]=65535,y=0;y<=X;y++)b=I,I=D[2*(y+1)+1],++z<Z&&b===I||(z<H?N.bl_tree[2*b]+=z:b!==0?(b!==A&&N.bl_tree[2*b]++,N.bl_tree[2*P]++):z<=10?N.bl_tree[2*S]++:N.bl_tree[2*B]++,A=b,H=(z=0)===I?(Z=138,3):b===I?(Z=6,3):(Z=7,4))}function K(N,D,X){var y,b,A=-1,I=D[1],z=0,Z=7,H=4;for(I===0&&(Z=138,H=3),y=0;y<=X;y++)if(b=I,I=D[2*(y+1)+1],!(++z<Z&&b===I)){if(z<H)for(;J(N,b,N.bl_tree),--z!=0;);else b!==0?(b!==A&&(J(N,b,N.bl_tree),z--),J(N,P,N.bl_tree),te(N,z-3,2)):z<=10?(J(N,S,N.bl_tree),te(N,z-3,3)):(J(N,B,N.bl_tree),te(N,z-11,7));A=b,H=(z=0)===I?(Z=138,3):b===I?(Z=6,3):(Z=7,4)}}h(F);var M=!1;function C(N,D,X,y){te(N,(p<<1)+(y?1:0),3),(function(b,A,I,z){me(b),ae(b,I),ae(b,~I),i.arraySet(b.pending_buf,b.window,A,I,b.pending),b.pending+=I})(N,D,X)}n._tr_init=function(N){M||((function(){var D,X,y,b,A,I=new Array(x+1);for(b=y=0;b<_-1;b++)for(V[b]=y,D=0;D<1<<U[b];D++)m[y++]=b;for(m[y-1]=b,b=A=0;b<16;b++)for(F[b]=A,D=0;D<1<<$[b];D++)R[A++]=b;for(A>>=7;b<d;b++)for(F[b]=A<<7,D=0;D<1<<$[b]-7;D++)R[256+A++]=b;for(X=0;X<=x;X++)I[X]=0;for(D=0;D<=143;)se[2*D+1]=8,D++,I[8]++;for(;D<=255;)se[2*D+1]=9,D++,I[9]++;for(;D<=279;)se[2*D+1]=7,D++,I[7]++;for(;D<=287;)se[2*D+1]=8,D++,I[8]++;for(Se(se,g+1,I),D=0;D<d;D++)v[2*D+1]=5,v[2*D]=ve(D,5);ie=new ee(se,U,w+1,g,x),q=new ee(v,$,0,d,x),ce=new ee(new Array(0),T,0,k,j)})(),M=!0),N.l_desc=new O(N.dyn_ltree,ie),N.d_desc=new O(N.dyn_dtree,q),N.bl_desc=new O(N.bl_tree,ce),N.bi_buf=0,N.bi_valid=0,fe(N)},n._tr_stored_block=C,n._tr_flush_block=function(N,D,X,y){var b,A,I=0;0<N.level?(N.strm.data_type===2&&(N.strm.data_type=(function(z){var Z,H=4093624447;for(Z=0;Z<=31;Z++,H>>>=1)if(1&H&&z.dyn_ltree[2*Z]!==0)return o;if(z.dyn_ltree[18]!==0||z.dyn_ltree[20]!==0||z.dyn_ltree[26]!==0)return l;for(Z=32;Z<w;Z++)if(z.dyn_ltree[2*Z]!==0)return l;return o})(N)),Re(N,N.l_desc),Re(N,N.d_desc),I=(function(z){var Z;for(c(z,z.dyn_ltree,z.l_desc.max_code),c(z,z.dyn_dtree,z.d_desc.max_code),Re(z,z.bl_desc),Z=k-1;3<=Z&&z.bl_tree[2*G[Z]+1]===0;Z--);return z.opt_len+=3*(Z+1)+5+5+4,Z})(N),b=N.opt_len+3+7>>>3,(A=N.static_len+3+7>>>3)<=b&&(b=A)):b=A=X+5,X+4<=b&&D!==-1?C(N,D,X,y):N.strategy===4||A===b?(te(N,2+(y?1:0),3),_e(N,se,v)):(te(N,4+(y?1:0),3),(function(z,Z,H,re){var he;for(te(z,Z-257,5),te(z,H-1,5),te(z,re-4,4),he=0;he<re;he++)te(z,z.bl_tree[2*G[he]+1],3);K(z,z.dyn_ltree,Z-1),K(z,z.dyn_dtree,H-1)})(N,N.l_desc.max_code+1,N.d_desc.max_code+1,I+1),_e(N,N.dyn_ltree,N.dyn_dtree)),fe(N),y&&me(N)},n._tr_tally=function(N,D,X){return N.pending_buf[N.d_buf+2*N.last_lit]=D>>>8&255,N.pending_buf[N.d_buf+2*N.last_lit+1]=255&D,N.pending_buf[N.l_buf+N.last_lit]=255&X,N.last_lit++,D===0?N.dyn_ltree[2*X]++:(N.matches++,D--,N.dyn_ltree[2*(m[X]+w+1)]++,N.dyn_dtree[2*L(D)]++),N.last_lit===N.lit_bufsize-1},n._tr_align=function(N){te(N,2,3),J(N,E,se),(function(D){D.bi_valid===16?(ae(D,D.bi_buf),D.bi_buf=0,D.bi_valid=0):8<=D.bi_valid&&(D.pending_buf[D.pending++]=255&D.bi_buf,D.bi_buf>>=8,D.bi_valid-=8)})(N)}},{"../utils/common":41}],53:[function(s,a,n){a.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(s,a,n){(function(i){(function(o,l){if(!o.setImmediate){var h,p,_,w,g=1,d={},k=!1,u=o.document,x=Object.getPrototypeOf&&Object.getPrototypeOf(o);x=x&&x.setTimeout?x:o,h={}.toString.call(o.process)==="[object process]"?function(P){process.nextTick(function(){j(P)})}:(function(){if(o.postMessage&&!o.importScripts){var P=!0,S=o.onmessage;return o.onmessage=function(){P=!1},o.postMessage("","*"),o.onmessage=S,P}})()?(w="setImmediate$"+Math.random()+"$",o.addEventListener?o.addEventListener("message",E,!1):o.attachEvent("onmessage",E),function(P){o.postMessage(w+P,"*")}):o.MessageChannel?((_=new MessageChannel).port1.onmessage=function(P){j(P.data)},function(P){_.port2.postMessage(P)}):u&&"onreadystatechange"in u.createElement("script")?(p=u.documentElement,function(P){var S=u.createElement("script");S.onreadystatechange=function(){j(P),S.onreadystatechange=null,p.removeChild(S),S=null},p.appendChild(S)}):function(P){setTimeout(j,0,P)},x.setImmediate=function(P){typeof P!="function"&&(P=new Function(""+P));for(var S=new Array(arguments.length-1),B=0;B<S.length;B++)S[B]=arguments[B+1];var U={callback:P,args:S};return d[g]=U,h(g),g++},x.clearImmediate=f}function f(P){delete d[P]}function j(P){if(k)setTimeout(j,0,P);else{var S=d[P];if(S){k=!0;try{(function(B){var U=B.callback,$=B.args;switch($.length){case 0:U();break;case 1:U($[0]);break;case 2:U($[0],$[1]);break;case 3:U($[0],$[1],$[2]);break;default:U.apply(l,$)}})(S)}finally{f(P),k=!1}}}}function E(P){P.source===o&&typeof P.data=="string"&&P.data.indexOf(w)===0&&j(+P.data.slice(w.length))}})(typeof self>"u"?i===void 0?this:i:self)}).call(this,typeof Rr<"u"?Rr:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(gs)),gs.exports}var xo=po();const go=Ei(xo),ca=5e3,bo=new Set([".jpg",".jpeg",".png",".webp",".gif"]),vo="__MACOSX",Tn={name:["Nombre","name","Name","nombre","NOMBRE","producto","Producto"],description:["Descripción","Descripcion","description","Description","descripcion","DESCRIPCION"],price:["Precio","price","Price","precio","PRECIO"],currency:["Moneda","currency","Currency","moneda","MONEDA"],externalId:["SKU","sku","id","external_id","ExternalId","codigo","Código","Codigo"],externalCategory:["Categoría","Categoria","category","Category","categoria","CATEGORIA"],imageFilename:["Imagen","image","Image","image_url","imagen","IMAGEN","foto","Foto"]};async function yo(e){if(e.name.toLowerCase().endsWith(".xls")&&!e.name.toLowerCase().endsWith(".xlsx"))throw new Error("El formato .xls (Excel 97-2003) no es compatible. Por favor guarda el archivo como .xlsx");return e.name.toLowerCase().endsWith(".zip")||e.type==="application/zip"||e.type==="application/x-zip-compressed"?wo(e):jo(e)}function da(e){switch(e.toLowerCase().split(".").pop()){case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"webp":return"image/webp";case"gif":return"image/gif";default:return"application/octet-stream"}}async function wo(e){const r=await go.loadAsync(e);let s=null;const a=new Map;if(r.forEach((o,l)=>{if(l.dir||o.startsWith(vo))return;const h=o.split("/").pop()?.toLowerCase()||"",p="."+h.split(".").pop();if(p===".xlsx")s||(s=l);else{if(p===".xls")throw new Error("El ZIP contiene un archivo .xls (Excel 97-2003) que no es compatible. Por favor convierte a .xlsx");bo.has(p)&&a.set(h,l)}}),!s)throw new Error("El ZIP debe contener un archivo Excel (.xlsx)");const n=await s.async("arraybuffer");return{rows:Rn(n),imageEntries:a,isZip:!0,fileName:e.name}}async function jo(e){const r=await e.arrayBuffer();return{rows:Rn(r),imageEntries:new Map,isZip:!1,fileName:e.name}}function Rn(e){const r=Ti(e,{type:"array"}),s=r.SheetNames[0];if(!s)throw new Error("El archivo Excel no contiene hojas");const a=r.Sheets[s],n=Ri.sheet_to_json(a);if(n.length===0)throw new Error("El archivo Excel no contiene filas de datos (solo encabezados)");if(n.length>ca)throw new Error(`El archivo excede el límite de ${ca} filas (tiene ${n.length})`);const i=n.map(ko);if(!i.some(l=>l.name!==void 0)&&i.length>0){const l=Object.values(Tn).flat(),h=Object.keys(n[0]);throw new Error(`No se reconocieron las columnas del Excel. Columnas encontradas: ${h.slice(0,5).join(", ")}${h.length>5?"...":""}. Esperadas: ${l.slice(0,6).join(", ")}...`)}return i}function ko(e){const r=_=>{const w=Tn[_];for(const g of w)if(e[g]!==void 0&&e[g]!==null&&e[g]!=="")return e[g]},s=r("name"),a=r("description"),n=r("price"),i=r("currency"),o=r("externalId"),l=r("externalCategory"),h=r("imageFilename"),p=n!==void 0?parseFloat(String(n)):void 0;return{name:s!=null?String(s).trim():void 0,description:a!=null?String(a).trim():void 0,price:p!==void 0&&!isNaN(p)?p:void 0,currency:i!=null?String(i).trim():void 0,externalId:o!=null?String(o).trim():void 0,externalCategory:l!=null?String(l).trim():void 0,imageFilename:h!=null?String(h).trim():void 0}}const _o=new Set(jn.map(e=>e.value)),No="USD";async function So(e,r,s){let a=0,n=0,i=0;const o=[],l=new Set,h=new Set,p=new Set;for(let g=0;g<e.length;g++){const d=e[g],k=g+2,u=[],x=[];(!d.name||d.name.trim()==="")&&u.push("Nombre es requerido"),d.name&&d.name.length>255&&u.push(`Nombre excede 255 caracteres (tiene ${d.name.length})`),d.description&&d.description.length>5e3&&u.push(`Descripción excede 5000 caracteres (tiene ${d.description.length})`);let f=!1;d.price===void 0||d.price===null||isNaN(d.price)?(u.push("Precio válido es requerido"),f=!0):d.price<0&&(u.push("Precio no puede ser negativo"),f=!0);const j=d.currency?.toUpperCase()||No;_o.has(j)||u.push(`Moneda '${d.currency}' no soportada. Válidas: USD, EUR, PEN, COP, MXN, CLP, ARS, BRL`),d.externalId&&d.externalId.length>100&&u.push(`SKU excede 100 caracteres (tiene ${d.externalId.length})`),d.externalCategory&&d.externalCategory.length>100&&u.push(`Categoría excede 100 caracteres (tiene ${d.externalCategory.length})`),!f&&d.price===0&&x.push("Precio es 0 — el producto se importará como gratuito");let E,P;if(d.imageFilename&&s){const B=d.imageFilename.toLowerCase();l.add(B);const U=r.get(B);if(U){h.add(B);try{E=await U.async("blob"),P=URL.createObjectURL(E)}catch{x.push(`No se pudo leer '${d.imageFilename}' del ZIP — se importará sin imagen`)}}else p.add(B),x.push(`Imagen '${d.imageFilename}' no encontrada en el ZIP — se importará sin imagen`)}else d.imageFilename&&!s&&x.push("Las imágenes solo se procesan desde archivos ZIP. Se importará sin imagen");const S=u.length>0?"error":"valid";S==="valid"?(a++,x.length>0&&i++):n++,o.push({rowNumber:k,status:S,data:{...d,currency:j,price:d.price!==void 0&&!isNaN(d.price)?Math.round(d.price*100)/100:d.price},errors:u,warnings:x,imageBlob:E,imagePreviewUrl:P})}const _=r.size,w=_-h.size;return{totalRows:e.length,validRows:a,invalidRows:n,warningRows:i,items:o,imageStats:{referencedInExcel:l.size,foundInZip:h.size,missingFromZip:p.size,totalImagesInZip:_,unreferencedInZip:w}}}function bs(e){for(const r of e)r.imagePreviewUrl&&(URL.revokeObjectURL(r.imagePreviewUrl),r.imagePreviewUrl=void 0)}const ua=50*1024*1024,$r=5,ha={image:{maxBytes:10*1024*1024},video:{maxBytes:0},audio:{maxBytes:0},document:{maxBytes:0}},vs=[{key:"upload",label:"Archivo"},{key:"preview",label:"Revisar"},{key:"uploading",label:"Procesar"},{key:"success",label:"Listo"}],ys={status:"idle",progress:{current:0,total:0},results:new Map,summary:{existing:0,new:0,toOptimize:0}};function Co({onSuccess:e,catalogs:r=[],trigger:s}){const[a,n]=Y.useState(!1),[i,o]=Y.useState("upload"),[l,h]=Y.useState(null),[p,_]=Y.useState(!1),[w,g]=Y.useState(""),[d,k]=Y.useState(null),[u,x]=Y.useState(null),[f,j]=Y.useState("all"),[E,P]=Y.useState({current:0,total:0,percent:0}),[S,B]=Y.useState({uploaded:0,deduplicated:0,failed:0,failedRows:[]}),[U,$]=Y.useState(0),[T,G]=Y.useState([]),[se,v]=Y.useState("all"),[R,m]=Y.useState(""),[V,ie]=Y.useState(""),q=Y.useRef(!1),ce=Y.useRef(null),[F,ee]=Y.useState(ys),O=Y.useRef(null),L=Y.useRef(null),ae=Os(I=>I.currentOrganization),{channels:te,fetchChannels:J}=an($t(I=>({channels:I.channels,fetchChannels:I.fetchChannels})));Y.useEffect(()=>{ae?.id&&a&&J({withDeleted:!1})},[ae?.id,a,J]);const ve=Y.useMemo(()=>te.filter(I=>I.isActive&&!I.deletedAt&&!I.disconnectedFromMetaAt&&!I.deactivatedAt&&!I.archivedAt),[te]),Se=Y.useMemo(()=>{if(ve.length===0)return ha;let I=1/0;for(const z of ve){const Z=Sn(z.type),H=z.config?.mediaLimits?.outbound?.image?.maxBytes??Z.outbound.image.maxBytes??1/0;H<I&&(I=H)}return{image:{maxBytes:I===1/0?ha.image.maxBytes:I},video:{maxBytes:0},audio:{maxBytes:0},document:{maxBytes:0}}},[ve]);Y.useEffect(()=>()=>{u&&bs(u.items)},[u]);const fe=Y.useMemo(()=>{if(!u)return[];switch(f){case"errors":return u.items.filter(I=>I.status==="error");case"warnings":return u.items.filter(I=>I.status==="valid"&&I.warnings.length>0);case"valid":return u.items.filter(I=>I.status==="valid"&&I.warnings.length===0);default:return u.items}},[u,f]),me=Y.useMemo(()=>{switch(se){case"inserted":return T.filter(I=>I.dbStatus==="inserted");case"failed":return T.filter(I=>I.dbStatus==="failed");case"skipped":return T.filter(I=>I.dbStatus==="skipped");case"image_issues":return T.filter(I=>I.imageStatus==="failed"||I.imageStatus==="missing_in_zip");default:return T}},[T,se]),ke=aa({count:fe.length,getScrollElement:()=>O.current,estimateSize:()=>52,overscan:10}),ye=aa({count:me.length,getScrollElement:()=>L.current,estimateSize:()=>44,overscan:10}),_e=Y.useMemo(()=>{const I=T.filter(re=>re.dbStatus==="inserted").length,z=T.filter(re=>re.dbStatus==="failed").length,Z=T.filter(re=>re.dbStatus==="skipped").length,H=T.filter(re=>re.imageStatus==="failed"||re.imageStatus==="missing_in_zip").length;return{inserted:I,failed:z,skipped:Z,imageIssues:H,total:T.length}},[T]),Re=Y.useCallback(()=>{u&&bs(u.items),o("upload"),h(null),_(!1),g(""),k(null),x(null),j("all"),P({current:0,total:0,percent:0}),B({uploaded:0,deduplicated:0,failed:0,failedRows:[]}),$(0),G([]),v("all"),m(""),ie(""),ee(ys),q.current=!1,ce.current&&(ce.current.abort(),ce.current=null)},[u]),c=I=>{n(I),I||setTimeout(Re,300)},K=Y.useCallback((I,z)=>{if(z.length>0){z[0]?.errors?.[0]?.code==="file-too-large"?ne.error(`Archivo muy grande. Máximo: ${ua/(1024*1024)} MB`):ne.error("Formato no válido. Usa .xlsx o .zip");return}I.length>0&&h(I[0])},[]),{getRootProps:M,getInputProps:C,isDragActive:N}=Oi({onDrop:K,accept:{"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/zip":[".zip"],"application/x-zip-compressed":[".zip"]},maxFiles:1,maxSize:ua}),D=async()=>{if(l){_(!0),m("Leyendo archivo...");try{const I=await yo(l);k(I),m(`Validando ${I.rows.length} filas...`);const z=await So(I.rows,I.imageEntries,I.isZip);x(z),j("all"),o("preview")}catch(I){ne.error(I.message||"Error al analizar el archivo")}finally{_(!1),m("")}}},X=Y.useCallback(async I=>{ee({status:"analyzing",progress:{current:0,total:I.length},results:new Map,summary:{existing:0,new:0,toOptimize:0}});const z=new Map;let Z=0,H=0,re=0,he=0;const ze=Se.image.maxBytes;for(let je=0;je<I.length;je+=$r){const Fe=I.slice(je,je+$r);await Promise.all(Fe.map(async ge=>{try{const xe=ge.data.imageFilename||"image.jpg",Ze=da(xe),$e=new File([ge.imageBlob],xe,{type:Ze}),Ae=$e.size,He=await $i.calculateHash($e),Qe=await wi.checkDuplicate(He),xt=Qe.exists&&!!Qe.gcsPath,mt=!xt&&ze>0&&Ae>ze;z.set(ge.rowNumber,{hash:He,isDuplicate:xt,gcsPath:Qe.gcsPath,willOptimize:mt,fileSizeBytes:Ae}),xt?Z++:(H++,mt&&re++)}catch{z.set(ge.rowNumber,{hash:"",isDuplicate:!1,willOptimize:!1,fileSizeBytes:0}),H++}finally{he++,ee(xe=>({...xe,progress:{current:he,total:I.length},results:new Map(z),summary:{existing:Z,new:H,toOptimize:re}}))}}))}ee(je=>({...je,status:"done"}))},[Se]);Y.useEffect(()=>{if(i==="preview"&&u){const I=u.items.filter(z=>z.status==="valid"&&z.imageBlob);I.length>0&&X(I)}},[i]);const y=async()=>{if(!u||!w){ne.error("Selecciona un catálogo para los productos importados");return}const I=u.items.filter(H=>H.status==="valid");if(I.length===0){ne.error("No hay productos válidos para importar");return}q.current=!1,o("uploading"),ie("images");const z={uploaded:0,deduplicated:0,failed:0,failedRows:[]},Z=new Map;for(const H of u.items)H.status!=="error"&&(H.data.imageFilename?!H.imageBlob&&H.warnings.some(re=>re.includes("no encontrada"))?Z.set(H.rowNumber,{status:"missing_in_zip"}):H.imageBlob||Z.set(H.rowNumber,{status:"none"}):Z.set(H.rowNumber,{status:"none"}));try{const H=I.filter(xe=>xe.imageBlob),re=H.length;P({current:0,total:re,percent:0});const he=new Map;if(re>0){let xe=0;for(let Ze=0;Ze<H.length&&!q.current;Ze+=$r){const $e=H.slice(Ze,Ze+$r);await Promise.all($e.map(async Ae=>{try{const He=Ae.data.imageFilename||"image.jpg",Qe=da(He),xt=new File([Ae.imageBlob],He,{type:Qe}),mt=await Cs.processFile(xt,{limits:Se});he.set(Ae.rowNumber,mt.gcsPath),mt.isDuplicate?(z.deduplicated++,Z.set(Ae.rowNumber,{status:"deduplicated"})):(z.uploaded++,Z.set(Ae.rowNumber,{status:"uploaded"}))}catch(He){z.failed++;const Qe=He.message||"Error desconocido";z.failedRows.push({rowNumber:Ae.rowNumber,name:Ae.data.name||"Sin nombre",error:Qe}),Z.set(Ae.rowNumber,{status:"failed",error:Qe})}finally{xe++,P({current:xe,total:re,percent:Math.round(xe/re*100)})}}))}}if(B({...z}),q.current){ne.info("Importación cancelada"),o("preview");return}const ze=I.map(xe=>({name:xe.data.name,description:xe.data.description||"",price:xe.data.price,currency:xe.data.currency||"USD",externalId:xe.data.externalId,externalCategory:xe.data.externalCategory,imageUrl:he.get(xe.rowNumber)||void 0}));ie("saving");const je=new AbortController;ce.current=je;const Fe=await we.bulkImportProducts(w,ze,je.signal);ce.current=null,$(Fe.inserted);const ge=[];for(const xe of u.items)xe.status==="error"&&ge.push({rowNumber:xe.rowNumber,name:xe.data.name||"Sin nombre",dbStatus:"skipped",imageStatus:"none"});I.forEach((xe,Ze)=>{const $e=Z.get(xe.rowNumber)||{status:"none"},Ae=Fe.results.find(Qe=>Qe.index===Ze);let He="skipped";Ae?.status==="inserted"?He="inserted":Ae?.status==="failed"&&(He="failed"),ge.push({rowNumber:xe.rowNumber,name:xe.data.name||"Sin nombre",dbStatus:He,imageStatus:$e.status,imageError:$e.error,dbError:Ae?.error,productId:Ae?.productId})}),ge.sort((xe,Ze)=>xe.rowNumber-Ze.rowNumber),G(ge),v("all"),o("success"),e()}catch(H){const re=H.response?.data?.message||H.message||"Error al importar productos";ne.error(Array.isArray(re)?re[0]:re),o("preview")}},b=async()=>{try{await we.downloadTemplate(),ne.success("Plantilla descargada")}catch{ne.error("Error al descargar plantilla")}},A=vs.findIndex(I=>I.key===i);return t.jsxs(nn,{open:a,onOpenChange:c,children:[t.jsx(ji,{asChild:!0,children:s??t.jsxs(ue,{variant:"outline",className:"gap-2",children:[t.jsx(Hr,{className:"h-4 w-4"}),"Importar"]})}),t.jsxs(on,{className:"sm:max-w-4xl max-h-[90vh] flex flex-col",children:[t.jsxs(ki,{children:[t.jsx(ln,{children:"Importación Masiva de Productos"}),t.jsx(cn,{className:"sr-only",children:"Wizard para importar productos desde un archivo Excel o ZIP"}),t.jsx("div",{className:"flex items-center gap-1 pt-2",children:vs.map((I,z)=>t.jsxs("div",{className:"flex items-center",children:[t.jsxs("div",{className:le("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium transition-colors",z<A&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",z===A&&"bg-primary/10 text-primary",z>A&&"bg-muted text-muted-foreground"),children:[z<A?t.jsx(rr,{className:"h-3.5 w-3.5"}):t.jsx("span",{className:le("w-4 h-4 rounded-full flex items-center justify-center text-[10px] font-bold",z===A?"bg-primary text-primary-foreground":"bg-muted-foreground/20 text-muted-foreground"),children:z+1}),I.label]}),z<vs.length-1&&t.jsx("div",{className:le("w-6 h-px mx-1",z<A?"bg-green-400":"bg-muted-foreground/20")})]},I.key))})]}),t.jsxs("div",{className:"flex-1 overflow-hidden py-3",children:[i==="upload"&&t.jsxs("div",{className:"h-full flex flex-col items-center justify-center space-y-4",children:[l?t.jsx(Rs,{className:"w-full max-w-lg",children:t.jsxs(Zs,{className:"p-6 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsx("div",{className:"p-2 bg-primary/10 rounded-md",children:t.jsx(Wr,{className:"h-8 w-8 text-primary"})}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium truncate max-w-[200px]",children:l.name}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:[(l.size/1024/1024).toFixed(2)," MB"]})]})]}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:I=>{I.stopPropagation(),h(null)},children:t.jsx(Ft,{className:"h-4 w-4"})})]})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{...M(),className:le("border-2 border-dashed rounded-lg p-10 text-center hover:bg-muted/50 cursor-pointer transition-colors w-full max-w-lg",N?"border-primary bg-primary/5":"border-muted-foreground/25"),children:[t.jsx("input",{...C()}),t.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[t.jsx("div",{className:"p-4 bg-primary/10 rounded-full",children:t.jsx(Hr,{className:"h-10 w-10 text-primary"})}),t.jsx("p",{className:"text-sm font-medium",children:"Arrastra tu archivo aquí o haz clic para seleccionar"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Formatos: .xlsx (Excel) o .zip (Excel + Imágenes) — Máx. 50 MB"})]})]}),t.jsx("div",{className:"w-full max-w-lg bg-blue-50/50 dark:bg-blue-950/10 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(dn,{className:"h-4 w-4 text-blue-600 mt-0.5 shrink-0"}),t.jsxs("div",{className:"space-y-1.5 text-xs",children:[t.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-200",children:"¿Cómo preparar tu archivo?"}),t.jsxs("div",{className:"text-blue-700 dark:text-blue-400 space-y-1",children:[t.jsxs("p",{children:[t.jsx("strong",{children:"Solo datos:"})," Sube un ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:".xlsx"})," con las columnas: Nombre, Precio, Descripción, Moneda, SKU, Categoría"]}),t.jsxs("p",{children:[t.jsx("strong",{children:"Con imágenes:"})," Crea un ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:".zip"})," que contenga el Excel + las imágenes. En la columna ",t.jsx("strong",{children:'"Imagen"'})," del Excel escribe el ",t.jsx("strong",{children:"nombre exacto del archivo"})," (ej: ",t.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"polo.jpg"}),")"]})]}),t.jsxs("div",{className:"bg-blue-100/50 dark:bg-blue-900/30 rounded p-2 font-mono text-[11px]",children:[t.jsx("span",{className:"text-blue-500",children:"mi_catalogo.zip"}),t.jsx("br",{})," ├── productos.xlsx",t.jsx("br",{})," ├── polo.jpg",t.jsx("br",{})," ├── laptop.png",t.jsx("br",{})," └── cafe.webp"]})]})]})}),t.jsxs(ue,{variant:"link",size:"sm",onClick:b,className:"text-muted-foreground gap-2",children:[t.jsx(Ui,{className:"h-4 w-4"}),"Descargar Plantilla Excel"]})]}),l&&t.jsxs("div",{className:"w-full max-w-lg space-y-1",children:[t.jsxs(ue,{onClick:D,disabled:p,className:"w-full",children:[p?t.jsx(be,{className:"animate-spin mr-2 h-4 w-4"}):t.jsx(Wt,{className:"mr-2 h-4 w-4"}),p?"Analizando...":"Analizar Archivo"]}),R&&t.jsx("p",{className:"text-xs text-center text-muted-foreground animate-pulse",children:R})]})]}),i==="preview"&&u&&t.jsxs("div",{className:"space-y-3 h-full flex flex-col",children:[t.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[t.jsx(Lr,{icon:t.jsx(rr,{className:"h-4 w-4 text-green-600"}),label:"Válidos",value:u.validRows,color:"green"}),t.jsx(Lr,{icon:t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),label:"Errores",value:u.invalidRows,color:"red"}),t.jsx(Lr,{icon:t.jsx(ct,{className:"h-4 w-4 text-amber-600"}),label:"Advertencias",value:u.warningRows,color:"amber",tooltip:"Productos válidos pero con observaciones (ej: imagen no encontrada)"}),t.jsx(Lr,{icon:t.jsx(Wr,{className:"h-4 w-4 text-blue-600"}),label:"Total",value:u.totalRows,color:"blue"})]}),d?.isZip&&u.imageStats.referencedInExcel>0&&t.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 dark:bg-slate-900/50 border rounded-lg px-3 py-2 text-xs",children:[t.jsx(At,{className:"h-4 w-4 text-slate-500 shrink-0"}),t.jsxs("span",{className:"text-slate-600 dark:text-slate-400",children:[t.jsx("strong",{children:u.imageStats.totalImagesInZip})," imágenes en ZIP"," · ",t.jsxs("span",{className:"text-green-600",children:[u.imageStats.foundInZip," vinculadas"]}),u.imageStats.missingFromZip>0&&t.jsxs(t.Fragment,{children:[" · ",t.jsxs("span",{className:"text-amber-600",children:[u.imageStats.missingFromZip," no encontradas"]})]}),u.imageStats.unreferencedInZip>0&&t.jsxs(t.Fragment,{children:[" · ",t.jsxs("span",{className:"text-slate-400",children:[u.imageStats.unreferencedInZip," sin usar"]})]})]})]}),F.status!=="idle"&&t.jsx("div",{className:"bg-violet-50 dark:bg-violet-900/10 border border-violet-200 dark:border-violet-800 rounded-lg px-3 py-2 text-xs",children:F.status==="analyzing"?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin text-violet-600 shrink-0"}),t.jsxs("span",{className:"text-violet-700 dark:text-violet-300",children:["Analizando imágenes... ",F.progress.current,"/",F.progress.total]}),t.jsx(qr,{value:F.progress.total>0?Math.round(F.progress.current/F.progress.total*100):0,className:"flex-1 h-1.5"})]}):t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsx(Wt,{className:"h-3.5 w-3.5 text-violet-600 shrink-0"}),t.jsx("span",{className:"text-violet-700 dark:text-violet-300 font-medium",children:"Análisis completo:"}),F.summary.existing>0&&t.jsxs("span",{className:"text-green-600 dark:text-green-400 flex items-center gap-0.5",children:[t.jsx(br,{className:"h-3 w-3"}),F.summary.existing," ya existen"]}),t.jsxs("span",{className:"text-blue-600 dark:text-blue-400 flex items-center gap-0.5",children:[t.jsx(vr,{className:"h-3 w-3"}),F.summary.new," nuevas"]}),F.summary.toOptimize>0&&t.jsxs("span",{className:"text-amber-600 dark:text-amber-400 flex items-center gap-0.5",children:[t.jsx(Wt,{className:"h-3 w-3"}),F.summary.toOptimize," se optimizarán"]})]})}),t.jsxs("div",{className:"flex items-center gap-3 bg-amber-50 dark:bg-amber-900/10 border border-amber-200 dark:border-amber-800 rounded-lg p-3",children:[t.jsx(dt,{className:"h-5 w-5 text-amber-600 shrink-0"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-amber-900 dark:text-amber-200",children:"Catálogo destino"}),t.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:r.length===0?"Primero debes crear un catálogo para asignar los productos":"Todos los productos se asignarán a este catálogo"})]}),r.length>0?t.jsxs(sr,{value:w,onValueChange:g,children:[t.jsx(ar,{className:"w-[200px] bg-white dark:bg-slate-900",children:t.jsx(nr,{placeholder:"Seleccionar..."})}),t.jsx(ir,{children:r.map(I=>t.jsx(kt,{value:I.id,children:I.name},I.id))})]}):t.jsx(Ce,{variant:"outline",className:"text-amber-700 border-amber-300",children:"Sin catálogos"})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Mostrar:"}),[{key:"all",label:"Todos",count:u.totalRows},{key:"errors",label:"Errores",count:u.invalidRows},{key:"warnings",label:"Advertencias",count:u.warningRows},{key:"valid",label:"Sin problemas",count:u.validRows-u.warningRows}].map(I=>t.jsxs("button",{onClick:()=>j(I.key),className:le("px-2 py-0.5 rounded text-xs font-medium transition-colors",f===I.key?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80",I.count===0&&"opacity-50"),disabled:I.count===0,children:[I.label," (",I.count,")"]},I.key))]}),t.jsxs("div",{className:"border rounded-md flex-1 overflow-hidden",children:[t.jsx(Qr,{children:t.jsx(Yr,{children:t.jsxs(or,{children:[t.jsx(De,{className:"w-[50px]",children:"Fila"}),t.jsx(De,{className:"w-[80px]",children:"Estado"}),t.jsx(De,{className:"w-[70px]",children:"Imagen"}),t.jsx(De,{children:"Nombre / SKU"}),t.jsx(De,{className:"w-[90px]",children:"Precio"}),t.jsx(De,{children:"Detalles"})]})})}),t.jsx("div",{ref:O,className:"h-[268px] overflow-auto",children:fe.length===0?t.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"No hay filas con este filtro"}):t.jsx("div",{style:{height:`${ke.getTotalSize()}px`,width:"100%",position:"relative"},children:ke.getVirtualItems().map(I=>{const z=fe[I.index],Z={position:"absolute",top:0,left:0,width:"100%",height:`${I.size}px`,transform:`translateY(${I.start}px)`};return t.jsxs("div",{style:Z,className:le("flex items-center border-b text-sm px-2",z.status==="error"&&"bg-red-50/50 dark:bg-red-950/10",z.status==="valid"&&z.warnings.length>0&&"bg-amber-50/30 dark:bg-amber-950/5"),children:[t.jsx("div",{className:"w-[50px] shrink-0 font-mono text-xs",children:z.rowNumber}),t.jsx("div",{className:"w-[80px] shrink-0",children:z.status==="error"?t.jsx(Ce,{variant:"destructive",className:"text-[10px]",children:"Error"}):z.warnings.length>0?t.jsx(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px]",children:"Aviso"}):t.jsx(Ce,{className:"bg-green-100 text-green-800 hover:bg-green-100 border-green-200 text-[10px]",children:"OK"})}),t.jsx("div",{className:"w-[70px] shrink-0",children:t.jsxs("div",{className:"flex items-center gap-1",children:[z.imagePreviewUrl?t.jsx("div",{className:"h-8 w-8 relative rounded overflow-hidden border shrink-0",children:t.jsx("img",{src:z.imagePreviewUrl,alt:"",className:"object-cover w-full h-full",loading:"lazy"})}):z.data.imageFilename?t.jsx("div",{className:"h-8 w-8 bg-amber-50 dark:bg-amber-900/20 flex items-center justify-center rounded border border-amber-200 shrink-0",children:t.jsx(On,{className:"h-3 w-3 text-amber-500"})}):t.jsx("span",{className:"text-muted-foreground text-xs",children:"—"}),F.results.has(z.rowNumber)&&(()=>{const H=F.results.get(z.rowNumber);return H.isDuplicate?t.jsx(Ce,{variant:"outline",className:"text-[8px] px-1 py-0 h-3.5 bg-green-50 text-green-600 border-green-200 whitespace-nowrap",children:"Existe"}):H.willOptimize?t.jsx(Ce,{variant:"outline",className:"text-[8px] px-1 py-0 h-3.5 bg-amber-50 text-amber-600 border-amber-200 whitespace-nowrap",children:"Optim."}):null})()]})}),t.jsxs("div",{className:"flex-1 min-w-0 pr-2",children:[t.jsx("div",{className:"font-medium text-sm truncate",children:z.data.name||t.jsx("span",{className:"text-red-500 italic",children:"Sin nombre"})}),z.data.externalId&&t.jsx("div",{className:"text-[11px] text-muted-foreground font-mono truncate",children:z.data.externalId})]}),t.jsx("div",{className:"w-[90px] shrink-0 font-mono text-xs text-right",children:zr(z.data.price,z.data.currency)}),t.jsxs("div",{className:"flex-1 min-w-0 text-[11px]",children:[z.errors.length>0&&t.jsxs("span",{className:"text-red-600 truncate block",children:[z.errors[0],z.errors.length>1&&` (+${z.errors.length-1})`]}),z.warnings.length>0&&t.jsxs("span",{className:"text-amber-600 truncate block",children:[z.warnings[0],z.warnings.length>1&&` (+${z.warnings.length-1})`]}),z.errors.length===0&&z.warnings.length===0&&t.jsx("span",{className:"text-muted-foreground truncate block",children:z.data.description})]})]},z.rowNumber)})})})]})]}),i==="uploading"&&t.jsxs("div",{className:"h-full flex flex-col items-center justify-center space-y-5",children:[t.jsx("div",{className:"w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center",children:t.jsx(be,{className:"h-8 w-8 text-primary animate-spin"})}),t.jsxs("div",{className:"space-y-3 text-center w-full max-w-md",children:[t.jsx("h3",{className:"text-lg font-semibold",children:V==="saving"?"Guardando en base de datos":"Procesando importación"}),V==="saving"?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Insertando ",u?.validRows||0," productos en el servidor..."]}),t.jsx(qr,{value:100,className:"h-2 animate-pulse"}),E.total>0&&t.jsxs("div",{className:"flex justify-center gap-4 text-xs text-muted-foreground",children:[S.uploaded>0&&t.jsxs("span",{className:"flex items-center gap-1 text-green-600",children:[t.jsx(vr,{className:"h-3 w-3"})," ",S.uploaded," subidas"]}),S.deduplicated>0&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-600",children:[t.jsx(br,{className:"h-3 w-3"})," ",S.deduplicated," reutilizadas"]})]})]}):E.total>0?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Imagen ",E.current," de ",E.total]}),t.jsx(qr,{value:E.percent,className:"h-2"}),t.jsxs("div",{className:"flex justify-center gap-4 text-xs text-muted-foreground",children:[S.uploaded>0&&t.jsxs("span",{className:"flex items-center gap-1 text-green-600",children:[t.jsx(vr,{className:"h-3 w-3"})," ",S.uploaded," subidas"]}),S.deduplicated>0&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-600",children:[t.jsx(br,{className:"h-3 w-3"})," ",S.deduplicated," reutilizadas"]}),S.failed>0&&t.jsxs("span",{className:"flex items-center gap-1 text-red-600",children:[t.jsx(Dt,{className:"h-3 w-3"})," ",S.failed," fallidas"]})]})]}):t.jsx("p",{className:"text-sm text-muted-foreground animate-pulse",children:"Preparando productos..."})]}),t.jsx(ue,{variant:"outline",size:"sm",onClick:()=>{q.current=!0,ce.current&&ce.current.abort()},children:"Cancelar"})]}),i==="success"&&t.jsxs("div",{className:"h-full flex flex-col space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-3 bg-green-50 dark:bg-green-950/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[t.jsx("div",{className:"w-10 h-10 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center shrink-0 animate-in zoom-in duration-500",children:t.jsx(uo,{className:"h-5 w-5 text-green-600"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm font-bold text-green-900 dark:text-green-200",children:"¡Importación Exitosa!"}),t.jsxs("p",{className:"text-xs text-green-700 dark:text-green-400",children:[U," productos creados en tu catálogo"]})]})]}),t.jsxs("div",{className:"grid grid-cols-5 gap-2",children:[t.jsx(fr,{icon:t.jsx(Ot,{className:"h-3.5 w-3.5 text-green-600"}),label:"Insertados",value:_e.inserted,color:"green"}),t.jsx(fr,{icon:t.jsx(vr,{className:"h-3.5 w-3.5 text-emerald-600"}),label:"Img subidas",value:S.uploaded,color:"emerald"}),t.jsx(fr,{icon:t.jsx(br,{className:"h-3.5 w-3.5 text-blue-600"}),label:"Img reutilizadas",value:S.deduplicated,color:"blue"}),t.jsx(fr,{icon:t.jsx(Dt,{className:"h-3.5 w-3.5 text-red-600"}),label:"Error DB",value:_e.failed,color:"red"}),t.jsx(fr,{icon:t.jsx(un,{className:"h-3.5 w-3.5 text-amber-600"}),label:"Omitidos",value:_e.skipped,color:"amber"})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Filtrar:"}),[{key:"all",label:"Todos",count:_e.total},{key:"inserted",label:"Insertados",count:_e.inserted},{key:"failed",label:"Error DB",count:_e.failed},{key:"skipped",label:"Omitidos",count:_e.skipped},{key:"image_issues",label:"Problemas imagen",count:_e.imageIssues}].map(I=>t.jsxs("button",{onClick:()=>v(I.key),className:le("px-2 py-0.5 rounded text-xs font-medium transition-colors",se===I.key?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80",I.count===0&&"opacity-50"),disabled:I.count===0,children:[I.label," (",I.count,")"]},I.key))]}),t.jsxs("div",{className:"border rounded-md flex-1 overflow-hidden",children:[t.jsx(Qr,{children:t.jsx(Yr,{children:t.jsxs(or,{children:[t.jsx(De,{className:"w-[50px]",children:"Fila"}),t.jsx(De,{children:"Producto"}),t.jsx(De,{className:"w-[120px]",children:"Base de Datos"}),t.jsx(De,{className:"w-[150px]",children:"Imagen"}),t.jsx(De,{children:"Detalle"})]})})}),t.jsx("div",{ref:L,className:"h-[248px] overflow-auto",children:me.length===0?t.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"No hay filas con este filtro"}):t.jsx("div",{style:{height:`${ye.getTotalSize()}px`,width:"100%",position:"relative"},children:ye.getVirtualItems().map(I=>{const z=me[I.index],Z={position:"absolute",top:0,left:0,width:"100%",height:`${I.size}px`,transform:`translateY(${I.start}px)`};return t.jsxs("div",{style:Z,className:le("flex items-center border-b text-sm px-2",z.dbStatus==="skipped"&&"bg-red-50/50 dark:bg-red-950/10",z.imageStatus==="failed"&&z.dbStatus!=="skipped"&&"bg-amber-50/30 dark:bg-amber-950/5"),children:[t.jsx("div",{className:"w-[50px] shrink-0 font-mono text-xs",children:z.rowNumber}),t.jsx("div",{className:"flex-1 min-w-0 pr-2",children:t.jsx("span",{className:"text-sm font-medium truncate block",children:z.name})}),t.jsx("div",{className:"w-[120px] shrink-0",children:t.jsx(zo,{status:z.dbStatus,error:z.dbError})}),t.jsx("div",{className:"w-[150px] shrink-0",children:t.jsx(Eo,{status:z.imageStatus})}),t.jsxs("div",{className:"flex-1 min-w-0 text-[11px] text-muted-foreground",children:[z.dbStatus==="skipped"&&"Error de validación",z.imageStatus==="failed"&&z.imageError&&t.jsx("span",{className:"text-amber-600 truncate block",children:z.imageError}),z.imageStatus==="missing_in_zip"&&t.jsx("span",{className:"text-amber-600",children:"No en ZIP"}),z.dbStatus==="inserted"&&z.imageStatus!=="failed"&&z.imageStatus!=="missing_in_zip"&&t.jsx("span",{className:"text-green-600",children:"✓"})]})]},z.rowNumber)})})})]})]})]}),t.jsxs(_i,{children:[i==="upload"&&t.jsx(ue,{variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),i==="preview"&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{variant:"outline",onClick:()=>{u&&bs(u.items),o("upload"),h(null),k(null),x(null),ee(ys)},children:"Atrás"}),t.jsxs(ue,{onClick:y,disabled:u?.validRows===0||!w,children:["Confirmar Importación (",u?.validRows," productos)"]})]}),i==="success"&&t.jsxs(t.Fragment,{children:[t.jsxs(ue,{variant:"outline",onClick:Re,className:"gap-2",children:[t.jsx(Bi,{className:"h-3.5 w-3.5"}),"Importar Otro"]}),t.jsx(ue,{onClick:()=>n(!1),children:"Cerrar"})]})]})]})]})}function Lr({icon:e,label:r,value:s,color:a,tooltip:n}){const i={green:"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-800",red:"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-800",amber:"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800",blue:"bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-800"},o={green:"text-green-700 dark:text-green-400",red:"text-red-700 dark:text-red-400",amber:"text-amber-700 dark:text-amber-400",blue:"text-blue-700 dark:text-blue-400"},l=t.jsx(Rs,{className:i[a],children:t.jsxs(Zs,{className:"p-3 flex items-center gap-2",children:[e,t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-medium text-muted-foreground",children:r}),t.jsx("p",{className:le("text-xl font-bold",o[a]),children:s})]})]})});return n?t.jsx(Ar,{children:t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:l}),t.jsx(rt,{children:t.jsx("p",{className:"text-xs",children:n})})]})}):l}function fr({icon:e,label:r,value:s,color:a}){const n={green:"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-800",emerald:"bg-emerald-50 dark:bg-emerald-950/20 border-emerald-200 dark:border-emerald-800",blue:"bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-800",red:"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-800",amber:"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800"},i={green:"text-green-700 dark:text-green-400",emerald:"text-emerald-700 dark:text-emerald-400",blue:"text-blue-700 dark:text-blue-400",red:"text-red-700 dark:text-red-400",amber:"text-amber-700 dark:text-amber-400"};return t.jsxs("div",{className:le("rounded-lg border p-2 flex items-center gap-1.5",n[a]),children:[e,t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-medium text-muted-foreground truncate",children:r}),t.jsx("p",{className:le("text-lg font-bold leading-none",i[a]),children:s})]})]})}function zo({status:e,error:r}){return e==="inserted"?t.jsxs(Ce,{className:"bg-green-100 text-green-800 hover:bg-green-100 border-green-200 text-[10px] gap-1",children:[t.jsx(Ot,{className:"h-3 w-3"}),"Insertado"]}):e==="failed"?t.jsx(Ar,{children:t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsxs(Ce,{variant:"destructive",className:"text-[10px] gap-1 cursor-help",children:[t.jsx(Dt,{className:"h-3 w-3"}),"Error DB"]})}),t.jsx(rt,{side:"top",className:"max-w-xs text-xs",children:r||"Error en transacción de base de datos"})]})}):t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(un,{className:"h-3 w-3"}),"Omitido"]})}function Eo({status:e}){switch(e){case"uploaded":return t.jsxs(Ce,{className:"bg-emerald-100 text-emerald-800 hover:bg-emerald-100 border-emerald-200 text-[10px] gap-1",children:[t.jsx(vr,{className:"h-3 w-3"}),"Subida"]});case"deduplicated":return t.jsxs(Ce,{className:"bg-blue-100 text-blue-800 hover:bg-blue-100 border-blue-200 text-[10px] gap-1",children:[t.jsx(br,{className:"h-3 w-3"}),"Reutilizada"]});case"failed":return t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(Dt,{className:"h-3 w-3"}),"Fallida"]});case"missing_in_zip":return t.jsxs(Ce,{className:"bg-amber-100 text-amber-800 hover:bg-amber-100 border-amber-200 text-[10px] gap-1",children:[t.jsx(On,{className:"h-3 w-3"}),"No en ZIP"]});case"none":return t.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted-foreground",children:[t.jsx(io,{className:"h-3 w-3"}),"Sin imagen"]})}}const pe={all:["products"],list:e=>[...pe.all,"list",e],detail:e=>[...pe.all,"detail",e],catalogs:()=>[...pe.all,"catalogs"],qdrantStatus:()=>[...pe.all,"qdrant-status"],qdrantOrphans:e=>[...pe.all,"qdrant-orphans",e],catalogFeedConfig:()=>[...pe.all,"catalog-feed","config"],shopifyConfig:()=>[...pe.all,"shopify","config"]};async function zs(e){try{const r=await we.getQdrantStatus(!0);e.setQueryData(pe.qdrantStatus(),r),e.invalidateQueries({queryKey:[...pe.all,"qdrant-orphans"]})}catch(r){console.warn("[Qdrant] Failed to refresh status cache:",r),e.invalidateQueries({queryKey:pe.qdrantStatus()})}}function Io(e={}){return ur({queryKey:pe.list(e),queryFn:()=>we.getProducts(e),placeholderData:hn,staleTime:1e3*60})}function Ao(){return ur({queryKey:pe.catalogs(),queryFn:()=>we.getCatalogs(),staleTime:1e3*60*5})}function Po(){const e=Ke();return Ge({mutationFn:r=>we.createProduct(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto creado")},onError:r=>ne.error(r.message||"Error al crear producto")})}function Fo(){const e=Ke();return Ge({mutationFn:({id:r,dto:s})=>we.updateProduct(r,s),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto actualizado")},onError:r=>ne.error(r.message||"Error al actualizar producto")})}function Do(){const e=Ke();return Ge({mutationFn:r=>we.deleteProduct(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.all}),ne.success("Producto eliminado permanentemente")},onError:r=>ne.error(r.message||"Error al eliminar producto")})}function Oo(){const e=Ke();return Ge({mutationFn:({id:r,isActive:s})=>we.toggleProductActive(r,s),onSuccess:(r,s)=>{e.invalidateQueries({queryKey:pe.all}),ne.success(s.isActive?"Producto activado":"Producto desactivado")},onError:r=>ne.error(r.message||"Error al cambiar estado")})}function To(){const e=Ke();return Ge({mutationFn:({ids:r,isActive:s})=>we.bulkToggleActive(r,s),onSuccess:({affected:r},s)=>{e.invalidateQueries({queryKey:pe.all});const a=s.isActive?"activado":"desactivado";ne.success(`${r} producto${r>1?"s":""} ${a}${r>1?"s":""}`)},onError:r=>ne.error(r.message||"Error en operación masiva")})}function Ro(){const e=Ke();return Ge({mutationFn:r=>we.bulkDelete(r),onSuccess:({affected:r})=>{e.invalidateQueries({queryKey:pe.all}),ne.success(`${r} producto${r>1?"s":""} eliminado${r>1?"s":""} permanentemente`)},onError:r=>ne.error(r.message||"Error al eliminar productos")})}function Zo(){const e=Ke();return Ge({mutationFn:r=>we.createCatalog(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Catálogo creado")},onError:r=>ne.error(r.message||"Error al crear catálogo")})}function $o(){const e=Ke();return Ge({mutationFn:({id:r,dto:s})=>we.updateCatalog(r,s),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),e.invalidateQueries({queryKey:pe.all}),ne.success("Catálogo actualizado")},onError:r=>ne.error(r.message||"Error al actualizar catálogo")})}function Lo(){const e=Ke();return Ge({mutationFn:r=>we.deleteCatalog(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogs()}),e.invalidateQueries({queryKey:pe.all}),ne.success("Catálogo eliminado")},onError:r=>ne.error(r.message||"Error al eliminar catálogo")})}function Uo(e=!0){return ur({queryKey:pe.qdrantStatus(),queryFn:()=>we.getQdrantStatus(),enabled:e,staleTime:1e3*60*5,refetchOnWindowFocus:!1,retry:1})}function Bo(){const e=Ke();return Ge({mutationFn:()=>we.getQdrantStatus(!0),onSuccess:r=>{e.setQueryData(pe.qdrantStatus(),r),e.invalidateQueries({queryKey:[...pe.all,"qdrant-orphans"]}),ne.success("Estado de consistencia actualizado")},onError:r=>ne.error(r.message||"Error al actualizar estado")})}function Mo(){const e=Ke();return Ge({mutationFn:()=>we.purgeQdrantOrphans(),onSuccess:async({deleted:r})=>{ne.success(`${r} registro${r!==1?"s":""} obsoleto${r!==1?"s":""} eliminado${r!==1?"s":""} del índice`),await zs(e)},onError:r=>ne.error(r.message||"Error al limpiar registros obsoletos")})}function Vo(e,r=!0){return ur({queryKey:pe.qdrantOrphans(e),queryFn:()=>we.getQdrantOrphans(e,10),enabled:r,staleTime:1e3*60*5,refetchOnWindowFocus:!1,placeholderData:hn})}function qo(){const e=Ke();return Ge({mutationFn:r=>we.syncMissingProducts(r),onSuccess:({queued:r})=>{ne.success(`${r} producto${r!==1?"s":""} enviado${r!==1?"s":""} a reindexar`),setTimeout(()=>zs(e),2500),setTimeout(()=>zs(e),6e3)},onError:r=>ne.error(r.message||"Error al reindexar productos")})}function Wo(){return Ge({mutationFn:e=>we.searchDebug(e),onError:e=>ne.error(e.message||"Error en búsqueda vectorial")})}function Ko(e=!0){return ur({queryKey:pe.catalogFeedConfig(),queryFn:()=>we.getCatalogFeedConfig(),enabled:e,staleTime:1e3*30,refetchOnWindowFocus:!1})}function Go(){const e=Ke();return Ge({mutationFn:r=>we.configureCatalogFeed(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Configuración guardada")},onError:r=>ne.error(r.message||"Error al guardar la configuración")})}function Ho(){const e=Ke();return Ge({mutationFn:()=>we.disableCatalogFeed(),onSuccess:()=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),ne.success("Sincronización desactivada")},onError:r=>ne.error(r.message||"Error al desactivar")})}function Qo(){const e=Ke();return Ge({mutationFn:()=>we.syncCatalogFeed(),onSuccess:r=>{e.invalidateQueries({queryKey:pe.catalogFeedConfig()}),e.invalidateQueries({queryKey:pe.all});const s=[];r.created&&s.push(`${r.created} nuevos`),r.updated&&s.push(`${r.updated} actualizados`),r.reactivated&&s.push(`${r.reactivated} reactivados`),r.deactivated&&s.push(`${r.deactivated} desactivados`),ne.success(s.length>0?`Sincronización completada: ${s.join(", ")}`:`Sincronización completada (${r.total} productos)`)},onError:r=>ne.error(r.message||"Error en la sincronización")})}function Yo(e=!0){return ur({queryKey:pe.shopifyConfig(),queryFn:()=>we.getShopifyConfig(),enabled:e,staleTime:1e3*30,refetchOnWindowFocus:!1})}function Xo(){const e=Ke();return Ge({mutationFn:r=>we.configureShopify(r),onSuccess:()=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),e.invalidateQueries({queryKey:pe.catalogs()}),ne.success("Tienda Shopify conectada")},onError:r=>ne.error(r.message||"Error al conectar Shopify")})}function Jo(){const e=Ke();return Ge({mutationFn:()=>we.disableShopify(),onSuccess:()=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),ne.success("Integración de Shopify desactivada")},onError:r=>ne.error(r.message||"Error al desactivar")})}function el(){const e=Ke();return Ge({mutationFn:()=>we.syncShopify(),onSuccess:r=>{e.invalidateQueries({queryKey:pe.shopifyConfig()}),e.invalidateQueries({queryKey:pe.all});const s=[];r.created&&s.push(`${r.created} nuevos`),r.updated&&s.push(`${r.updated} actualizados`),r.reactivated&&s.push(`${r.reactivated} reactivados`),r.deactivated&&s.push(`${r.deactivated} desactivados`),ne.success(s.length>0?`Sincronización completada: ${s.join(", ")}`:`Sincronización completada (${r.total} productos)`)},onError:r=>ne.error(r.message||"Error en la sincronización")})}function tl({trigger:e}){const[r,s]=Y.useState(!1),[a,n]=Y.useState(""),[i,o]=Y.useState(""),[l,h]=Y.useState(!1),p=Ko(r),_=Go(),w=Ho(),g=Qo(),d=p.data??null;Y.useEffect(()=>{d&&n(d.feedUrl)},[d]);const k=()=>{const S=a.trim(),B=i.trim();S&&(!d&&!B||_.mutate({feedUrl:S,catalogName:B||"Catálogo Externo"},{onSuccess:()=>o("")}))},u=()=>{g.mutate()},x=()=>{w.mutate(void 0,{onSuccess:()=>h(!1)})},f=_.isPending||g.isPending||w.isPending,j=d?.lastSyncStatus==="running"||g.isPending,E=a.trim().length>0&&(d!==null||i.trim().length>0),P=d!==null&&d.isActive&&!j;return t.jsxs(t.Fragment,{children:[t.jsxs(jr,{open:r,onOpenChange:s,children:[t.jsx(mn,{asChild:!0,children:e}),t.jsxs(kr,{side:"right",className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",children:[t.jsxs(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800",children:[t.jsxs(Nr,{className:"flex items-center gap-2 text-lg",children:[t.jsx(fn,{className:"h-5 w-5 text-primary"}),"Importar desde catálogo externo"]}),t.jsx(Kr,{children:"Sincroniza productos automáticamente desde un Meta Catalog Feed (JSON). Configura la URL una vez y la plataforma actualizará los productos cada noche."})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:p.isLoading?t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsx(be,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.jsxs(t.Fragment,{children:[d&&t.jsxs("div",{className:le("rounded-lg border p-3 text-sm",d.lastSyncStatus==="success"&&"bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-800",d.lastSyncStatus==="failed"&&"bg-red-50 dark:bg-red-950/30 border-red-200 dark:border-red-800",d.lastSyncStatus==="running"&&"bg-amber-50 dark:bg-amber-950/30 border-amber-200 dark:border-amber-800",d.lastSyncStatus==="idle"&&"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[d.lastSyncStatus==="success"&&t.jsx(rr,{className:"h-4 w-4 text-green-600"}),d.lastSyncStatus==="failed"&&t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),d.lastSyncStatus==="running"&&t.jsx(be,{className:"h-4 w-4 animate-spin text-amber-600"}),d.lastSyncStatus==="idle"&&t.jsx(Pr,{className:"h-4 w-4 text-slate-500"}),t.jsxs("span",{className:"font-semibold",children:[d.lastSyncStatus==="idle"&&"Sin ejecutar",d.lastSyncStatus==="running"&&"Sincronizando…",d.lastSyncStatus==="success"&&"Última sincronización OK",d.lastSyncStatus==="failed"&&"Última sincronización falló"]})]}),!d.isActive&&t.jsx(Ce,{variant:"outline",className:"text-xs",children:"Desactivada"})]}),d.lastSyncAt&&t.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:[as(d.lastSyncAt)," · ",d.lastSyncCount," producto",d.lastSyncCount!==1?"s":""," afectados"]}),d.lastSyncError&&t.jsx("p",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400 break-words",children:d.lastSyncError})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"feed-url",children:"URL del Meta Catalog Feed"}),t.jsx(st,{id:"feed-url",type:"url",placeholder:"https://www.datapath.ai/api/meta/catalog",value:a,onChange:S=>n(S.target.value),disabled:f}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Debe ser una URL pública (https) que devuelva JSON en formato Meta Catalog Feed."})]}),!d&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"catalog-name",children:"Nombre del catálogo destino"}),t.jsx(st,{id:"catalog-name",type:"text",placeholder:"Ej. Cursos Datapath",value:i,onChange:S=>o(S.target.value),maxLength:100,disabled:f}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Si ya existe un catálogo con ese nombre, se reutilizará. Si no, se creará uno nuevo."})]}),t.jsx("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 text-xs text-blue-900 dark:text-blue-200",children:'Los productos se sincronizan automáticamente cada noche a las 00:00 hora Lima. Puedes disparar una sincronización manual con el botón "Sincronizar ahora".'})]})}),t.jsxs("div",{className:"border-t border-slate-100 dark:border-slate-800 px-6 py-4 flex items-center justify-between gap-2",children:[t.jsx("div",{children:d&&t.jsxs(ue,{type:"button",variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30",onClick:()=>h(!0),disabled:f,children:[t.jsx(bt,{className:"h-3.5 w-3.5 mr-1.5"}),"Desactivar"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ue,{type:"button",variant:"outline",onClick:k,disabled:!E||f,children:_.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Guardando…"]}):"Guardar"}),t.jsx(ue,{type:"button",onClick:u,disabled:!P||f,className:"bg-primary hover:bg-primary/90",children:g.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Sincronizando…"]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-4 w-4 mr-1.5"}),"Sincronizar ahora"]})})]})]})]})]}),t.jsx(Kt,{open:l,onOpenChange:h,children:t.jsxs(Gt,{children:[t.jsxs(Ht,{children:[t.jsx(Qt,{children:"¿Desactivar la sincronización?"}),t.jsx(Yt,{children:"La sincronización automática se detendrá. Los productos ya importados se conservan tal cual; podrás reactivarla más adelante volviendo a guardar la URL."})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{disabled:w.isPending,children:"Cancelar"}),t.jsx(er,{onClick:x,disabled:w.isPending,className:"bg-red-600 hover:bg-red-700",children:w.isPending?t.jsx(be,{className:"h-4 w-4 animate-spin"}):"Desactivar"})]})]})})]})}function rl({trigger:e}){const[r,s]=Y.useState(!1),[a,n]=Y.useState(""),[i,o]=Y.useState(""),[l,h]=Y.useState(""),[p,_]=Y.useState(""),[w,g]=Y.useState(!1),d=Yo(r),k=Xo(),u=Jo(),x=el(),f=d.data??null;Y.useEffect(()=>{f&&(n(f.shopDomain),o(f.clientId))},[f]);const j=()=>{const T=a.trim(),G=i.trim(),se=l.trim(),v=p.trim();T&&(!f&&(!G||!se||!v)||k.mutate({shopDomain:T,...G?{clientId:G}:{},...se?{clientSecret:se}:{},...v?{catalogName:v}:{}},{onSuccess:()=>{h(""),_("")}}))},E=()=>{x.mutate()},P=()=>{u.mutate(void 0,{onSuccess:()=>g(!1)})},S=k.isPending||x.isPending||u.isPending,B=f?.lastSyncStatus==="running"||x.isPending,U=a.trim().length>0&&(f!==null||i.trim().length>0&&l.trim().length>0&&p.trim().length>0),$=f!==null&&f.isActive&&!B;return t.jsxs(t.Fragment,{children:[t.jsxs(jr,{open:r,onOpenChange:s,children:[t.jsx(mn,{asChild:!0,children:e}),t.jsxs(kr,{side:"right",className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",children:[t.jsxs(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800",children:[t.jsxs(Nr,{className:"flex items-center gap-2 text-lg",children:[t.jsx(kn,{className:"h-5 w-5 text-primary"}),"Importar desde Shopify"]}),t.jsx(Kr,{children:"Conecta tu tienda Shopify una vez y la plataforma importará tus productos y los mantendrá actualizados cada noche."})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:d.isLoading?t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsx(be,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.jsxs(t.Fragment,{children:[f&&t.jsxs("div",{className:le("rounded-lg border p-3 text-sm",f.lastSyncStatus==="success"&&"bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-800",f.lastSyncStatus==="failed"&&"bg-red-50 dark:bg-red-950/30 border-red-200 dark:border-red-800",f.lastSyncStatus==="running"&&"bg-amber-50 dark:bg-amber-950/30 border-amber-200 dark:border-amber-800",f.lastSyncStatus==="idle"&&"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[f.lastSyncStatus==="success"&&t.jsx(rr,{className:"h-4 w-4 text-green-600"}),f.lastSyncStatus==="failed"&&t.jsx(Dt,{className:"h-4 w-4 text-red-600"}),f.lastSyncStatus==="running"&&t.jsx(be,{className:"h-4 w-4 animate-spin text-amber-600"}),f.lastSyncStatus==="idle"&&t.jsx(Pr,{className:"h-4 w-4 text-slate-500"}),t.jsxs("span",{className:"font-semibold",children:[f.lastSyncStatus==="idle"&&"Sin ejecutar",f.lastSyncStatus==="running"&&"Sincronizando…",f.lastSyncStatus==="success"&&"Última sincronización OK",f.lastSyncStatus==="failed"&&"Última sincronización falló"]})]}),!f.isActive&&t.jsx(Ce,{variant:"outline",className:"text-xs",children:"Desactivada"})]}),f.lastSyncAt&&t.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:[as(f.lastSyncAt)," ·"," ",f.lastSyncCount," producto",f.lastSyncCount!==1?"s":""," afectados"]}),f.lastSyncError&&t.jsx("p",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400 break-words",children:f.lastSyncError})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-domain",children:"Dominio de la tienda"}),t.jsx(st,{id:"shopify-domain",type:"text",placeholder:"mitienda.myshopify.com",value:a,onChange:T=>n(T.target.value),disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"El dominio permanente de tu tienda (termina en .myshopify.com)."})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-client-id",children:"ID de cliente (Client ID)"}),t.jsx(st,{id:"shopify-client-id",type:"text",autoComplete:"off",placeholder:"f1657b1a5035fc8390…",value:i,onChange:T=>o(T.target.value),disabled:S})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-client-secret",children:"Secreto (Client secret)"}),t.jsx(st,{id:"shopify-client-secret",type:"password",autoComplete:"off",placeholder:f?"•••••••• (guardado — déjalo vacío para mantenerlo)":"Secreto de la app",value:l,onChange:T=>h(T.target.value),disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"En el dev dashboard de tu app: Configuración → Credenciales → copia el “ID de cliente” y el “Secreto”. La app debe estar instalada en tu tienda con el permiso read_products."})]}),!f&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(yt,{htmlFor:"shopify-catalog-name",children:"Nombre del catálogo destino"}),t.jsx(st,{id:"shopify-catalog-name",type:"text",placeholder:"Ej. Tienda Shopify",value:p,onChange:T=>_(T.target.value),maxLength:100,disabled:S}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Si ya existe un catálogo con ese nombre, se reutilizará. Si no, se creará uno nuevo."})]}),t.jsx("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 text-xs text-blue-900 dark:text-blue-200",children:"Los productos se sincronizan automáticamente cada noche a las 00:15 hora Lima. Puedes disparar una sincronización manual con el botón “Sincronizar ahora”."})]})}),t.jsxs("div",{className:"border-t border-slate-100 dark:border-slate-800 px-6 py-4 flex items-center justify-between gap-2",children:[t.jsx("div",{children:f&&t.jsxs(ue,{type:"button",variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30",onClick:()=>g(!0),disabled:S,children:[t.jsx(bt,{className:"h-3.5 w-3.5 mr-1.5"}),"Desactivar"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ue,{type:"button",variant:"outline",onClick:j,disabled:!U||S,children:k.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Guardando…"]}):f?"Guardar":"Conectar"}),t.jsx(ue,{type:"button",onClick:E,disabled:!$||S,className:"bg-primary hover:bg-primary/90",children:x.isPending?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-1.5"}),"Sincronizando…"]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-4 w-4 mr-1.5"}),"Sincronizar ahora"]})})]})]})]})]}),t.jsx(Kt,{open:w,onOpenChange:g,children:t.jsxs(Gt,{children:[t.jsxs(Ht,{children:[t.jsx(Qt,{children:"¿Desactivar la sincronización de Shopify?"}),t.jsx(Yt,{children:"La sincronización automática se detendrá. Los productos ya importados se conservan tal cual; podrás reactivarla más adelante volviendo a conectar la tienda."})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{disabled:u.isPending,children:"Cancelar"}),t.jsx(er,{onClick:P,disabled:u.isPending,className:"bg-red-600 hover:bg-red-700",children:u.isPending?t.jsx(be,{className:"h-4 w-4 animate-spin"}):"Desactivar"})]})]})})]})}var Or=e=>e.type==="checkbox",Pt=e=>e instanceof Date,nt=e=>e==null;const Zn=e=>typeof e=="object";var Me=e=>!nt(e)&&!Array.isArray(e)&&Zn(e)&&!Pt(e),sl=e=>Me(e)&&e.target?Or(e.target)?e.target.checked:e.target.value:e,al=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,nl=(e,r)=>e.has(al(r)),il=e=>{const r=e.constructor&&e.constructor.prototype;return Me(r)&&r.hasOwnProperty("isPrototypeOf")},Us=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function We(e){if(e instanceof Date)return new Date(e);const r=typeof FileList<"u"&&e instanceof FileList;if(Us&&(e instanceof Blob||r))return e;const s=Array.isArray(e);if(!s&&!(Me(e)&&il(e)))return e;const a=s?[]:Object.create(Object.getPrototypeOf(e));for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(a[n]=We(e[n]));return a}var ns=e=>/^\w*$/.test(e),Oe=e=>e===void 0,Bs=e=>Array.isArray(e)?e.filter(Boolean):[],Ms=e=>Bs(e.replace(/["|']|\]/g,"").split(/\.|\[/)),oe=(e,r,s)=>{if(!r||!Me(e))return s;const a=(ns(r)?[r]:Ms(r)).reduce((n,i)=>nt(n)?n:n[i],e);return Oe(a)||a===e?Oe(e[r])?s:e[r]:a},gt=e=>typeof e=="boolean",ft=e=>typeof e=="function",Ee=(e,r,s)=>{let a=-1;const n=ns(r)?[r]:Ms(r),i=n.length,o=i-1;for(;++a<i;){const l=n[a];let h=s;if(a!==o){const p=e[l];h=Me(p)||Array.isArray(p)?p:isNaN(+n[a+1])?{}:[]}if(l==="__proto__"||l==="constructor"||l==="prototype")return;e[l]=h,e=e[l]}};const ma={BLUR:"blur",FOCUS_OUT:"focusout"},pt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},vt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},ol=Xe.createContext(null);ol.displayName="HookFormControlContext";var ll=(e,r,s,a=!0)=>{const n={defaultValues:r._defaultValues};for(const i in e)Object.defineProperty(n,i,{get:()=>{const o=i;return r._proxyFormState[o]!==pt.all&&(r._proxyFormState[o]=!a||pt.all),e[o]}});return n};const cl=typeof window<"u"?Xe.useLayoutEffect:Xe.useEffect;var lt=e=>typeof e=="string",dl=(e,r,s,a,n)=>lt(e)?(a&&r.watch.add(e),oe(s,e,n)):Array.isArray(e)?e.map(i=>(a&&r.watch.add(i),oe(s,i))):(a&&(r.watchAll=!0),s),Es=e=>nt(e)||!Zn(e);function jt(e,r,s=new WeakSet){if(Es(e)||Es(r))return Object.is(e,r);if(Pt(e)&&Pt(r))return Object.is(e.getTime(),r.getTime());const a=Object.keys(e),n=Object.keys(r);if(a.length!==n.length)return!1;if(s.has(e)||s.has(r))return!0;s.add(e),s.add(r);for(const i of a){const o=e[i];if(!n.includes(i))return!1;if(i!=="ref"){const l=r[i];if(Pt(o)&&Pt(l)||Me(o)&&Me(l)||Array.isArray(o)&&Array.isArray(l)?!jt(o,l,s):!Object.is(o,l))return!1}}return!0}const ul=Xe.createContext(null);ul.displayName="HookFormContext";var Vs=(e,r,s,a,n)=>r?{...s[e],types:{...s[e]&&s[e].types?s[e].types:{},[a]:n||!0}}:{},yr=e=>Array.isArray(e)?e:[e],fa=()=>{let e=[];return{get observers(){return e},next:n=>{for(const i of e)i.next&&i.next(n)},subscribe:n=>(e.push(n),{unsubscribe:()=>{e=e.filter(i=>i!==n)}}),unsubscribe:()=>{e=[]}}};function $n(e,r){const s={};for(const a in e)if(e.hasOwnProperty(a)){const n=e[a],i=r[a];if(n&&Me(n)&&i){const o=$n(n,i);Me(o)&&(s[a]=o)}else e[a]&&(s[a]=i)}return s}var Je=e=>Me(e)&&!Object.keys(e).length,qs=e=>e.type==="file",Xr=e=>{if(!Us)return!1;const r=e?e.ownerDocument:0;return e instanceof(r&&r.defaultView?r.defaultView.HTMLElement:HTMLElement)},Ln=e=>e.type==="select-multiple",Ws=e=>e.type==="radio",hl=e=>Ws(e)||Or(e),ws=e=>Xr(e)&&e.isConnected;function ml(e,r){const s=r.slice(0,-1).length;let a=0;for(;a<s;)e=Oe(e)?a++:e[r[a++]];return e}function fl(e){for(const r in e)if(e.hasOwnProperty(r)&&!Oe(e[r]))return!1;return!0}function Be(e,r){const s=Array.isArray(r)?r:ns(r)?[r]:Ms(r),a=s.length===1?e:ml(e,s),n=s.length-1,i=s[n];return a&&delete a[i],n!==0&&(Me(a)&&Je(a)||Array.isArray(a)&&fl(a))&&Be(e,s.slice(0,-1)),e}var pl=e=>{for(const r in e)if(ft(e[r]))return!0;return!1};function Un(e){return Array.isArray(e)||Me(e)&&!pl(e)}function Is(e,r={}){for(const s in e){const a=e[s];Un(a)?(r[s]=Array.isArray(a)?[]:{},Is(a,r[s])):Oe(a)||(r[s]=!0)}return r}function Vt(e,r,s){s||(s=Is(r));for(const a in e){const n=e[a];if(Un(n))Oe(r)||Es(s[a])?s[a]=Is(n,Array.isArray(n)?[]:{}):Vt(n,nt(r)?{}:r[a],s[a]);else{const i=r[a];s[a]=!jt(n,i)}}return s}const pa={value:!1,isValid:!1},xa={value:!0,isValid:!0};var Bn=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter(s=>s&&s.checked&&!s.disabled).map(s=>s.value);return{value:r,isValid:!!r.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Oe(e[0].attributes.value)?Oe(e[0].value)||e[0].value===""?xa:{value:e[0].value,isValid:!0}:xa:pa}return pa},Mn=(e,{valueAsNumber:r,valueAsDate:s,setValueAs:a})=>Oe(e)?e:r?e===""?NaN:e&&+e:s&<(e)?new Date(e):a?a(e):e;const ga={isValid:!1,value:null};var Vn=e=>Array.isArray(e)?e.reduce((r,s)=>s&&s.checked&&!s.disabled?{isValid:!0,value:s.value}:r,ga):ga;function ba(e){const r=e.ref;return qs(r)?r.files:Ws(r)?Vn(e.refs).value:Ln(r)?[...r.selectedOptions].map(({value:s})=>s):Or(r)?Bn(e.refs).value:Mn(Oe(r.value)?e.ref.value:r.value,e)}var xl=(e,r,s,a)=>{const n={};for(const i of e){const o=oe(r,i);o&&Ee(n,i,o._f)}return{criteriaMode:s,names:[...e],fields:n,shouldUseNativeValidation:a}},Jr=e=>e instanceof RegExp,pr=e=>Oe(e)?e:Jr(e)?e.source:Me(e)?Jr(e.value)?e.value.source:e.value:e,va=e=>({isOnSubmit:!e||e===pt.onSubmit,isOnBlur:e===pt.onBlur,isOnChange:e===pt.onChange,isOnAll:e===pt.all,isOnTouch:e===pt.onTouched});const ya="AsyncFunction";var gl=e=>!!e&&!!e.validate&&!!(ft(e.validate)&&e.validate.constructor.name===ya||Me(e.validate)&&Object.values(e.validate).find(r=>r.constructor.name===ya)),bl=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),wa=(e,r,s)=>!s&&(r.watchAll||r.watch.has(e)||[...r.watch].some(a=>e.startsWith(a)&&/^\.\w+/.test(e.slice(a.length))));const wr=(e,r,s,a)=>{for(const n of s||Object.keys(e)){const i=oe(e,n);if(i){const{_f:o,...l}=i;if(o){if(o.refs&&o.refs[0]&&r(o.refs[0],n)&&!a)return!0;if(o.ref&&r(o.ref,o.name)&&!a)return!0;if(wr(l,r))break}else if(Me(l)&&wr(l,r))break}}};function ja(e,r,s){const a=oe(e,s);if(a||ns(s))return{error:a,name:s};const n=s.split(".");for(;n.length;){const i=n.join("."),o=oe(r,i),l=oe(e,i);if(o&&!Array.isArray(o)&&s!==i)return{name:s};if(l&&l.type)return{name:i,error:l};if(l&&l.root&&l.root.type)return{name:`${i}.root`,error:l.root};n.pop()}return{name:s}}var vl=(e,r,s,a)=>{s(e);const{name:n,...i}=e;return Je(i)||Object.keys(i).length>=Object.keys(r).length||Object.keys(i).find(o=>r[o]===(!a||pt.all))},yl=(e,r,s)=>!e||!r||e===r||yr(e).some(a=>a&&(s?a===r:a.startsWith(r)||r.startsWith(a))),wl=(e,r,s,a,n)=>n.isOnAll?!1:!s&&n.isOnTouch?!(r||e):(s?a.isOnBlur:n.isOnBlur)?!e:(s?a.isOnChange:n.isOnChange)?e:!0,jl=(e,r)=>!Bs(oe(e,r)).length&&Be(e,r),kl=(e,r,s)=>{const a=yr(oe(e,s));return Ee(a,"root",r[s]),Ee(e,s,a),e};function ka(e,r,s="validate"){if(lt(e)||Array.isArray(e)&&e.every(lt)||gt(e)&&!e)return{type:s,message:lt(e)?e:"",ref:r}}var Mt=e=>Me(e)&&!Jr(e)?e:{value:e,message:""},_a=async(e,r,s,a,n,i)=>{const{ref:o,refs:l,required:h,maxLength:p,minLength:_,min:w,max:g,pattern:d,validate:k,name:u,valueAsNumber:x,mount:f}=e._f,j=oe(s,u);if(!f||r.has(u))return{};const E=l?l[0]:o,P=v=>{n&&E.reportValidity&&(E.setCustomValidity(gt(v)?"":v||""),E.reportValidity())},S={},B=Ws(o),U=Or(o),$=B||U,T=(x||qs(o))&&Oe(o.value)&&Oe(j)||Xr(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,G=Vs.bind(null,u,a,S),se=(v,R,m,V=vt.maxLength,ie=vt.minLength)=>{const q=v?R:m;S[u]={type:v?V:ie,message:q,ref:o,...G(v?V:ie,q)}};if(i?!Array.isArray(j)||!j.length:h&&(!$&&(T||nt(j))||gt(j)&&!j||U&&!Bn(l).isValid||B&&!Vn(l).isValid)){const{value:v,message:R}=lt(h)?{value:!!h,message:h}:Mt(h);if(v&&(S[u]={type:vt.required,message:R,ref:E,...G(vt.required,R)},!a))return P(R),S}if(!T&&(!nt(w)||!nt(g))){let v,R;const m=Mt(g),V=Mt(w);if(!nt(j)&&!isNaN(j)){const ie=o.valueAsNumber||j&&+j;nt(m.value)||(v=ie>m.value),nt(V.value)||(R=ie<V.value)}else{const ie=o.valueAsDate||new Date(j),q=ee=>new Date(new Date().toDateString()+" "+ee),ce=o.type=="time",F=o.type=="week";lt(m.value)&&j&&(v=ce?q(j)>q(m.value):F?j>m.value:ie>new Date(m.value)),lt(V.value)&&j&&(R=ce?q(j)<q(V.value):F?j<V.value:ie<new Date(V.value))}if((v||R)&&(se(!!v,m.message,V.message,vt.max,vt.min),!a))return P(S[u].message),S}if((p||_)&&!T&&(lt(j)||i&&Array.isArray(j))){const v=Mt(p),R=Mt(_),m=!nt(v.value)&&j.length>+v.value,V=!nt(R.value)&&j.length<+R.value;if((m||V)&&(se(m,v.message,R.message),!a))return P(S[u].message),S}if(d&&!T&<(j)){const{value:v,message:R}=Mt(d);if(Jr(v)&&!j.match(v)&&(S[u]={type:vt.pattern,message:R,ref:o,...G(vt.pattern,R)},!a))return P(R),S}if(k){if(ft(k)){const v=await k(j,s),R=ka(v,E);if(R&&(S[u]={...R,...G(vt.validate,R.message)},!a))return P(R.message),S}else if(Me(k)){let v={};for(const R in k){if(!Je(v)&&!a)break;const m=ka(await k[R](j,s),E,R);m&&(v={...m,...G(R,m.message)},P(m.message),a&&(S[u]=v))}if(!Je(v)&&(S[u]={ref:E,...v},!a))return S}}return P(!0),S};const _l={mode:pt.onSubmit,reValidateMode:pt.onChange,shouldFocusError:!0};function Nl(e={}){let r={..._l,...e},s={submitCount:0,isDirty:!1,isReady:!1,isLoading:ft(r.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:r.errors||{},disabled:r.disabled||!1},a={},n=Me(r.defaultValues)||Me(r.values)?We(r.defaultValues||r.values)||{}:{},i=r.shouldUnregister?{}:We(n),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},l={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},h,p=0;const _={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={..._};let g={...w};const d={array:fa(),state:fa()},k=r.criteriaMode===pt.all,u=y=>b=>{clearTimeout(p),p=setTimeout(y,b)},x=async y=>{if(!o.keepIsValid&&!r.disabled&&(w.isValid||g.isValid||y)){let b;r.resolver?(b=Je((await $()).errors),f()):b=await G(a,!0),b!==s.isValid&&d.state.next({isValid:b})}},f=(y,b)=>{!r.disabled&&(w.isValidating||w.validatingFields||g.isValidating||g.validatingFields)&&((y||Array.from(l.mount)).forEach(A=>{A&&(b?Ee(s.validatingFields,A,b):Be(s.validatingFields,A))}),d.state.next({validatingFields:s.validatingFields,isValidating:!Je(s.validatingFields)}))},j=(y,b=[],A,I,z=!0,Z=!0)=>{if(I&&A&&!r.disabled){if(o.action=!0,Z&&Array.isArray(oe(a,y))){const H=A(oe(a,y),I.argA,I.argB);z&&Ee(a,y,H)}if(Z&&Array.isArray(oe(s.errors,y))){const H=A(oe(s.errors,y),I.argA,I.argB);z&&Ee(s.errors,y,H),jl(s.errors,y)}if((w.touchedFields||g.touchedFields)&&Z&&Array.isArray(oe(s.touchedFields,y))){const H=A(oe(s.touchedFields,y),I.argA,I.argB);z&&Ee(s.touchedFields,y,H)}(w.dirtyFields||g.dirtyFields)&&(s.dirtyFields=Vt(n,i)),d.state.next({name:y,isDirty:v(y,b),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else Ee(i,y,b)},E=(y,b)=>{Ee(s.errors,y,b),d.state.next({errors:s.errors})},P=y=>{s.errors=y,d.state.next({errors:s.errors,isValid:!1})},S=(y,b,A,I)=>{const z=oe(a,y);if(z){const Z=oe(i,y,Oe(A)?oe(n,y):A);Oe(Z)||I&&I.defaultChecked||b?Ee(i,y,b?Z:ba(z._f)):V(y,Z),o.mount&&!o.action&&x()}},B=(y,b,A,I,z)=>{let Z=!1,H=!1;const re={name:y};if(!r.disabled){if(!A||I){(w.isDirty||g.isDirty)&&(H=s.isDirty,s.isDirty=re.isDirty=v(),Z=H!==re.isDirty);const he=jt(oe(n,y),b);H=!!oe(s.dirtyFields,y),he?Be(s.dirtyFields,y):Ee(s.dirtyFields,y,!0),re.dirtyFields=s.dirtyFields,Z=Z||(w.dirtyFields||g.dirtyFields)&&H!==!he}if(A){const he=oe(s.touchedFields,y);he||(Ee(s.touchedFields,y,A),re.touchedFields=s.touchedFields,Z=Z||(w.touchedFields||g.touchedFields)&&he!==A)}Z&&z&&d.state.next(re)}return Z?re:{}},U=(y,b,A,I)=>{const z=oe(s.errors,y),Z=(w.isValid||g.isValid)&>(b)&&s.isValid!==b;if(r.delayError&&A?(h=u(()=>E(y,A)),h(r.delayError)):(clearTimeout(p),h=null,A?Ee(s.errors,y,A):Be(s.errors,y)),(A?!jt(z,A):z)||!Je(I)||Z){const H={...I,...Z&>(b)?{isValid:b}:{},errors:s.errors,name:y};s={...s,...H},d.state.next(H)}},$=async y=>(f(y,!0),await r.resolver(i,r.context,xl(y||l.mount,a,r.criteriaMode,r.shouldUseNativeValidation))),T=async y=>{const{errors:b}=await $(y);if(f(y),y)for(const A of y){const I=oe(b,A);I?Ee(s.errors,A,I):Be(s.errors,A)}else s.errors=b;return b},G=async(y,b,A={valid:!0})=>{for(const I in y){const z=y[I];if(z){const{_f:Z,...H}=z;if(Z){const re=l.array.has(Z.name),he=z._f&&gl(z._f);he&&w.validatingFields&&f([Z.name],!0);const ze=await _a(z,l.disabled,i,k,r.shouldUseNativeValidation&&!b,re);if(he&&w.validatingFields&&f([Z.name]),ze[Z.name]&&(A.valid=!1,b||e.shouldUseNativeValidation))break;!b&&(oe(ze,Z.name)?re?kl(s.errors,ze,Z.name):Ee(s.errors,Z.name,ze[Z.name]):Be(s.errors,Z.name))}!Je(H)&&await G(H,b,A)}}return A.valid},se=()=>{for(const y of l.unMount){const b=oe(a,y);b&&(b._f.refs?b._f.refs.every(A=>!ws(A)):!ws(b._f.ref))&&fe(y)}l.unMount=new Set},v=(y,b)=>!r.disabled&&(y&&b&&Ee(i,y,b),!jt(O(),n)),R=(y,b,A)=>dl(y,l,{...o.mount?i:Oe(b)?n:lt(y)?{[y]:b}:b},A,b),m=y=>Bs(oe(o.mount?i:n,y,r.shouldUnregister?oe(n,y,[]):[])),V=(y,b,A={})=>{const I=oe(a,y);let z=b;if(I){const Z=I._f;Z&&(!Z.disabled&&Ee(i,y,Mn(b,Z)),z=Xr(Z.ref)&&nt(b)?"":b,Ln(Z.ref)?[...Z.ref.options].forEach(H=>H.selected=z.includes(H.value)):Z.refs?Or(Z.ref)?Z.refs.forEach(H=>{(!H.defaultChecked||!H.disabled)&&(Array.isArray(z)?H.checked=!!z.find(re=>re===H.value):H.checked=z===H.value||!!z)}):Z.refs.forEach(H=>H.checked=H.value===z):qs(Z.ref)?Z.ref.value="":(Z.ref.value=z,Z.ref.type||d.state.next({name:y,values:We(i)})))}(A.shouldDirty||A.shouldTouch)&&B(y,z,A.shouldTouch,A.shouldDirty,!0),A.shouldValidate&&ee(y)},ie=(y,b,A)=>{for(const I in b){if(!b.hasOwnProperty(I))return;const z=b[I],Z=y+"."+I,H=oe(a,Z);(l.array.has(y)||Me(z)||H&&!H._f)&&!Pt(z)?ie(Z,z,A):V(Z,z,A)}},q=(y,b,A={})=>{const I=oe(a,y),z=l.array.has(y),Z=We(b);Ee(i,y,Z),z?(d.array.next({name:y,values:We(i)}),(w.isDirty||w.dirtyFields||g.isDirty||g.dirtyFields)&&A.shouldDirty&&d.state.next({name:y,dirtyFields:Vt(n,i),isDirty:v(y,Z)})):I&&!I._f&&!nt(Z)?ie(y,Z,A):V(y,Z,A),wa(y,l)?d.state.next({...s,name:y,values:We(i)}):d.state.next({name:o.mount?y:void 0,values:We(i)})},ce=async y=>{o.mount=!0;const b=y.target;let A=b.name,I=!0;const z=oe(a,A),Z=he=>{I=Number.isNaN(he)||Pt(he)&&isNaN(he.getTime())||jt(he,oe(i,A,he))},H=va(r.mode),re=va(r.reValidateMode);if(z){let he,ze;const je=b.type?ba(z._f):sl(y),Fe=y.type===ma.BLUR||y.type===ma.FOCUS_OUT,ge=!bl(z._f)&&!r.resolver&&!oe(s.errors,A)&&!z._f.deps||wl(Fe,oe(s.touchedFields,A),s.isSubmitted,re,H),xe=wa(A,l,Fe);Ee(i,A,je),Fe?(!b||!b.readOnly)&&(z._f.onBlur&&z._f.onBlur(y),h&&h(0)):z._f.onChange&&z._f.onChange(y);const Ze=B(A,je,Fe),$e=!Je(Ze)||xe;if(!Fe&&d.state.next({name:A,type:y.type,values:We(i)}),ge)return(w.isValid||g.isValid)&&(r.mode==="onBlur"?Fe&&x():Fe||x()),$e&&d.state.next({name:A,...xe?{}:Ze});if(!Fe&&xe&&d.state.next({...s}),r.resolver){const{errors:Ae}=await $([A]);if(f([A]),Z(je),I){const He=ja(s.errors,a,A),Qe=ja(Ae,a,He.name||A);he=Qe.error,A=Qe.name,ze=Je(Ae)}}else f([A],!0),he=(await _a(z,l.disabled,i,k,r.shouldUseNativeValidation))[A],f([A]),Z(je),I&&(he?ze=!1:(w.isValid||g.isValid)&&(ze=await G(a,!0)));I&&(z._f.deps&&(!Array.isArray(z._f.deps)||z._f.deps.length>0)&&ee(z._f.deps),U(A,ze,he,Ze))}},F=(y,b)=>{if(oe(s.errors,b)&&y.focus)return y.focus(),1},ee=async(y,b={})=>{let A,I;const z=yr(y);if(r.resolver){const Z=await T(Oe(y)?y:z);A=Je(Z),I=y?!z.some(H=>oe(Z,H)):A}else y?(I=(await Promise.all(z.map(async Z=>{const H=oe(a,Z);return await G(H&&H._f?{[Z]:H}:H)}))).every(Boolean),!(!I&&!s.isValid)&&x()):I=A=await G(a);return d.state.next({...!lt(y)||(w.isValid||g.isValid)&&A!==s.isValid?{}:{name:y},...r.resolver||!y?{isValid:A}:{},errors:s.errors}),b.shouldFocus&&!I&&wr(a,F,y?z:l.mount),I},O=(y,b)=>{let A={...o.mount?i:n};return b&&(A=$n(b.dirtyFields?s.dirtyFields:s.touchedFields,A)),Oe(y)?A:lt(y)?oe(A,y):y.map(I=>oe(A,I))},L=(y,b)=>({invalid:!!oe((b||s).errors,y),isDirty:!!oe((b||s).dirtyFields,y),error:oe((b||s).errors,y),isValidating:!!oe(s.validatingFields,y),isTouched:!!oe((b||s).touchedFields,y)}),ae=y=>{const b=y?yr(y):void 0;b?.forEach(A=>Be(s.errors,A)),b?b.forEach(A=>{d.state.next({name:A,errors:s.errors})}):d.state.next({errors:{}})},te=(y,b,A)=>{const I=(oe(a,y,{_f:{}})._f||{}).ref,z=oe(s.errors,y)||{},{ref:Z,message:H,type:re,...he}=z;Ee(s.errors,y,{...he,...b,ref:I}),d.state.next({name:y,errors:s.errors,isValid:!1}),A&&A.shouldFocus&&I&&I.focus&&I.focus()},J=(y,b)=>ft(y)?d.state.subscribe({next:A=>"values"in A&&y(R(void 0,b),A)}):R(y,b,!0),ve=y=>d.state.subscribe({next:b=>{yl(y.name,b.name,y.exact)&&vl(b,y.formState||w,N,y.reRenderRoot)&&y.callback({values:{...i},...s,...b,defaultValues:n})}}).unsubscribe,Se=y=>(o.mount=!0,g={...g,...y.formState},ve({...y,formState:{..._,...y.formState}})),fe=(y,b={})=>{for(const A of y?yr(y):l.mount)l.mount.delete(A),l.array.delete(A),b.keepValue||(Be(a,A),Be(i,A)),!b.keepError&&Be(s.errors,A),!b.keepDirty&&Be(s.dirtyFields,A),!b.keepTouched&&Be(s.touchedFields,A),!b.keepIsValidating&&Be(s.validatingFields,A),!r.shouldUnregister&&!b.keepDefaultValue&&Be(n,A);d.state.next({values:We(i)}),d.state.next({...s,...b.keepDirty?{isDirty:v()}:{}}),!b.keepIsValid&&x()},me=({disabled:y,name:b})=>{if(gt(y)&&o.mount||y||l.disabled.has(b)){const z=l.disabled.has(b)!==!!y;y?l.disabled.add(b):l.disabled.delete(b),z&&o.mount&&!o.action&&x()}},ke=(y,b={})=>{let A=oe(a,y);const I=gt(b.disabled)||gt(r.disabled);return Ee(a,y,{...A||{},_f:{...A&&A._f?A._f:{ref:{name:y}},name:y,mount:!0,...b}}),l.mount.add(y),A?me({disabled:gt(b.disabled)?b.disabled:r.disabled,name:y}):S(y,!0,b.value),{...I?{disabled:b.disabled||r.disabled}:{},...r.progressive?{required:!!b.required,min:pr(b.min),max:pr(b.max),minLength:pr(b.minLength),maxLength:pr(b.maxLength),pattern:pr(b.pattern)}:{},name:y,onChange:ce,onBlur:ce,ref:z=>{if(z){ke(y,b),A=oe(a,y);const Z=Oe(z.value)&&z.querySelectorAll&&z.querySelectorAll("input,select,textarea")[0]||z,H=hl(Z),re=A._f.refs||[];if(H?re.find(he=>he===Z):Z===A._f.ref)return;Ee(a,y,{_f:{...A._f,...H?{refs:[...re.filter(ws),Z,...Array.isArray(oe(n,y))?[{}]:[]],ref:{type:Z.type,name:y}}:{ref:Z}}}),S(y,!1,void 0,Z)}else A=oe(a,y,{}),A._f&&(A._f.mount=!1),(r.shouldUnregister||b.shouldUnregister)&&!(nl(l.array,y)&&o.action)&&l.unMount.add(y)}}},ye=()=>r.shouldFocusError&&wr(a,F,l.mount),_e=y=>{gt(y)&&(d.state.next({disabled:y}),wr(a,(b,A)=>{const I=oe(a,A);I&&(b.disabled=I._f.disabled||y,Array.isArray(I._f.refs)&&I._f.refs.forEach(z=>{z.disabled=I._f.disabled||y}))},0,!1))},Re=(y,b)=>async A=>{let I;A&&(A.preventDefault&&A.preventDefault(),A.persist&&A.persist());let z=We(i);if(d.state.next({isSubmitting:!0}),r.resolver){const{errors:Z,values:H}=await $();f(),s.errors=Z,z=We(H)}else await G(a);if(l.disabled.size)for(const Z of l.disabled)Be(z,Z);if(Be(s.errors,"root"),Je(s.errors)){d.state.next({errors:{}});try{await y(z,A)}catch(Z){I=Z}}else b&&await b({...s.errors},A),ye(),setTimeout(ye);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Je(s.errors)&&!I,submitCount:s.submitCount+1,errors:s.errors}),I)throw I},c=(y,b={})=>{oe(a,y)&&(Oe(b.defaultValue)?q(y,We(oe(n,y))):(q(y,b.defaultValue),Ee(n,y,We(b.defaultValue))),b.keepTouched||Be(s.touchedFields,y),b.keepDirty||(Be(s.dirtyFields,y),s.isDirty=b.defaultValue?v(y,We(oe(n,y))):v()),b.keepError||(Be(s.errors,y),w.isValid&&x()),d.state.next({...s}))},K=(y,b={})=>{const A=y?We(y):n,I=We(A),z=Je(y),Z=z?n:I;if(b.keepDefaultValues||(n=A),!b.keepValues){if(b.keepDirtyValues){const H=new Set([...l.mount,...Object.keys(Vt(n,i))]);for(const re of Array.from(H)){const he=oe(s.dirtyFields,re),ze=oe(i,re),je=oe(Z,re);he&&!Oe(ze)?Ee(Z,re,ze):!he&&!Oe(je)&&q(re,je)}}else{if(Us&&Oe(y))for(const H of l.mount){const re=oe(a,H);if(re&&re._f){const he=Array.isArray(re._f.refs)?re._f.refs[0]:re._f.ref;if(Xr(he)){const ze=he.closest("form");if(ze){ze.reset();break}}}}if(b.keepFieldsRef)for(const H of l.mount)q(H,oe(Z,H));else a={}}i=r.shouldUnregister?b.keepDefaultValues?We(n):{}:We(Z),d.array.next({values:{...Z}}),d.state.next({values:{...Z}})}l={mount:b.keepDirtyValues?l.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!w.isValid||!!b.keepIsValid||!!b.keepDirtyValues||!r.shouldUnregister&&!Je(Z),o.watch=!!r.shouldUnregister,o.keepIsValid=!!b.keepIsValid,o.action=!1,b.keepErrors||(s.errors={}),d.state.next({submitCount:b.keepSubmitCount?s.submitCount:0,isDirty:z?!1:b.keepDirty?s.isDirty:!!(b.keepDefaultValues&&!jt(y,n)),isSubmitted:b.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:z?{}:b.keepDirtyValues?b.keepDefaultValues&&i?Vt(n,i):s.dirtyFields:b.keepDefaultValues&&y?Vt(n,y):b.keepDirty?s.dirtyFields:{},touchedFields:b.keepTouched?s.touchedFields:{},errors:b.keepErrors?s.errors:{},isSubmitSuccessful:b.keepIsSubmitSuccessful?s.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:n})},M=(y,b)=>K(ft(y)?y(i):y,{...r.resetOptions,...b}),C=(y,b={})=>{const A=oe(a,y),I=A&&A._f;if(I){const z=I.refs?I.refs[0]:I.ref;z.focus&&setTimeout(()=>{z.focus(),b.shouldSelect&&ft(z.select)&&z.select()})}},N=y=>{s={...s,...y}},X={control:{register:ke,unregister:fe,getFieldState:L,handleSubmit:Re,setError:te,_subscribe:ve,_runSchema:$,_updateIsValidating:f,_focusError:ye,_getWatch:R,_getDirty:v,_setValid:x,_setFieldArray:j,_setDisabledField:me,_setErrors:P,_getFieldArray:m,_reset:K,_resetDefaultValues:()=>ft(r.defaultValues)&&r.defaultValues().then(y=>{M(y,r.resetOptions),d.state.next({isLoading:!1})}),_removeUnmounted:se,_disableForm:_e,_subjects:d,_proxyFormState:w,get _fields(){return a},get _formValues(){return i},get _state(){return o},set _state(y){o=y},get _defaultValues(){return n},get _names(){return l},set _names(y){l=y},get _formState(){return s},get _options(){return r},set _options(y){r={...r,...y}}},subscribe:Se,trigger:ee,register:ke,handleSubmit:Re,watch:J,setValue:q,getValues:O,reset:M,resetField:c,clearErrors:ae,unregister:fe,setError:te,setFocus:C,getFieldState:L};return{...X,formControl:X}}function Sl(e={}){const r=Xe.useRef(void 0),s=Xe.useRef(void 0),[a,n]=Xe.useState({isDirty:!1,isValidating:!1,isLoading:ft(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:ft(e.defaultValues)?void 0:e.defaultValues});if(!r.current)if(e.formControl)r.current={...e.formControl,formState:a},e.defaultValues&&!ft(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:o,...l}=Nl(e);r.current={...l,formState:a}}const i=r.current.control;return i._options=e,cl(()=>{const o=i._subscribe({formState:i._proxyFormState,callback:()=>n({...i._formState}),reRenderRoot:!0});return n(l=>({...l,isReady:!0})),i._formState.isReady=!0,o},[i]),Xe.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),Xe.useEffect(()=>{e.mode&&(i._options.mode=e.mode),e.reValidateMode&&(i._options.reValidateMode=e.reValidateMode)},[i,e.mode,e.reValidateMode]),Xe.useEffect(()=>{e.errors&&(i._setErrors(e.errors),i._focusError())},[i,e.errors]),Xe.useEffect(()=>{e.shouldUnregister&&i._subjects.state.next({values:i._getWatch()})},[i,e.shouldUnregister]),Xe.useEffect(()=>{if(i._proxyFormState.isDirty){const o=i._getDirty();o!==a.isDirty&&i._subjects.state.next({isDirty:o})}},[i,a.isDirty]),Xe.useEffect(()=>{var o;e.values&&!jt(e.values,s.current)?(i._reset(e.values,{keepFieldsRef:!0,...i._options.resetOptions}),!((o=i._options.resetOptions)===null||o===void 0)&&o.keepIsValid||i._setValid(),s.current=e.values,n(l=>({...l}))):i._resetDefaultValues()},[i,e.values]),Xe.useEffect(()=>{i._state.mount||(i._setValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),r.current.formState=Xe.useMemo(()=>ll(a,i),[i,a]),r.current}const Na=(e,r,s)=>{if(e&&"reportValidity"in e){const a=oe(s,r);e.setCustomValidity(a&&a.message||""),e.reportValidity()}},As=(e,r)=>{for(const s in r.fields){const a=r.fields[s];a&&a.ref&&"reportValidity"in a.ref?Na(a.ref,s,e):a&&a.refs&&a.refs.forEach(n=>Na(n,s,e))}},Sa=(e,r)=>{r.shouldUseNativeValidation&&As(e,r);const s={};for(const a in e){const n=oe(r.fields,a),i=Object.assign(e[a]||{},{ref:n&&n.ref});if(Cl(r.names||Object.keys(e),a)){const o=Object.assign({},oe(s,a));Ee(o,"root",i),Ee(s,a,o)}else Ee(s,a,i)}return s},Cl=(e,r)=>{const s=Ca(r);return e.some(a=>Ca(a).match(`^${s}\\.\\d+`))};function Ca(e){return e.replace(/\]|\[/g,"")}function Q(e,r,s){function a(l,h){if(l._zod||Object.defineProperty(l,"_zod",{value:{def:h,constr:o,traits:new Set},enumerable:!1}),l._zod.traits.has(e))return;l._zod.traits.add(e),r(l,h);const p=o.prototype,_=Object.keys(p);for(let w=0;w<_.length;w++){const g=_[w];g in l||(l[g]=p[g].bind(l))}}const n=s?.Parent??Object;class i extends n{}Object.defineProperty(i,"name",{value:e});function o(l){var h;const p=s?.Parent?new i:this;a(p,l),(h=p._zod).deferred??(h.deferred=[]);for(const _ of p._zod.deferred)_();return p}return Object.defineProperty(o,"init",{value:a}),Object.defineProperty(o,Symbol.hasInstance,{value:l=>s?.Parent&&l instanceof s.Parent?!0:l?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}class tr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class qn extends Error{constructor(r){super(`Encountered unidirectional transform during encode: ${r}`),this.name="ZodEncodeError"}}const Wn={};function Tt(e){return Wn}function zl(e){const r=Object.values(e).filter(a=>typeof a=="number");return Object.entries(e).filter(([a,n])=>r.indexOf(+a)===-1).map(([a,n])=>n)}function Ps(e,r){return typeof r=="bigint"?r.toString():r}function Ks(e){return{get value(){{const r=e();return Object.defineProperty(this,"value",{value:r}),r}}}}function Gs(e){return e==null}function Hs(e){const r=e.startsWith("^")?1:0,s=e.endsWith("$")?e.length-1:e.length;return e.slice(r,s)}function El(e,r){const s=(e.toString().split(".")[1]||"").length,a=r.toString();let n=(a.split(".")[1]||"").length;if(n===0&&/\d?e-\d?/.test(a)){const h=a.match(/\d?e-(\d?)/);h?.[1]&&(n=Number.parseInt(h[1]))}const i=s>n?s:n,o=Number.parseInt(e.toFixed(i).replace(".","")),l=Number.parseInt(r.toFixed(i).replace(".",""));return o%l/10**i}const za=Symbol("evaluating");function Ie(e,r,s){let a;Object.defineProperty(e,r,{get(){if(a!==za)return a===void 0&&(a=za,a=s()),a},set(n){Object.defineProperty(e,r,{value:n})},configurable:!0})}function Lt(e,r,s){Object.defineProperty(e,r,{value:s,writable:!0,enumerable:!0,configurable:!0})}function Ut(...e){const r={};for(const s of e){const a=Object.getOwnPropertyDescriptors(s);Object.assign(r,a)}return Object.defineProperties({},r)}function Ea(e){return JSON.stringify(e)}function Il(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Kn="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function es(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Al=Ks(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Er(e){if(es(e)===!1)return!1;const r=e.constructor;if(r===void 0||typeof r!="function")return!0;const s=r.prototype;return!(es(s)===!1||Object.prototype.hasOwnProperty.call(s,"isPrototypeOf")===!1)}function Gn(e){return Er(e)?{...e}:Array.isArray(e)?[...e]:e}const Pl=new Set(["string","number","symbol"]);function cr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _t(e,r,s){const a=new e._zod.constr(r??e._zod.def);return(!r||s?.parent)&&(a._zod.parent=e),a}function de(e){const r=e;if(!r)return{};if(typeof r=="string")return{error:()=>r};if(r?.message!==void 0){if(r?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");r.error=r.message}return delete r.message,typeof r.error=="string"?{...r,error:()=>r.error}:r}function Fl(e){return Object.keys(e).filter(r=>e[r]._zod.optin==="optional"&&e[r]._zod.optout==="optional")}const Dl={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ol(e,r){const s=e._zod.def,a=Ut(e._zod.def,{get shape(){const n={};for(const i in r){if(!(i in s.shape))throw new Error(`Unrecognized key: "${i}"`);r[i]&&(n[i]=s.shape[i])}return Lt(this,"shape",n),n},checks:[]});return _t(e,a)}function Tl(e,r){const s=e._zod.def,a=Ut(e._zod.def,{get shape(){const n={...e._zod.def.shape};for(const i in r){if(!(i in s.shape))throw new Error(`Unrecognized key: "${i}"`);r[i]&&delete n[i]}return Lt(this,"shape",n),n},checks:[]});return _t(e,a)}function Rl(e,r){if(!Er(r))throw new Error("Invalid input to extend: expected a plain object");const s=e._zod.def.checks;if(s&&s.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const n=Ut(e._zod.def,{get shape(){const i={...e._zod.def.shape,...r};return Lt(this,"shape",i),i},checks:[]});return _t(e,n)}function Zl(e,r){if(!Er(r))throw new Error("Invalid input to safeExtend: expected a plain object");const s={...e._zod.def,get shape(){const a={...e._zod.def.shape,...r};return Lt(this,"shape",a),a},checks:e._zod.def.checks};return _t(e,s)}function $l(e,r){const s=Ut(e._zod.def,{get shape(){const a={...e._zod.def.shape,...r._zod.def.shape};return Lt(this,"shape",a),a},get catchall(){return r._zod.def.catchall},checks:[]});return _t(e,s)}function Ll(e,r,s){const a=Ut(r._zod.def,{get shape(){const n=r._zod.def.shape,i={...n};if(s)for(const o in s){if(!(o in n))throw new Error(`Unrecognized key: "${o}"`);s[o]&&(i[o]=e?new e({type:"optional",innerType:n[o]}):n[o])}else for(const o in n)i[o]=e?new e({type:"optional",innerType:n[o]}):n[o];return Lt(this,"shape",i),i},checks:[]});return _t(r,a)}function Ul(e,r,s){const a=Ut(r._zod.def,{get shape(){const n=r._zod.def.shape,i={...n};if(s)for(const o in s){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);s[o]&&(i[o]=new e({type:"nonoptional",innerType:n[o]}))}else for(const o in n)i[o]=new e({type:"nonoptional",innerType:n[o]});return Lt(this,"shape",i),i},checks:[]});return _t(r,a)}function qt(e,r=0){if(e.aborted===!0)return!0;for(let s=r;s<e.issues.length;s++)if(e.issues[s]?.continue!==!0)return!0;return!1}function Hn(e,r){return r.map(s=>{var a;return(a=s).path??(a.path=[]),s.path.unshift(e),s})}function Ur(e){return typeof e=="string"?e:e?.message}function Rt(e,r,s){const a={...e,path:e.path??[]};if(!e.message){const n=Ur(e.inst?._zod.def?.error?.(e))??Ur(r?.error?.(e))??Ur(s.customError?.(e))??Ur(s.localeError?.(e))??"Invalid input";a.message=n}return delete a.inst,delete a.continue,r?.reportInput||delete a.input,a}function Qs(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Ir(...e){const[r,s,a]=e;return typeof r=="string"?{message:r,code:"custom",input:s,inst:a}:{...r}}const Qn=(e,r)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:r,enumerable:!1}),e.message=JSON.stringify(r,Ps,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ys=Q("$ZodError",Qn),is=Q("$ZodError",Qn,{Parent:Error});function Bl(e,r=s=>s.message){const s={},a=[];for(const n of e.issues)n.path.length>0?(s[n.path[0]]=s[n.path[0]]||[],s[n.path[0]].push(r(n))):a.push(r(n));return{formErrors:a,fieldErrors:s}}function Ml(e,r=s=>s.message){const s={_errors:[]},a=n=>{for(const i of n.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>a({issues:o}));else if(i.code==="invalid_key")a({issues:i.issues});else if(i.code==="invalid_element")a({issues:i.issues});else if(i.path.length===0)s._errors.push(r(i));else{let o=s,l=0;for(;l<i.path.length;){const h=i.path[l];l===i.path.length-1?(o[h]=o[h]||{_errors:[]},o[h]._errors.push(r(i))):o[h]=o[h]||{_errors:[]},o=o[h],l++}}};return a(e),s}const os=e=>(r,s,a,n)=>{const i=a?Object.assign(a,{async:!1}):{async:!1},o=r._zod.run({value:s,issues:[]},i);if(o instanceof Promise)throw new tr;if(o.issues.length){const l=new(n?.Err??e)(o.issues.map(h=>Rt(h,i,Tt())));throw Kn(l,n?.callee),l}return o.value},Vl=os(is),ls=e=>async(r,s,a,n)=>{const i=a?Object.assign(a,{async:!0}):{async:!0};let o=r._zod.run({value:s,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const l=new(n?.Err??e)(o.issues.map(h=>Rt(h,i,Tt())));throw Kn(l,n?.callee),l}return o.value},ql=ls(is),cs=e=>(r,s,a)=>{const n=a?{...a,async:!1}:{async:!1},i=r._zod.run({value:s,issues:[]},n);if(i instanceof Promise)throw new tr;return i.issues.length?{success:!1,error:new(e??Ys)(i.issues.map(o=>Rt(o,n,Tt())))}:{success:!0,data:i.value}},Wl=cs(is),ds=e=>async(r,s,a)=>{const n=a?Object.assign(a,{async:!0}):{async:!0};let i=r._zod.run({value:s,issues:[]},n);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(o=>Rt(o,n,Tt())))}:{success:!0,data:i.value}},Kl=ds(is),Gl=e=>(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return os(e)(r,s,n)},Hl=e=>(r,s,a)=>os(e)(r,s,a),Ql=e=>async(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return ls(e)(r,s,n)},Yl=e=>async(r,s,a)=>ls(e)(r,s,a),Xl=e=>(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return cs(e)(r,s,n)},Jl=e=>(r,s,a)=>cs(e)(r,s,a),ec=e=>async(r,s,a)=>{const n=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return ds(e)(r,s,n)},tc=e=>async(r,s,a)=>ds(e)(r,s,a),rc=/^[cC][^\s-]{8,}$/,sc=/^[0-9a-z]+$/,ac=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,nc=/^[0-9a-vA-V]{20}$/,ic=/^[A-Za-z0-9]{27}$/,oc=/^[a-zA-Z0-9_-]{21}$/,lc=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,cc=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ia=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,dc=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,uc="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function hc(){return new RegExp(uc,"u")}const mc=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,fc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,pc=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,xc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,gc=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Yn=/^[A-Za-z0-9_-]*$/,bc=/^\+(?:[0-9]){6,14}[0-9]$/,Xn="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",vc=new RegExp(`^${Xn}$`);function Jn(e){const r="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${r}`:e.precision===0?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${e.precision}}`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}function yc(e){return new RegExp(`^${Jn(e)}$`)}function wc(e){const r=Jn({precision:e.precision}),s=["Z"];e.local&&s.push(""),e.offset&&s.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const a=`${r}(?:${s.join("|")})`;return new RegExp(`^${Xn}T(?:${a})$`)}const jc=e=>{const r=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${r}$`)},kc=/^-?\d+$/,_c=/^-?\d+(?:\.\d+)?/,Nc=/^[^A-Z]*$/,Sc=/^[^a-z]*$/,ot=Q("$ZodCheck",(e,r)=>{var s;e._zod??(e._zod={}),e._zod.def=r,(s=e._zod).onattach??(s.onattach=[])}),ei={number:"number",bigint:"bigint",object:"date"},ti=Q("$ZodCheckLessThan",(e,r)=>{ot.init(e,r);const s=ei[typeof r.value];e._zod.onattach.push(a=>{const n=a._zod.bag,i=(r.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;r.value<i&&(r.inclusive?n.maximum=r.value:n.exclusiveMaximum=r.value)}),e._zod.check=a=>{(r.inclusive?a.value<=r.value:a.value<r.value)||a.issues.push({origin:s,code:"too_big",maximum:r.value,input:a.value,inclusive:r.inclusive,inst:e,continue:!r.abort})}}),ri=Q("$ZodCheckGreaterThan",(e,r)=>{ot.init(e,r);const s=ei[typeof r.value];e._zod.onattach.push(a=>{const n=a._zod.bag,i=(r.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;r.value>i&&(r.inclusive?n.minimum=r.value:n.exclusiveMinimum=r.value)}),e._zod.check=a=>{(r.inclusive?a.value>=r.value:a.value>r.value)||a.issues.push({origin:s,code:"too_small",minimum:r.value,input:a.value,inclusive:r.inclusive,inst:e,continue:!r.abort})}}),Cc=Q("$ZodCheckMultipleOf",(e,r)=>{ot.init(e,r),e._zod.onattach.push(s=>{var a;(a=s._zod.bag).multipleOf??(a.multipleOf=r.value)}),e._zod.check=s=>{if(typeof s.value!=typeof r.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof s.value=="bigint"?s.value%r.value===BigInt(0):El(s.value,r.value)===0)||s.issues.push({origin:typeof s.value,code:"not_multiple_of",divisor:r.value,input:s.value,inst:e,continue:!r.abort})}}),zc=Q("$ZodCheckNumberFormat",(e,r)=>{ot.init(e,r),r.format=r.format||"float64";const s=r.format?.includes("int"),a=s?"int":"number",[n,i]=Dl[r.format];e._zod.onattach.push(o=>{const l=o._zod.bag;l.format=r.format,l.minimum=n,l.maximum=i,s&&(l.pattern=kc)}),e._zod.check=o=>{const l=o.value;if(s){if(!Number.isInteger(l)){o.issues.push({expected:a,format:r.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?o.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,continue:!r.abort}):o.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:a,continue:!r.abort});return}}l<n&&o.issues.push({origin:"number",input:l,code:"too_small",minimum:n,inclusive:!0,inst:e,continue:!r.abort}),l>i&&o.issues.push({origin:"number",input:l,code:"too_big",maximum:i,inst:e})}}),Ec=Q("$ZodCheckMaxLength",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag.maximum??Number.POSITIVE_INFINITY;r.maximum<n&&(a._zod.bag.maximum=r.maximum)}),e._zod.check=a=>{const n=a.value;if(n.length<=r.maximum)return;const o=Qs(n);a.issues.push({origin:o,code:"too_big",maximum:r.maximum,inclusive:!0,input:n,inst:e,continue:!r.abort})}}),Ic=Q("$ZodCheckMinLength",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag.minimum??Number.NEGATIVE_INFINITY;r.minimum>n&&(a._zod.bag.minimum=r.minimum)}),e._zod.check=a=>{const n=a.value;if(n.length>=r.minimum)return;const o=Qs(n);a.issues.push({origin:o,code:"too_small",minimum:r.minimum,inclusive:!0,input:n,inst:e,continue:!r.abort})}}),Ac=Q("$ZodCheckLengthEquals",(e,r)=>{var s;ot.init(e,r),(s=e._zod.def).when??(s.when=a=>{const n=a.value;return!Gs(n)&&n.length!==void 0}),e._zod.onattach.push(a=>{const n=a._zod.bag;n.minimum=r.length,n.maximum=r.length,n.length=r.length}),e._zod.check=a=>{const n=a.value,i=n.length;if(i===r.length)return;const o=Qs(n),l=i>r.length;a.issues.push({origin:o,...l?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:a.value,inst:e,continue:!r.abort})}}),us=Q("$ZodCheckStringFormat",(e,r)=>{var s,a;ot.init(e,r),e._zod.onattach.push(n=>{const i=n._zod.bag;i.format=r.format,r.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(r.pattern))}),r.pattern?(s=e._zod).check??(s.check=n=>{r.pattern.lastIndex=0,!r.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:r.format,input:n.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:e,continue:!r.abort})}):(a=e._zod).check??(a.check=()=>{})}),Pc=Q("$ZodCheckRegex",(e,r)=>{us.init(e,r),e._zod.check=s=>{r.pattern.lastIndex=0,!r.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:"regex",input:s.value,pattern:r.pattern.toString(),inst:e,continue:!r.abort})}}),Fc=Q("$ZodCheckLowerCase",(e,r)=>{r.pattern??(r.pattern=Nc),us.init(e,r)}),Dc=Q("$ZodCheckUpperCase",(e,r)=>{r.pattern??(r.pattern=Sc),us.init(e,r)}),Oc=Q("$ZodCheckIncludes",(e,r)=>{ot.init(e,r);const s=cr(r.includes),a=new RegExp(typeof r.position=="number"?`^.{${r.position}}${s}`:s);r.pattern=a,e._zod.onattach.push(n=>{const i=n._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(a)}),e._zod.check=n=>{n.value.includes(r.includes,r.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:n.value,inst:e,continue:!r.abort})}}),Tc=Q("$ZodCheckStartsWith",(e,r)=>{ot.init(e,r);const s=new RegExp(`^${cr(r.prefix)}.*`);r.pattern??(r.pattern=s),e._zod.onattach.push(a=>{const n=a._zod.bag;n.patterns??(n.patterns=new Set),n.patterns.add(s)}),e._zod.check=a=>{a.value.startsWith(r.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:a.value,inst:e,continue:!r.abort})}}),Rc=Q("$ZodCheckEndsWith",(e,r)=>{ot.init(e,r);const s=new RegExp(`.*${cr(r.suffix)}$`);r.pattern??(r.pattern=s),e._zod.onattach.push(a=>{const n=a._zod.bag;n.patterns??(n.patterns=new Set),n.patterns.add(s)}),e._zod.check=a=>{a.value.endsWith(r.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:a.value,inst:e,continue:!r.abort})}}),Zc=Q("$ZodCheckOverwrite",(e,r)=>{ot.init(e,r),e._zod.check=s=>{s.value=r.tx(s.value)}});class $c{constructor(r=[]){this.content=[],this.indent=0,this&&(this.args=r)}indented(r){this.indent+=1,r(this),this.indent-=1}write(r){if(typeof r=="function"){r(this,{execution:"sync"}),r(this,{execution:"async"});return}const a=r.split(`
|
|
3
3
|
`).filter(o=>o),n=Math.min(...a.map(o=>o.length-o.trimStart().length)),i=a.map(o=>o.slice(n)).map(o=>" ".repeat(this.indent*2)+o);for(const o of i)this.content.push(o)}compile(){const r=Function,s=this?.args,n=[...(this?.content??[""]).map(i=>` ${i}`)];return new r(...s,n.join(`
|
|
4
|
-
`))}}const
|
|
4
|
+
`))}}const Lc={major:4,minor:1,patch:13},Ue=Q("$ZodType",(e,r)=>{var s;e??(e={}),e._zod.def=r,e._zod.bag=e._zod.bag||{},e._zod.version=Lc;const a=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&a.unshift(e);for(const n of a)for(const i of n._zod.onattach)i(e);if(a.length===0)(s=e._zod).deferred??(s.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const n=(o,l,h)=>{let p=qt(o),_;for(const w of l){if(w._zod.def.when){if(!w._zod.def.when(o))continue}else if(p)continue;const g=o.issues.length,d=w._zod.check(o);if(d instanceof Promise&&h?.async===!1)throw new tr;if(_||d instanceof Promise)_=(_??Promise.resolve()).then(async()=>{await d,o.issues.length!==g&&(p||(p=qt(o,g)))});else{if(o.issues.length===g)continue;p||(p=qt(o,g))}}return _?_.then(()=>o):o},i=(o,l,h)=>{if(qt(o))return o.aborted=!0,o;const p=n(l,a,h);if(p instanceof Promise){if(h.async===!1)throw new tr;return p.then(_=>e._zod.parse(_,h))}return e._zod.parse(p,h)};e._zod.run=(o,l)=>{if(l.skipChecks)return e._zod.parse(o,l);if(l.direction==="backward"){const p=e._zod.parse({value:o.value,issues:[]},{...l,skipChecks:!0});return p instanceof Promise?p.then(_=>i(_,o,l)):i(p,o,l)}const h=e._zod.parse(o,l);if(h instanceof Promise){if(l.async===!1)throw new tr;return h.then(p=>n(p,a,l))}return n(h,a,l)}}e["~standard"]={validate:n=>{try{const i=Wl(e,n);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return Kl(e,n).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Xs=Q("$ZodString",(e,r)=>{Ue.init(e,r),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??jc(e._zod.bag),e._zod.parse=(s,a)=>{if(r.coerce)try{s.value=String(s.value)}catch{}return typeof s.value=="string"||s.issues.push({expected:"string",code:"invalid_type",input:s.value,inst:e}),s}}),Pe=Q("$ZodStringFormat",(e,r)=>{us.init(e,r),Xs.init(e,r)}),Uc=Q("$ZodGUID",(e,r)=>{r.pattern??(r.pattern=cc),Pe.init(e,r)}),Bc=Q("$ZodUUID",(e,r)=>{if(r.version){const a={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(a===void 0)throw new Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=Ia(a))}else r.pattern??(r.pattern=Ia());Pe.init(e,r)}),Mc=Q("$ZodEmail",(e,r)=>{r.pattern??(r.pattern=dc),Pe.init(e,r)}),Vc=Q("$ZodURL",(e,r)=>{Pe.init(e,r),e._zod.check=s=>{try{const a=s.value.trim(),n=new URL(a);r.hostname&&(r.hostname.lastIndex=0,r.hostname.test(n.hostname)||s.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:r.hostname.source,input:s.value,inst:e,continue:!r.abort})),r.protocol&&(r.protocol.lastIndex=0,r.protocol.test(n.protocol.endsWith(":")?n.protocol.slice(0,-1):n.protocol)||s.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:s.value,inst:e,continue:!r.abort})),r.normalize?s.value=n.href:s.value=a;return}catch{s.issues.push({code:"invalid_format",format:"url",input:s.value,inst:e,continue:!r.abort})}}}),qc=Q("$ZodEmoji",(e,r)=>{r.pattern??(r.pattern=hc()),Pe.init(e,r)}),Wc=Q("$ZodNanoID",(e,r)=>{r.pattern??(r.pattern=oc),Pe.init(e,r)}),Kc=Q("$ZodCUID",(e,r)=>{r.pattern??(r.pattern=rc),Pe.init(e,r)}),Gc=Q("$ZodCUID2",(e,r)=>{r.pattern??(r.pattern=sc),Pe.init(e,r)}),Hc=Q("$ZodULID",(e,r)=>{r.pattern??(r.pattern=ac),Pe.init(e,r)}),Qc=Q("$ZodXID",(e,r)=>{r.pattern??(r.pattern=nc),Pe.init(e,r)}),Yc=Q("$ZodKSUID",(e,r)=>{r.pattern??(r.pattern=ic),Pe.init(e,r)}),Xc=Q("$ZodISODateTime",(e,r)=>{r.pattern??(r.pattern=wc(r)),Pe.init(e,r)}),Jc=Q("$ZodISODate",(e,r)=>{r.pattern??(r.pattern=vc),Pe.init(e,r)}),ed=Q("$ZodISOTime",(e,r)=>{r.pattern??(r.pattern=yc(r)),Pe.init(e,r)}),td=Q("$ZodISODuration",(e,r)=>{r.pattern??(r.pattern=lc),Pe.init(e,r)}),rd=Q("$ZodIPv4",(e,r)=>{r.pattern??(r.pattern=mc),Pe.init(e,r),e._zod.bag.format="ipv4"}),sd=Q("$ZodIPv6",(e,r)=>{r.pattern??(r.pattern=fc),Pe.init(e,r),e._zod.bag.format="ipv6",e._zod.check=s=>{try{new URL(`http://[${s.value}]`)}catch{s.issues.push({code:"invalid_format",format:"ipv6",input:s.value,inst:e,continue:!r.abort})}}}),ad=Q("$ZodCIDRv4",(e,r)=>{r.pattern??(r.pattern=pc),Pe.init(e,r)}),nd=Q("$ZodCIDRv6",(e,r)=>{r.pattern??(r.pattern=xc),Pe.init(e,r),e._zod.check=s=>{const a=s.value.split("/");try{if(a.length!==2)throw new Error;const[n,i]=a;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${n}]`)}catch{s.issues.push({code:"invalid_format",format:"cidrv6",input:s.value,inst:e,continue:!r.abort})}}});function si(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const id=Q("$ZodBase64",(e,r)=>{r.pattern??(r.pattern=gc),Pe.init(e,r),e._zod.bag.contentEncoding="base64",e._zod.check=s=>{si(s.value)||s.issues.push({code:"invalid_format",format:"base64",input:s.value,inst:e,continue:!r.abort})}});function od(e){if(!Yn.test(e))return!1;const r=e.replace(/[-_]/g,a=>a==="-"?"+":"/"),s=r.padEnd(Math.ceil(r.length/4)*4,"=");return si(s)}const ld=Q("$ZodBase64URL",(e,r)=>{r.pattern??(r.pattern=Yn),Pe.init(e,r),e._zod.bag.contentEncoding="base64url",e._zod.check=s=>{od(s.value)||s.issues.push({code:"invalid_format",format:"base64url",input:s.value,inst:e,continue:!r.abort})}}),cd=Q("$ZodE164",(e,r)=>{r.pattern??(r.pattern=bc),Pe.init(e,r)});function dd(e,r=null){try{const s=e.split(".");if(s.length!==3)return!1;const[a]=s;if(!a)return!1;const n=JSON.parse(atob(a));return!("typ"in n&&n?.typ!=="JWT"||!n.alg||r&&(!("alg"in n)||n.alg!==r))}catch{return!1}}const ud=Q("$ZodJWT",(e,r)=>{Pe.init(e,r),e._zod.check=s=>{dd(s.value,r.alg)||s.issues.push({code:"invalid_format",format:"jwt",input:s.value,inst:e,continue:!r.abort})}}),ai=Q("$ZodNumber",(e,r)=>{Ue.init(e,r),e._zod.pattern=e._zod.bag.pattern??_c,e._zod.parse=(s,a)=>{if(r.coerce)try{s.value=Number(s.value)}catch{}const n=s.value;if(typeof n=="number"&&!Number.isNaN(n)&&Number.isFinite(n))return s;const i=typeof n=="number"?Number.isNaN(n)?"NaN":Number.isFinite(n)?void 0:"Infinity":void 0;return s.issues.push({expected:"number",code:"invalid_type",input:n,inst:e,...i?{received:i}:{}}),s}}),hd=Q("$ZodNumberFormat",(e,r)=>{zc.init(e,r),ai.init(e,r)}),md=Q("$ZodUnknown",(e,r)=>{Ue.init(e,r),e._zod.parse=s=>s}),fd=Q("$ZodNever",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>(s.issues.push({expected:"never",code:"invalid_type",input:s.value,inst:e}),s)});function Aa(e,r,s){e.issues.length&&r.issues.push(...Hn(s,e.issues)),r.value[s]=e.value}const pd=Q("$ZodArray",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>{const n=s.value;if(!Array.isArray(n))return s.issues.push({expected:"array",code:"invalid_type",input:n,inst:e}),s;s.value=Array(n.length);const i=[];for(let o=0;o<n.length;o++){const l=n[o],h=r.element._zod.run({value:l,issues:[]},a);h instanceof Promise?i.push(h.then(p=>Aa(p,s,o))):Aa(h,s,o)}return i.length?Promise.all(i).then(()=>s):s}});function ts(e,r,s,a){e.issues.length&&r.issues.push(...Hn(s,e.issues)),e.value===void 0?s in a&&(r.value[s]=void 0):r.value[s]=e.value}function ni(e){const r=Object.keys(e.shape);for(const a of r)if(!e.shape?.[a]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const s=Fl(e.shape);return{...e,keys:r,keySet:new Set(r),numKeys:r.length,optionalKeys:new Set(s)}}function ii(e,r,s,a,n,i){const o=[],l=n.keySet,h=n.catchall._zod,p=h.def.type;for(const _ in r){if(l.has(_))continue;if(p==="never"){o.push(_);continue}const w=h.run({value:r[_],issues:[]},a);w instanceof Promise?e.push(w.then(g=>ts(g,s,_,r))):ts(w,s,_,r)}return o.length&&s.issues.push({code:"unrecognized_keys",keys:o,input:r,inst:i}),e.length?Promise.all(e).then(()=>s):s}const xd=Q("$ZodObject",(e,r)=>{if(Ue.init(e,r),!Object.getOwnPropertyDescriptor(r,"shape")?.get){const l=r.shape;Object.defineProperty(r,"shape",{get:()=>{const h={...l};return Object.defineProperty(r,"shape",{value:h}),h}})}const a=Ks(()=>ni(r));Ie(e._zod,"propValues",()=>{const l=r.shape,h={};for(const p in l){const _=l[p]._zod;if(_.values){h[p]??(h[p]=new Set);for(const w of _.values)h[p].add(w)}}return h});const n=es,i=r.catchall;let o;e._zod.parse=(l,h)=>{o??(o=a.value);const p=l.value;if(!n(p))return l.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),l;l.value={};const _=[],w=o.shape;for(const g of o.keys){const k=w[g]._zod.run({value:p[g],issues:[]},h);k instanceof Promise?_.push(k.then(u=>ts(u,l,g,p))):ts(k,l,g,p)}return i?ii(_,p,l,h,a.value,e):_.length?Promise.all(_).then(()=>l):l}}),gd=Q("$ZodObjectJIT",(e,r)=>{xd.init(e,r);const s=e._zod.parse,a=Ks(()=>ni(r)),n=g=>{const d=new $c(["shape","payload","ctx"]),k=a.value,u=E=>{const P=Ea(E);return`shape[${P}]._zod.run({ value: input[${P}], issues: [] }, ctx)`};d.write("const input = payload.value;");const x=Object.create(null);let f=0;for(const E of k.keys)x[E]=`key_${f++}`;d.write("const newResult = {};");for(const E of k.keys){const P=x[E],S=Ea(E);d.write(`const ${P} = ${u(E)};`),d.write(`
|
|
5
5
|
if (${P}.issues.length) {
|
|
6
6
|
payload.issues = payload.issues.concat(${P}.issues.map(iss => ({
|
|
7
7
|
...iss,
|
|
@@ -18,4 +18,4 @@ import{c as $t,j as t,l as le,h as Os,au as an,P as Lt,t as ne,Q as wi,a3 as nn,
|
|
|
18
18
|
newResult[${S}] = ${P}.value;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
`)}d.write("payload.value = newResult;"),d.write("return payload;");const j=d.compile();return(E,P)=>j(g,E,P)};let i;const o=es,l=!Wn.jitless,p=l&&Pl.value,_=r.catchall;let w;e._zod.parse=(g,d)=>{w??(w=a.value);const k=g.value;return o(k)?l&&p&&d?.async===!1&&d.jitless!==!0?(i||(i=n(r.shape)),g=i(g,d),_?ii([],k,g,d,w,e):g):s(g,d):(g.issues.push({expected:"object",code:"invalid_type",input:k,inst:e}),g)}});function Pa(e,r,s,a){for(const i of e)if(i.issues.length===0)return r.value=i.value,r;const n=e.filter(i=>!Wt(i));return n.length===1?(r.value=n[0].value,n[0]):(r.issues.push({code:"invalid_union",input:r.value,inst:s,errors:e.map(i=>i.issues.map(o=>Rt(o,a,Tt())))}),r)}const vd=Q("$ZodUnion",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.options.some(n=>n._zod.optin==="optional")?"optional":void 0),Ie(e._zod,"optout",()=>r.options.some(n=>n._zod.optout==="optional")?"optional":void 0),Ie(e._zod,"values",()=>{if(r.options.every(n=>n._zod.values))return new Set(r.options.flatMap(n=>Array.from(n._zod.values)))}),Ie(e._zod,"pattern",()=>{if(r.options.every(n=>n._zod.pattern)){const n=r.options.map(i=>i._zod.pattern);return new RegExp(`^(${n.map(i=>Hs(i.source)).join("|")})$`)}});const s=r.options.length===1,a=r.options[0]._zod.run;e._zod.parse=(n,i)=>{if(s)return a(n,i);let o=!1;const l=[];for(const h of r.options){const p=h._zod.run({value:n.value,issues:[]},i);if(p instanceof Promise)l.push(p),o=!0;else{if(p.issues.length===0)return p;l.push(p)}}return o?Promise.all(l).then(h=>Pa(h,n,e,i)):Pa(l,n,e,i)}}),yd=Q("$ZodIntersection",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>{const n=s.value,i=r.left._zod.run({value:n,issues:[]},a),o=r.right._zod.run({value:n,issues:[]},a);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([h,p])=>Fa(s,h,p)):Fa(s,i,o)}});function Fs(e,r){if(e===r)return{valid:!0,data:e};if(e instanceof Date&&r instanceof Date&&+e==+r)return{valid:!0,data:e};if(Er(e)&&Er(r)){const s=Object.keys(r),a=Object.keys(e).filter(i=>s.indexOf(i)!==-1),n={...e,...r};for(const i of a){const o=Fs(e[i],r[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};n[i]=o.data}return{valid:!0,data:n}}if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return{valid:!1,mergeErrorPath:[]};const s=[];for(let a=0;a<e.length;a++){const n=e[a],i=r[a],o=Fs(n,i);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s.push(o.data)}return{valid:!0,data:s}}return{valid:!1,mergeErrorPath:[]}}function Fa(e,r,s){if(r.issues.length&&e.issues.push(...r.issues),s.issues.length&&e.issues.push(...s.issues),Wt(e))return e;const a=Fs(r.value,s.value);if(!a.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}const wd=Q("$ZodEnum",(e,r)=>{Ue.init(e,r);const s=El(r.entries),a=new Set(s);e._zod.values=a,e._zod.pattern=new RegExp(`^(${s.filter(n=>Fl.has(typeof n)).map(n=>typeof n=="string"?dr(n):n.toString()).join("|")})$`),e._zod.parse=(n,i)=>{const o=n.value;return a.has(o)||n.issues.push({code:"invalid_value",values:s,input:o,inst:e}),n}}),jd=Q("$ZodLiteral",(e,r)=>{if(Ue.init(e,r),r.values.length===0)throw new Error("Cannot create literal schema with no valid values");const s=new Set(r.values);e._zod.values=s,e._zod.pattern=new RegExp(`^(${r.values.map(a=>typeof a=="string"?dr(a):a?dr(a.toString()):String(a)).join("|")})$`),e._zod.parse=(a,n)=>{const i=a.value;return s.has(i)||a.issues.push({code:"invalid_value",values:r.values,input:i,inst:e}),a}}),kd=Q("$ZodTransform",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>{if(a.direction==="backward")throw new qn(e.constructor.name);const n=r.transform(s.value,s);if(a.async)return(n instanceof Promise?n:Promise.resolve(n)).then(o=>(s.value=o,s));if(n instanceof Promise)throw new rr;return s.value=n,s}});function Da(e,r){return e.issues.length&&r===void 0?{issues:[],value:void 0}:e}const _d=Q("$ZodOptional",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",e._zod.optout="optional",Ie(e._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,void 0]):void 0),Ie(e._zod,"pattern",()=>{const s=r.innerType._zod.pattern;return s?new RegExp(`^(${Hs(s.source)})?$`):void 0}),e._zod.parse=(s,a)=>{if(r.innerType._zod.optin==="optional"){const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Da(i,s.value)):Da(n,s.value)}return s.value===void 0?s:r.innerType._zod.run(s,a)}}),Nd=Q("$ZodNullable",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.innerType._zod.optin),Ie(e._zod,"optout",()=>r.innerType._zod.optout),Ie(e._zod,"pattern",()=>{const s=r.innerType._zod.pattern;return s?new RegExp(`^(${Hs(s.source)}|null)$`):void 0}),Ie(e._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,null]):void 0),e._zod.parse=(s,a)=>s.value===null?s:r.innerType._zod.run(s,a)}),Sd=Q("$ZodDefault",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);if(s.value===void 0)return s.value=r.defaultValue,s;const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Oa(i,r)):Oa(n,r)}});function Oa(e,r){return e.value===void 0&&(e.value=r.defaultValue),e}const Cd=Q("$ZodPrefault",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>(a.direction==="backward"||s.value===void 0&&(s.value=r.defaultValue),r.innerType._zod.run(s,a))}),zd=Q("$ZodNonOptional",(e,r)=>{Ue.init(e,r),Ie(e._zod,"values",()=>{const s=r.innerType._zod.values;return s?new Set([...s].filter(a=>a!==void 0)):void 0}),e._zod.parse=(s,a)=>{const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Ta(i,e)):Ta(n,e)}});function Ta(e,r){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:r}),e}const Ed=Q("$ZodCatch",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.innerType._zod.optin),Ie(e._zod,"optout",()=>r.innerType._zod.optout),Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>(s.value=i.value,i.issues.length&&(s.value=r.catchValue({...s,error:{issues:i.issues.map(o=>Rt(o,a,Tt()))},input:s.value}),s.issues=[]),s)):(s.value=n.value,n.issues.length&&(s.value=r.catchValue({...s,error:{issues:n.issues.map(i=>Rt(i,a,Tt()))},input:s.value}),s.issues=[]),s)}}),Id=Q("$ZodPipe",(e,r)=>{Ue.init(e,r),Ie(e._zod,"values",()=>r.in._zod.values),Ie(e._zod,"optin",()=>r.in._zod.optin),Ie(e._zod,"optout",()=>r.out._zod.optout),Ie(e._zod,"propValues",()=>r.in._zod.propValues),e._zod.parse=(s,a)=>{if(a.direction==="backward"){const i=r.out._zod.run(s,a);return i instanceof Promise?i.then(o=>Br(o,r.in,a)):Br(i,r.in,a)}const n=r.in._zod.run(s,a);return n instanceof Promise?n.then(i=>Br(i,r.out,a)):Br(n,r.out,a)}});function Br(e,r,s){return e.issues.length?(e.aborted=!0,e):r._zod.run({value:e.value,issues:e.issues},s)}const Ad=Q("$ZodReadonly",(e,r)=>{Ue.init(e,r),Ie(e._zod,"propValues",()=>r.innerType._zod.propValues),Ie(e._zod,"values",()=>r.innerType._zod.values),Ie(e._zod,"optin",()=>r.innerType?._zod?.optin),Ie(e._zod,"optout",()=>r.innerType?._zod?.optout),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(Ra):Ra(n)}});function Ra(e){return e.value=Object.freeze(e.value),e}const Pd=Q("$ZodCustom",(e,r)=>{ot.init(e,r),Ue.init(e,r),e._zod.parse=(s,a)=>s,e._zod.check=s=>{const a=s.value,n=r.fn(a);if(n instanceof Promise)return n.then(i=>Za(i,s,a,e));Za(n,s,a,e)}});function Za(e,r,s,a){if(!e){const n={code:"custom",input:s,inst:a,path:[...a._zod.def.path??[]],continue:!a._zod.def.abort};a._zod.def.params&&(n.params=a._zod.def.params),r.issues.push(Ir(n))}}var $a;class Fd{constructor(){this._map=new WeakMap,this._idmap=new Map}add(r,...s){const a=s[0];if(this._map.set(r,a),a&&typeof a=="object"&&"id"in a){if(this._idmap.has(a.id))throw new Error(`ID ${a.id} already exists in the registry`);this._idmap.set(a.id,r)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(r){const s=this._map.get(r);return s&&typeof s=="object"&&"id"in s&&this._idmap.delete(s.id),this._map.delete(r),this}get(r){const s=r._zod.parent;if(s){const a={...this.get(s)??{}};delete a.id;const n={...a,...this._map.get(r)};return Object.keys(n).length?n:void 0}return this._map.get(r)}has(r){return this._map.has(r)}}function Dd(){return new Fd}($a=globalThis).__zod_globalRegistry??($a.__zod_globalRegistry=Dd());const Mr=globalThis.__zod_globalRegistry;function Od(e,r){return new e({type:"string",...de(r)})}function Td(e,r){return new e({type:"string",format:"email",check:"string_format",abort:!1,...de(r)})}function La(e,r){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...de(r)})}function Rd(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...de(r)})}function Zd(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...de(r)})}function $d(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...de(r)})}function Ld(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...de(r)})}function Ud(e,r){return new e({type:"string",format:"url",check:"string_format",abort:!1,...de(r)})}function Bd(e,r){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...de(r)})}function Md(e,r){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...de(r)})}function Vd(e,r){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...de(r)})}function qd(e,r){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...de(r)})}function Wd(e,r){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...de(r)})}function Kd(e,r){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...de(r)})}function Gd(e,r){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...de(r)})}function Hd(e,r){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...de(r)})}function Qd(e,r){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...de(r)})}function Yd(e,r){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...de(r)})}function Xd(e,r){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...de(r)})}function Jd(e,r){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...de(r)})}function eu(e,r){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...de(r)})}function tu(e,r){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...de(r)})}function ru(e,r){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...de(r)})}function su(e,r){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...de(r)})}function au(e,r){return new e({type:"string",format:"date",check:"string_format",...de(r)})}function nu(e,r){return new e({type:"string",format:"time",check:"string_format",precision:null,...de(r)})}function iu(e,r){return new e({type:"string",format:"duration",check:"string_format",...de(r)})}function ou(e,r){return new e({type:"number",coerce:!0,checks:[],...de(r)})}function lu(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...de(r)})}function cu(e){return new e({type:"unknown"})}function du(e,r){return new e({type:"never",...de(r)})}function Ua(e,r){return new ti({check:"less_than",...de(r),value:e,inclusive:!1})}function js(e,r){return new ti({check:"less_than",...de(r),value:e,inclusive:!0})}function Ba(e,r){return new ri({check:"greater_than",...de(r),value:e,inclusive:!1})}function ks(e,r){return new ri({check:"greater_than",...de(r),value:e,inclusive:!0})}function Ma(e,r){return new zc({check:"multiple_of",...de(r),value:e})}function oi(e,r){return new Ic({check:"max_length",...de(r),maximum:e})}function rs(e,r){return new Ac({check:"min_length",...de(r),minimum:e})}function li(e,r){return new Pc({check:"length_equals",...de(r),length:e})}function uu(e,r){return new Fc({check:"string_format",format:"regex",...de(r),pattern:e})}function hu(e){return new Dc({check:"string_format",format:"lowercase",...de(e)})}function mu(e){return new Oc({check:"string_format",format:"uppercase",...de(e)})}function fu(e,r){return new Tc({check:"string_format",format:"includes",...de(r),includes:e})}function pu(e,r){return new Rc({check:"string_format",format:"starts_with",...de(r),prefix:e})}function xu(e,r){return new Zc({check:"string_format",format:"ends_with",...de(r),suffix:e})}function mr(e){return new $c({check:"overwrite",tx:e})}function gu(e){return mr(r=>r.normalize(e))}function bu(){return mr(e=>e.trim())}function vu(){return mr(e=>e.toLowerCase())}function yu(){return mr(e=>e.toUpperCase())}function wu(){return mr(e=>Al(e))}function ju(e,r,s){return new e({type:"array",element:r,...de(s)})}function ku(e,r,s){return new e({type:"custom",check:"custom",fn:r,...de(s)})}function _u(e){const r=Nu(s=>(s.addIssue=a=>{if(typeof a=="string")s.issues.push(Ir(a,s.value,r._zod.def));else{const n=a;n.fatal&&(n.continue=!1),n.code??(n.code="custom"),n.input??(n.input=s.value),n.inst??(n.inst=r),n.continue??(n.continue=!r._zod.def.abort),s.issues.push(Ir(n))}},e(s.value,s)));return r}function Nu(e,r){const s=new ot({check:"custom",...de(r)});return s._zod.check=e,s}function Va(e,r){try{var s=e()}catch(a){return r(a)}return s&&s.then?s.then(void 0,r):s}function Su(e,r){for(var s={};e.length;){var a=e[0],n=a.code,i=a.message,o=a.path.join(".");if(!s[o])if("unionErrors"in a){var l=a.unionErrors[0].errors[0];s[o]={message:l.message,type:l.code}}else s[o]={message:i,type:n};if("unionErrors"in a&&a.unionErrors.forEach(function(_){return _.errors.forEach(function(w){return e.push(w)})}),r){var h=s[o].types,p=h&&h[a.code];s[o]=Vs(o,r,s,n,p?[].concat(p,a.message):a.message)}e.shift()}return s}function Cu(e,r){for(var s={};e.length;){var a=e[0],n=a.code,i=a.message,o=a.path.join(".");if(!s[o])if(a.code==="invalid_union"&&a.errors.length>0){var l=a.errors[0][0];s[o]={message:l.message,type:l.code}}else s[o]={message:i,type:n};if(a.code==="invalid_union"&&a.errors.forEach(function(_){return _.forEach(function(w){return e.push(w)})}),r){var h=s[o].types,p=h&&h[a.code];s[o]=Vs(o,r,s,n,p?[].concat(p,a.message):a.message)}e.shift()}return s}function zu(e,r,s){if(s===void 0&&(s={}),(function(a){return"_def"in a&&typeof a._def=="object"&&"typeName"in a._def})(e))return function(a,n,i){try{return Promise.resolve(Va(function(){return Promise.resolve(e[s.mode==="sync"?"parse":"parseAsync"](a,r)).then(function(o){return i.shouldUseNativeValidation&&As({},i),{errors:{},values:s.raw?Object.assign({},a):o}})},function(o){if((function(l){return Array.isArray(l?.issues)})(o))return{values:{},errors:Sa(Su(o.errors,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}};if((function(a){return"_zod"in a&&typeof a._zod=="object"})(e))return function(a,n,i){try{return Promise.resolve(Va(function(){return Promise.resolve((s.mode==="sync"?ql:Wl)(e,a,r)).then(function(o){return i.shouldUseNativeValidation&&As({},i),{errors:{},values:s.raw?Object.assign({},a):o}})},function(o){if((function(l){return l instanceof Ys})(o))return{values:{},errors:Sa(Cu(o.issues,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}};throw new Error("Invalid input: not a Zod schema")}const Eu=Q("ZodISODateTime",(e,r)=>{Jc.init(e,r),Te.init(e,r)});function Iu(e){return su(Eu,e)}const Au=Q("ZodISODate",(e,r)=>{ed.init(e,r),Te.init(e,r)});function Pu(e){return au(Au,e)}const Fu=Q("ZodISOTime",(e,r)=>{td.init(e,r),Te.init(e,r)});function Du(e){return nu(Fu,e)}const Ou=Q("ZodISODuration",(e,r)=>{rd.init(e,r),Te.init(e,r)});function Tu(e){return iu(Ou,e)}const Ru=(e,r)=>{Ys.init(e,r),e.name="ZodError",Object.defineProperties(e,{format:{value:s=>Vl(e,s)},flatten:{value:s=>Ml(e,s)},addIssue:{value:s=>{e.issues.push(s),e.message=JSON.stringify(e.issues,Ps,2)}},addIssues:{value:s=>{e.issues.push(...s),e.message=JSON.stringify(e.issues,Ps,2)}},isEmpty:{get(){return e.issues.length===0}}})},ht=Q("ZodError",Ru,{Parent:Error}),Zu=os(ht),$u=ls(ht),Lu=cs(ht),Uu=ds(ht),Bu=Hl(ht),Mu=Ql(ht),Vu=Yl(ht),qu=Xl(ht),Wu=Jl(ht),Ku=ec(ht),Gu=tc(ht),Hu=rc(ht),Ve=Q("ZodType",(e,r)=>(Ue.init(e,r),e.def=r,e.type=r.type,Object.defineProperty(e,"_def",{value:r}),e.check=(...s)=>e.clone(Bt(r,{checks:[...r.checks??[],...s.map(a=>typeof a=="function"?{_zod:{check:a,def:{check:"custom"},onattach:[]}}:a)]})),e.clone=(s,a)=>_t(e,s,a),e.brand=()=>e,e.register=((s,a)=>(s.add(e,a),e)),e.parse=(s,a)=>Zu(e,s,a,{callee:e.parse}),e.safeParse=(s,a)=>Lu(e,s,a),e.parseAsync=async(s,a)=>$u(e,s,a,{callee:e.parseAsync}),e.safeParseAsync=async(s,a)=>Uu(e,s,a),e.spa=e.safeParseAsync,e.encode=(s,a)=>Bu(e,s,a),e.decode=(s,a)=>Mu(e,s,a),e.encodeAsync=async(s,a)=>Vu(e,s,a),e.decodeAsync=async(s,a)=>qu(e,s,a),e.safeEncode=(s,a)=>Wu(e,s,a),e.safeDecode=(s,a)=>Ku(e,s,a),e.safeEncodeAsync=async(s,a)=>Gu(e,s,a),e.safeDecodeAsync=async(s,a)=>Hu(e,s,a),e.refine=(s,a)=>e.check(Bh(s,a)),e.superRefine=s=>e.check(Mh(s)),e.overwrite=s=>e.check(mr(s)),e.optional=()=>Ha(e),e.nullable=()=>Qa(e),e.nullish=()=>Ha(Qa(e)),e.nonoptional=s=>Oh(e,s),e.array=()=>vh(e),e.or=s=>kh([e,s]),e.and=s=>Nh(e,s),e.transform=s=>Ya(e,Eh(s)),e.default=s=>Ph(e,s),e.prefault=s=>Dh(e,s),e.catch=s=>Rh(e,s),e.pipe=s=>Ya(e,s),e.readonly=()=>Lh(e),e.describe=s=>{const a=e.clone();return Mr.add(a,{description:s}),a},Object.defineProperty(e,"description",{get(){return Mr.get(e)?.description},configurable:!0}),e.meta=(...s)=>{if(s.length===0)return Mr.get(e);const a=e.clone();return Mr.add(a,s[0]),a},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ci=Q("_ZodString",(e,r)=>{Xs.init(e,r),Ve.init(e,r);const s=e._zod.bag;e.format=s.format??null,e.minLength=s.minimum??null,e.maxLength=s.maximum??null,e.regex=(...a)=>e.check(uu(...a)),e.includes=(...a)=>e.check(fu(...a)),e.startsWith=(...a)=>e.check(pu(...a)),e.endsWith=(...a)=>e.check(xu(...a)),e.min=(...a)=>e.check(rs(...a)),e.max=(...a)=>e.check(oi(...a)),e.length=(...a)=>e.check(li(...a)),e.nonempty=(...a)=>e.check(rs(1,...a)),e.lowercase=a=>e.check(hu(a)),e.uppercase=a=>e.check(mu(a)),e.trim=()=>e.check(bu()),e.normalize=(...a)=>e.check(gu(...a)),e.toLowerCase=()=>e.check(vu()),e.toUpperCase=()=>e.check(yu()),e.slugify=()=>e.check(wu())}),Qu=Q("ZodString",(e,r)=>{Xs.init(e,r),ci.init(e,r),e.email=s=>e.check(Td(Yu,s)),e.url=s=>e.check(Ud(Xu,s)),e.jwt=s=>e.check(ru(mh,s)),e.emoji=s=>e.check(Bd(Ju,s)),e.guid=s=>e.check(La(qa,s)),e.uuid=s=>e.check(Rd(Vr,s)),e.uuidv4=s=>e.check(Zd(Vr,s)),e.uuidv6=s=>e.check($d(Vr,s)),e.uuidv7=s=>e.check(Ld(Vr,s)),e.nanoid=s=>e.check(Md(eh,s)),e.guid=s=>e.check(La(qa,s)),e.cuid=s=>e.check(Vd(th,s)),e.cuid2=s=>e.check(qd(rh,s)),e.ulid=s=>e.check(Wd(sh,s)),e.base64=s=>e.check(Jd(dh,s)),e.base64url=s=>e.check(eu(uh,s)),e.xid=s=>e.check(Kd(ah,s)),e.ksuid=s=>e.check(Gd(nh,s)),e.ipv4=s=>e.check(Hd(ih,s)),e.ipv6=s=>e.check(Qd(oh,s)),e.cidrv4=s=>e.check(Yd(lh,s)),e.cidrv6=s=>e.check(Xd(ch,s)),e.e164=s=>e.check(tu(hh,s)),e.datetime=s=>e.check(Iu(s)),e.date=s=>e.check(Pu(s)),e.time=s=>e.check(Du(s)),e.duration=s=>e.check(Tu(s))});function Ct(e){return Od(Qu,e)}const Te=Q("ZodStringFormat",(e,r)=>{Pe.init(e,r),ci.init(e,r)}),Yu=Q("ZodEmail",(e,r)=>{Vc.init(e,r),Te.init(e,r)}),qa=Q("ZodGUID",(e,r)=>{Bc.init(e,r),Te.init(e,r)}),Vr=Q("ZodUUID",(e,r)=>{Mc.init(e,r),Te.init(e,r)}),Xu=Q("ZodURL",(e,r)=>{qc.init(e,r),Te.init(e,r)}),Ju=Q("ZodEmoji",(e,r)=>{Wc.init(e,r),Te.init(e,r)}),eh=Q("ZodNanoID",(e,r)=>{Kc.init(e,r),Te.init(e,r)}),th=Q("ZodCUID",(e,r)=>{Gc.init(e,r),Te.init(e,r)}),rh=Q("ZodCUID2",(e,r)=>{Hc.init(e,r),Te.init(e,r)}),sh=Q("ZodULID",(e,r)=>{Qc.init(e,r),Te.init(e,r)}),ah=Q("ZodXID",(e,r)=>{Yc.init(e,r),Te.init(e,r)}),nh=Q("ZodKSUID",(e,r)=>{Xc.init(e,r),Te.init(e,r)}),ih=Q("ZodIPv4",(e,r)=>{sd.init(e,r),Te.init(e,r)}),oh=Q("ZodIPv6",(e,r)=>{ad.init(e,r),Te.init(e,r)}),lh=Q("ZodCIDRv4",(e,r)=>{nd.init(e,r),Te.init(e,r)}),ch=Q("ZodCIDRv6",(e,r)=>{id.init(e,r),Te.init(e,r)}),dh=Q("ZodBase64",(e,r)=>{od.init(e,r),Te.init(e,r)}),uh=Q("ZodBase64URL",(e,r)=>{cd.init(e,r),Te.init(e,r)}),hh=Q("ZodE164",(e,r)=>{dd.init(e,r),Te.init(e,r)}),mh=Q("ZodJWT",(e,r)=>{hd.init(e,r),Te.init(e,r)}),di=Q("ZodNumber",(e,r)=>{ai.init(e,r),Ve.init(e,r),e.gt=(a,n)=>e.check(Ba(a,n)),e.gte=(a,n)=>e.check(ks(a,n)),e.min=(a,n)=>e.check(ks(a,n)),e.lt=(a,n)=>e.check(Ua(a,n)),e.lte=(a,n)=>e.check(js(a,n)),e.max=(a,n)=>e.check(js(a,n)),e.int=a=>e.check(Wa(a)),e.safe=a=>e.check(Wa(a)),e.positive=a=>e.check(Ba(0,a)),e.nonnegative=a=>e.check(ks(0,a)),e.negative=a=>e.check(Ua(0,a)),e.nonpositive=a=>e.check(js(0,a)),e.multipleOf=(a,n)=>e.check(Ma(a,n)),e.step=(a,n)=>e.check(Ma(a,n)),e.finite=()=>e;const s=e._zod.bag;e.minValue=Math.max(s.minimum??Number.NEGATIVE_INFINITY,s.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(s.maximum??Number.POSITIVE_INFINITY,s.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(s.format??"").includes("int")||Number.isSafeInteger(s.multipleOf??.5),e.isFinite=!0,e.format=s.format??null}),fh=Q("ZodNumberFormat",(e,r)=>{md.init(e,r),di.init(e,r)});function Wa(e){return lu(fh,e)}const ph=Q("ZodUnknown",(e,r)=>{fd.init(e,r),Ve.init(e,r)});function Ka(){return cu(ph)}const xh=Q("ZodNever",(e,r)=>{pd.init(e,r),Ve.init(e,r)});function gh(e){return du(xh,e)}const bh=Q("ZodArray",(e,r)=>{xd.init(e,r),Ve.init(e,r),e.element=r.element,e.min=(s,a)=>e.check(rs(s,a)),e.nonempty=s=>e.check(rs(1,s)),e.max=(s,a)=>e.check(oi(s,a)),e.length=(s,a)=>e.check(li(s,a)),e.unwrap=()=>e.element});function vh(e,r){return ju(bh,e,r)}const yh=Q("ZodObject",(e,r)=>{bd.init(e,r),Ve.init(e,r),Ie(e,"shape",()=>r.shape),e.keyof=()=>Sh(Object.keys(e._zod.def.shape)),e.catchall=s=>e.clone({...e._zod.def,catchall:s}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ka()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ka()}),e.strict=()=>e.clone({...e._zod.def,catchall:gh()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=s=>Zl(e,s),e.safeExtend=s=>$l(e,s),e.merge=s=>Ll(e,s),e.pick=s=>Tl(e,s),e.omit=s=>Rl(e,s),e.partial=(...s)=>Ul(ui,e,s[0]),e.required=(...s)=>Bl(hi,e,s[0])});function wh(e,r){const s={type:"object",shape:e??{},...de(r)};return new yh(s)}const jh=Q("ZodUnion",(e,r)=>{vd.init(e,r),Ve.init(e,r),e.options=r.options});function kh(e,r){return new jh({type:"union",options:e,...de(r)})}const _h=Q("ZodIntersection",(e,r)=>{yd.init(e,r),Ve.init(e,r)});function Nh(e,r){return new _h({type:"intersection",left:e,right:r})}const Ds=Q("ZodEnum",(e,r)=>{wd.init(e,r),Ve.init(e,r),e.enum=r.entries,e.options=Object.values(r.entries);const s=new Set(Object.keys(r.entries));e.extract=(a,n)=>{const i={};for(const o of a)if(s.has(o))i[o]=r.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Ds({...r,checks:[],...de(n),entries:i})},e.exclude=(a,n)=>{const i={...r.entries};for(const o of a)if(s.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Ds({...r,checks:[],...de(n),entries:i})}});function Sh(e,r){const s=Array.isArray(e)?Object.fromEntries(e.map(a=>[a,a])):e;return new Ds({type:"enum",entries:s,...de(r)})}const Ch=Q("ZodLiteral",(e,r)=>{jd.init(e,r),Ve.init(e,r),e.values=new Set(r.values),Object.defineProperty(e,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function Ga(e,r){return new Ch({type:"literal",values:Array.isArray(e)?e:[e],...de(r)})}const zh=Q("ZodTransform",(e,r)=>{kd.init(e,r),Ve.init(e,r),e._zod.parse=(s,a)=>{if(a.direction==="backward")throw new qn(e.constructor.name);s.addIssue=i=>{if(typeof i=="string")s.issues.push(Ir(i,s.value,r));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=s.value),o.inst??(o.inst=e),s.issues.push(Ir(o))}};const n=r.transform(s.value,s);return n instanceof Promise?n.then(i=>(s.value=i,s)):(s.value=n,s)}});function Eh(e){return new zh({type:"transform",transform:e})}const ui=Q("ZodOptional",(e,r)=>{_d.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Ha(e){return new ui({type:"optional",innerType:e})}const Ih=Q("ZodNullable",(e,r)=>{Nd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Qa(e){return new Ih({type:"nullable",innerType:e})}const Ah=Q("ZodDefault",(e,r)=>{Sd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ph(e,r){return new Ah({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():Gn(r)}})}const Fh=Q("ZodPrefault",(e,r)=>{Cd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Dh(e,r){return new Fh({type:"prefault",innerType:e,get defaultValue(){return typeof r=="function"?r():Gn(r)}})}const hi=Q("ZodNonOptional",(e,r)=>{zd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Oh(e,r){return new hi({type:"nonoptional",innerType:e,...de(r)})}const Th=Q("ZodCatch",(e,r)=>{Ed.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Rh(e,r){return new Th({type:"catch",innerType:e,catchValue:typeof r=="function"?r:()=>r})}const Zh=Q("ZodPipe",(e,r)=>{Id.init(e,r),Ve.init(e,r),e.in=r.in,e.out=r.out});function Ya(e,r){return new Zh({type:"pipe",in:e,out:r})}const $h=Q("ZodReadonly",(e,r)=>{Ad.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Lh(e){return new $h({type:"readonly",innerType:e})}const Uh=Q("ZodCustom",(e,r)=>{Pd.init(e,r),Ve.init(e,r)});function Bh(e,r={}){return ku(Uh,e,r)}function Mh(e){return _u(e)}function Vh(e){return ou(di,e)}const xr={image:10*1024*1024,audio:25*1024*1024,video:50*1024*1024,document:25*1024*1024},qh="image/*,video/*,audio/*,.pdf,.doc,.docx";function wt(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function _s(e){return e.startsWith("image/")?"image":e.startsWith("audio/")?"audio":e.startsWith("video/")?"video":"document"}function Wh(e){let r=1/0;for(const s of e){const a=Sn(s.type),n=s.config?.mediaLimits?.outbound?.image?.maxBytes??a.outbound.image.maxBytes??1/0;n<r&&(r=n)}return r===1/0?0:r}const Kh={HASHING:{label:"Calculando identidad...",detail:"Hash SHA-256 del archivo",color:"text-violet-500"},CHECKING_DEDUP:{label:"Verificando existencia...",detail:"Buscando duplicados",color:"text-blue-500"},OPTIMIZING:{label:"Optimizando imagen...",detail:"Comprimiendo para canales",color:"text-amber-500"},GENERATING_THUMB:{label:"Generando vista previa...",detail:"Thumbnail 300px",color:"text-cyan-500"},UPLOADING:{label:"Subiendo a la nube...",detail:"Upload seguro",color:"text-primary"},CONFIRMING:{label:"Confirmando...",detail:"Registro en base de datos",color:"text-emerald-500"}},Gh={WHATSAPP:{label:"WhatsApp",compatible:"bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-900/20 dark:text-emerald-400 dark:border-emerald-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},WEB:{label:"Web",compatible:"bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-900/20 dark:text-indigo-400 dark:border-indigo-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},INSTAGRAM:{label:"Instagram",compatible:"bg-pink-50 text-pink-700 border-pink-200 dark:bg-pink-900/20 dark:text-pink-400 dark:border-pink-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},FACEBOOK:{label:"Facebook",compatible:"bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-900/20 dark:text-blue-400 dark:border-blue-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"}},Hh={label:"?",compatible:"bg-slate-50 text-slate-600 border-slate-200 dark:bg-slate-800 dark:text-slate-400 dark:border-slate-700",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"};function Qh(e){return Gh[e?.toUpperCase()]||Hh}function Yh({channels:e,fileSizeBytes:r,mimeType:s}){const a=Y.useMemo(()=>Ui(e,r,s),[e,r,s]),n=a.filter(o=>o.isCompatible).length,i=n===a.length;return t.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100 dark:border-slate-800/60",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx(fo,{className:"h-2.5 w-2.5 text-muted-foreground/50"}),t.jsx("span",{className:"text-[9px] uppercase font-bold tracking-widest text-muted-foreground/60",children:"Canales"}),t.jsxs("span",{className:le("text-[9px] font-bold px-1 py-px rounded",i?"text-emerald-600 bg-emerald-50 dark:text-emerald-400 dark:bg-emerald-900/20":"text-amber-600 bg-amber-50 dark:text-amber-400 dark:bg-amber-900/20"),children:[n,"/",a.length]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(o=>{const l=Qh(o.channelType);return t.jsx(Ar,{children:t.jsxs(et,{delayDuration:0,children:[t.jsx(tt,{asChild:!0,children:t.jsxs("span",{className:le("inline-flex items-center gap-1 px-2 py-1 rounded-lg border text-[10px] font-semibold cursor-default transition-all",o.isCompatible?l.compatible:l.incompatible),children:[o.isCompatible?t.jsx(sa,{className:"h-3 w-3"}):t.jsx(ct,{className:"h-3 w-3"}),t.jsx("span",{children:l.label}),!o.isCompatible&&t.jsx("span",{className:"text-[8px] opacity-70 font-bold ml-0.5",children:wt(o.limitBytes)})]})}),t.jsx(rt,{side:"top",className:le("text-[11px] max-w-[240px] px-3 py-2 shadow-lg",!o.isCompatible&&"border-rose-200 dark:border-rose-800"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[o.isCompatible?t.jsx(sa,{className:"h-3.5 w-3.5 text-emerald-500 shrink-0 mt-0.5"}):t.jsx(ct,{className:"h-3.5 w-3.5 text-rose-500 shrink-0 mt-0.5"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-bold",children:o.channelName}),t.jsx("p",{className:"text-muted-foreground mt-0.5",children:o.isCompatible?`Compatible — máx. ${wt(o.limitBytes)}`:o.reason})]})]})})]})},o.channelId)})})]})}function Xh({media:e,onChange:r}){const[s,a]=Y.useState("IDLE"),[n,i]=Y.useState(!1),[o,l]=Y.useState(new Set),[h,p]=Y.useState(new Set),_=Y.useRef(null),w=Y.useRef(0),g=Os(F=>F.currentOrganization),{channels:d,fetchChannels:k}=an(Lt(F=>({channels:F.channels,fetchChannels:F.fetchChannels})));Y.useEffect(()=>{g?.id&&k({withDeleted:!1})},[g?.id,k]);const u=Y.useMemo(()=>d.filter(F=>F.isActive&&!F.deletedAt&&!F.disconnectedFromMetaAt&&!F.deactivatedAt&&!F.archivedAt),[d]),x=Y.useMemo(()=>({image:{maxBytes:Wh(u)||xr.image},video:{maxBytes:xr.video},audio:{maxBytes:xr.audio},document:{maxBytes:xr.document}}),[u]),f=Y.useCallback(F=>{const ee=_s(F.type),O=xr[ee];return F.size>O?`${F.name} excede el límite de ${wt(O)}`:null},[]),j=Y.useCallback(async F=>{const ee=f(F);if(ee){ne.error(ee);return}a("HASHING");try{const O=await Cs.processFile(F,{limits:x,onProgress:te=>a(te)}),L=_s(F.type),ae={id:O.hash||crypto.randomUUID(),url:O.thumbnailUrl||O.signedUrl||"",type:L,name:F.name,gcsPath:O.gcsPath,thumbnailUrl:O.thumbnailUrl||void 0,mimeType:O.mimeType||F.type,fileSizeBytes:O.size||F.size};r([...e,ae]),O.isDuplicate?(p(te=>new Set(te).add(ae.id)),ne.success("Archivo ya existente (reutilizado)")):O.isOptimized?(l(te=>new Set(te).add(ae.id)),ne.success(`Imagen optimizada: ${wt(F.size)} → ${wt(O.size)}`)):ne.success("Archivo subido correctamente")}catch(O){ne.error(O.message||"Error al subir archivo")}finally{a("IDLE")}},[e,r,f,x]),E=Y.useCallback(async F=>{const ee=F.target.files?.[0];ee&&await j(ee),F.target.value=""},[j]),P=Y.useCallback(F=>{const ee=[...e];ee.splice(F,1),r(ee)},[e,r]),S=Y.useCallback(async F=>{const ee=e[F];if(ee){a("OPTIMIZING");try{const O=ee.url||ee.thumbnailUrl||"";if(!O){ne.error("No se puede obtener el archivo para re-subir");return}const ae=await(await fetch(O)).blob(),te=new File([ae],ee.name||"image.jpg",{type:ee.mimeType||ae.type}),J=await Cs.processFile(te,{limits:x,onProgress:me=>a(me),skipDedup:!0}),ve=_s(te.type),Se={id:J.hash||crypto.randomUUID(),url:J.thumbnailUrl||J.signedUrl||"",type:ve,name:ee.name,gcsPath:J.gcsPath,thumbnailUrl:J.thumbnailUrl||void 0,mimeType:J.mimeType||te.type,fileSizeBytes:J.size||te.size},fe=[...e];fe[F]=Se,r(fe),p(me=>{const ke=new Set(me);return ke.delete(ee.id),ke}),J.isOptimized?(l(me=>new Set(me).add(Se.id)),ne.success(`Imagen optimizada: ${wt(te.size)} → ${wt(J.size)}`)):ne.success("Archivo re-subido correctamente")}catch(O){ne.error(O.message||"Error al re-subir archivo")}finally{a("IDLE")}}},[e,r,x]),B=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation(),w.current+=1,F.dataTransfer.items?.length&&i(!0)},[]),U=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation(),w.current-=1,w.current===0&&i(!1)},[]),$=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation()},[]),T=Y.useCallback(async F=>{F.preventDefault(),F.stopPropagation(),i(!1),w.current=0;const ee=F.dataTransfer.files?.[0];ee&&await j(ee)},[j]),G=F=>{switch(F){case"image":return t.jsx(At,{className:"h-5 w-5 text-blue-500"});case"audio":return t.jsx(En,{className:"h-5 w-5 text-amber-500"});case"video":return t.jsx(Cn,{className:"h-5 w-5 text-purple-500"});default:return t.jsx(zn,{className:"h-5 w-5 text-slate-400"})}},se=F=>{switch(F){case"image":return"bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400";case"audio":return"bg-amber-50 text-amber-600 dark:bg-amber-900/20 dark:text-amber-400";case"video":return"bg-purple-50 text-purple-600 dark:bg-purple-900/20 dark:text-purple-400";default:return"bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400"}},v=F=>{switch(F){case"image":return"Imagen";case"audio":return"Audio";case"video":return"Video";default:return"Documento"}},[R,m]=Y.useState(new Set),V=Y.useCallback(F=>{m(ee=>{const O=new Set(ee);return O.has(F)?O.delete(F):O.add(F),O})},[]),ie=Y.useCallback((F,ee,O)=>{const L=[...e];L[F]={...L[F],[ee]:O||null},r(L)},[e,r]),q=s!=="IDLE"&&s!=="DONE"&&s!=="ERROR",ce=q?Kh[s]:null;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 bg-violet-50 dark:bg-violet-900/20 rounded-lg flex items-center justify-center",children:t.jsx(Hr,{className:"h-3.5 w-3.5 text-violet-500"})}),t.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-slate-500",children:"Multimedia"}),e.length>0&&t.jsxs("span",{className:"ml-auto text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-2 py-0.5 rounded-full",children:[e.length," ",e.length===1?"archivo":"archivos"]})]}),t.jsxs("div",{onDragEnter:B,onDragLeave:U,onDragOver:$,onDrop:T,onClick:()=>!q&&_.current?.click(),className:le("relative border-2 border-dashed rounded-2xl p-6 text-center transition-all duration-200 cursor-pointer group",n?"border-primary bg-primary/5 scale-[1.01]":"border-slate-200 dark:border-slate-700 hover:border-primary/40 hover:bg-slate-50/50 dark:hover:bg-slate-800/30",q&&"pointer-events-none opacity-60"),children:[t.jsx("input",{ref:_,type:"file",className:"hidden",accept:qh,onChange:E,disabled:q}),t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[q?t.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:t.jsx(be,{className:le("h-5 w-5 animate-spin",ce?.color||"text-primary")})}):n?t.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center animate-pulse",children:t.jsx(ia,{className:"h-5 w-5 text-primary"})}):t.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center group-hover:bg-primary/10 transition-colors",children:t.jsx(ia,{className:"h-5 w-5 text-slate-400 group-hover:text-primary transition-colors"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:q?ce?.label:n?"Soltar archivo aquí":"Arrastra o haz click para subir"}),q&&ce?.detail?t.jsx("p",{className:le("text-[11px] mt-0.5 font-medium animate-pulse",ce.color),children:ce.detail}):!q&&t.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Imágenes (10 MB), Videos (50 MB), Audio (25 MB), PDF/DOC (25 MB)"})]})]})]}),e.length>0&&t.jsx("div",{className:"grid grid-cols-1 gap-2",children:e.map((F,ee)=>t.jsxs("div",{className:"relative group bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 rounded-xl p-2.5 hover:shadow-sm transition-all",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[F.type==="image"&&F.url?t.jsx("div",{className:"w-12 h-12 rounded-lg overflow-hidden shrink-0 bg-slate-100 dark:bg-slate-800",children:t.jsx("img",{src:F.url,alt:F.name,className:"object-cover w-full h-full"})}):t.jsx("div",{className:"w-12 h-12 rounded-lg shrink-0 bg-slate-50 dark:bg-slate-800 flex items-center justify-center",children:G(F.type)}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"text-sm font-medium text-slate-800 dark:text-slate-200 truncate",children:F.name}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[F.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-500 dark:text-slate-400",children:wt(F.fileSizeBytes)}),t.jsx("span",{className:le("text-[10px] font-bold uppercase px-1.5 py-0.5 rounded-md",se(F.type)),children:v(F.type)}),F.gcsPath&&t.jsx(sr,{className:"h-3 w-3 text-emerald-500"}),o.has(F.id)&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-bold uppercase px-1.5 py-0.5 rounded-md bg-amber-50 text-amber-600 dark:bg-amber-900/20 dark:text-amber-400",children:[t.jsx(Fr,{className:"h-2.5 w-2.5"}),"Optimizada"]}),h.has(F.id)&&t.jsx(Ar,{children:t.jsxs(et,{delayDuration:0,children:[t.jsx(tt,{asChild:!0,children:t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-bold uppercase px-1.5 py-0.5 rounded-md bg-sky-50 text-sky-600 dark:bg-sky-900/20 dark:text-sky-400 group/dedup cursor-default",children:[t.jsx(Zi,{className:"h-2.5 w-2.5"}),"Cloud Reused",t.jsx("button",{type:"button",className:"ml-0.5 rounded-full hover:bg-sky-200 dark:hover:bg-sky-800 p-px transition-colors",onClick:O=>{O.stopPropagation(),S(ee)},disabled:q,children:t.jsx(Ft,{className:"h-2.5 w-2.5"})})]})}),t.jsxs(rt,{side:"top",className:"text-[11px] max-w-[240px] px-3 py-2",children:[t.jsx("p",{className:"font-semibold",children:"Archivo reutilizado de la nube"}),t.jsxs("p",{className:"text-muted-foreground mt-0.5",children:["Este archivo ya existía. Haz click en ",t.jsx("strong",{children:"✕"})," para forzar una nueva carga con optimización."]})]})]})})]})]}),t.jsx(ue,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-rose-500 hover:bg-rose-50 dark:hover:bg-rose-900/20 shrink-0",onClick:O=>{O.stopPropagation(),P(ee)},children:t.jsx(Ft,{className:"h-3.5 w-3.5"})})]}),t.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100 dark:border-slate-800/60",children:[t.jsxs("button",{type:"button",onClick:()=>V(F.id),className:"flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-wider text-muted-foreground/60 hover:text-muted-foreground transition-colors w-full",children:[t.jsx(_n,{className:"h-2.5 w-2.5"}),t.jsx("span",{children:"Contexto para IA"}),(F.description||F.salesContext)&&t.jsx(sr,{className:"h-2.5 w-2.5 text-emerald-500"}),R.has(F.id)?t.jsx(yn,{className:"h-3 w-3 ml-auto"}):t.jsx(Dr,{className:"h-3 w-3 ml-auto"})]}),R.has(F.id)&&t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 mb-0.5 block",children:"Descripción del recurso"}),t.jsx("input",{type:"text",placeholder:"Ej: Video demo del producto en uso",value:F.description||"",onChange:O=>ie(ee,"description",O.target.value),maxLength:500,className:"w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-primary/40"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 mb-0.5 block",children:"Cuándo usarlo en la conversación"}),t.jsx("input",{type:"text",placeholder:"Ej: Cuando el cliente duda de la calidad",value:F.salesContext||"",onChange:O=>ie(ee,"salesContext",O.target.value),maxLength:500,className:"w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-primary/40"})]})]})]}),F.fileSizeBytes&&F.mimeType&&u.length>0&&t.jsx(Yh,{channels:u,fileSizeBytes:F.fileSizeBytes,mimeType:F.mimeType})]},F.id||ee))})]})}const Jh=wh({name:Ct().min(1,"Nombre es requerido").max(255),description:Ct().min(1,"Descripción es requerida"),price:Vh().min(0,"Precio debe ser mayor o igual a 0"),currency:Ct().min(1,"Moneda es requerida"),externalId:Ct().max(100).optional().or(Ga("")),externalCategory:Ct().max(100).optional().or(Ga("")),catalogId:Ct().uuid("Selecciona un catálogo"),imageUrl:Ct().optional()});function Ns({icon:e,label:r,iconBg:s,accentHover:a,badge:n,children:i}){return t.jsxs(Rs,{className:le("border-border/40 shadow-sm bg-background/50 group transition-all duration-200 overflow-hidden",a),children:[t.jsxs(Fi,{className:"flex flex-row items-center justify-between space-y-0 px-4 py-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:le("w-6 h-6 rounded-md flex items-center justify-center",s),children:e}),t.jsx(Di,{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:r})]}),n]}),t.jsx(Zs,{className:"space-y-3 pt-0 px-4 pb-4",children:i})]})}function zt({children:e,required:r}){return t.jsxs(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:[e,r&&t.jsx("span",{className:"text-rose-500 ml-0.5",children:"*"})]})}function em({product:e,catalogs:r,organizationId:s,isSubmitting:a,onSubmit:n}){const{register:i,handleSubmit:o,setValue:l,watch:h,formState:{errors:p}}=Cl({resolver:zu(Jh),defaultValues:e?{name:e.name,description:e.description||"",price:Number(e.price),currency:e.currency||"USD",externalId:e.externalId||"",externalCategory:e.externalCategory||"",catalogId:e.catalogId||"",imageUrl:e.imageUrl}:{name:"",description:"",price:0,currency:"USD",externalId:"",externalCategory:"",catalogId:"",imageUrl:void 0}}),_=h("currency"),w=h("catalogId"),[g,d]=Y.useState(()=>e?.media&&e.media.length>0?e.media:e&&(e.thumbnailUrl||e.imageUrl)?[{id:"existing",url:e.thumbnailUrl||"",type:"image",name:e.media?.[0]?.name||"Imagen del producto",gcsPath:e.imageUrl,thumbnailUrl:e.thumbnailUrl}]:[]),k=x=>{d(x);const f=x.find(j=>j.type==="image");l("imageUrl",f?.gcsPath||void 0)},u=x=>{n({...x,media:g})};return t.jsxs("form",{onSubmit:o(u),className:"space-y-3 pb-2",children:[t.jsxs(Ns,{icon:t.jsx(it,{className:"h-3.5 w-3.5 text-indigo-500"}),label:"Información Básica",iconBg:"bg-indigo-500/10",accentHover:"hover:border-indigo-500/20",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Nombre del producto"}),t.jsx(st,{...i("name"),placeholder:"Ej: Curso de Marketing Digital",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-medium"}),p.name&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.name.message})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(zt,{required:!0,children:"Descripción"}),t.jsxs(Ce,{variant:"outline",className:"text-[9px] font-bold uppercase tracking-wider px-2 py-0 border-amber-500/30 text-amber-600 dark:text-amber-400 bg-amber-500/5 flex items-center gap-1",children:[t.jsx(Fr,{className:"h-2.5 w-2.5"}),"Clave para IA"]})]}),t.jsx(vn,{...i("description"),placeholder:"Describe el producto con detalle: características, beneficios, público objetivo. La IA usará esta información para recomendarlo.",className:"min-h-[90px] rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 resize-none text-sm leading-relaxed"}),p.description&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.description.message})]})]}),t.jsx(Xh,{media:g,organizationId:s,onChange:k}),t.jsx(Ns,{icon:t.jsx(cr,{className:"h-3.5 w-3.5 text-emerald-500"}),label:"Precio",iconBg:"bg-emerald-500/10",accentHover:"hover:border-emerald-500/20",children:t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Monto"}),t.jsx(st,{type:"number",step:"0.01",...i("price"),placeholder:"0.00",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-medium font-mono"}),p.price&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.price.message})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Moneda"}),t.jsxs(ar,{value:_,onValueChange:x=>l("currency",x),children:[t.jsx(nr,{className:"h-9 rounded-lg bg-muted/30 border-border/50",children:t.jsx(ir,{})}),t.jsx(or,{className:"rounded-lg",children:jn.map(x=>t.jsx(kt,{value:x.value,className:"rounded-lg",children:x.label},x.value))})]})]})]})}),t.jsxs(Ns,{icon:t.jsx(dt,{className:"h-3.5 w-3.5 text-violet-500"}),label:"Clasificación",iconBg:"bg-violet-500/10",accentHover:"hover:border-violet-500/20",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Catálogo"}),t.jsxs(ar,{value:w,onValueChange:x=>l("catalogId",x),children:[t.jsx(nr,{className:"h-9 rounded-lg bg-muted/30 border-border/50",children:t.jsx(ir,{placeholder:"Seleccionar catálogo..."})}),t.jsx(or,{className:"rounded-lg",children:r.map(x=>t.jsx(kt,{value:x.id,className:"rounded-lg",children:x.name},x.id))})]}),p.catalogId&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.catalogId.message})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(In,{className:"h-3 w-3 text-muted-foreground/50"}),t.jsx(zt,{children:"SKU / ID Externo"})]}),t.jsx(st,{...i("externalId"),placeholder:"Opcional",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-mono"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ss,{className:"h-3 w-3 text-muted-foreground/50"}),t.jsx(zt,{children:"Categoría"})]}),t.jsx(st,{...i("externalCategory"),placeholder:"Opcional",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm"})]})]})]}),t.jsxs(ue,{type:"submit",className:"w-full h-10 rounded-lg bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 font-bold text-sm transition-all",disabled:a,children:[a?t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"}):t.jsx(An,{className:"h-4 w-4 mr-2"}),e?"Guardar cambios":"Crear Producto"]})]})}function tm(e,r,s=5){const a=Math.min(r,s);if(r<=s)return Array.from({length:a},(i,o)=>o+1);const n=Math.floor(s/2);return e<=n+1?Array.from({length:a},(i,o)=>o+1):e>=r-n?Array.from({length:a},(i,o)=>r-a+1+o):Array.from({length:a},(i,o)=>e-n+o)}const Ss=({label:e,column:r,currentSort:s,currentOrder:a,onSort:n,className:i})=>{const o=s===r;return t.jsxs("button",{type:"button",onClick:()=>n?.(r),className:le("flex items-center gap-1 font-black uppercase text-[10px] tracking-widest transition-colors group/sort",o?"text-primary":"text-slate-400 hover:text-slate-600 dark:hover:text-slate-300",i),children:[e,o?a==="ASC"?t.jsx(Vi,{className:"w-3 h-3"}):t.jsx(qi,{className:"w-3 h-3"}):t.jsx(Wi,{className:"w-3 h-3 opacity-0 group-hover/sort:opacity-50 transition-opacity"})]})},rm={default:{color:"text-slate-600",bgClass:"bg-slate-50 dark:bg-slate-800"}};function sm(e){if(!e)return rm.default;const r=e.split("").reduce((a,n)=>a+n.charCodeAt(0),0),s=[{color:"text-violet-600",bgClass:"bg-violet-50 dark:bg-violet-900/20"},{color:"text-blue-600",bgClass:"bg-blue-50 dark:bg-blue-900/20"},{color:"text-emerald-600",bgClass:"bg-emerald-50 dark:bg-emerald-900/20"},{color:"text-amber-600",bgClass:"bg-amber-50 dark:bg-amber-900/20"},{color:"text-rose-600",bgClass:"bg-rose-50 dark:bg-rose-900/20"},{color:"text-indigo-600",bgClass:"bg-indigo-50 dark:bg-indigo-900/20"},{color:"text-teal-600",bgClass:"bg-teal-50 dark:bg-teal-900/20"}];return s[r%s.length]}const mi=Y.memo(({products:e,catalogs:r,isLoading:s,selectedIds:a,onSelect:n,onSelectAll:i,onViewDetail:o,onEdit:l,onDelete:h,onToggleActive:p,onSyncProduct:_,missingIds:w,page:g,total:d,limit:k,onPageChange:u,density:x="comfortable",sortBy:f,sortOrder:j,onSort:E})=>{if(s)return t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 p-16 flex flex-col items-center justify-center gap-6 animate-pulse",children:[t.jsx("div",{className:"w-16 h-16 bg-slate-50 dark:bg-slate-800 rounded-2xl flex items-center justify-center",children:t.jsx(be,{className:"w-8 h-8 animate-spin text-primary"})}),t.jsxs("div",{className:"space-y-2 text-center",children:[t.jsx("p",{className:"text-slate-900 dark:text-white font-black text-lg",children:"Cargando productos"}),t.jsx("p",{className:"text-slate-500 text-sm",children:"Obteniendo inventario..."})]})]});if(e.length===0)return t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(it,{className:"w-10 h-10 text-slate-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2 tracking-tight",children:"Sin productos"}),t.jsx("p",{className:"text-slate-500 max-w-sm mx-auto text-sm leading-relaxed",children:"No hay productos que coincidan con los filtros seleccionados."})]});const P=e.length>0&&a.length===e.length,S=Math.ceil(d/k),B=Y.useMemo(()=>tm(g,S),[g,S]),U=$=>$&&r.find(T=>T.id===$)?.name||"—";return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden flex flex-col animate-in fade-in slide-in-from-bottom-2 duration-500",children:[t.jsx("div",{className:"overflow-x-auto no-scrollbar",children:t.jsxs(Qr,{children:[t.jsx(Yr,{children:t.jsxs(lr,{className:"bg-slate-50/30 dark:bg-slate-800/20 hover:bg-slate-50/30 dark:hover:bg-slate-800/20 border-slate-100 dark:border-slate-800",children:[t.jsx(De,{className:le("w-[50px] pl-6",x==="compact"?"py-3":"py-5"),children:t.jsx(oa,{checked:P,onCheckedChange:$=>i(!!$),className:"data-[state=checked]:bg-primary data-[state=checked]:border-primary rounded-[6px]"})}),t.jsx(De,{className:le("pl-2 min-w-[280px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Producto",column:"name",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("min-w-[120px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Categoría",column:"externalCategory",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("min-w-[120px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Precio",column:"price",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("font-black uppercase text-[10px] tracking-widest text-slate-400 min-w-[120px]",x==="compact"?"py-3":"py-5"),children:"Catálogo"}),t.jsx(De,{className:le("font-black uppercase text-[10px] tracking-widest text-slate-400 min-w-[100px]",x==="compact"?"py-3":"py-5"),children:"SKU"}),t.jsx(De,{className:"w-[80px] pr-6"})]})}),t.jsx(wn,{children:e.map($=>{const T=a.includes($.id),G=sm($.externalCategory),se=w?.has($.id)??!1;return t.jsxs(lr,{className:le("group cursor-pointer hover:bg-slate-50/80 dark:hover:bg-slate-800/50 border-slate-50/50 dark:border-slate-800/50 transition-all duration-300",T&&"bg-primary/5 dark:bg-primary/10 hover:bg-primary/10",!$.isActive&&"opacity-50 grayscale",x==="compact"&&"h-12"),onClick:()=>o($),children:[t.jsx(ut,{className:le("pl-6",x==="compact"?"py-1.5":"py-4"),onClick:v=>v.stopPropagation(),children:t.jsx(oa,{checked:T,onCheckedChange:()=>n($.id),className:"data-[state=checked]:bg-primary rounded-[6px]"})}),t.jsx(ut,{className:le("pl-2",x==="compact"?"py-1.5":"py-4"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsx("div",{className:"relative group-hover:scale-105 transition-transform duration-300",children:t.jsx("div",{className:le("flex items-center justify-center rounded-2xl border-2 border-white dark:border-slate-800 shadow-md overflow-hidden bg-slate-50 dark:bg-slate-800",x==="compact"?"h-10 w-10":"h-12 w-12"),children:$.thumbnailUrl||$.media?.[0]?.thumbnailUrl?t.jsx("img",{src:$.thumbnailUrl||$.media?.[0]?.thumbnailUrl||"",alt:$.name,className:"h-full w-full object-cover"}):t.jsx(it,{className:"w-5 h-5 text-slate-300"})})}),t.jsxs("div",{className:"min-w-0 flex flex-col",children:[t.jsx("span",{className:le("text-slate-900 dark:text-white truncate leading-tight group-hover:text-primary transition-colors",x==="compact"?"text-[13px] font-semibold":"text-sm font-black"),children:$.name}),t.jsx("span",{className:le("text-slate-500 dark:text-slate-400 truncate block mt-0.5 max-w-[260px]",x==="compact"?"text-[10px]":"text-[11px]"),children:$.description}),se&&t.jsxs("span",{className:"flex items-center gap-1 mt-1 text-[10px] font-bold text-amber-600 dark:text-amber-400",children:[t.jsx(ct,{className:"w-3 h-3"}),"Sin indexar en búsqueda IA"]})]})]})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:$.externalCategory?t.jsxs(Ce,{variant:"outline",className:le("text-[11px] font-bold px-3 py-1 rounded-full border-none flex items-center gap-1.5 w-fit",G.bgClass,G.color),children:[t.jsx(ss,{className:"w-3 h-3"}),$.externalCategory]}):t.jsx("span",{className:"text-slate-300 text-xs",children:"—"})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-emerald-50 dark:bg-emerald-900/20 flex items-center justify-center",children:t.jsx(cr,{className:"w-3.5 h-3.5 text-emerald-500"})}),t.jsx("span",{className:"text-[13px] font-bold text-slate-700 dark:text-slate-300 font-mono",children:zr($.price,$.currency)})]})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:t.jsx("span",{className:"text-[12px] font-medium text-slate-500 dark:text-slate-400",children:U($.catalogId)})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:$.externalId?t.jsx("span",{className:"text-[11px] font-mono text-slate-500 dark:text-slate-400 bg-slate-50 dark:bg-slate-800 px-2.5 py-1 rounded-lg",children:$.externalId}):t.jsx("span",{className:"text-slate-300 text-xs",children:"—"})}),t.jsx(ut,{className:le("text-right pr-6",x==="compact"?"py-1.5":"py-4"),onClick:v=>v.stopPropagation(),children:t.jsx("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity translate-x-4 group-hover:translate-x-0 duration-300",children:t.jsxs(pn,{children:[t.jsx(xn,{asChild:!0,children:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-slate-200/50",children:t.jsx(Pn,{className:"h-4 w-4 text-slate-400"})})}),t.jsxs(gn,{align:"end",className:"w-48 p-2 rounded-2xl shadow-2xl border-slate-100",children:[t.jsx(bn,{className:"text-[10px] uppercase font-black tracking-widest text-slate-400 p-2",children:"Opciones"}),t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>o($),className:"rounded-xl p-2.5 font-bold text-sm",children:[t.jsx(Fn,{className:"mr-3 h-4 w-4 text-slate-400"}),"Ver Detalles"]}),t.jsxs(It,{onClick:()=>l($),className:"rounded-xl p-2.5 font-bold text-sm",children:[t.jsx($s,{className:"mr-3 h-4 w-4 text-slate-400"}),"Editar"]}),t.jsx(Gr,{className:"bg-slate-50"}),p&&t.jsx(It,{onClick:()=>p($),className:le("rounded-xl p-2.5 font-bold text-sm",$.isActive?"text-amber-600 focus:text-amber-700 focus:bg-amber-50":"text-emerald-600 focus:text-emerald-700 focus:bg-emerald-50"),children:$.isActive?t.jsxs(t.Fragment,{children:[t.jsx(Cr,{className:"mr-3 h-4 w-4"}),"Desactivar"]}):t.jsxs(t.Fragment,{children:[t.jsx(Ls,{className:"mr-3 h-4 w-4"}),"Activar"]})}),se&&_&&t.jsxs(It,{onClick:()=>_($),className:"rounded-xl p-2.5 font-bold text-sm text-blue-600 focus:text-blue-700 focus:bg-blue-50",children:[t.jsx(hr,{className:"mr-3 h-4 w-4"}),"Reindexar IA"]}),t.jsxs(It,{onClick:()=>h($),className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50",children:[t.jsx(bt,{className:"mr-3 h-4 w-4"}),"Eliminar permanente"]})]})]})})})]},$.id)})})]})}),d>0&&t.jsxs("div",{className:"px-6 py-3 bg-slate-50/80 dark:bg-slate-900/50 border-t border-slate-100 dark:border-slate-800 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[11px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest",children:S>1?t.jsxs(t.Fragment,{children:["Página ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:g})," de ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:S})]}):t.jsxs(t.Fragment,{children:["Página ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:"1"})," de ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:"1"})]})}),t.jsx("span",{className:"w-px h-4 bg-slate-200 dark:bg-slate-700"}),t.jsx("span",{className:"text-[11px] font-medium text-slate-400 dark:text-slate-500",children:d<=k?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:d})," producto",d!==1?"s":""]}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:[(g-1)*k+1,"–",Math.min(g*k,d)]})," de ",t.jsx("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:d})," productos"]})})]}),S>1&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ue,{variant:"outline",size:"sm",disabled:g<=1,onClick:()=>u(g-1),className:"h-8 px-3 rounded-xl font-bold text-[11px] text-slate-600 border-slate-200 bg-white hover:bg-slate-50 transition-all shadow-sm dark:bg-slate-800 dark:border-slate-700 dark:text-slate-300",children:"Anterior"}),t.jsx("div",{className:"flex items-center gap-0.5",children:B.map($=>t.jsx("button",{onClick:()=>u($),className:`h-8 w-8 rounded-lg text-[11px] font-bold transition-all ${$===g?"bg-primary text-white shadow-sm":"text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-800 dark:text-slate-400"}`,children:$},$))}),t.jsx(ue,{variant:"outline",size:"sm",disabled:g>=S,onClick:()=>u(g+1),className:"h-8 px-3 rounded-xl font-bold text-[11px] text-slate-600 border-slate-200 bg-white hover:bg-slate-50 transition-all shadow-sm dark:bg-slate-800 dark:border-slate-700 dark:text-slate-300",children:"Siguiente"})]})]})]})});mi.displayName="ProductsTable";function am({product:e,catalogs:r,open:s,onOpenChange:a,onEdit:n,onDelete:i,onToggleActive:o}){const l=e&&r.find(S=>S.id===e.catalogId)?.name||"—",h=e?.media?.[0]??null,p=h?.thumbnailUrl||e?.thumbnailUrl||null,[_,w]=Y.useState(null),[g,d]=Y.useState(!1),[k,u]=Y.useState(!1);Y.useEffect(()=>{s||(w(null),d(!1),u(!1))},[s,e?.id]);const x=h?.gcsPath||e?.imageUrl||null,f=!!(p||x),j=Y.useCallback(async()=>{if(_){u(!0);return}if(x){d(!0);try{const S=await we.getSignedUrl(x);w(S),u(!0)}catch{}finally{d(!1)}}},[_,x]),E=S=>S?S<1024?`${S} B`:S<1024*1024?`${(S/1024).toFixed(1)} KB`:`${(S/(1024*1024)).toFixed(1)} MB`:"",P=S=>{try{return as(S,{style:"date-only"})}catch{return S}};return t.jsx(jr,{open:s,onOpenChange:a,children:t.jsx(kr,{className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",title:e?`Detalle: ${e.name}`:"Cargando...",description:"Detalle de producto",children:e?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800 shrink-0",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:le("w-14 h-14 rounded-2xl shrink-0 overflow-hidden border-2 shadow-md flex items-center justify-center bg-slate-50 dark:bg-slate-800",e.isActive===!1?"border-amber-200 dark:border-amber-800/50 opacity-60 grayscale":"border-white dark:border-slate-800"),children:p?t.jsx("img",{src:p,alt:e.name,className:"h-full w-full object-cover"}):t.jsx(it,{className:"w-6 h-6 text-slate-300"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Nr,{className:"text-lg font-black text-slate-900 dark:text-white truncate",children:e.name}),e.isActive===!1&&t.jsxs(Ce,{variant:"outline",className:"text-[10px] font-bold px-2 py-0.5 rounded-full border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400 shrink-0 flex items-center gap-1",children:[t.jsx(Cr,{className:"w-2.5 h-2.5"}),"Desactivado"]})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsxs(Ce,{variant:"outline",className:"text-[11px] font-bold px-2.5 py-0.5 rounded-full border-none bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 flex items-center gap-1",children:[t.jsx(cr,{className:"w-3 h-3"}),zr(e.price,e.currency)]}),e.externalCategory&&t.jsxs(Ce,{variant:"outline",className:"text-[11px] font-bold px-2.5 py-0.5 rounded-full border-none bg-violet-50 dark:bg-violet-900/20 text-violet-600 flex items-center gap-1",children:[t.jsx(ss,{className:"w-3 h-3"}),e.externalCategory]})]})]})]})}),e.isActive===!1&&t.jsxs("div",{className:"mx-4 mt-3 flex items-center gap-3 rounded-xl bg-amber-50 dark:bg-amber-950/40 border border-amber-200/60 dark:border-amber-800/40 px-4 py-3 shrink-0",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100 dark:bg-amber-900/50 flex items-center justify-center shrink-0",children:t.jsx(Cr,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-xs font-bold text-amber-700 dark:text-amber-300",children:"Producto desactivado"}),t.jsx("p",{className:"text-[11px] text-amber-600/70 dark:text-amber-400/60 mt-0.5",children:"No visible para la IA ni clientes"})]}),o&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>o(e),className:"shrink-0 h-8 rounded-lg text-xs font-bold border-amber-300 dark:border-amber-700 text-amber-700 dark:text-amber-300 hover:bg-amber-100 dark:hover:bg-amber-900/50 gap-1.5",children:[t.jsx(Ls,{className:"h-3.5 w-3.5"}),"Activar"]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"px-6 py-5 space-y-5",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(In,{className:"h-3.5 w-3.5"}),"SKU / ID Externo"]}),t.jsx("p",{className:"font-mono text-xs text-slate-700 dark:text-slate-300 truncate",children:e.externalId||"—"})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(dt,{className:"h-3.5 w-3.5"}),"Catálogo"]}),t.jsx("p",{className:"text-sm font-bold text-slate-700 dark:text-slate-300",children:l})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(cr,{className:"h-3.5 w-3.5"}),"Precio"]}),t.jsx("p",{className:"text-sm font-black text-emerald-600 font-mono",children:zr(e.price,e.currency)})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(Ki,{className:"h-3.5 w-3.5"}),"Creado"]}),t.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:P(e.createdAt)})]})]}),t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-2",children:[t.jsx(Wr,{className:"h-3.5 w-3.5"}),"Descripción (Clave para IA)"]}),t.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300 leading-relaxed whitespace-pre-wrap",children:e.description||"Sin descripción"})]}),t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-3",children:[t.jsx(At,{className:"h-3.5 w-3.5"}),"Imagen del producto"]}),f?t.jsx("div",{className:"space-y-2.5",children:k&&_?t.jsxs("div",{className:"rounded-xl overflow-hidden border border-slate-200 dark:border-slate-700 shadow-sm relative",children:[t.jsx("img",{src:_,alt:e.name,className:"w-full h-auto max-h-[400px] object-contain bg-white dark:bg-slate-900"}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-white/90 dark:bg-slate-900/90 backdrop-blur-sm border-t border-slate-100 dark:border-slate-800",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[h?.name&&t.jsx("span",{className:"text-[11px] font-medium text-slate-500 dark:text-slate-400 truncate max-w-[180px]",children:h.name}),h?.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded shrink-0",children:E(h.fileSizeBytes)}),h?.mimeType&&t.jsx("span",{className:"text-[10px] font-bold uppercase text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded shrink-0",children:h.mimeType.split("/")[1]||h.mimeType})]}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>u(!1),className:"h-6 w-6 rounded-md text-slate-400 hover:text-slate-600 shrink-0",children:t.jsx(Ft,{className:"h-3.5 w-3.5"})})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"rounded-xl overflow-hidden border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900",children:[t.jsx("div",{className:"flex items-center justify-center p-3",children:t.jsx("div",{className:"w-24 h-24 rounded-lg overflow-hidden shrink-0",children:p?t.jsx("img",{src:p,alt:e.name,className:"w-full h-full object-contain"}):t.jsx("div",{className:"w-full h-full flex items-center justify-center bg-slate-50 dark:bg-slate-800 rounded-lg",children:t.jsx(At,{className:"h-6 w-6 text-slate-300"})})})}),h&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-t border-slate-100 dark:border-slate-800",children:[h.name&&t.jsx("span",{className:"text-[11px] font-medium text-slate-500 dark:text-slate-400 truncate min-w-0",children:h.name}),t.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[h.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded",children:E(h.fileSizeBytes)}),h.mimeType&&t.jsx("span",{className:"text-[10px] font-bold uppercase text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded",children:h.mimeType.split("/")[1]||h.mimeType})]})]})]}),x&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:j,disabled:g,className:"w-full h-8 text-xs rounded-lg gap-1.5",children:[g?t.jsx(be,{className:"h-3 w-3 animate-spin"}):t.jsx(Dn,{className:"h-3 w-3"}),g?"Cargando imagen...":"Ver imagen completa"]})]})}):t.jsxs("div",{className:"flex flex-col items-center justify-center py-6 gap-2",children:[t.jsx("div",{className:"w-11 h-11 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:t.jsx(At,{className:"h-5 w-5 text-slate-300 dark:text-slate-600"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-xs font-medium text-slate-400 dark:text-slate-500",children:"Sin imagen"}),t.jsx("p",{className:"text-[11px] text-slate-300 dark:text-slate-600 mt-0.5",children:"Edita el producto para agregar una"})]})]})]}),e.media&&e.media.length>0&&t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-3",children:[t.jsx(Fr,{className:"h-3.5 w-3.5"}),"Recursos de venta",t.jsx("span",{className:"ml-auto text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded-full",children:e.media.length})]}),t.jsx("div",{className:"space-y-2",children:e.media.map((S,B)=>{const U=S.type==="image"?t.jsx(At,{className:"h-3.5 w-3.5 text-blue-500"}):S.type==="audio"?t.jsx(En,{className:"h-3.5 w-3.5 text-amber-500"}):S.type==="video"?t.jsx(Cn,{className:"h-3.5 w-3.5 text-purple-500"}):t.jsx(zn,{className:"h-3.5 w-3.5 text-slate-400"}),$=S.type==="image"?"Imagen":S.type==="audio"?"Audio":S.type==="video"?"Video":"Documento";return t.jsxs("div",{className:"flex items-start gap-2.5 p-2.5 bg-white dark:bg-slate-900 rounded-lg border border-slate-100 dark:border-slate-800",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-50 dark:bg-slate-800 flex items-center justify-center shrink-0 mt-0.5",children:U}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-200 truncate",children:S.name}),t.jsx("span",{className:"text-[9px] font-bold uppercase px-1.5 py-0.5 rounded bg-slate-100 dark:bg-slate-800 text-slate-500 shrink-0",children:$}),S.fileSizeBytes&&t.jsx("span",{className:"text-[9px] font-bold text-slate-400 shrink-0",children:E(S.fileSizeBytes)})]}),S.description&&t.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-0.5 leading-relaxed",children:S.description}),S.salesContext&&t.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[t.jsx(_n,{className:"h-2.5 w-2.5 text-violet-400 shrink-0"}),t.jsx("span",{className:"text-[10px] text-violet-500 dark:text-violet-400 italic",children:S.salesContext})]})]})]},S.id||B)})})]})]})}),t.jsxs("div",{className:"px-6 py-4 border-t border-slate-100 dark:border-slate-800 flex items-center gap-2 shrink-0",children:[t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>{a(!1),n(e)},className:"rounded-xl flex-1",children:[t.jsx($s,{className:"h-4 w-4 mr-2"}),"Editar"]}),t.jsx(ue,{variant:"outline",size:"sm",onClick:()=>{a(!1),i(e)},className:"rounded-xl text-rose-600 hover:text-rose-700 hover:bg-rose-50",children:t.jsx(bt,{className:"h-4 w-4"})})]})]}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800 shrink-0",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(at,{className:"w-14 h-14 rounded-xl shrink-0"}),t.jsxs("div",{className:"flex-1 space-y-2",children:[t.jsx(at,{className:"h-6 w-3/4"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(at,{className:"h-5 w-20 rounded-full"}),t.jsx(at,{className:"h-5 w-20 rounded-full"})]})]})]})}),t.jsxs("div",{className:"flex-1 px-6 py-5 space-y-5",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"})]}),t.jsx(at,{className:"h-[200px] w-full rounded-xl"})]})]})})})}const Xa={query:"",maxPrice:"",category:"",limit:"10",scoreThreshold:.3,filtersOpen:!1,results:null,currentLimit:10,isLoadingMore:!1},qe=Ts(e=>({...Xa,setQuery:r=>e({query:r}),setMaxPrice:r=>e({maxPrice:r}),setCategory:r=>e({category:r}),setLimit:r=>e({limit:r,currentLimit:parseInt(r,10)||10}),setScoreThreshold:r=>e({scoreThreshold:r}),setFiltersOpen:r=>e({filtersOpen:r}),setResults:r=>e({results:r}),setCurrentLimit:r=>e({currentLimit:r}),setIsLoadingMore:r=>e({isLoadingMore:r}),appendResults:r=>e(s=>{if(!s.results)return{results:r};const a=new Set(s.results.results.map(i=>i.id)),n=r.results.filter(i=>!a.has(i.id));return{results:{...r,results:[...s.results.results,...n],metadata:{...r.metadata,total_results:s.results.results.length+n.length}}}}),reset:()=>e(Xa)}));function nm(e){return e>=.7?{label:"Excelente",className:"bg-emerald-100 text-emerald-700 border-emerald-200",barColor:"bg-emerald-500"}:e>=.5?{label:"Bueno",className:"bg-blue-100 text-blue-700 border-blue-200",barColor:"bg-blue-500"}:e>=.3?{label:"Regular",className:"bg-amber-100 text-amber-700 border-amber-200",barColor:"bg-amber-500"}:{label:"Bajo",className:"bg-red-100 text-red-700 border-red-200",barColor:"bg-red-400"}}function Ja(e){return e.pg_exists?e.pg_active===!1?{label:"Inactivo en PG",className:"bg-amber-100 text-amber-700 border-amber-200"}:{label:"OK en PG",className:"bg-emerald-100 text-emerald-700 border-emerald-200"}:{label:"No existe en PG",className:"bg-red-100 text-red-700 border-red-200"}}function en(e){return e?{label:"Activo",className:"bg-emerald-100 text-emerald-700 border-emerald-200"}:{label:"Inactivo",className:"bg-amber-100 text-amber-700 border-amber-200"}}function im(){const e=qe(v=>v.query),r=qe(v=>v.setQuery),s=qe(v=>v.maxPrice),a=qe(v=>v.setMaxPrice),n=qe(v=>v.category),i=qe(v=>v.setCategory),o=qe(v=>v.limit),l=qe(v=>v.setLimit),h=qe(v=>v.scoreThreshold),p=qe(v=>v.setScoreThreshold),_=qe(v=>v.filtersOpen),w=qe(v=>v.setFiltersOpen),g=qe(v=>v.results),d=qe(v=>v.setResults),k=qe(v=>v.currentLimit),u=qe(v=>v.setCurrentLimit),x=qe(v=>v.isLoadingMore),f=qe(v=>v.setIsLoadingMore),j=qe(v=>v.appendResults),[E,P]=Y.useState(!1),S=Ko(),B=S.isPending&&!x,U=()=>{if(!e.trim())return;const v=parseInt(o,10)||10;u(v),S.mutate({query:e.trim(),...s?{maxPrice:parseFloat(s)}:{},...n?{category:n}:{},limit:v,scoreThreshold:h},{onSuccess:R=>d(R)})},$=parseInt(o,10)||10,T=()=>{if(!e.trim())return;const v=k+$;u(v),f(!0),S.mutate({query:e.trim(),...s?{maxPrice:parseFloat(s)}:{},...n?{category:n}:{},limit:v,scoreThreshold:h},{onSuccess:R=>{j(R),f(!1)},onError:()=>f(!1)})},G=v=>{v.key==="Enter"&&U()},se=async()=>{P(!0);try{await we.reindexProducts(),ne.success("Reindex iniciado. Los productos se sincronizaran a Qdrant en segundo plano.")}catch(v){const R=v instanceof Error?v.message:"Error al iniciar reindex";ne.error(R)}finally{P(!1)}};return t.jsxs("div",{className:"space-y-5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-purple-600 flex items-center justify-center shadow-md shadow-violet-200 dark:shadow-violet-900/30",children:t.jsx(Fr,{className:"h-5 w-5 text-white"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-bold text-slate-900 dark:text-slate-100",children:"Sandbox de Busqueda IA"}),t.jsx("p",{className:"text-xs text-slate-500",children:"Experimenta con la busqueda vectorial que usa el agente"})]})]}),t.jsxs(Ce,{variant:"outline",className:"text-violet-600 border-violet-200 bg-violet-50 dark:bg-violet-900/20 dark:border-violet-800 dark:text-violet-400 text-xs gap-1.5",children:[t.jsx(Kt,{className:"h-3 w-3"}),"Misma busqueda del agente"]})]}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm p-5",children:[t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx(Sr,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 h-4.5 w-4.5 text-slate-400"}),t.jsx(st,{value:e,onChange:v=>r(v.target.value),onKeyDown:G,placeholder:"Busca como lo haria un cliente... (ej: camiseta azul barata, laptop gaming)",className:"h-12 pl-11 pr-4 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-2xl text-base",disabled:B}),B&&t.jsx(be,{className:"absolute right-3.5 top-1/2 -translate-y-1/2 h-4.5 w-4.5 text-violet-500 animate-spin"})]}),t.jsx(ue,{onClick:U,disabled:!e.trim()||B,className:"rounded-2xl px-6 h-12 bg-gradient-to-r from-violet-600 to-purple-600 hover:from-violet-700 hover:to-purple-700 shadow-md shadow-violet-200 dark:shadow-violet-900/30",children:B?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"})," Buscando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Sr,{className:"h-4 w-4 mr-2"})," Buscar"]})})]}),t.jsxs(Hi,{open:_,onOpenChange:w,children:[t.jsx(Qi,{asChild:!0,children:t.jsxs("button",{className:"flex items-center gap-1.5 mt-3 text-xs font-medium text-slate-500 hover:text-slate-700 dark:hover:text-slate-300 transition-colors",children:[t.jsx(Nn,{className:"h-3.5 w-3.5"}),"Filtros avanzados",t.jsx(Dr,{className:le("h-3.5 w-3.5 transition-transform duration-200",_&&"rotate-180")})]})}),t.jsx(Yi,{children:t.jsx("div",{className:"mt-3 pt-3 border-t border-slate-100 dark:border-slate-800",children:t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Precio maximo"}),t.jsx(st,{value:s,onChange:v=>a(v.target.value),onKeyDown:G,placeholder:"Sin limite",type:"number",step:"0.01",min:"0",className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",disabled:B})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Categoria"}),t.jsx(st,{value:n,onChange:v=>i(v.target.value),onKeyDown:G,placeholder:"Todas",className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",disabled:B})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Limite de resultados"}),t.jsxs(ar,{value:o,onValueChange:l,disabled:B,children:[t.jsx(nr,{className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",children:t.jsx(ir,{})}),t.jsx(or,{children:[5,10,20,50].map(v=>t.jsxs(kt,{value:String(v),children:[v," resultados"]},v))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Umbral de similitud"}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(dn,{className:"h-3 w-3 text-slate-400 cursor-help"})}),t.jsx(rt,{side:"top",className:"max-w-[220px]",children:"Score minimo de similitud coseno para incluir un resultado. Menor = mas resultados (menos precisos). El agente usa 0.3 por defecto."})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Gi,{value:[h],onValueChange:([v])=>p(v),min:0,max:1,step:.05,className:"flex-1",disabled:B}),t.jsx("span",{className:"text-xs font-mono font-bold text-violet-600 dark:text-violet-400 w-8 text-right",children:h.toFixed(2)})]})]})]})})})]})]}),!g&&!S.isError&&t.jsx(om,{}),S.isError&&t.jsx(lm,{message:S.error?.message||"Error desconocido"}),g&&g.results.length===0&&t.jsx(t.Fragment,{children:g.diagnostics?t.jsx(cm,{diagnostics:g.diagnostics,metadata:g.metadata,query:g.query,scoreThreshold:h,isReindexing:E,onReindex:se}):t.jsx(dm,{query:g.query,metadata:g.metadata})}),g&&g.results.length>0&&t.jsx(um,{data:g,scoreThreshold:h,onLoadMore:T,isLoadingMore:x,canLoadMore:g.results.length>=k,loadMoreCount:$})]})}function om(){return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-dashed border-slate-200 dark:border-slate-700 p-14 text-center",children:[t.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-violet-100 to-purple-100 dark:from-violet-900/30 dark:to-purple-900/30 flex items-center justify-center mx-auto mb-5",children:t.jsx(Sr,{className:"h-7 w-7 text-violet-500"})}),t.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-2",children:"Prueba la busqueda vectorial"}),t.jsx("p",{className:"text-sm text-slate-500 max-w-lg mx-auto mb-5",children:"Escribe una consulta en lenguaje natural para ver exactamente lo que el agente de IA obtiene al buscar productos. Veras scores de relevancia, imagenes, estado en Qdrant y verificacion contra PostgreSQL."}),t.jsx("div",{className:"flex flex-wrap justify-center gap-2",children:["camiseta azul","laptop gaming barata","zapatos de cuero"].map(e=>t.jsxs("span",{className:"text-xs bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400 px-3 py-1.5 rounded-full",children:['"',e,'"']},e))})]})}function lm({message:e}){return t.jsxs("div",{className:"bg-red-50 dark:bg-red-900/10 rounded-[20px] border border-red-200 dark:border-red-800 p-6 text-center",children:[t.jsx(ct,{className:"h-8 w-8 text-red-400 mx-auto mb-2"}),t.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 font-medium",children:"Error en la busqueda"}),t.jsx("p",{className:"text-xs text-red-500 mt-1 font-mono",children:e})]})}function cm({diagnostics:e,metadata:r,query:s,scoreThreshold:a,isReindexing:n,onReindex:i}){const o=!e.collection_exists,l=e.collection_exists&&e.vectors_count===0,h=e.collection_exists&&e.vectors_count>0,p=e.pg_products_count>0;return t.jsx("div",{className:"bg-amber-50 dark:bg-amber-900/10 rounded-[20px] border border-amber-200 dark:border-amber-800 shadow-sm p-6",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center shrink-0 mt-0.5",children:t.jsx(ct,{className:"h-5 w-5 text-amber-600"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h4",{className:"font-semibold text-amber-800 dark:text-amber-200 mb-1",children:o?"Coleccion vectorial no existe":l?"Coleccion vectorial vacia":`Sin resultados para "${s}"`}),t.jsxs("p",{className:"text-sm text-amber-700 dark:text-amber-300 mb-3",children:[o&&p&&t.jsxs(t.Fragment,{children:["La coleccion ",t.jsx("code",{className:"bg-amber-200/50 px-1.5 py-0.5 rounded text-xs font-mono",children:r.collection})," no existe en Qdrant, pero tienes ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PostgreSQL. Los productos necesitan ser indexados."]}),o&&!p&&t.jsx(t.Fragment,{children:"La coleccion no existe y no hay productos en PostgreSQL. Crea productos primero."}),l&&p&&t.jsxs(t.Fragment,{children:["La coleccion ",t.jsx("code",{className:"bg-amber-200/50 px-1.5 py-0.5 rounded text-xs font-mono",children:r.collection})," existe pero tiene ",t.jsx("strong",{children:"0 vectores"}),". Tienes ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PostgreSQL que no han sido sincronizados."]}),l&&!p&&t.jsx(t.Fragment,{children:"La coleccion esta vacia y no hay productos en PostgreSQL. Crea productos primero."}),h&&t.jsxs(t.Fragment,{children:["La coleccion tiene ",t.jsxs("strong",{children:[e.vectors_count," vectores"]})," y ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PG, pero ninguno supero el umbral de similitud (",a.toFixed(2),') para "',s,'". Prueba bajando el umbral o con otra consulta.']})]}),e.raw_top_scores&&e.raw_top_scores.length>0&&t.jsxs("div",{className:"mb-3 bg-amber-100/50 dark:bg-amber-900/20 rounded-xl p-4",children:[t.jsx("p",{className:"text-xs font-semibold text-amber-700 dark:text-amber-300 mb-2.5",children:"Top scores reales (sin umbral, sin filtros):"}),t.jsx("div",{className:"space-y-2",children:e.raw_top_scores.map((_,w)=>t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"font-mono text-xs font-bold text-amber-700 dark:text-amber-300 w-14 shrink-0",children:_.score.toFixed(4)}),t.jsx("div",{className:"h-2 flex-1 max-w-40 bg-amber-200 dark:bg-amber-800 rounded-full overflow-hidden",children:t.jsx("div",{className:le("h-full rounded-full transition-all",_.score>=a?"bg-emerald-500":"bg-red-400"),style:{width:`${Math.min(_.score*100,100)}%`}})}),t.jsx("span",{className:"text-xs text-amber-600 dark:text-amber-400 truncate flex-1",children:_.product_name}),_.score<a&&t.jsx("span",{className:"text-[10px] text-red-500 font-medium shrink-0",children:"< umbral"})]},w))})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[{icon:Ot,text:e.collection_exists?"Coleccion existe":"Coleccion no existe"},{icon:it,text:`${e.vectors_count} vectores`},{icon:Ot,text:`${e.pg_products_count} en PG`},{icon:Pr,text:`${r.search_time_ms}ms`}].map((_,w)=>t.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400",children:[t.jsx(_.icon,{className:"h-3 w-3"})," ",_.text]},w))}),p&&t.jsx(ue,{onClick:i,disabled:n,variant:"outline",size:"sm",className:"rounded-full border-amber-300 text-amber-700 hover:bg-amber-100 hover:text-amber-800",children:n?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin mr-2"})," Reindexando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-3.5 w-3.5 mr-2"})," Reindexar productos a Qdrant"]})})]})]})})}function dm({query:e,metadata:r}){return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm p-10 text-center",children:[t.jsx(it,{className:"h-10 w-10 text-slate-300 mx-auto mb-3"}),t.jsx("h4",{className:"font-medium text-slate-700 dark:text-slate-300 mb-1",children:"Sin resultados"}),t.jsxs("p",{className:"text-sm text-slate-500",children:['No se encontraron productos para "',e,'"']}),t.jsxs("div",{className:"flex items-center justify-center gap-4 mt-3 text-xs text-slate-400",children:[t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Pr,{className:"h-3 w-3"})," ",r.search_time_ms,"ms"]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Ot,{className:"h-3 w-3"})," ",r.collection]})]})]})}function um({data:e,scoreThreshold:r,onLoadMore:s,isLoadingMore:a,canLoadMore:n,loadMoreCount:i}){const{results:o,metadata:l}=e,h=o.length>0?o.reduce((g,d)=>g+d.score,0)/o.length:0,p=Object.keys(l.filters_applied).length,_=[];l.embedding_ms!=null&&_.push(`Embedding: ${l.embedding_ms}ms`),l.qdrant_ms!=null&&_.push(`Qdrant: ${l.qdrant_ms}ms`),l.pg_ms!=null&&_.push(`PG check: ${l.pg_ms}ms`),_.push(`Total: ${l.search_time_ms}ms`);const w=_.join(" · ");return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[t.jsx(gr,{icon:Ni,label:"Resultados",value:String(o.length),accent:"violet"}),t.jsx(gr,{icon:Pr,label:"Tiempo",value:`${l.search_time_ms}ms`,accent:"blue",title:w}),t.jsx(gr,{icon:Kt,label:"Score promedio",value:h.toFixed(3),accent:h>=.5?"emerald":h>=.3?"amber":"red"}),t.jsx(gr,{icon:Ot,label:"Coleccion",value:l.collection.replace("products_v2_","").substring(0,8)+"...",accent:"slate",title:l.collection,copyValue:l.collection}),t.jsx(gr,{icon:Nn,label:"Umbral",value:r.toFixed(2),accent:"purple",extra:p>0?`+${p} filtros`:void 0})]}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-slate-100 dark:border-slate-800 bg-slate-50/80 dark:bg-slate-800/50 text-[10px] font-semibold uppercase tracking-wider text-slate-400",children:[t.jsx("span",{className:"w-5 text-right",children:"#"}),t.jsx("span",{className:"w-8"}),t.jsx("span",{className:"flex-1",children:"Producto"}),t.jsx("span",{className:"shrink-0 w-24 text-right",children:"Precio"}),t.jsx("span",{className:"shrink-0 w-28 text-right",children:"Score"}),t.jsx("span",{className:"shrink-0 w-9 text-center",children:"Estado"}),t.jsx("span",{className:"w-3.5"})]}),t.jsx("div",{className:"divide-y divide-slate-50 dark:divide-slate-800/50",children:o.map((g,d)=>t.jsx(fm,{result:g,rank:d+1},g.id))}),n&&t.jsx("div",{className:"flex justify-center py-3 border-t border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30",children:t.jsx(ue,{variant:"ghost",size:"sm",onClick:s,disabled:a,className:"rounded-full px-5 text-xs text-violet-600 hover:text-violet-700 hover:bg-violet-50 dark:text-violet-400 dark:hover:bg-violet-900/20",children:a?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Cargando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Dr,{className:"h-3.5 w-3.5 mr-1.5"})," Cargar mas resultados (+",i,")"]})})})]})]})}function gr({icon:e,label:r,value:s,accent:a,title:n,extra:i,copyValue:o}){const[l,h]=Y.useState(!1),p={violet:"bg-violet-50 dark:bg-violet-900/20 text-violet-600 dark:text-violet-400",blue:"bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400",emerald:"bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400",amber:"bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400",red:"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400",slate:"bg-slate-50 dark:bg-slate-800 text-slate-600 dark:text-slate-400",purple:"bg-purple-50 dark:bg-purple-900/20 text-purple-600 dark:text-purple-400"},_=()=>{o&&(navigator.clipboard.writeText(o),h(!0),setTimeout(()=>h(!1),1500))};return t.jsxs("div",{className:le("flex items-center gap-2.5 rounded-xl px-3.5 py-2.5 border border-transparent",p[a]||p.slate,o&&"cursor-pointer hover:opacity-80 active:scale-[0.98] transition-all"),title:n||(o?"Clic para copiar":void 0),onClick:o?_:void 0,children:[t.jsx(e,{className:"h-4 w-4 shrink-0 opacity-70"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider opacity-60",children:r}),t.jsxs("p",{className:"text-sm font-bold truncate",children:[l?"Copiado!":s,!l&&i&&t.jsx("span",{className:"text-[10px] font-normal opacity-60 ml-1",children:i})]})]})]})}function hm(e){const r=e.pg_metadata?.media;if(r&&r.length>0){const a=r[0];if(a.type==="video"||a.mimeType?.startsWith("video/"))return"video";if(a.type==="document"||a.mimeType?.startsWith("application/"))return"document";if(a.type==="image"||a.mimeType?.startsWith("image/"))return"image"}const s=e.qdrant_metadata?.product_image_name?.toLowerCase();return s?/\.(mp4|webm|mov|avi|3gp)$/i.test(s)?"video":/\.(pdf|docx?|xlsx?|csv|txt|epub)$/i.test(s)?"document":"image":e.product_thumbnail||e.product_image?"image":"none"}function mm(e){switch(e){case"video":return $i;case"document":return Wr;case"image":return At;default:return it}}function fm({result:e,rank:r}){const s=nm(e.score),[a,n]=Y.useState(!1),[i,o]=Y.useState(!1),[l,h]=Y.useState(!1),[p,_]=Y.useState(!1),[w,g]=Y.useState(null),[d,k]=Y.useState(!1),u=e.pg_exists&&e.pg_active!==!1,x=e.is_active,f=hm(e),j=mm(f),E=e.product_thumbnail_url,P=!!E&&!l,S=!!e.product_image,B=Y.useCallback(async U=>{if(U.stopPropagation(),!e.product_image){ne.error("Este producto no tiene imagen original (product_image es null)");return}if(w){_(!0);return}if(!e.product_image.startsWith("gs://")){g(e.product_image),_(!0);return}k(!0);try{const $=await Bi.getSignedUrl(e.product_image);if(!$){ne.error("La firma devolvio null. Path: "+e.product_image);return}g($),_(!0)}catch($){const T=$ instanceof Error?$.message:"Error desconocido";ne.error("Error al firmar imagen: "+T),console.warn("[handleViewFullImage] Failed to sign",e.product_image,$)}finally{k(!1)}},[e.product_image,w]);return t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>n(!a),className:le("w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors","hover:bg-slate-50 dark:hover:bg-slate-800/50",a&&"bg-slate-50/80 dark:bg-slate-800/30"),children:[t.jsx("span",{className:"text-[11px] font-mono text-slate-400 w-5 text-right shrink-0",children:r}),t.jsx("div",{className:"shrink-0",children:P?t.jsx("img",{src:E,alt:e.product_name,className:"w-8 h-8 rounded-lg object-cover border border-slate-200 dark:border-slate-700",onError:()=>h(!0)}):t.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-100 dark:bg-slate-800 flex items-center justify-center border border-slate-200 dark:border-slate-700",children:t.jsx(j,{className:"h-3.5 w-3.5 text-slate-300"})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100 truncate",children:e.product_name}),e.product_sku&&t.jsx("p",{className:"text-[10px] font-mono text-slate-400 truncate",children:e.product_sku})]}),t.jsx("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-300 shrink-0 w-24 text-right tabular-nums",children:zr(e.product_price,e.product_currency)}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 w-28 justify-end",children:[t.jsx("div",{className:"h-1.5 w-10 bg-slate-100 dark:bg-slate-800 rounded-full overflow-hidden",children:t.jsx("div",{className:le("h-full rounded-full",s.barColor),style:{width:`${Math.min(e.score*100,100)}%`}})}),t.jsx("span",{className:"text-[11px] font-mono font-bold text-slate-600 dark:text-slate-400 w-12 text-right",children:e.score.toFixed(3)})]}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 w-9 justify-center",children:[t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{className:le("w-2 h-2 rounded-full",u?"bg-emerald-500":e.pg_exists?"bg-amber-400":"bg-red-400")})}),t.jsxs(rt,{side:"top",className:"text-xs",children:["PG: ",e.pg_exists?e.pg_active===!1?"Inactivo":"OK":"No existe"]})]}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{className:le("w-2 h-2 rounded-full",x?"bg-emerald-500":"bg-amber-400")})}),t.jsxs(rt,{side:"top",className:"text-xs",children:["Qdrant: ",x?"Activo":"Inactivo"]})]})]}),t.jsx(Dr,{className:le("h-3.5 w-3.5 text-slate-400 shrink-0 transition-transform duration-200",a&&"rotate-180")})]}),a&&t.jsxs("div",{className:"px-4 pb-4 pt-2 bg-slate-50/50 dark:bg-slate-800/20",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[t.jsxs(Ce,{variant:"outline",className:le("text-[10px] px-2 py-0",en(e.is_active).className),children:["Qdrant: ",en(e.is_active).label]}),t.jsx(Ce,{variant:"outline",className:le("text-[10px] px-2 py-0",Ja(e).className),children:Ja(e).label}),t.jsxs(Ce,{className:le("text-[10px] px-2 py-0",s.className),children:["Score: ",s.label]}),e.catalog_id&&t.jsxs("span",{className:"text-[10px] text-slate-400",title:e.catalog_id,children:["Cat: ",e.catalog_id.substring(0,8),"..."]}),!e.pg_exists&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ct,{className:"h-3.5 w-3.5 text-red-400 cursor-help"})}),t.jsx(rt,{children:"Este producto existe en Qdrant pero no en PostgreSQL. Puede ser un producto eliminado que no se sincronizo."})]}),e.pg_exists&&e.pg_active!==e.is_active&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ct,{className:"h-3.5 w-3.5 text-amber-400 cursor-help"})}),t.jsxs(rt,{children:["Discrepancia: Qdrant dice ",e.is_active?"activo":"inactivo"," pero PG dice ",e.pg_active?"activo":"inactivo",". Necesita resincronizar."]})]}),t.jsx("span",{className:"flex-1"}),t.jsxs("button",{onClick:U=>{U.stopPropagation(),o(!i)},className:"flex items-center gap-1 text-[11px] text-slate-400 hover:text-slate-600 dark:hover:text-slate-300 transition-colors",children:[i?t.jsx(Cr,{className:"h-3 w-3"}):t.jsx(Fn,{className:"h-3 w-3"}),i?"Ocultar contenido":"Ver contenido vectorial"]}),S&&t.jsxs("button",{onClick:B,disabled:d,className:"flex items-center gap-1 text-[11px] text-violet-500 hover:text-violet-700 dark:hover:text-violet-300 transition-colors disabled:opacity-50",children:[d?t.jsx(be,{className:"h-3 w-3 animate-spin"}):t.jsx(Dn,{className:"h-3 w-3"}),"Ver imagen completa"]})]}),i&&t.jsx("p",{className:"mb-3 text-xs text-slate-500 bg-slate-100 dark:bg-slate-800 rounded-lg p-3 font-mono leading-relaxed border border-slate-200 dark:border-slate-700",children:e.content}),t.jsx(pm,{result:e})]}),p&&t.jsx(nn,{open:p,onOpenChange:_,children:t.jsxs(on,{className:"sm:max-w-3xl p-2 bg-black/95 border-none",children:[t.jsx(ln,{className:"sr-only",children:e.product_name}),t.jsx(cn,{className:"sr-only",children:"Imagen completa del producto"}),w?t.jsx("img",{src:w,alt:e.product_name,className:"w-full h-auto max-h-[80vh] object-contain rounded-lg"}):t.jsx("div",{className:"flex items-center justify-center h-48",children:t.jsx(be,{className:"h-8 w-8 text-white animate-spin"})}),t.jsxs("p",{className:"text-center text-xs text-slate-400 mt-2",children:[e.product_name,t.jsx("span",{className:"text-slate-600 ml-2 font-mono text-[10px]",children:"(firmada on-demand)"})]})]})})]})}function pm({result:e}){const r=e.pg_metadata,s=e.qdrant_metadata;return t.jsx("div",{className:"bg-slate-50 dark:bg-slate-800/50 rounded-xl border border-slate-100 dark:border-slate-700 overflow-hidden",children:t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-slate-200 dark:divide-slate-700",children:[t.jsxs("div",{className:"p-4",children:[t.jsxs("h5",{className:"text-[11px] font-semibold uppercase tracking-wider text-blue-600 dark:text-blue-400 mb-3 flex items-center gap-1.5",children:[t.jsx(Ot,{className:"h-3 w-3"})," PostgreSQL"]}),r?t.jsxs("div",{className:"space-y-2.5",children:[r.description&&t.jsx(Le,{label:"Descripcion",value:r.description,multiline:!0}),r.external_category&&t.jsx(Le,{label:"Categoria",children:t.jsx(Ce,{variant:"outline",className:"text-[10px] bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 border-blue-200",children:r.external_category})}),t.jsx(Le,{label:"Metadata (jsonb)",children:Object.keys(r.metadata).length===0?t.jsx("span",{className:"text-xs text-slate-400 italic",children:"Vacio"}):t.jsx("div",{className:"flex flex-wrap gap-1",children:Object.entries(r.metadata).map(([a,n])=>t.jsxs("span",{className:"text-[10px] bg-slate-200 dark:bg-slate-700 text-slate-600 dark:text-slate-300 px-2 py-0.5 rounded-md font-mono",title:typeof n=="object"?JSON.stringify(n):String(n),children:[a,": ",typeof n=="object"?JSON.stringify(n):String(n)]},a))})}),t.jsx(Le,{label:`Media (${r.media.length})`,children:r.media.length===0?t.jsx("span",{className:"text-xs text-slate-400 italic",children:"Sin archivos"}):t.jsx("div",{className:"space-y-1",children:r.media.map((a,n)=>t.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-slate-500",children:[t.jsx("span",{className:"bg-slate-200 dark:bg-slate-700 px-1.5 py-0.5 rounded text-slate-600 dark:text-slate-400 font-mono uppercase",children:a.type||"file"}),t.jsx("span",{className:"truncate",children:a.name||"Sin nombre"}),a.fileSizeBytes&&t.jsxs("span",{className:"text-slate-400 shrink-0",children:[(a.fileSizeBytes/1024).toFixed(0),"KB"]})]},n))})}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"Creado",value:tn(r.created_at)}),t.jsx(Le,{label:"Actualizado",value:tn(r.updated_at)})]}),(r.created_by||r.updated_by)&&t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.created_by&&t.jsx(Le,{label:"Creado por",value:r.created_by}),r.updated_by&&t.jsx(Le,{label:"Editado por",value:r.updated_by})]})]}):t.jsx("p",{className:"text-xs text-slate-400 italic",children:"Producto no existe en PostgreSQL"})]}),t.jsxs("div",{className:"p-4",children:[t.jsxs("h5",{className:"text-[11px] font-semibold uppercase tracking-wider text-purple-600 dark:text-purple-400 mb-3 flex items-center gap-1.5",children:[t.jsx(Kt,{className:"h-3 w-3"})," Qdrant Payload",t.jsx("span",{className:"font-normal normal-case tracking-normal text-slate-400 ml-1",children:"(lo que ve el agente)"})]}),t.jsxs("div",{className:"space-y-2.5",children:[t.jsx(Le,{label:"id",value:e.id,mono:!0}),t.jsx(Le,{label:"source_id",value:s.source_id,mono:!0}),t.jsx(Le,{label:"type",value:s.type}),t.jsx(Le,{label:"organization_id",value:s.organization_id,mono:!0}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsx("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:"Datos del producto"}),t.jsx(Le,{label:"product_name",value:e.product_name}),t.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"product_price",value:String(e.product_price),highlight:!0}),t.jsx(Le,{label:"product_currency",value:e.product_currency,highlight:!0})]}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_sku",value:e.product_sku||"—",mono:!0,highlight:!0})}),t.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"is_active",value:String(e.is_active)}),t.jsx(Le,{label:"catalog_id",value:e.catalog_id||"—",mono:!0})]})]}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsx("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:"Media (paths raw)"}),t.jsx(Le,{label:"product_image",value:e.product_image||"—",mono:!0}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_thumbnail",value:e.product_thumbnail||"—",mono:!0})}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_image_name",value:s.product_image_name||"—"})})]}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsxs("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:["content ",t.jsx("span",{className:"normal-case",children:"(texto embebido)"})]}),t.jsx("p",{className:"text-xs text-slate-500 bg-purple-50 dark:bg-purple-900/20 rounded-lg p-2.5 font-mono leading-relaxed border border-purple-100 dark:border-purple-800 line-clamp-4",children:e.content})]})]})]})]})})}function Le({label:e,value:r,mono:s,multiline:a,highlight:n,children:i}){const[o,l]=Y.useState(!1),h=()=>{!s||!r||(navigator.clipboard.writeText(r),l(!0),setTimeout(()=>l(!1),1200))};return t.jsxs("div",{className:le(n&&"bg-violet-50 dark:bg-violet-900/20 rounded-lg px-2 py-1.5 ring-1 ring-violet-200/70 dark:ring-violet-700/50"),children:[t.jsx("p",{className:le("text-[10px] font-medium uppercase tracking-wider mb-0.5",n?"text-violet-500 dark:text-violet-400":"text-slate-400"),children:e}),i||t.jsx("p",{className:le("text-xs",n?"text-violet-700 dark:text-violet-200 font-semibold":"text-slate-600 dark:text-slate-300",s&&"font-mono text-[11px] break-all cursor-pointer hover:text-violet-600 dark:hover:text-violet-400 transition-colors",a&&"line-clamp-3"),title:s?o?"Copiado!":"Clic para copiar":r,onClick:s?h:void 0,children:o?t.jsx("span",{className:"text-violet-600 dark:text-violet-400",children:"Copiado!"}):r})]})}function tn(e){if(!e)return"—";try{return new Date(e).toLocaleDateString("es",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}const rn={catalogId:"",search:"",category:""},Zt=Ts(e=>({filters:rn,page:1,limit:50,sortBy:"createdAt",sortOrder:"DESC",selectedIds:[],density:"comfortable",selectedProductId:null,setFilters:r=>e(s=>({filters:{...s.filters,...r},page:1,selectedIds:[]})),setPage:r=>e({page:r,selectedIds:[]}),resetFilters:()=>e({filters:rn,page:1,selectedIds:[],sortBy:"createdAt",sortOrder:"DESC"}),setSorting:r=>e(s=>({sortBy:r,sortOrder:s.sortBy===r&&s.sortOrder==="DESC"?"ASC":"DESC",page:1})),toggleSelection:r=>e(s=>({selectedIds:s.selectedIds.includes(r)?s.selectedIds.filter(a=>a!==r):[...s.selectedIds,r]})),selectAll:r=>e({selectedIds:r}),clearSelection:()=>e({selectedIds:[]}),setDensity:r=>e({density:r}),setSelectedProduct:r=>e({selectedProductId:r})})),xm=()=>Zt(Lt(e=>e.filters)),gm=()=>Zt(Lt(e=>({page:e.page,limit:e.limit}))),bm=()=>Zt(Lt(e=>({sortBy:e.sortBy,sortOrder:e.sortOrder}))),vm=()=>Zt(Lt(e=>({selectedIds:e.selectedIds,toggleSelection:e.toggleSelection,selectAll:e.selectAll,clearSelection:e.clearSelection}))),ym=()=>Zt(Lt(e=>({setFilters:e.setFilters,setPage:e.setPage,resetFilters:e.resetFilters,setSorting:e.setSorting,setDensity:e.setDensity,setSelectedProduct:e.setSelectedProduct,clearSelection:e.clearSelection}))),sn={status:"idle",progress:0,synced:0,errors:0,total:0,jobId:null,message:null},wm=Ts(e=>({...sn,startReindex:r=>e({status:"processing",progress:0,synced:0,errors:0,total:0,jobId:r,message:"Iniciando reindex..."}),updateProgress:r=>e(s=>({...s,...r})),reset:()=>e(sn)}));function jm({status:e,isLoading:r,onReindex:s,isReindexing:a,canReindex:n}){const[i,o]=Y.useState(!1),[l,h]=Y.useState(!1),[p,_]=Y.useState(1),w=Vo(),{data:g,isLoading:d}=qo(p,l&&(e?.orphanedCount??0)>0);if(r||!e||e.orphanedCount===0&&e.missingCount===0)return null;const k=async()=>{o(!1),h(!1),await w.mutateAsync()},u=e.orphanedCount,x=u!==1,f=e.missingCount,j=f!==1,E=g?Math.ceil(g.total/g.limit):1;return t.jsxs("div",{className:"flex flex-col gap-2",children:[u>0&&t.jsxs("div",{className:"rounded-2xl border border-amber-200 bg-amber-50/80 dark:bg-amber-950/20 dark:border-amber-800/50 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center shrink-0",children:t.jsx(ct,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("p",{className:"text-sm font-bold text-amber-800 dark:text-amber-300",children:[u," producto",x?"s":""," obsoleto",x?"s":""," en el índice de búsqueda IA"]}),t.jsxs("p",{className:"text-xs text-amber-600/80 dark:text-amber-400/70 mt-0.5",children:["El agente IA puede referenciar producto",x?"s":""," que ya no existe",x?"n":"","."]})]}),t.jsxs(ue,{variant:"ghost",size:"sm",onClick:()=>h(!l),className:"shrink-0 rounded-xl text-amber-700 hover:bg-amber-100 dark:text-amber-400 dark:hover:bg-amber-900/30",children:[l?t.jsx(yn,{className:"mr-1.5 h-3.5 w-3.5"}):t.jsx(Dr,{className:"mr-1.5 h-3.5 w-3.5"}),"Ver detalles"]}),t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>o(!0),disabled:w.isPending,className:"shrink-0 rounded-xl border-amber-300 text-amber-700 hover:bg-amber-100 dark:border-amber-700 dark:text-amber-400 dark:hover:bg-amber-900/30",children:[w.isPending?t.jsx(be,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):t.jsx(bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Limpiar todo"]})]}),l&&t.jsx("div",{className:"border-t border-amber-200/60 dark:border-amber-800/40",children:d?t.jsxs("div",{className:"flex items-center justify-center py-6 gap-2 text-amber-600",children:[t.jsx(be,{className:"w-4 h-4 animate-spin"}),t.jsx("span",{className:"text-xs font-medium",children:"Cargando registros..."})]}):g&&g.items.length>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"divide-y divide-amber-100 dark:divide-amber-900/30",children:g.items.map(P=>t.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 hover:bg-amber-100/50 dark:hover:bg-amber-900/20 transition-colors",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100/80 dark:bg-amber-900/40 flex items-center justify-center shrink-0",children:t.jsx(it,{className:"w-3.5 h-3.5 text-amber-500"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-xs font-bold text-amber-800 dark:text-amber-300 truncate",children:P.payload.product_name||"Sin nombre"}),t.jsxs("p",{className:"text-[10px] text-amber-600/70 dark:text-amber-400/60 font-mono truncate",children:["ID: ",P.id]})]}),P.payload.product_price!=null&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-bold text-amber-700 dark:text-amber-300 shrink-0",children:[t.jsx(cr,{className:"w-3 h-3"}),P.payload.product_currency," ",P.payload.product_price]}),P.payload.product_sku&&t.jsx("span",{className:"text-[10px] font-mono text-amber-600/70 dark:text-amber-400/60 bg-amber-100 dark:bg-amber-900/40 px-2 py-0.5 rounded-md shrink-0",children:P.payload.product_sku})]},P.id))}),E>1&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-t border-amber-200/60 dark:border-amber-800/40",children:[t.jsxs("span",{className:"text-[10px] font-bold text-amber-600/70 dark:text-amber-400/60 uppercase tracking-wider",children:["Página ",p," de ",E," · ",g.total," registros"]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(ue,{variant:"ghost",size:"sm",disabled:p<=1,onClick:()=>_(p-1),className:"h-7 px-2.5 text-xs rounded-lg text-amber-700 hover:bg-amber-100 dark:text-amber-400",children:"Anterior"}),t.jsx(ue,{variant:"ghost",size:"sm",disabled:p>=E,onClick:()=>_(p+1),className:"h-7 px-2.5 text-xs rounded-lg text-amber-700 hover:bg-amber-100 dark:text-amber-400",children:"Siguiente"})]})]})]}):t.jsx("p",{className:"text-center py-4 text-xs text-amber-600/70",children:"No se encontraron registros"})})]}),f>0&&t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-2xl border border-blue-200 bg-blue-50/80 dark:bg-blue-950/20 dark:border-blue-800/50",children:[t.jsx("div",{className:"w-9 h-9 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center shrink-0",children:t.jsx(Sr,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("p",{className:"text-sm font-bold text-blue-800 dark:text-blue-300",children:[f," producto",j?"s":""," sin indexar en la búsqueda IA"]}),t.jsxs("p",{className:"text-xs text-blue-600/80 dark:text-blue-400/70 mt-0.5",children:["Marcado",j?"s":""," en la tabla con",t.jsx(ct,{className:"w-3 h-3 inline mx-1 text-amber-500"}),"— puedes sincronizar individual o reindexar todo."]})]}),n&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:s,disabled:a,className:"shrink-0 rounded-xl border-blue-300 text-blue-700 hover:bg-blue-100 dark:border-blue-700 dark:text-blue-400 dark:hover:bg-blue-900/30",children:[a?t.jsx(be,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):t.jsx(hr,{className:"mr-1.5 h-3.5 w-3.5"}),"Reindexar"]})]}),t.jsx(Gt,{open:i,onOpenChange:o,children:t.jsxs(Ht,{children:[t.jsxs(Qt,{children:[t.jsx(Yt,{children:"Limpiar índice de búsqueda IA"}),t.jsxs(Xt,{children:["Se eliminarán ",t.jsxs("strong",{children:[u," registro",x?"s":""," obsoleto",x?"s":""]})," del índice de búsqueda IA que ya no corresponden a productos existentes. Tus productos actuales no se verán afectados."]})]}),t.jsxs(Jt,{children:[t.jsx(er,{children:"Cancelar"}),t.jsxs(tr,{onClick:k,children:["Limpiar ",u," registro",x?"s":""]})]})]})})]})}const Et=({icon:e,label:r,value:s,bgClass:a})=>t.jsxs("div",{className:"bg-white dark:bg-slate-900 p-4 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm flex items-center gap-4 transition-all duration-300 group",children:[t.jsx("div",{className:le("w-11 h-11 rounded-xl flex items-center justify-center shrink-0 shadow-inner group-hover:scale-110 transition-transform duration-300",a),children:e}),t.jsxs("div",{children:[s!==void 0?t.jsx("p",{className:"text-2xl font-black text-slate-900 dark:text-white leading-none tracking-tighter",children:s}):t.jsx("p",{className:"text-sm font-black text-slate-400 leading-none",children:"—"}),t.jsx("p",{className:"text-[9px] uppercase font-black text-slate-400 mt-1 tracking-widest",children:r})]})]});function f0(){const{currentOrganization:e}=Os(),r=Ke(),[s,a]=Y.useState("products"),n=xm(),{page:i,limit:o}=gm(),{sortBy:l,sortOrder:h}=bm(),{selectedIds:p,toggleSelection:_,selectAll:w,clearSelection:g}=vm(),{setFilters:d,setPage:k,resetFilters:u,setSorting:x,setDensity:f,setSelectedProduct:j}=ym(),E=Zt(W=>W.density),P=Zt(W=>W.selectedProductId),[S,B]=Y.useState(n.search),U=Ji(S,400);Y.useEffect(()=>{U!==n.search&&d({search:U})},[U,n.search,d]);const{data:$,isLoading:T,isFetching:G}=Ao({search:n.search||void 0,catalogId:n.catalogId||void 0,page:i,limit:o,withDeleted:!1}),{data:se=[],isLoading:v}=Po(),R=T||v,m=$?.data??[],V=n.category?m.filter(W=>W.externalCategory===n.category):m;$?.totalPages;const ie=n.category?V.length:$?.total??0,q=Y.useMemo(()=>{const W=new Set;return V.forEach(Ne=>{Ne.externalCategory&&W.add(Ne.externalCategory)}),Array.from(W).sort()},[V]),ce=Y.useMemo(()=>V.find(W=>W.id===P)??null,[V,P]),F=Fo(),ee=Do(),O=Oo(),L=To(),ae=Ro(),te=Zo(),J=$o(),ve=Lo(),Se=Uo(),[fe,me]=Y.useState(!1),[ke,ye]=Y.useState(!1),[_e,Re]=Y.useState(null),[c,K]=Y.useState(null),[M,C]=Y.useState(null),[N,D]=Y.useState(null),[X,y]=Y.useState(!1),[b,A]=Y.useState({name:"",description:""}),I=async W=>{if(e)try{const Ne=Array.isArray(W.media)&&W.media.length>0,ta={name:W.name,description:W.description,price:W.price,currency:W.currency,externalId:W.externalId||void 0,externalCategory:W.externalCategory||void 0,catalogId:W.catalogId,imageUrl:W.imageUrl||void 0,media:Ne?W.media:[]};_e?await ee.mutateAsync({id:_e.id,dto:ta}):await F.mutateAsync(ta),me(!1),Re(null)}catch(Ne){console.warn("[Products] submit error (toast handled by hook):",Ne)}},z=Y.useCallback(W=>{Re(W),me(!0)},[]),Z=()=>{Re(null),me(!0)},H=Y.useCallback(W=>{C(W)},[]),re=Y.useCallback(async()=>{if(M)try{await O.mutateAsync(M.id),C(null)}catch(W){console.warn("[Products] delete error (toast handled by hook):",W)}},[M,O]),he=Y.useCallback(async W=>{try{await ae.mutateAsync({ids:p,isActive:W}),g()}catch(Ne){console.warn("[Products] bulk toggle error (toast handled by hook):",Ne)}},[p,ae,g]),ze=Y.useCallback(async()=>{try{await te.mutateAsync(p),g()}catch(W){console.warn("[Products] bulk delete error (toast handled by hook):",W)}y(!1)},[p,te,g]),je=Y.useMemo(()=>V.filter(W=>p.includes(W.id)),[V,p]),Fe=je.filter(W=>W.isActive).length,ge=je.filter(W=>!W.isActive).length,xe=Y.useCallback(W=>{j(W.id)},[j]),Ze=()=>{K(null),A({name:"",description:""}),ye(!0)},$e=W=>{K(W),A({name:W.name,description:W.description||""}),ye(!0)},Ae=async W=>{if(W.preventDefault(),!!e)try{c?await ve.mutateAsync({id:c.id,dto:{name:b.name,description:b.description||void 0}}):await J.mutateAsync({name:b.name,description:b.description||void 0}),ye(!1),K(null),A({name:"",description:""})}catch(Ne){console.warn("[Products] catalog save error (toast handled by hook):",Ne)}},He=Y.useCallback(async()=>{if(N)try{await Se.mutateAsync(N.id),D(null)}catch(W){console.warn("[Products] catalog delete error (toast handled by hook):",W)}},[N,Se]),Qe=Y.useCallback(()=>{u(),B(""),ne.success("Filtros reiniciados",{id:"filters-reset"})},[u]),[xt,mt]=Y.useState(!1),Nt=async()=>{mt(!0);try{await we.exportProducts({search:n.search||void 0,catalogId:n.catalogId||void 0}),ne.success("Exportación descargada")}catch{ne.error("Error al exportar productos")}finally{mt(!1)}},St=Si(W=>W.user?.isSuperAdmin),{can:Tr,esAdmin:fi}=Ci(),{data:hs,isLoading:pi}=Bo(Tr("manage:products")),xi=hs?.missingIds?.length?new Set(hs.missingIds):void 0,gi=Wo(),ms=Mo(),Ye=wm(),Mt=Ye.status==="processing";Y.useEffect(()=>zi.onProductsReindexProgress(Ne=>{Ye.updateProgress({status:Ne.status,progress:Ne.progress,synced:Ne.synced,errors:Ne.errors,total:Ne.total,message:Ne.message||null}),Ne.status==="completed"?(ne.success(`Reindex completado: ${Ne.synced} productos sincronizados`),setTimeout(()=>Ye.reset(),5e3),r.invalidateQueries({queryKey:pe.all}),r.invalidateQueries({queryKey:pe.qdrantStatus()})):Ne.status==="failed"&&(ne.error(Ne.message||"Error durante el reindex"),setTimeout(()=>Ye.reset(),5e3))}),[]);const Js=async()=>{try{const W=await we.reindexProducts();Ye.startReindex(W.jobId)}catch(W){const Ne=W;Ne.response?.status===409?ne.warning("Ya hay un reindex en progreso para esta organización"):ne.error(Ne.message||"Error al iniciar reindex")}},bi=n.catalogId||n.category||S,vi=F.isPending||ee.isPending,ea=J.isPending||ve.isPending,yi=Y.useMemo(()=>se.reduce((W,Ne)=>W+(Ne.productCount??0),0),[se]);return t.jsxs(Ar,{children:[t.jsx(Ii,{children:t.jsxs("div",{className:"h-full overflow-y-auto no-scrollbar",children:[t.jsx(Ai,{title:"Gestión de Productos",description:"Administra tu inventario para que los Agentes puedan recomendar y vender",icon:it,actions:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("div",{className:"flex items-center bg-slate-100/60 dark:bg-slate-800/50 rounded-full p-1 gap-0.5",children:[Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ue,{onClick:()=>ms.mutate(),disabled:ms.isPending,variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(hr,{className:le("h-4 w-4 text-slate-500",ms.isPending&&"animate-spin text-primary")})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Verificar consistencia IA"})})]}),St&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsxs(ue,{onClick:Js,disabled:Mt||Ye.status==="completed",variant:"ghost",size:"icon",className:le("h-9 w-9 rounded-full transition-all relative overflow-hidden",Mt?"bg-amber-100 dark:bg-amber-900/30 ring-2 ring-amber-400/50":Ye.status==="completed"?"bg-green-100 dark:bg-green-900/30 ring-2 ring-green-400/50":"bg-amber-50 dark:bg-amber-900/20 ring-1 ring-amber-300/40 hover:ring-amber-400/60 hover:bg-amber-100 dark:hover:bg-amber-900/40"),children:[Mt&&t.jsx("div",{className:"absolute inset-0 bg-amber-300/30 dark:bg-amber-500/20 transition-all duration-500 ease-out rounded-full",style:{width:`${Ye.progress}%`}}),t.jsx("span",{className:"relative",children:Mt?t.jsx(be,{className:"h-4 w-4 text-amber-600 animate-spin"}):Ye.status==="completed"?t.jsx(fs,{className:"h-4 w-4 text-green-500"}):t.jsx(fs,{className:"h-4 w-4 text-amber-600"})})]})}),t.jsxs(rt,{side:"bottom",className:"max-w-[280px]",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx(fs,{className:"h-3 w-3 text-amber-500"}),t.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-amber-600",children:"Super Admin"})]}),t.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:Mt?`Reindexando… ${Ye.progress}% (${Ye.synced}/${Ye.total} · ${Ye.errors} errores)`:Ye.status==="completed"?`✓ ${Ye.synced} productos sincronizados`:"Reconstruye el índice de búsqueda IA completo. Regenera embeddings de todos los productos."})]})]}),fi&&V.length>0&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ue,{onClick:Nt,variant:"ghost",size:"icon",disabled:xt,className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:xt?t.jsx(be,{className:"h-4 w-4 text-slate-500 animate-spin"}):t.jsx(eo,{className:"h-4 w-4 text-slate-500"})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Exportar productos"})})]}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(zo,{catalogs:se,onSuccess:()=>r.invalidateQueries({queryKey:pe.all}),trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(Hr,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar productos"})})]}),Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(rl,{trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(fn,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar desde API"})})]}),Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(sl,{trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(kn,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar desde Shopify"})})]})]}),se.length>0&&t.jsxs(ue,{onClick:Z,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-5 ml-1",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"}),"Nuevo Producto"]})]})}),t.jsx(Pi,{className:"space-y-6",children:t.jsxs(Xi,{defaultValue:"products",value:s,onValueChange:a,children:[t.jsx("div",{className:"flex items-center gap-1 mb-6 border-b border-slate-100 dark:border-slate-800",children:[{value:"products",label:"Productos",icon:it,count:ie},{value:"catalogs",label:"Catálogos",icon:dt,count:se.length},{value:"ai-search",label:"Búsqueda IA",icon:Fr}].map(W=>t.jsxs("button",{onClick:()=>a(W.value),className:le("flex items-center gap-2 px-4 py-2.5 text-sm font-bold transition-all relative -mb-[1px] border-b-2",s===W.value?"text-primary border-primary":"text-slate-400 border-transparent hover:text-slate-600 dark:hover:text-slate-300 hover:border-slate-200 dark:hover:border-slate-700"),children:[t.jsx(W.icon,{className:"h-4 w-4"}),W.label,W.count!==void 0&&t.jsx("span",{className:le("text-[10px] font-black px-1.5 py-0.5 rounded-full min-w-[20px] text-center leading-none",s===W.value?"bg-primary/10 text-primary":"bg-slate-100 text-slate-400 dark:bg-slate-800 dark:text-slate-500"),children:W.count})]},W.value))}),t.jsx(xs,{value:"products",className:"space-y-6",children:v?t.jsxs("div",{className:"space-y-4",children:[t.jsx(at,{className:"h-24 w-full rounded-[24px]"}),t.jsx(at,{className:"h-14 w-full rounded-[24px]"}),t.jsx(at,{className:"h-64 w-full rounded-[32px]"})]}):se.length===0?t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(dt,{className:"w-10 h-10 text-slate-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2",children:"No hay catálogos"}),t.jsx("p",{className:"text-slate-500 max-w-md mb-6",children:"Debes crear al menos un catálogo antes de agregar productos."}),t.jsx(ue,{onClick:()=>a("catalogs"),className:"rounded-full px-6",children:"Ir a Catálogos"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4 px-1",children:[t.jsx(na,{className:"h-4 w-4 text-slate-400"}),t.jsx("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:"Resumen"})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[t.jsx(Et,{icon:t.jsx(it,{className:"w-5 h-5 text-indigo-500"}),label:"Total Productos",value:ie,bgClass:"bg-indigo-50 dark:bg-indigo-900/10"}),t.jsx(Et,{icon:t.jsx(dt,{className:"w-5 h-5 text-violet-500"}),label:"Catálogos",value:se.length,bgClass:"bg-violet-50 dark:bg-violet-900/10"}),t.jsx(Et,{icon:t.jsx(ss,{className:"w-5 h-5 text-blue-500"}),label:"Categorías",value:q.length,bgClass:"bg-blue-50 dark:bg-blue-900/10"}),t.jsx(Et,{icon:t.jsx(cr,{className:"w-5 h-5 text-emerald-500"}),label:"Monedas",value:new Set(V.map(W=>W.currency)).size,bgClass:"bg-emerald-50 dark:bg-emerald-900/10"})]})]}),t.jsx(jm,{status:hs,isLoading:pi,onReindex:Js,isReindexing:Mt,canReindex:!!St}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 p-3 rounded-[24px] border border-slate-100 dark:border-slate-800 shadow-sm flex flex-col xl:flex-row items-center justify-between gap-3 sticky top-[72px] z-10 backdrop-blur-md bg-opacity-95",children:[t.jsxs("div",{className:"flex items-center gap-3 w-full xl:w-auto",children:[t.jsxs("div",{className:"relative flex-1 xl:w-72",children:[G?t.jsx(be,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-primary animate-spin"}):t.jsx(Sr,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),t.jsx(st,{placeholder:"Buscar por nombre o SKU...",value:S,onChange:W=>B(W.target.value),className:"h-11 pl-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-sm focus-visible:ring-1 focus-visible:ring-primary/20 transition-all font-medium"}),S&&t.jsx(Ft,{className:"absolute right-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400 cursor-pointer hover:text-slate-600 transition-colors",onClick:()=>B("")})]}),bi&&t.jsxs(ue,{variant:"ghost",size:"sm",onClick:Qe,className:"text-[11px] font-bold uppercase tracking-tight text-rose-500 hover:text-rose-600 hover:bg-rose-50 dark:hover:bg-rose-900/10 whitespace-nowrap rounded-xl transition-all",children:[t.jsx(Ft,{className:"w-3.5 h-3.5 mr-1"}),"Limpiar"]})]}),t.jsxs("div",{className:"flex items-center gap-2 w-full xl:w-auto overflow-x-auto no-scrollbar pb-1 xl:pb-0",children:[t.jsxs(ar,{value:n.catalogId||"all",onValueChange:W=>d({catalogId:W==="all"?"":W}),children:[t.jsx(nr,{className:"h-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-[13px] font-medium w-full xl:w-[160px]",children:t.jsx(ir,{placeholder:"Catálogo"})}),t.jsxs(or,{className:"rounded-2xl",children:[t.jsx(kt,{value:"all",className:"rounded-xl",children:"Todos"}),se.map(W=>t.jsx(kt,{value:W.id,className:"rounded-xl",children:W.name},W.id))]})]}),q.length>0&&t.jsxs(ar,{value:n.category||"all",onValueChange:W=>d({category:W==="all"?"":W}),children:[t.jsx(nr,{className:"h-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-[13px] font-medium w-full xl:w-[160px]",children:t.jsx(ir,{placeholder:"Categoría"})}),t.jsxs(or,{className:"rounded-2xl",children:[t.jsx(kt,{value:"all",className:"rounded-xl",children:"Todas"}),q.map(W=>t.jsx(kt,{value:W,className:"rounded-xl",children:W},W))]})]}),t.jsx("div",{className:"h-6 w-[1px] bg-slate-100 dark:bg-slate-800 hidden md:block shrink-0 mx-1"}),t.jsxs("div",{className:"flex bg-slate-100/50 dark:bg-slate-800/50 p-1 rounded-xl shrink-0",children:[t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>f("comfortable"),className:le("h-8 w-8 rounded-lg transition-all",E==="comfortable"?"bg-white dark:bg-slate-900 shadow-sm text-primary":"text-slate-400 hover:text-slate-600"),children:t.jsx(to,{className:"h-4 w-4"})}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>f("compact"),className:le("h-8 w-8 rounded-lg transition-all",E==="compact"?"bg-white dark:bg-slate-900 shadow-sm text-primary":"text-slate-400 hover:text-slate-600"),children:t.jsx(so,{className:"h-4 w-4"})})]})]})]}),t.jsx(mi,{products:V,catalogs:se,isLoading:R,selectedIds:p,onSelect:_,onSelectAll:W=>w(W?V.map(Ne=>Ne.id):[]),onViewDetail:xe,onEdit:z,onDelete:H,onToggleActive:W=>L.mutate({id:W.id,isActive:!W.isActive}),onSyncProduct:W=>gi.mutate([W.id]),missingIds:xi,page:i,total:ie,limit:o,onPageChange:k,density:E,sortBy:l,sortOrder:h,onSort:x})]})}),t.jsx(xs,{value:"catalogs",className:"space-y-6",children:v?t.jsxs("div",{className:"space-y-4",children:[t.jsx(at,{className:"h-24 w-full rounded-[24px]"}),t.jsx(at,{className:"h-64 w-full rounded-[32px]"})]}):se.length===0?t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-violet-50 dark:bg-violet-900/20 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(dt,{className:"w-10 h-10 text-violet-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2",children:"No hay catálogos"}),t.jsx("p",{className:"text-slate-500 max-w-md mb-6",children:"Crea tu primer catálogo para comenzar a organizar tus productos. Los catálogos ayudan a la IA a recomendar mejor."}),t.jsxs(ue,{onClick:Ze,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-6",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"})," Crear primer catálogo"]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4 px-1",children:[t.jsx(na,{className:"h-4 w-4 text-slate-400"}),t.jsx("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:"Resumen de catálogos"})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[t.jsx(Et,{icon:t.jsx(dt,{className:"w-5 h-5 text-violet-500"}),label:"Total Catálogos",value:se.length,bgClass:"bg-violet-50 dark:bg-violet-900/10"}),t.jsx(Et,{icon:t.jsx(it,{className:"w-5 h-5 text-indigo-500"}),label:"Productos Totales",value:yi,bgClass:"bg-indigo-50 dark:bg-indigo-900/10"}),t.jsx(Et,{icon:t.jsx(ro,{className:"w-5 h-5 text-amber-500"}),label:"Catálogo Default",value:se.filter(W=>W.isDefault).length,bgClass:"bg-amber-50 dark:bg-amber-900/10"})]})]}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 px-1",children:[t.jsx(dt,{className:"h-4 w-4 text-slate-400"}),t.jsxs("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:[se.length," catálogo",se.length!==1?"s":""]})]}),t.jsxs(ue,{onClick:Ze,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-5",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"})," Nuevo Catálogo"]})]}),t.jsx("div",{className:"bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-500",children:t.jsxs(Qr,{children:[t.jsx(Yr,{children:t.jsxs(lr,{className:"bg-slate-50/30 dark:bg-slate-800/20 hover:bg-slate-50/30 dark:hover:bg-slate-800/20 border-slate-100 dark:border-slate-800",children:[t.jsx(De,{className:"py-5 pl-6 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Nombre"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Descripción"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Productos"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Creación"}),t.jsx(De,{className:"w-[80px] pr-6"})]})}),t.jsx(wn,{children:se.map(W=>t.jsxs(lr,{className:"group hover:bg-slate-50/80 dark:hover:bg-slate-800/50 border-slate-50/50 dark:border-slate-800/50 transition-all",children:[t.jsx(ut,{className:"py-4 pl-6",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-violet-50 dark:bg-violet-900/20 flex items-center justify-center shrink-0",children:t.jsx(dt,{className:"w-4 h-4 text-violet-500"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("span",{className:"font-black text-sm text-slate-900 dark:text-white truncate block",children:W.name}),W.isDefault&&t.jsx(Ce,{className:"mt-0.5 text-[9px] rounded-full bg-amber-50 text-amber-600 border-amber-200 px-1.5 py-0",children:"Default"})]})]})}),t.jsx(ut,{className:"py-4 text-sm max-w-[300px]",children:W.description?t.jsx("span",{className:"text-slate-600 dark:text-slate-400 line-clamp-2",children:W.description}):t.jsx("span",{className:"text-slate-300 dark:text-slate-600 italic text-xs",children:"Sin descripción"})}),t.jsx(ut,{className:"py-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-indigo-50 dark:bg-indigo-900/20 flex items-center justify-center",children:t.jsx(it,{className:"w-3.5 h-3.5 text-indigo-500"})}),t.jsx("span",{className:"text-[13px] font-bold text-slate-700 dark:text-slate-300",children:W.productCount??0})]})}),t.jsx(ut,{className:"py-4 text-sm text-slate-500",children:as(W.createdAt,{style:"date-only"})}),t.jsx(ut,{className:"text-right pr-6 py-4",onClick:Ne=>Ne.stopPropagation(),children:t.jsx("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity translate-x-4 group-hover:translate-x-0 duration-300",children:t.jsxs(pn,{children:[t.jsx(xn,{asChild:!0,children:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-slate-200/50",children:t.jsx(Pn,{className:"h-4 w-4 text-slate-400"})})}),t.jsxs(gn,{align:"end",className:"w-48 p-2 rounded-2xl shadow-2xl border-slate-100",children:[t.jsx(bn,{className:"text-[10px] uppercase font-black tracking-widest text-slate-400 p-2",children:"Opciones"}),t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>$e(W),className:"rounded-xl p-2.5 font-bold text-sm cursor-pointer",children:[t.jsx($s,{className:"mr-3 h-4 w-4 text-slate-400"}),"Editar"]}),!W.isDefault&&t.jsxs(t.Fragment,{children:[t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>D(W),className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50 cursor-pointer",children:[t.jsx(bt,{className:"mr-3 h-4 w-4"}),"Eliminar"]})]})]})]})})})]},W.id))})]})})]})}),t.jsx(xs,{value:"ai-search",className:"space-y-6",children:t.jsx(im,{})})]})})]})}),t.jsx(jr,{open:fe,onOpenChange:W=>{me(W),W||Re(null)},children:t.jsxs(kr,{className:"w-full sm:w-[540px] md:w-[620px] sm:max-w-none overflow-hidden p-0 flex flex-col",children:[t.jsx("div",{className:"px-5 py-3 bg-muted/20 border-b border-border/40 shrink-0",children:t.jsx(_r,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary/10 flex items-center justify-center shrink-0 border border-primary/20",children:t.jsx(it,{className:"h-5 w-5 text-primary"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(Nr,{className:"text-lg font-bold tracking-tight",children:_e?"Editar Producto":"Nuevo Producto"}),t.jsx(Ce,{variant:"outline",className:le("uppercase text-[9px] font-bold tracking-widest px-1.5",_e?"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20":"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20"),children:_e?"Editando":"Nuevo"})]}),t.jsx(Kr,{className:"text-[11px] text-muted-foreground/70 font-medium mt-0.5 leading-tight",children:_e?"Modifica los datos del producto. Los cambios se sincronizarán con la IA.":"Completa la información. La IA usará estos datos para recomendar."})]})]})})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-4 pb-5",children:t.jsx(em,{product:_e,catalogs:se,organizationId:e.id,isSubmitting:vi,onSubmit:I},_e?.id||"new")})]})}),t.jsx(jr,{open:ke,onOpenChange:W=>{ye(W),W||(K(null),A({name:"",description:""}))},children:t.jsxs(kr,{className:"w-full sm:w-[480px] sm:max-w-none overflow-hidden p-0 flex flex-col",children:[t.jsx("div",{className:"px-5 py-3 bg-muted/20 border-b border-border/40 shrink-0",children:t.jsx(_r,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"h-10 w-10 rounded-xl bg-violet-500/10 flex items-center justify-center shrink-0 border border-violet-500/20",children:t.jsx(dt,{className:"h-5 w-5 text-violet-500"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(Nr,{className:"text-lg font-bold tracking-tight",children:c?"Editar Catálogo":"Nuevo Catálogo"}),t.jsx(Ce,{variant:"outline",className:le("uppercase text-[9px] font-bold tracking-widest px-1.5",c?"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20":"bg-violet-500/10 text-violet-600 dark:text-violet-400 border-violet-500/20"),children:c?"Editando":"Nuevo"})]}),t.jsx(Kr,{className:"text-[11px] text-muted-foreground/70 font-medium mt-0.5 leading-tight",children:c?"Modifica el nombre y la descripción del catálogo.":"Los catálogos agrupan productos para que la IA pueda recomendarlos mejor."})]})]})})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-4 pb-5",children:t.jsxs("form",{onSubmit:Ae,className:"space-y-3 pb-2",children:[t.jsxs("div",{className:"border border-border/40 shadow-sm bg-background/50 rounded-lg overflow-hidden hover:border-violet-500/20 transition-all duration-200",children:[t.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5",children:[t.jsx("div",{className:"w-6 h-6 rounded-md flex items-center justify-center bg-violet-500/10",children:t.jsx(dt,{className:"h-3.5 w-3.5 text-violet-500"})}),t.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:"Información del catálogo"})]}),t.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:["Nombre ",t.jsx("span",{className:"text-rose-500 ml-0.5",children:"*"})]}),t.jsx(st,{required:!0,value:b.name,onChange:W=>A({...b,name:W.target.value}),placeholder:"Ej: Ropa Verano 2025",className:"h-9 rounded-lg bg-muted/30 border-border/50 text-sm focus-visible:ring-1 focus-visible:ring-primary/30 font-medium"}),t.jsx("p",{className:"text-[10px] text-muted-foreground/50 leading-snug",children:"Usa un nombre descriptivo para agrupar productos similares."})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:"Descripción"}),t.jsx(Ce,{variant:"outline",className:"text-[9px] font-bold uppercase tracking-wider text-muted-foreground/50 border-border/50 rounded-md px-1.5 py-0",children:"Opcional"})]}),t.jsx(vn,{value:b.description,onChange:W=>A({...b,description:W.target.value}),placeholder:"Describe el propósito de este catálogo...",className:"min-h-[80px] rounded-lg bg-muted/30 border-border/50 text-sm focus-visible:ring-1 focus-visible:ring-primary/30 resize-none leading-relaxed font-medium"})]})]})]}),t.jsxs(ue,{type:"submit",className:"w-full h-10 rounded-lg bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 font-bold text-sm transition-all",disabled:ea,children:[ea?t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"}):t.jsx(An,{className:"h-4 w-4 mr-2"}),c?"Guardar cambios":"Crear Catálogo"]})]})})]})}),t.jsx(am,{product:ce,catalogs:se,open:!!ce,onOpenChange:W=>{W||j(null)},onEdit:z,onDelete:H,onToggleActive:W=>L.mutate({id:W.id,isActive:!W.isActive})}),p.length>0&&t.jsx("div",{className:"fixed bottom-8 left-1/2 transform -translate-x-1/2 z-50 animate-in slide-in-from-bottom-5 fade-in duration-300",children:t.jsxs("div",{className:"bg-slate-900 text-white px-7 py-3.5 rounded-full shadow-[0_20px_50px_rgba(0,0,0,0.3)] flex items-center gap-5 border border-slate-800/50 backdrop-blur-xl bg-opacity-95",children:[t.jsxs("span",{className:"text-[13px] font-bold flex items-center gap-2.5",children:[t.jsx("div",{className:"bg-primary text-white w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-black shadow-lg shadow-primary/40",children:p.length}),"Seleccionados"]}),t.jsx("div",{className:"h-5 w-[1px] bg-white/10"}),t.jsxs("div",{className:"flex items-center gap-2",children:[ge>0&&t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:()=>he(!0),disabled:ae.isPending,children:[ae.isPending?t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}):t.jsx(Ls,{className:"w-4 h-4 mr-2 text-emerald-400"}),"Activar",ge<p.length?` (${ge})`:""]}),Fe>0&&t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:()=>he(!1),disabled:ae.isPending,children:[ae.isPending?t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}):t.jsx(Cr,{className:"w-4 h-4 mr-2 text-amber-400"}),"Desactivar",Fe<p.length?` (${Fe})`:""]}),t.jsx("div",{className:"h-5 w-[1px] bg-white/10"}),t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-rose-500/20 text-white rounded-xl px-4 transition-all",onClick:()=>y(!0),disabled:te.isPending,children:[t.jsx(bt,{className:"w-4 h-4 mr-2 text-rose-400"}),"Eliminar"]})]}),t.jsx(ue,{size:"icon",variant:"ghost",className:"h-7 w-7 rounded-full hover:bg-white/10 transition-all text-slate-400 hover:text-white",onClick:()=>g(),children:t.jsx(Ft,{className:"w-4 h-4"})})]})}),t.jsx(Gt,{open:!!M,onOpenChange:W=>{W||C(null)},children:t.jsxs(Ht,{className:"rounded-2xl",children:[t.jsxs(Qt,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Yt,{className:"text-lg font-bold",children:['Eliminar "',M?.name,'"']})]}),t.jsxs(Xt,{className:"text-sm text-slate-500 leading-relaxed",children:["Esta acción es ",t.jsx("span",{className:"font-semibold text-rose-600",children:"permanente e irreversible"}),'. El producto será eliminado completamente del sistema y no podrá recuperarse. Si solo quieres que la IA deje de recomendarlo, usa la opción "Desactivar".']})]}),t.jsxs(Jt,{children:[t.jsx(er,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(tr,{onClick:re,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[O.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar permanente"]})]})]})}),t.jsx(Gt,{open:X,onOpenChange:W=>{W||y(!1)},children:t.jsxs(Ht,{className:"rounded-2xl",children:[t.jsxs(Qt,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Yt,{className:"text-lg font-bold",children:["Eliminar ",p.length," producto",p.length>1?"s":""]})]}),t.jsxs(Xt,{className:"text-sm text-slate-500 leading-relaxed",children:["Esta acción es ",t.jsx("span",{className:"font-semibold text-rose-600",children:"permanente e irreversible"}),". Se eliminarán ",p.length," producto",p.length>1?"s":"",' completamente del sistema y no podrán recuperarse. Si solo quieres que la IA deje de recomendarlos, usa la opción "Desactivar".']})]}),t.jsxs(Jt,{children:[t.jsx(er,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(tr,{onClick:ze,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[te.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar ",p.length," producto",p.length>1?"s":""]})]})]})}),t.jsx(Gt,{open:!!N,onOpenChange:W=>{W||D(null)},children:t.jsxs(Ht,{className:"rounded-2xl",children:[t.jsxs(Qt,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Yt,{className:"text-lg font-bold",children:['Eliminar "',N?.name,'"']})]}),t.jsx(Xt,{className:"text-sm text-slate-500 leading-relaxed",children:"El catálogo será eliminado permanentemente. Si contiene productos activos, deberás moverlos o desactivarlos primero."})]}),t.jsxs(Jt,{children:[t.jsx(er,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(tr,{onClick:He,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[Se.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar"]})]})]})})]})}export{f0 as default};
|
|
21
|
+
`)}d.write("payload.value = newResult;"),d.write("return payload;");const j=d.compile();return(E,P)=>j(g,E,P)};let i;const o=es,l=!Wn.jitless,p=l&&Al.value,_=r.catchall;let w;e._zod.parse=(g,d)=>{w??(w=a.value);const k=g.value;return o(k)?l&&p&&d?.async===!1&&d.jitless!==!0?(i||(i=n(r.shape)),g=i(g,d),_?ii([],k,g,d,w,e):g):s(g,d):(g.issues.push({expected:"object",code:"invalid_type",input:k,inst:e}),g)}});function Pa(e,r,s,a){for(const i of e)if(i.issues.length===0)return r.value=i.value,r;const n=e.filter(i=>!qt(i));return n.length===1?(r.value=n[0].value,n[0]):(r.issues.push({code:"invalid_union",input:r.value,inst:s,errors:e.map(i=>i.issues.map(o=>Rt(o,a,Tt())))}),r)}const bd=Q("$ZodUnion",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.options.some(n=>n._zod.optin==="optional")?"optional":void 0),Ie(e._zod,"optout",()=>r.options.some(n=>n._zod.optout==="optional")?"optional":void 0),Ie(e._zod,"values",()=>{if(r.options.every(n=>n._zod.values))return new Set(r.options.flatMap(n=>Array.from(n._zod.values)))}),Ie(e._zod,"pattern",()=>{if(r.options.every(n=>n._zod.pattern)){const n=r.options.map(i=>i._zod.pattern);return new RegExp(`^(${n.map(i=>Hs(i.source)).join("|")})$`)}});const s=r.options.length===1,a=r.options[0]._zod.run;e._zod.parse=(n,i)=>{if(s)return a(n,i);let o=!1;const l=[];for(const h of r.options){const p=h._zod.run({value:n.value,issues:[]},i);if(p instanceof Promise)l.push(p),o=!0;else{if(p.issues.length===0)return p;l.push(p)}}return o?Promise.all(l).then(h=>Pa(h,n,e,i)):Pa(l,n,e,i)}}),vd=Q("$ZodIntersection",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>{const n=s.value,i=r.left._zod.run({value:n,issues:[]},a),o=r.right._zod.run({value:n,issues:[]},a);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([h,p])=>Fa(s,h,p)):Fa(s,i,o)}});function Fs(e,r){if(e===r)return{valid:!0,data:e};if(e instanceof Date&&r instanceof Date&&+e==+r)return{valid:!0,data:e};if(Er(e)&&Er(r)){const s=Object.keys(r),a=Object.keys(e).filter(i=>s.indexOf(i)!==-1),n={...e,...r};for(const i of a){const o=Fs(e[i],r[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};n[i]=o.data}return{valid:!0,data:n}}if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return{valid:!1,mergeErrorPath:[]};const s=[];for(let a=0;a<e.length;a++){const n=e[a],i=r[a],o=Fs(n,i);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s.push(o.data)}return{valid:!0,data:s}}return{valid:!1,mergeErrorPath:[]}}function Fa(e,r,s){if(r.issues.length&&e.issues.push(...r.issues),s.issues.length&&e.issues.push(...s.issues),qt(e))return e;const a=Fs(r.value,s.value);if(!a.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return e.value=a.data,e}const yd=Q("$ZodEnum",(e,r)=>{Ue.init(e,r);const s=zl(r.entries),a=new Set(s);e._zod.values=a,e._zod.pattern=new RegExp(`^(${s.filter(n=>Pl.has(typeof n)).map(n=>typeof n=="string"?cr(n):n.toString()).join("|")})$`),e._zod.parse=(n,i)=>{const o=n.value;return a.has(o)||n.issues.push({code:"invalid_value",values:s,input:o,inst:e}),n}}),wd=Q("$ZodLiteral",(e,r)=>{if(Ue.init(e,r),r.values.length===0)throw new Error("Cannot create literal schema with no valid values");const s=new Set(r.values);e._zod.values=s,e._zod.pattern=new RegExp(`^(${r.values.map(a=>typeof a=="string"?cr(a):a?cr(a.toString()):String(a)).join("|")})$`),e._zod.parse=(a,n)=>{const i=a.value;return s.has(i)||a.issues.push({code:"invalid_value",values:r.values,input:i,inst:e}),a}}),jd=Q("$ZodTransform",(e,r)=>{Ue.init(e,r),e._zod.parse=(s,a)=>{if(a.direction==="backward")throw new qn(e.constructor.name);const n=r.transform(s.value,s);if(a.async)return(n instanceof Promise?n:Promise.resolve(n)).then(o=>(s.value=o,s));if(n instanceof Promise)throw new tr;return s.value=n,s}});function Da(e,r){return e.issues.length&&r===void 0?{issues:[],value:void 0}:e}const kd=Q("$ZodOptional",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",e._zod.optout="optional",Ie(e._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,void 0]):void 0),Ie(e._zod,"pattern",()=>{const s=r.innerType._zod.pattern;return s?new RegExp(`^(${Hs(s.source)})?$`):void 0}),e._zod.parse=(s,a)=>{if(r.innerType._zod.optin==="optional"){const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Da(i,s.value)):Da(n,s.value)}return s.value===void 0?s:r.innerType._zod.run(s,a)}}),_d=Q("$ZodNullable",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.innerType._zod.optin),Ie(e._zod,"optout",()=>r.innerType._zod.optout),Ie(e._zod,"pattern",()=>{const s=r.innerType._zod.pattern;return s?new RegExp(`^(${Hs(s.source)}|null)$`):void 0}),Ie(e._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,null]):void 0),e._zod.parse=(s,a)=>s.value===null?s:r.innerType._zod.run(s,a)}),Nd=Q("$ZodDefault",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);if(s.value===void 0)return s.value=r.defaultValue,s;const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Oa(i,r)):Oa(n,r)}});function Oa(e,r){return e.value===void 0&&(e.value=r.defaultValue),e}const Sd=Q("$ZodPrefault",(e,r)=>{Ue.init(e,r),e._zod.optin="optional",Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>(a.direction==="backward"||s.value===void 0&&(s.value=r.defaultValue),r.innerType._zod.run(s,a))}),Cd=Q("$ZodNonOptional",(e,r)=>{Ue.init(e,r),Ie(e._zod,"values",()=>{const s=r.innerType._zod.values;return s?new Set([...s].filter(a=>a!==void 0)):void 0}),e._zod.parse=(s,a)=>{const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>Ta(i,e)):Ta(n,e)}});function Ta(e,r){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:r}),e}const zd=Q("$ZodCatch",(e,r)=>{Ue.init(e,r),Ie(e._zod,"optin",()=>r.innerType._zod.optin),Ie(e._zod,"optout",()=>r.innerType._zod.optout),Ie(e._zod,"values",()=>r.innerType._zod.values),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(i=>(s.value=i.value,i.issues.length&&(s.value=r.catchValue({...s,error:{issues:i.issues.map(o=>Rt(o,a,Tt()))},input:s.value}),s.issues=[]),s)):(s.value=n.value,n.issues.length&&(s.value=r.catchValue({...s,error:{issues:n.issues.map(i=>Rt(i,a,Tt()))},input:s.value}),s.issues=[]),s)}}),Ed=Q("$ZodPipe",(e,r)=>{Ue.init(e,r),Ie(e._zod,"values",()=>r.in._zod.values),Ie(e._zod,"optin",()=>r.in._zod.optin),Ie(e._zod,"optout",()=>r.out._zod.optout),Ie(e._zod,"propValues",()=>r.in._zod.propValues),e._zod.parse=(s,a)=>{if(a.direction==="backward"){const i=r.out._zod.run(s,a);return i instanceof Promise?i.then(o=>Br(o,r.in,a)):Br(i,r.in,a)}const n=r.in._zod.run(s,a);return n instanceof Promise?n.then(i=>Br(i,r.out,a)):Br(n,r.out,a)}});function Br(e,r,s){return e.issues.length?(e.aborted=!0,e):r._zod.run({value:e.value,issues:e.issues},s)}const Id=Q("$ZodReadonly",(e,r)=>{Ue.init(e,r),Ie(e._zod,"propValues",()=>r.innerType._zod.propValues),Ie(e._zod,"values",()=>r.innerType._zod.values),Ie(e._zod,"optin",()=>r.innerType?._zod?.optin),Ie(e._zod,"optout",()=>r.innerType?._zod?.optout),e._zod.parse=(s,a)=>{if(a.direction==="backward")return r.innerType._zod.run(s,a);const n=r.innerType._zod.run(s,a);return n instanceof Promise?n.then(Ra):Ra(n)}});function Ra(e){return e.value=Object.freeze(e.value),e}const Ad=Q("$ZodCustom",(e,r)=>{ot.init(e,r),Ue.init(e,r),e._zod.parse=(s,a)=>s,e._zod.check=s=>{const a=s.value,n=r.fn(a);if(n instanceof Promise)return n.then(i=>Za(i,s,a,e));Za(n,s,a,e)}});function Za(e,r,s,a){if(!e){const n={code:"custom",input:s,inst:a,path:[...a._zod.def.path??[]],continue:!a._zod.def.abort};a._zod.def.params&&(n.params=a._zod.def.params),r.issues.push(Ir(n))}}var $a;class Pd{constructor(){this._map=new WeakMap,this._idmap=new Map}add(r,...s){const a=s[0];if(this._map.set(r,a),a&&typeof a=="object"&&"id"in a){if(this._idmap.has(a.id))throw new Error(`ID ${a.id} already exists in the registry`);this._idmap.set(a.id,r)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(r){const s=this._map.get(r);return s&&typeof s=="object"&&"id"in s&&this._idmap.delete(s.id),this._map.delete(r),this}get(r){const s=r._zod.parent;if(s){const a={...this.get(s)??{}};delete a.id;const n={...a,...this._map.get(r)};return Object.keys(n).length?n:void 0}return this._map.get(r)}has(r){return this._map.has(r)}}function Fd(){return new Pd}($a=globalThis).__zod_globalRegistry??($a.__zod_globalRegistry=Fd());const Mr=globalThis.__zod_globalRegistry;function Dd(e,r){return new e({type:"string",...de(r)})}function Od(e,r){return new e({type:"string",format:"email",check:"string_format",abort:!1,...de(r)})}function La(e,r){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...de(r)})}function Td(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...de(r)})}function Rd(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...de(r)})}function Zd(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...de(r)})}function $d(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...de(r)})}function Ld(e,r){return new e({type:"string",format:"url",check:"string_format",abort:!1,...de(r)})}function Ud(e,r){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...de(r)})}function Bd(e,r){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...de(r)})}function Md(e,r){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...de(r)})}function Vd(e,r){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...de(r)})}function qd(e,r){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...de(r)})}function Wd(e,r){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...de(r)})}function Kd(e,r){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...de(r)})}function Gd(e,r){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...de(r)})}function Hd(e,r){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...de(r)})}function Qd(e,r){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...de(r)})}function Yd(e,r){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...de(r)})}function Xd(e,r){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...de(r)})}function Jd(e,r){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...de(r)})}function eu(e,r){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...de(r)})}function tu(e,r){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...de(r)})}function ru(e,r){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...de(r)})}function su(e,r){return new e({type:"string",format:"date",check:"string_format",...de(r)})}function au(e,r){return new e({type:"string",format:"time",check:"string_format",precision:null,...de(r)})}function nu(e,r){return new e({type:"string",format:"duration",check:"string_format",...de(r)})}function iu(e,r){return new e({type:"number",coerce:!0,checks:[],...de(r)})}function ou(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...de(r)})}function lu(e){return new e({type:"unknown"})}function cu(e,r){return new e({type:"never",...de(r)})}function Ua(e,r){return new ti({check:"less_than",...de(r),value:e,inclusive:!1})}function js(e,r){return new ti({check:"less_than",...de(r),value:e,inclusive:!0})}function Ba(e,r){return new ri({check:"greater_than",...de(r),value:e,inclusive:!1})}function ks(e,r){return new ri({check:"greater_than",...de(r),value:e,inclusive:!0})}function Ma(e,r){return new Cc({check:"multiple_of",...de(r),value:e})}function oi(e,r){return new Ec({check:"max_length",...de(r),maximum:e})}function rs(e,r){return new Ic({check:"min_length",...de(r),minimum:e})}function li(e,r){return new Ac({check:"length_equals",...de(r),length:e})}function du(e,r){return new Pc({check:"string_format",format:"regex",...de(r),pattern:e})}function uu(e){return new Fc({check:"string_format",format:"lowercase",...de(e)})}function hu(e){return new Dc({check:"string_format",format:"uppercase",...de(e)})}function mu(e,r){return new Oc({check:"string_format",format:"includes",...de(r),includes:e})}function fu(e,r){return new Tc({check:"string_format",format:"starts_with",...de(r),prefix:e})}function pu(e,r){return new Rc({check:"string_format",format:"ends_with",...de(r),suffix:e})}function mr(e){return new Zc({check:"overwrite",tx:e})}function xu(e){return mr(r=>r.normalize(e))}function gu(){return mr(e=>e.trim())}function bu(){return mr(e=>e.toLowerCase())}function vu(){return mr(e=>e.toUpperCase())}function yu(){return mr(e=>Il(e))}function wu(e,r,s){return new e({type:"array",element:r,...de(s)})}function ju(e,r,s){return new e({type:"custom",check:"custom",fn:r,...de(s)})}function ku(e){const r=_u(s=>(s.addIssue=a=>{if(typeof a=="string")s.issues.push(Ir(a,s.value,r._zod.def));else{const n=a;n.fatal&&(n.continue=!1),n.code??(n.code="custom"),n.input??(n.input=s.value),n.inst??(n.inst=r),n.continue??(n.continue=!r._zod.def.abort),s.issues.push(Ir(n))}},e(s.value,s)));return r}function _u(e,r){const s=new ot({check:"custom",...de(r)});return s._zod.check=e,s}function Va(e,r){try{var s=e()}catch(a){return r(a)}return s&&s.then?s.then(void 0,r):s}function Nu(e,r){for(var s={};e.length;){var a=e[0],n=a.code,i=a.message,o=a.path.join(".");if(!s[o])if("unionErrors"in a){var l=a.unionErrors[0].errors[0];s[o]={message:l.message,type:l.code}}else s[o]={message:i,type:n};if("unionErrors"in a&&a.unionErrors.forEach(function(_){return _.errors.forEach(function(w){return e.push(w)})}),r){var h=s[o].types,p=h&&h[a.code];s[o]=Vs(o,r,s,n,p?[].concat(p,a.message):a.message)}e.shift()}return s}function Su(e,r){for(var s={};e.length;){var a=e[0],n=a.code,i=a.message,o=a.path.join(".");if(!s[o])if(a.code==="invalid_union"&&a.errors.length>0){var l=a.errors[0][0];s[o]={message:l.message,type:l.code}}else s[o]={message:i,type:n};if(a.code==="invalid_union"&&a.errors.forEach(function(_){return _.forEach(function(w){return e.push(w)})}),r){var h=s[o].types,p=h&&h[a.code];s[o]=Vs(o,r,s,n,p?[].concat(p,a.message):a.message)}e.shift()}return s}function Cu(e,r,s){if(s===void 0&&(s={}),(function(a){return"_def"in a&&typeof a._def=="object"&&"typeName"in a._def})(e))return function(a,n,i){try{return Promise.resolve(Va(function(){return Promise.resolve(e[s.mode==="sync"?"parse":"parseAsync"](a,r)).then(function(o){return i.shouldUseNativeValidation&&As({},i),{errors:{},values:s.raw?Object.assign({},a):o}})},function(o){if((function(l){return Array.isArray(l?.issues)})(o))return{values:{},errors:Sa(Nu(o.errors,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}};if((function(a){return"_zod"in a&&typeof a._zod=="object"})(e))return function(a,n,i){try{return Promise.resolve(Va(function(){return Promise.resolve((s.mode==="sync"?Vl:ql)(e,a,r)).then(function(o){return i.shouldUseNativeValidation&&As({},i),{errors:{},values:s.raw?Object.assign({},a):o}})},function(o){if((function(l){return l instanceof Ys})(o))return{values:{},errors:Sa(Su(o.issues,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}};throw new Error("Invalid input: not a Zod schema")}const zu=Q("ZodISODateTime",(e,r)=>{Xc.init(e,r),Te.init(e,r)});function Eu(e){return ru(zu,e)}const Iu=Q("ZodISODate",(e,r)=>{Jc.init(e,r),Te.init(e,r)});function Au(e){return su(Iu,e)}const Pu=Q("ZodISOTime",(e,r)=>{ed.init(e,r),Te.init(e,r)});function Fu(e){return au(Pu,e)}const Du=Q("ZodISODuration",(e,r)=>{td.init(e,r),Te.init(e,r)});function Ou(e){return nu(Du,e)}const Tu=(e,r)=>{Ys.init(e,r),e.name="ZodError",Object.defineProperties(e,{format:{value:s=>Ml(e,s)},flatten:{value:s=>Bl(e,s)},addIssue:{value:s=>{e.issues.push(s),e.message=JSON.stringify(e.issues,Ps,2)}},addIssues:{value:s=>{e.issues.push(...s),e.message=JSON.stringify(e.issues,Ps,2)}},isEmpty:{get(){return e.issues.length===0}}})},ht=Q("ZodError",Tu,{Parent:Error}),Ru=os(ht),Zu=ls(ht),$u=cs(ht),Lu=ds(ht),Uu=Gl(ht),Bu=Hl(ht),Mu=Ql(ht),Vu=Yl(ht),qu=Xl(ht),Wu=Jl(ht),Ku=ec(ht),Gu=tc(ht),Ve=Q("ZodType",(e,r)=>(Ue.init(e,r),e.def=r,e.type=r.type,Object.defineProperty(e,"_def",{value:r}),e.check=(...s)=>e.clone(Ut(r,{checks:[...r.checks??[],...s.map(a=>typeof a=="function"?{_zod:{check:a,def:{check:"custom"},onattach:[]}}:a)]})),e.clone=(s,a)=>_t(e,s,a),e.brand=()=>e,e.register=((s,a)=>(s.add(e,a),e)),e.parse=(s,a)=>Ru(e,s,a,{callee:e.parse}),e.safeParse=(s,a)=>$u(e,s,a),e.parseAsync=async(s,a)=>Zu(e,s,a,{callee:e.parseAsync}),e.safeParseAsync=async(s,a)=>Lu(e,s,a),e.spa=e.safeParseAsync,e.encode=(s,a)=>Uu(e,s,a),e.decode=(s,a)=>Bu(e,s,a),e.encodeAsync=async(s,a)=>Mu(e,s,a),e.decodeAsync=async(s,a)=>Vu(e,s,a),e.safeEncode=(s,a)=>qu(e,s,a),e.safeDecode=(s,a)=>Wu(e,s,a),e.safeEncodeAsync=async(s,a)=>Ku(e,s,a),e.safeDecodeAsync=async(s,a)=>Gu(e,s,a),e.refine=(s,a)=>e.check(Uh(s,a)),e.superRefine=s=>e.check(Bh(s)),e.overwrite=s=>e.check(mr(s)),e.optional=()=>Ha(e),e.nullable=()=>Qa(e),e.nullish=()=>Ha(Qa(e)),e.nonoptional=s=>Dh(e,s),e.array=()=>bh(e),e.or=s=>jh([e,s]),e.and=s=>_h(e,s),e.transform=s=>Ya(e,zh(s)),e.default=s=>Ah(e,s),e.prefault=s=>Fh(e,s),e.catch=s=>Th(e,s),e.pipe=s=>Ya(e,s),e.readonly=()=>$h(e),e.describe=s=>{const a=e.clone();return Mr.add(a,{description:s}),a},Object.defineProperty(e,"description",{get(){return Mr.get(e)?.description},configurable:!0}),e.meta=(...s)=>{if(s.length===0)return Mr.get(e);const a=e.clone();return Mr.add(a,s[0]),a},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ci=Q("_ZodString",(e,r)=>{Xs.init(e,r),Ve.init(e,r);const s=e._zod.bag;e.format=s.format??null,e.minLength=s.minimum??null,e.maxLength=s.maximum??null,e.regex=(...a)=>e.check(du(...a)),e.includes=(...a)=>e.check(mu(...a)),e.startsWith=(...a)=>e.check(fu(...a)),e.endsWith=(...a)=>e.check(pu(...a)),e.min=(...a)=>e.check(rs(...a)),e.max=(...a)=>e.check(oi(...a)),e.length=(...a)=>e.check(li(...a)),e.nonempty=(...a)=>e.check(rs(1,...a)),e.lowercase=a=>e.check(uu(a)),e.uppercase=a=>e.check(hu(a)),e.trim=()=>e.check(gu()),e.normalize=(...a)=>e.check(xu(...a)),e.toLowerCase=()=>e.check(bu()),e.toUpperCase=()=>e.check(vu()),e.slugify=()=>e.check(yu())}),Hu=Q("ZodString",(e,r)=>{Xs.init(e,r),ci.init(e,r),e.email=s=>e.check(Od(Qu,s)),e.url=s=>e.check(Ld(Yu,s)),e.jwt=s=>e.check(tu(hh,s)),e.emoji=s=>e.check(Ud(Xu,s)),e.guid=s=>e.check(La(qa,s)),e.uuid=s=>e.check(Td(Vr,s)),e.uuidv4=s=>e.check(Rd(Vr,s)),e.uuidv6=s=>e.check(Zd(Vr,s)),e.uuidv7=s=>e.check($d(Vr,s)),e.nanoid=s=>e.check(Bd(Ju,s)),e.guid=s=>e.check(La(qa,s)),e.cuid=s=>e.check(Md(eh,s)),e.cuid2=s=>e.check(Vd(th,s)),e.ulid=s=>e.check(qd(rh,s)),e.base64=s=>e.check(Xd(ch,s)),e.base64url=s=>e.check(Jd(dh,s)),e.xid=s=>e.check(Wd(sh,s)),e.ksuid=s=>e.check(Kd(ah,s)),e.ipv4=s=>e.check(Gd(nh,s)),e.ipv6=s=>e.check(Hd(ih,s)),e.cidrv4=s=>e.check(Qd(oh,s)),e.cidrv6=s=>e.check(Yd(lh,s)),e.e164=s=>e.check(eu(uh,s)),e.datetime=s=>e.check(Eu(s)),e.date=s=>e.check(Au(s)),e.time=s=>e.check(Fu(s)),e.duration=s=>e.check(Ou(s))});function Ct(e){return Dd(Hu,e)}const Te=Q("ZodStringFormat",(e,r)=>{Pe.init(e,r),ci.init(e,r)}),Qu=Q("ZodEmail",(e,r)=>{Mc.init(e,r),Te.init(e,r)}),qa=Q("ZodGUID",(e,r)=>{Uc.init(e,r),Te.init(e,r)}),Vr=Q("ZodUUID",(e,r)=>{Bc.init(e,r),Te.init(e,r)}),Yu=Q("ZodURL",(e,r)=>{Vc.init(e,r),Te.init(e,r)}),Xu=Q("ZodEmoji",(e,r)=>{qc.init(e,r),Te.init(e,r)}),Ju=Q("ZodNanoID",(e,r)=>{Wc.init(e,r),Te.init(e,r)}),eh=Q("ZodCUID",(e,r)=>{Kc.init(e,r),Te.init(e,r)}),th=Q("ZodCUID2",(e,r)=>{Gc.init(e,r),Te.init(e,r)}),rh=Q("ZodULID",(e,r)=>{Hc.init(e,r),Te.init(e,r)}),sh=Q("ZodXID",(e,r)=>{Qc.init(e,r),Te.init(e,r)}),ah=Q("ZodKSUID",(e,r)=>{Yc.init(e,r),Te.init(e,r)}),nh=Q("ZodIPv4",(e,r)=>{rd.init(e,r),Te.init(e,r)}),ih=Q("ZodIPv6",(e,r)=>{sd.init(e,r),Te.init(e,r)}),oh=Q("ZodCIDRv4",(e,r)=>{ad.init(e,r),Te.init(e,r)}),lh=Q("ZodCIDRv6",(e,r)=>{nd.init(e,r),Te.init(e,r)}),ch=Q("ZodBase64",(e,r)=>{id.init(e,r),Te.init(e,r)}),dh=Q("ZodBase64URL",(e,r)=>{ld.init(e,r),Te.init(e,r)}),uh=Q("ZodE164",(e,r)=>{cd.init(e,r),Te.init(e,r)}),hh=Q("ZodJWT",(e,r)=>{ud.init(e,r),Te.init(e,r)}),di=Q("ZodNumber",(e,r)=>{ai.init(e,r),Ve.init(e,r),e.gt=(a,n)=>e.check(Ba(a,n)),e.gte=(a,n)=>e.check(ks(a,n)),e.min=(a,n)=>e.check(ks(a,n)),e.lt=(a,n)=>e.check(Ua(a,n)),e.lte=(a,n)=>e.check(js(a,n)),e.max=(a,n)=>e.check(js(a,n)),e.int=a=>e.check(Wa(a)),e.safe=a=>e.check(Wa(a)),e.positive=a=>e.check(Ba(0,a)),e.nonnegative=a=>e.check(ks(0,a)),e.negative=a=>e.check(Ua(0,a)),e.nonpositive=a=>e.check(js(0,a)),e.multipleOf=(a,n)=>e.check(Ma(a,n)),e.step=(a,n)=>e.check(Ma(a,n)),e.finite=()=>e;const s=e._zod.bag;e.minValue=Math.max(s.minimum??Number.NEGATIVE_INFINITY,s.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(s.maximum??Number.POSITIVE_INFINITY,s.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(s.format??"").includes("int")||Number.isSafeInteger(s.multipleOf??.5),e.isFinite=!0,e.format=s.format??null}),mh=Q("ZodNumberFormat",(e,r)=>{hd.init(e,r),di.init(e,r)});function Wa(e){return ou(mh,e)}const fh=Q("ZodUnknown",(e,r)=>{md.init(e,r),Ve.init(e,r)});function Ka(){return lu(fh)}const ph=Q("ZodNever",(e,r)=>{fd.init(e,r),Ve.init(e,r)});function xh(e){return cu(ph,e)}const gh=Q("ZodArray",(e,r)=>{pd.init(e,r),Ve.init(e,r),e.element=r.element,e.min=(s,a)=>e.check(rs(s,a)),e.nonempty=s=>e.check(rs(1,s)),e.max=(s,a)=>e.check(oi(s,a)),e.length=(s,a)=>e.check(li(s,a)),e.unwrap=()=>e.element});function bh(e,r){return wu(gh,e,r)}const vh=Q("ZodObject",(e,r)=>{gd.init(e,r),Ve.init(e,r),Ie(e,"shape",()=>r.shape),e.keyof=()=>Nh(Object.keys(e._zod.def.shape)),e.catchall=s=>e.clone({...e._zod.def,catchall:s}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ka()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ka()}),e.strict=()=>e.clone({...e._zod.def,catchall:xh()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=s=>Rl(e,s),e.safeExtend=s=>Zl(e,s),e.merge=s=>$l(e,s),e.pick=s=>Ol(e,s),e.omit=s=>Tl(e,s),e.partial=(...s)=>Ll(ui,e,s[0]),e.required=(...s)=>Ul(hi,e,s[0])});function yh(e,r){const s={type:"object",shape:e??{},...de(r)};return new vh(s)}const wh=Q("ZodUnion",(e,r)=>{bd.init(e,r),Ve.init(e,r),e.options=r.options});function jh(e,r){return new wh({type:"union",options:e,...de(r)})}const kh=Q("ZodIntersection",(e,r)=>{vd.init(e,r),Ve.init(e,r)});function _h(e,r){return new kh({type:"intersection",left:e,right:r})}const Ds=Q("ZodEnum",(e,r)=>{yd.init(e,r),Ve.init(e,r),e.enum=r.entries,e.options=Object.values(r.entries);const s=new Set(Object.keys(r.entries));e.extract=(a,n)=>{const i={};for(const o of a)if(s.has(o))i[o]=r.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Ds({...r,checks:[],...de(n),entries:i})},e.exclude=(a,n)=>{const i={...r.entries};for(const o of a)if(s.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Ds({...r,checks:[],...de(n),entries:i})}});function Nh(e,r){const s=Array.isArray(e)?Object.fromEntries(e.map(a=>[a,a])):e;return new Ds({type:"enum",entries:s,...de(r)})}const Sh=Q("ZodLiteral",(e,r)=>{wd.init(e,r),Ve.init(e,r),e.values=new Set(r.values),Object.defineProperty(e,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function Ga(e,r){return new Sh({type:"literal",values:Array.isArray(e)?e:[e],...de(r)})}const Ch=Q("ZodTransform",(e,r)=>{jd.init(e,r),Ve.init(e,r),e._zod.parse=(s,a)=>{if(a.direction==="backward")throw new qn(e.constructor.name);s.addIssue=i=>{if(typeof i=="string")s.issues.push(Ir(i,s.value,r));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=s.value),o.inst??(o.inst=e),s.issues.push(Ir(o))}};const n=r.transform(s.value,s);return n instanceof Promise?n.then(i=>(s.value=i,s)):(s.value=n,s)}});function zh(e){return new Ch({type:"transform",transform:e})}const ui=Q("ZodOptional",(e,r)=>{kd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Ha(e){return new ui({type:"optional",innerType:e})}const Eh=Q("ZodNullable",(e,r)=>{_d.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Qa(e){return new Eh({type:"nullable",innerType:e})}const Ih=Q("ZodDefault",(e,r)=>{Nd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ah(e,r){return new Ih({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():Gn(r)}})}const Ph=Q("ZodPrefault",(e,r)=>{Sd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Fh(e,r){return new Ph({type:"prefault",innerType:e,get defaultValue(){return typeof r=="function"?r():Gn(r)}})}const hi=Q("ZodNonOptional",(e,r)=>{Cd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function Dh(e,r){return new hi({type:"nonoptional",innerType:e,...de(r)})}const Oh=Q("ZodCatch",(e,r)=>{zd.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Th(e,r){return new Oh({type:"catch",innerType:e,catchValue:typeof r=="function"?r:()=>r})}const Rh=Q("ZodPipe",(e,r)=>{Ed.init(e,r),Ve.init(e,r),e.in=r.in,e.out=r.out});function Ya(e,r){return new Rh({type:"pipe",in:e,out:r})}const Zh=Q("ZodReadonly",(e,r)=>{Id.init(e,r),Ve.init(e,r),e.unwrap=()=>e._zod.def.innerType});function $h(e){return new Zh({type:"readonly",innerType:e})}const Lh=Q("ZodCustom",(e,r)=>{Ad.init(e,r),Ve.init(e,r)});function Uh(e,r={}){return ju(Lh,e,r)}function Bh(e){return ku(e)}function Mh(e){return iu(di,e)}const xr={image:10*1024*1024,audio:25*1024*1024,video:50*1024*1024,document:25*1024*1024},Vh="image/*,video/*,audio/*,.pdf,.doc,.docx";function wt(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function _s(e){return e.startsWith("image/")?"image":e.startsWith("audio/")?"audio":e.startsWith("video/")?"video":"document"}function qh(e){let r=1/0;for(const s of e){const a=Sn(s.type),n=s.config?.mediaLimits?.outbound?.image?.maxBytes??a.outbound.image.maxBytes??1/0;n<r&&(r=n)}return r===1/0?0:r}const Wh={HASHING:{label:"Calculando identidad...",detail:"Hash SHA-256 del archivo",color:"text-violet-500"},CHECKING_DEDUP:{label:"Verificando existencia...",detail:"Buscando duplicados",color:"text-blue-500"},OPTIMIZING:{label:"Optimizando imagen...",detail:"Comprimiendo para canales",color:"text-amber-500"},GENERATING_THUMB:{label:"Generando vista previa...",detail:"Thumbnail 300px",color:"text-cyan-500"},UPLOADING:{label:"Subiendo a la nube...",detail:"Upload seguro",color:"text-primary"},CONFIRMING:{label:"Confirmando...",detail:"Registro en base de datos",color:"text-emerald-500"}},Kh={WHATSAPP:{label:"WhatsApp",compatible:"bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-900/20 dark:text-emerald-400 dark:border-emerald-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},WEB:{label:"Web",compatible:"bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-900/20 dark:text-indigo-400 dark:border-indigo-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},INSTAGRAM:{label:"Instagram",compatible:"bg-pink-50 text-pink-700 border-pink-200 dark:bg-pink-900/20 dark:text-pink-400 dark:border-pink-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"},FACEBOOK:{label:"Facebook",compatible:"bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-900/20 dark:text-blue-400 dark:border-blue-800",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"}},Gh={label:"?",compatible:"bg-slate-50 text-slate-600 border-slate-200 dark:bg-slate-800 dark:text-slate-400 dark:border-slate-700",incompatible:"bg-rose-50 text-rose-600 border-rose-200 dark:bg-rose-900/20 dark:text-rose-400 dark:border-rose-800"};function Hh(e){return Kh[e?.toUpperCase()]||Gh}function Qh({channels:e,fileSizeBytes:r,mimeType:s}){const a=Y.useMemo(()=>Li(e,r,s),[e,r,s]),n=a.filter(o=>o.isCompatible).length,i=n===a.length;return t.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100 dark:border-slate-800/60",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx(mo,{className:"h-2.5 w-2.5 text-muted-foreground/50"}),t.jsx("span",{className:"text-[9px] uppercase font-bold tracking-widest text-muted-foreground/60",children:"Canales"}),t.jsxs("span",{className:le("text-[9px] font-bold px-1 py-px rounded",i?"text-emerald-600 bg-emerald-50 dark:text-emerald-400 dark:bg-emerald-900/20":"text-amber-600 bg-amber-50 dark:text-amber-400 dark:bg-amber-900/20"),children:[n,"/",a.length]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(o=>{const l=Hh(o.channelType);return t.jsx(Ar,{children:t.jsxs(et,{delayDuration:0,children:[t.jsx(tt,{asChild:!0,children:t.jsxs("span",{className:le("inline-flex items-center gap-1 px-2 py-1 rounded-lg border text-[10px] font-semibold cursor-default transition-all",o.isCompatible?l.compatible:l.incompatible),children:[o.isCompatible?t.jsx(sa,{className:"h-3 w-3"}):t.jsx(ct,{className:"h-3 w-3"}),t.jsx("span",{children:l.label}),!o.isCompatible&&t.jsx("span",{className:"text-[8px] opacity-70 font-bold ml-0.5",children:wt(o.limitBytes)})]})}),t.jsx(rt,{side:"top",className:le("text-[11px] max-w-[240px] px-3 py-2 shadow-lg",!o.isCompatible&&"border-rose-200 dark:border-rose-800"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[o.isCompatible?t.jsx(sa,{className:"h-3.5 w-3.5 text-emerald-500 shrink-0 mt-0.5"}):t.jsx(ct,{className:"h-3.5 w-3.5 text-rose-500 shrink-0 mt-0.5"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-bold",children:o.channelName}),t.jsx("p",{className:"text-muted-foreground mt-0.5",children:o.isCompatible?`Compatible — máx. ${wt(o.limitBytes)}`:o.reason})]})]})})]})},o.channelId)})})]})}function Yh({media:e,onChange:r}){const[s,a]=Y.useState("IDLE"),[n,i]=Y.useState(!1),[o,l]=Y.useState(new Set),[h,p]=Y.useState(new Set),_=Y.useRef(null),w=Y.useRef(0),g=Os(F=>F.currentOrganization),{channels:d,fetchChannels:k}=an($t(F=>({channels:F.channels,fetchChannels:F.fetchChannels})));Y.useEffect(()=>{g?.id&&k({withDeleted:!1})},[g?.id,k]);const u=Y.useMemo(()=>d.filter(F=>F.isActive&&!F.deletedAt&&!F.disconnectedFromMetaAt&&!F.deactivatedAt&&!F.archivedAt),[d]),x=Y.useMemo(()=>({image:{maxBytes:qh(u)||xr.image},video:{maxBytes:xr.video},audio:{maxBytes:xr.audio},document:{maxBytes:xr.document}}),[u]),f=Y.useCallback(F=>{const ee=_s(F.type),O=xr[ee];return F.size>O?`${F.name} excede el límite de ${wt(O)}`:null},[]),j=Y.useCallback(async F=>{const ee=f(F);if(ee){ne.error(ee);return}a("HASHING");try{const O=await Cs.processFile(F,{limits:x,onProgress:te=>a(te)}),L=_s(F.type),ae={id:O.hash||crypto.randomUUID(),url:O.thumbnailUrl||O.signedUrl||"",type:L,name:F.name,gcsPath:O.gcsPath,thumbnailUrl:O.thumbnailUrl||void 0,mimeType:O.mimeType||F.type,fileSizeBytes:O.size||F.size};r([...e,ae]),O.isDuplicate?(p(te=>new Set(te).add(ae.id)),ne.success("Archivo ya existente (reutilizado)")):O.isOptimized?(l(te=>new Set(te).add(ae.id)),ne.success(`Imagen optimizada: ${wt(F.size)} → ${wt(O.size)}`)):ne.success("Archivo subido correctamente")}catch(O){ne.error(O.message||"Error al subir archivo")}finally{a("IDLE")}},[e,r,f,x]),E=Y.useCallback(async F=>{const ee=F.target.files?.[0];ee&&await j(ee),F.target.value=""},[j]),P=Y.useCallback(F=>{const ee=[...e];ee.splice(F,1),r(ee)},[e,r]),S=Y.useCallback(async F=>{const ee=e[F];if(ee){a("OPTIMIZING");try{const O=ee.url||ee.thumbnailUrl||"";if(!O){ne.error("No se puede obtener el archivo para re-subir");return}const ae=await(await fetch(O)).blob(),te=new File([ae],ee.name||"image.jpg",{type:ee.mimeType||ae.type}),J=await Cs.processFile(te,{limits:x,onProgress:me=>a(me),skipDedup:!0}),ve=_s(te.type),Se={id:J.hash||crypto.randomUUID(),url:J.thumbnailUrl||J.signedUrl||"",type:ve,name:ee.name,gcsPath:J.gcsPath,thumbnailUrl:J.thumbnailUrl||void 0,mimeType:J.mimeType||te.type,fileSizeBytes:J.size||te.size},fe=[...e];fe[F]=Se,r(fe),p(me=>{const ke=new Set(me);return ke.delete(ee.id),ke}),J.isOptimized?(l(me=>new Set(me).add(Se.id)),ne.success(`Imagen optimizada: ${wt(te.size)} → ${wt(J.size)}`)):ne.success("Archivo re-subido correctamente")}catch(O){ne.error(O.message||"Error al re-subir archivo")}finally{a("IDLE")}}},[e,r,x]),B=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation(),w.current+=1,F.dataTransfer.items?.length&&i(!0)},[]),U=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation(),w.current-=1,w.current===0&&i(!1)},[]),$=Y.useCallback(F=>{F.preventDefault(),F.stopPropagation()},[]),T=Y.useCallback(async F=>{F.preventDefault(),F.stopPropagation(),i(!1),w.current=0;const ee=F.dataTransfer.files?.[0];ee&&await j(ee)},[j]),G=F=>{switch(F){case"image":return t.jsx(At,{className:"h-5 w-5 text-blue-500"});case"audio":return t.jsx(En,{className:"h-5 w-5 text-amber-500"});case"video":return t.jsx(Cn,{className:"h-5 w-5 text-purple-500"});default:return t.jsx(zn,{className:"h-5 w-5 text-slate-400"})}},se=F=>{switch(F){case"image":return"bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400";case"audio":return"bg-amber-50 text-amber-600 dark:bg-amber-900/20 dark:text-amber-400";case"video":return"bg-purple-50 text-purple-600 dark:bg-purple-900/20 dark:text-purple-400";default:return"bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400"}},v=F=>{switch(F){case"image":return"Imagen";case"audio":return"Audio";case"video":return"Video";default:return"Documento"}},[R,m]=Y.useState(new Set),V=Y.useCallback(F=>{m(ee=>{const O=new Set(ee);return O.has(F)?O.delete(F):O.add(F),O})},[]),ie=Y.useCallback((F,ee,O)=>{const L=[...e];L[F]={...L[F],[ee]:O||null},r(L)},[e,r]),q=s!=="IDLE"&&s!=="DONE"&&s!=="ERROR",ce=q?Wh[s]:null;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 bg-violet-50 dark:bg-violet-900/20 rounded-lg flex items-center justify-center",children:t.jsx(Hr,{className:"h-3.5 w-3.5 text-violet-500"})}),t.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-slate-500",children:"Multimedia"}),e.length>0&&t.jsxs("span",{className:"ml-auto text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-2 py-0.5 rounded-full",children:[e.length," ",e.length===1?"archivo":"archivos"]})]}),t.jsxs("div",{onDragEnter:B,onDragLeave:U,onDragOver:$,onDrop:T,onClick:()=>!q&&_.current?.click(),className:le("relative border-2 border-dashed rounded-2xl p-6 text-center transition-all duration-200 cursor-pointer group",n?"border-primary bg-primary/5 scale-[1.01]":"border-slate-200 dark:border-slate-700 hover:border-primary/40 hover:bg-slate-50/50 dark:hover:bg-slate-800/30",q&&"pointer-events-none opacity-60"),children:[t.jsx("input",{ref:_,type:"file",className:"hidden",accept:Vh,onChange:E,disabled:q}),t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[q?t.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:t.jsx(be,{className:le("h-5 w-5 animate-spin",ce?.color||"text-primary")})}):n?t.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center animate-pulse",children:t.jsx(ia,{className:"h-5 w-5 text-primary"})}):t.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center group-hover:bg-primary/10 transition-colors",children:t.jsx(ia,{className:"h-5 w-5 text-slate-400 group-hover:text-primary transition-colors"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:q?ce?.label:n?"Soltar archivo aquí":"Arrastra o haz click para subir"}),q&&ce?.detail?t.jsx("p",{className:le("text-[11px] mt-0.5 font-medium animate-pulse",ce.color),children:ce.detail}):!q&&t.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Imágenes (10 MB), Videos (50 MB), Audio (25 MB), PDF/DOC (25 MB)"})]})]})]}),e.length>0&&t.jsx("div",{className:"grid grid-cols-1 gap-2",children:e.map((F,ee)=>t.jsxs("div",{className:"relative group bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 rounded-xl p-2.5 hover:shadow-sm transition-all",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[F.type==="image"&&F.url?t.jsx("div",{className:"w-12 h-12 rounded-lg overflow-hidden shrink-0 bg-slate-100 dark:bg-slate-800",children:t.jsx("img",{src:F.url,alt:F.name,className:"object-cover w-full h-full"})}):t.jsx("div",{className:"w-12 h-12 rounded-lg shrink-0 bg-slate-50 dark:bg-slate-800 flex items-center justify-center",children:G(F.type)}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"text-sm font-medium text-slate-800 dark:text-slate-200 truncate",children:F.name}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[F.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-500 dark:text-slate-400",children:wt(F.fileSizeBytes)}),t.jsx("span",{className:le("text-[10px] font-bold uppercase px-1.5 py-0.5 rounded-md",se(F.type)),children:v(F.type)}),F.gcsPath&&t.jsx(rr,{className:"h-3 w-3 text-emerald-500"}),o.has(F.id)&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-bold uppercase px-1.5 py-0.5 rounded-md bg-amber-50 text-amber-600 dark:bg-amber-900/20 dark:text-amber-400",children:[t.jsx(Fr,{className:"h-2.5 w-2.5"}),"Optimizada"]}),h.has(F.id)&&t.jsx(Ar,{children:t.jsxs(et,{delayDuration:0,children:[t.jsx(tt,{asChild:!0,children:t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-bold uppercase px-1.5 py-0.5 rounded-md bg-sky-50 text-sky-600 dark:bg-sky-900/20 dark:text-sky-400 group/dedup cursor-default",children:[t.jsx(Mi,{className:"h-2.5 w-2.5"}),"Cloud Reused",t.jsx("button",{type:"button",className:"ml-0.5 rounded-full hover:bg-sky-200 dark:hover:bg-sky-800 p-px transition-colors",onClick:O=>{O.stopPropagation(),S(ee)},disabled:q,children:t.jsx(Ft,{className:"h-2.5 w-2.5"})})]})}),t.jsxs(rt,{side:"top",className:"text-[11px] max-w-[240px] px-3 py-2",children:[t.jsx("p",{className:"font-semibold",children:"Archivo reutilizado de la nube"}),t.jsxs("p",{className:"text-muted-foreground mt-0.5",children:["Este archivo ya existía. Haz click en ",t.jsx("strong",{children:"✕"})," para forzar una nueva carga con optimización."]})]})]})})]})]}),t.jsx(ue,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-rose-500 hover:bg-rose-50 dark:hover:bg-rose-900/20 shrink-0",onClick:O=>{O.stopPropagation(),P(ee)},children:t.jsx(Ft,{className:"h-3.5 w-3.5"})})]}),t.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-100 dark:border-slate-800/60",children:[t.jsxs("button",{type:"button",onClick:()=>V(F.id),className:"flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-wider text-muted-foreground/60 hover:text-muted-foreground transition-colors w-full",children:[t.jsx(_n,{className:"h-2.5 w-2.5"}),t.jsx("span",{children:"Contexto para IA"}),(F.description||F.salesContext)&&t.jsx(rr,{className:"h-2.5 w-2.5 text-emerald-500"}),R.has(F.id)?t.jsx(yn,{className:"h-3 w-3 ml-auto"}):t.jsx(Dr,{className:"h-3 w-3 ml-auto"})]}),R.has(F.id)&&t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 mb-0.5 block",children:"Descripción del recurso"}),t.jsx("input",{type:"text",placeholder:"Ej: Video demo del producto en uso",value:F.description||"",onChange:O=>ie(ee,"description",O.target.value),maxLength:500,className:"w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-primary/40"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 mb-0.5 block",children:"Cuándo usarlo en la conversación"}),t.jsx("input",{type:"text",placeholder:"Ej: Cuando el cliente duda de la calidad",value:F.salesContext||"",onChange:O=>ie(ee,"salesContext",O.target.value),maxLength:500,className:"w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-primary/40"})]})]})]}),F.fileSizeBytes&&F.mimeType&&u.length>0&&t.jsx(Qh,{channels:u,fileSizeBytes:F.fileSizeBytes,mimeType:F.mimeType})]},F.id||ee))})]})}const Xh=yh({name:Ct().min(1,"Nombre es requerido").max(255),description:Ct().min(1,"Descripción es requerida"),price:Mh().min(0,"Precio debe ser mayor o igual a 0"),currency:Ct().min(1,"Moneda es requerida"),externalId:Ct().max(100).optional().or(Ga("")),externalCategory:Ct().max(100).optional().or(Ga("")),catalogId:Ct().uuid("Selecciona un catálogo"),imageUrl:Ct().optional()});function Ns({icon:e,label:r,iconBg:s,accentHover:a,badge:n,children:i}){return t.jsxs(Rs,{className:le("border-border/40 shadow-sm bg-background/50 group transition-all duration-200 overflow-hidden",a),children:[t.jsxs(Fi,{className:"flex flex-row items-center justify-between space-y-0 px-4 py-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:le("w-6 h-6 rounded-md flex items-center justify-center",s),children:e}),t.jsx(Di,{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:r})]}),n]}),t.jsx(Zs,{className:"space-y-3 pt-0 px-4 pb-4",children:i})]})}function zt({children:e,required:r}){return t.jsxs(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:[e,r&&t.jsx("span",{className:"text-rose-500 ml-0.5",children:"*"})]})}function Jh({product:e,catalogs:r,organizationId:s,isSubmitting:a,onSubmit:n}){const{register:i,handleSubmit:o,setValue:l,watch:h,formState:{errors:p}}=Sl({resolver:Cu(Xh),defaultValues:e?{name:e.name,description:e.description||"",price:Number(e.price),currency:e.currency||"USD",externalId:e.externalId||"",externalCategory:e.externalCategory||"",catalogId:e.catalogId||"",imageUrl:e.imageUrl}:{name:"",description:"",price:0,currency:"USD",externalId:"",externalCategory:"",catalogId:"",imageUrl:void 0}}),_=h("currency"),w=h("catalogId"),[g,d]=Y.useState(()=>e?.media&&e.media.length>0?e.media:e&&(e.thumbnailUrl||e.imageUrl)?[{id:"existing",url:e.thumbnailUrl||"",type:"image",name:e.media?.[0]?.name||"Imagen del producto",gcsPath:e.imageUrl,thumbnailUrl:e.thumbnailUrl}]:[]),k=x=>{d(x);const f=x.find(j=>j.type==="image");l("imageUrl",f?.gcsPath||void 0)},u=x=>{n({...x,media:g})};return t.jsxs("form",{onSubmit:o(u),className:"space-y-3 pb-2",children:[t.jsxs(Ns,{icon:t.jsx(it,{className:"h-3.5 w-3.5 text-indigo-500"}),label:"Información Básica",iconBg:"bg-indigo-500/10",accentHover:"hover:border-indigo-500/20",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Nombre del producto"}),t.jsx(st,{...i("name"),placeholder:"Ej: Curso de Marketing Digital",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-medium"}),p.name&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.name.message})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(zt,{required:!0,children:"Descripción"}),t.jsxs(Ce,{variant:"outline",className:"text-[9px] font-bold uppercase tracking-wider px-2 py-0 border-amber-500/30 text-amber-600 dark:text-amber-400 bg-amber-500/5 flex items-center gap-1",children:[t.jsx(Fr,{className:"h-2.5 w-2.5"}),"Clave para IA"]})]}),t.jsx(vn,{...i("description"),placeholder:"Describe el producto con detalle: características, beneficios, público objetivo. La IA usará esta información para recomendarlo.",className:"min-h-[90px] rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 resize-none text-sm leading-relaxed"}),p.description&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.description.message})]})]}),t.jsx(Yh,{media:g,organizationId:s,onChange:k}),t.jsx(Ns,{icon:t.jsx(lr,{className:"h-3.5 w-3.5 text-emerald-500"}),label:"Precio",iconBg:"bg-emerald-500/10",accentHover:"hover:border-emerald-500/20",children:t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Monto"}),t.jsx(st,{type:"number",step:"0.01",...i("price"),placeholder:"0.00",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-medium font-mono"}),p.price&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.price.message})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Moneda"}),t.jsxs(sr,{value:_,onValueChange:x=>l("currency",x),children:[t.jsx(ar,{className:"h-9 rounded-lg bg-muted/30 border-border/50",children:t.jsx(nr,{})}),t.jsx(ir,{className:"rounded-lg",children:jn.map(x=>t.jsx(kt,{value:x.value,className:"rounded-lg",children:x.label},x.value))})]})]})]})}),t.jsxs(Ns,{icon:t.jsx(dt,{className:"h-3.5 w-3.5 text-violet-500"}),label:"Clasificación",iconBg:"bg-violet-500/10",accentHover:"hover:border-violet-500/20",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(zt,{required:!0,children:"Catálogo"}),t.jsxs(sr,{value:w,onValueChange:x=>l("catalogId",x),children:[t.jsx(ar,{className:"h-9 rounded-lg bg-muted/30 border-border/50",children:t.jsx(nr,{placeholder:"Seleccionar catálogo..."})}),t.jsx(ir,{className:"rounded-lg",children:r.map(x=>t.jsx(kt,{value:x.id,className:"rounded-lg",children:x.name},x.id))})]}),p.catalogId&&t.jsx("p",{className:"text-[10px] text-rose-500 font-bold uppercase tracking-wide",children:p.catalogId.message})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(In,{className:"h-3 w-3 text-muted-foreground/50"}),t.jsx(zt,{children:"SKU / ID Externo"})]}),t.jsx(st,{...i("externalId"),placeholder:"Opcional",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm font-mono"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ss,{className:"h-3 w-3 text-muted-foreground/50"}),t.jsx(zt,{children:"Categoría"})]}),t.jsx(st,{...i("externalCategory"),placeholder:"Opcional",className:"h-9 rounded-lg bg-muted/30 border-border/50 focus-visible:ring-1 focus-visible:ring-primary/30 text-sm"})]})]})]}),t.jsxs(ue,{type:"submit",className:"w-full h-10 rounded-lg bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 font-bold text-sm transition-all",disabled:a,children:[a?t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"}):t.jsx(An,{className:"h-4 w-4 mr-2"}),e?"Guardar cambios":"Crear Producto"]})]})}function em(e,r,s=5){const a=Math.min(r,s);if(r<=s)return Array.from({length:a},(i,o)=>o+1);const n=Math.floor(s/2);return e<=n+1?Array.from({length:a},(i,o)=>o+1):e>=r-n?Array.from({length:a},(i,o)=>r-a+1+o):Array.from({length:a},(i,o)=>e-n+o)}const Ss=({label:e,column:r,currentSort:s,currentOrder:a,onSort:n,className:i})=>{const o=s===r;return t.jsxs("button",{type:"button",onClick:()=>n?.(r),className:le("flex items-center gap-1 font-black uppercase text-[10px] tracking-widest transition-colors group/sort",o?"text-primary":"text-slate-400 hover:text-slate-600 dark:hover:text-slate-300",i),children:[e,o?a==="ASC"?t.jsx(Vi,{className:"w-3 h-3"}):t.jsx(qi,{className:"w-3 h-3"}):t.jsx(Wi,{className:"w-3 h-3 opacity-0 group-hover/sort:opacity-50 transition-opacity"})]})},tm={default:{color:"text-slate-600",bgClass:"bg-slate-50 dark:bg-slate-800"}};function rm(e){if(!e)return tm.default;const r=e.split("").reduce((a,n)=>a+n.charCodeAt(0),0),s=[{color:"text-violet-600",bgClass:"bg-violet-50 dark:bg-violet-900/20"},{color:"text-blue-600",bgClass:"bg-blue-50 dark:bg-blue-900/20"},{color:"text-emerald-600",bgClass:"bg-emerald-50 dark:bg-emerald-900/20"},{color:"text-amber-600",bgClass:"bg-amber-50 dark:bg-amber-900/20"},{color:"text-rose-600",bgClass:"bg-rose-50 dark:bg-rose-900/20"},{color:"text-indigo-600",bgClass:"bg-indigo-50 dark:bg-indigo-900/20"},{color:"text-teal-600",bgClass:"bg-teal-50 dark:bg-teal-900/20"}];return s[r%s.length]}const mi=Y.memo(({products:e,catalogs:r,isLoading:s,selectedIds:a,onSelect:n,onSelectAll:i,onViewDetail:o,onEdit:l,onDelete:h,onToggleActive:p,onSyncProduct:_,missingIds:w,page:g,total:d,limit:k,onPageChange:u,density:x="comfortable",sortBy:f,sortOrder:j,onSort:E})=>{if(s)return t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 p-16 flex flex-col items-center justify-center gap-6 animate-pulse",children:[t.jsx("div",{className:"w-16 h-16 bg-slate-50 dark:bg-slate-800 rounded-2xl flex items-center justify-center",children:t.jsx(be,{className:"w-8 h-8 animate-spin text-primary"})}),t.jsxs("div",{className:"space-y-2 text-center",children:[t.jsx("p",{className:"text-slate-900 dark:text-white font-black text-lg",children:"Cargando productos"}),t.jsx("p",{className:"text-slate-500 text-sm",children:"Obteniendo inventario..."})]})]});if(e.length===0)return t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(it,{className:"w-10 h-10 text-slate-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2 tracking-tight",children:"Sin productos"}),t.jsx("p",{className:"text-slate-500 max-w-sm mx-auto text-sm leading-relaxed",children:"No hay productos que coincidan con los filtros seleccionados."})]});const P=e.length>0&&a.length===e.length,S=Math.ceil(d/k),B=Y.useMemo(()=>em(g,S),[g,S]),U=$=>$&&r.find(T=>T.id===$)?.name||"—";return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden flex flex-col animate-in fade-in slide-in-from-bottom-2 duration-500",children:[t.jsx("div",{className:"overflow-x-auto no-scrollbar",children:t.jsxs(Qr,{children:[t.jsx(Yr,{children:t.jsxs(or,{className:"bg-slate-50/30 dark:bg-slate-800/20 hover:bg-slate-50/30 dark:hover:bg-slate-800/20 border-slate-100 dark:border-slate-800",children:[t.jsx(De,{className:le("w-[50px] pl-6",x==="compact"?"py-3":"py-5"),children:t.jsx(oa,{checked:P,onCheckedChange:$=>i(!!$),className:"data-[state=checked]:bg-primary data-[state=checked]:border-primary rounded-[6px]"})}),t.jsx(De,{className:le("pl-2 min-w-[280px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Producto",column:"name",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("min-w-[120px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Categoría",column:"externalCategory",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("min-w-[120px]",x==="compact"?"py-3":"py-5"),children:t.jsx(Ss,{label:"Precio",column:"price",currentSort:f,currentOrder:j,onSort:E})}),t.jsx(De,{className:le("font-black uppercase text-[10px] tracking-widest text-slate-400 min-w-[120px]",x==="compact"?"py-3":"py-5"),children:"Catálogo"}),t.jsx(De,{className:le("font-black uppercase text-[10px] tracking-widest text-slate-400 min-w-[100px]",x==="compact"?"py-3":"py-5"),children:"SKU"}),t.jsx(De,{className:"w-[80px] pr-6"})]})}),t.jsx(wn,{children:e.map($=>{const T=a.includes($.id),G=rm($.externalCategory),se=w?.has($.id)??!1;return t.jsxs(or,{className:le("group cursor-pointer hover:bg-slate-50/80 dark:hover:bg-slate-800/50 border-slate-50/50 dark:border-slate-800/50 transition-all duration-300",T&&"bg-primary/5 dark:bg-primary/10 hover:bg-primary/10",!$.isActive&&"opacity-50 grayscale",x==="compact"&&"h-12"),onClick:()=>o($),children:[t.jsx(ut,{className:le("pl-6",x==="compact"?"py-1.5":"py-4"),onClick:v=>v.stopPropagation(),children:t.jsx(oa,{checked:T,onCheckedChange:()=>n($.id),className:"data-[state=checked]:bg-primary rounded-[6px]"})}),t.jsx(ut,{className:le("pl-2",x==="compact"?"py-1.5":"py-4"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsx("div",{className:"relative group-hover:scale-105 transition-transform duration-300",children:t.jsx("div",{className:le("flex items-center justify-center rounded-2xl border-2 border-white dark:border-slate-800 shadow-md overflow-hidden bg-slate-50 dark:bg-slate-800",x==="compact"?"h-10 w-10":"h-12 w-12"),children:$.thumbnailUrl||$.media?.[0]?.thumbnailUrl?t.jsx("img",{src:$.thumbnailUrl||$.media?.[0]?.thumbnailUrl||"",alt:$.name,className:"h-full w-full object-cover"}):t.jsx(it,{className:"w-5 h-5 text-slate-300"})})}),t.jsxs("div",{className:"min-w-0 flex flex-col",children:[t.jsx("span",{className:le("text-slate-900 dark:text-white truncate leading-tight group-hover:text-primary transition-colors",x==="compact"?"text-[13px] font-semibold":"text-sm font-black"),children:$.name}),t.jsx("span",{className:le("text-slate-500 dark:text-slate-400 truncate block mt-0.5 max-w-[260px]",x==="compact"?"text-[10px]":"text-[11px]"),children:$.description}),se&&t.jsxs("span",{className:"flex items-center gap-1 mt-1 text-[10px] font-bold text-amber-600 dark:text-amber-400",children:[t.jsx(ct,{className:"w-3 h-3"}),"Sin indexar en búsqueda IA"]})]})]})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:$.externalCategory?t.jsxs(Ce,{variant:"outline",className:le("text-[11px] font-bold px-3 py-1 rounded-full border-none flex items-center gap-1.5 w-fit",G.bgClass,G.color),children:[t.jsx(ss,{className:"w-3 h-3"}),$.externalCategory]}):t.jsx("span",{className:"text-slate-300 text-xs",children:"—"})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-emerald-50 dark:bg-emerald-900/20 flex items-center justify-center",children:t.jsx(lr,{className:"w-3.5 h-3.5 text-emerald-500"})}),t.jsx("span",{className:"text-[13px] font-bold text-slate-700 dark:text-slate-300 font-mono",children:zr($.price,$.currency)})]})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:t.jsx("span",{className:"text-[12px] font-medium text-slate-500 dark:text-slate-400",children:U($.catalogId)})}),t.jsx(ut,{className:x==="compact"?"py-1.5":"py-4",children:$.externalId?t.jsx("span",{className:"text-[11px] font-mono text-slate-500 dark:text-slate-400 bg-slate-50 dark:bg-slate-800 px-2.5 py-1 rounded-lg",children:$.externalId}):t.jsx("span",{className:"text-slate-300 text-xs",children:"—"})}),t.jsx(ut,{className:le("text-right pr-6",x==="compact"?"py-1.5":"py-4"),onClick:v=>v.stopPropagation(),children:t.jsx("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity translate-x-4 group-hover:translate-x-0 duration-300",children:t.jsxs(pn,{children:[t.jsx(xn,{asChild:!0,children:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-slate-200/50",children:t.jsx(Pn,{className:"h-4 w-4 text-slate-400"})})}),t.jsxs(gn,{align:"end",className:"w-48 p-2 rounded-2xl shadow-2xl border-slate-100",children:[t.jsx(bn,{className:"text-[10px] uppercase font-black tracking-widest text-slate-400 p-2",children:"Opciones"}),t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>o($),className:"rounded-xl p-2.5 font-bold text-sm",children:[t.jsx(Fn,{className:"mr-3 h-4 w-4 text-slate-400"}),"Ver Detalles"]}),t.jsxs(It,{onClick:()=>l($),className:"rounded-xl p-2.5 font-bold text-sm",children:[t.jsx($s,{className:"mr-3 h-4 w-4 text-slate-400"}),"Editar"]}),t.jsx(Gr,{className:"bg-slate-50"}),p&&t.jsx(It,{onClick:()=>p($),className:le("rounded-xl p-2.5 font-bold text-sm",$.isActive?"text-amber-600 focus:text-amber-700 focus:bg-amber-50":"text-emerald-600 focus:text-emerald-700 focus:bg-emerald-50"),children:$.isActive?t.jsxs(t.Fragment,{children:[t.jsx(Cr,{className:"mr-3 h-4 w-4"}),"Desactivar"]}):t.jsxs(t.Fragment,{children:[t.jsx(Ls,{className:"mr-3 h-4 w-4"}),"Activar"]})}),se&&_&&t.jsxs(It,{onClick:()=>_($),className:"rounded-xl p-2.5 font-bold text-sm text-blue-600 focus:text-blue-700 focus:bg-blue-50",children:[t.jsx(hr,{className:"mr-3 h-4 w-4"}),"Reindexar IA"]}),t.jsxs(It,{onClick:()=>h($),className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50",children:[t.jsx(bt,{className:"mr-3 h-4 w-4"}),"Eliminar permanente"]})]})]})})})]},$.id)})})]})}),d>0&&t.jsxs("div",{className:"px-6 py-3 bg-slate-50/80 dark:bg-slate-900/50 border-t border-slate-100 dark:border-slate-800 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[11px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest",children:S>1?t.jsxs(t.Fragment,{children:["Página ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:g})," de ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:S})]}):t.jsxs(t.Fragment,{children:["Página ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:"1"})," de ",t.jsx("span",{className:"text-slate-600 dark:text-slate-200",children:"1"})]})}),t.jsx("span",{className:"w-px h-4 bg-slate-200 dark:bg-slate-700"}),t.jsx("span",{className:"text-[11px] font-medium text-slate-400 dark:text-slate-500",children:d<=k?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:d})," producto",d!==1?"s":""]}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:[(g-1)*k+1,"–",Math.min(g*k,d)]})," de ",t.jsx("span",{className:"font-bold text-slate-600 dark:text-slate-300",children:d})," productos"]})})]}),S>1&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ue,{variant:"outline",size:"sm",disabled:g<=1,onClick:()=>u(g-1),className:"h-8 px-3 rounded-xl font-bold text-[11px] text-slate-600 border-slate-200 bg-white hover:bg-slate-50 transition-all shadow-sm dark:bg-slate-800 dark:border-slate-700 dark:text-slate-300",children:"Anterior"}),t.jsx("div",{className:"flex items-center gap-0.5",children:B.map($=>t.jsx("button",{onClick:()=>u($),className:`h-8 w-8 rounded-lg text-[11px] font-bold transition-all ${$===g?"bg-primary text-white shadow-sm":"text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-800 dark:text-slate-400"}`,children:$},$))}),t.jsx(ue,{variant:"outline",size:"sm",disabled:g>=S,onClick:()=>u(g+1),className:"h-8 px-3 rounded-xl font-bold text-[11px] text-slate-600 border-slate-200 bg-white hover:bg-slate-50 transition-all shadow-sm dark:bg-slate-800 dark:border-slate-700 dark:text-slate-300",children:"Siguiente"})]})]})]})});mi.displayName="ProductsTable";function sm({product:e,catalogs:r,open:s,onOpenChange:a,onEdit:n,onDelete:i,onToggleActive:o}){const l=e&&r.find(S=>S.id===e.catalogId)?.name||"—",h=e?.media?.[0]??null,p=h?.thumbnailUrl||e?.thumbnailUrl||null,[_,w]=Y.useState(null),[g,d]=Y.useState(!1),[k,u]=Y.useState(!1);Y.useEffect(()=>{s||(w(null),d(!1),u(!1))},[s,e?.id]);const x=h?.gcsPath||e?.imageUrl||null,f=!!(p||x),j=Y.useCallback(async()=>{if(_){u(!0);return}if(x){d(!0);try{const S=await we.getSignedUrl(x);w(S),u(!0)}catch{}finally{d(!1)}}},[_,x]),E=S=>S?S<1024?`${S} B`:S<1024*1024?`${(S/1024).toFixed(1)} KB`:`${(S/(1024*1024)).toFixed(1)} MB`:"",P=S=>{try{return as(S,{style:"date-only"})}catch{return S}};return t.jsx(jr,{open:s,onOpenChange:a,children:t.jsx(kr,{className:"w-full sm:max-w-[480px] p-0 flex flex-col overflow-hidden",title:e?`Detalle: ${e.name}`:"Cargando...",description:"Detalle de producto",children:e?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800 shrink-0",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:le("w-14 h-14 rounded-2xl shrink-0 overflow-hidden border-2 shadow-md flex items-center justify-center bg-slate-50 dark:bg-slate-800",e.isActive===!1?"border-amber-200 dark:border-amber-800/50 opacity-60 grayscale":"border-white dark:border-slate-800"),children:p?t.jsx("img",{src:p,alt:e.name,className:"h-full w-full object-cover"}):t.jsx(it,{className:"w-6 h-6 text-slate-300"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Nr,{className:"text-lg font-black text-slate-900 dark:text-white truncate",children:e.name}),e.isActive===!1&&t.jsxs(Ce,{variant:"outline",className:"text-[10px] font-bold px-2 py-0.5 rounded-full border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400 shrink-0 flex items-center gap-1",children:[t.jsx(Cr,{className:"w-2.5 h-2.5"}),"Desactivado"]})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsxs(Ce,{variant:"outline",className:"text-[11px] font-bold px-2.5 py-0.5 rounded-full border-none bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 flex items-center gap-1",children:[t.jsx(lr,{className:"w-3 h-3"}),zr(e.price,e.currency)]}),e.externalCategory&&t.jsxs(Ce,{variant:"outline",className:"text-[11px] font-bold px-2.5 py-0.5 rounded-full border-none bg-violet-50 dark:bg-violet-900/20 text-violet-600 flex items-center gap-1",children:[t.jsx(ss,{className:"w-3 h-3"}),e.externalCategory]})]})]})]})}),e.isActive===!1&&t.jsxs("div",{className:"mx-4 mt-3 flex items-center gap-3 rounded-xl bg-amber-50 dark:bg-amber-950/40 border border-amber-200/60 dark:border-amber-800/40 px-4 py-3 shrink-0",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100 dark:bg-amber-900/50 flex items-center justify-center shrink-0",children:t.jsx(Cr,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-xs font-bold text-amber-700 dark:text-amber-300",children:"Producto desactivado"}),t.jsx("p",{className:"text-[11px] text-amber-600/70 dark:text-amber-400/60 mt-0.5",children:"No visible para la IA ni clientes"})]}),o&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>o(e),className:"shrink-0 h-8 rounded-lg text-xs font-bold border-amber-300 dark:border-amber-700 text-amber-700 dark:text-amber-300 hover:bg-amber-100 dark:hover:bg-amber-900/50 gap-1.5",children:[t.jsx(Ls,{className:"h-3.5 w-3.5"}),"Activar"]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"px-6 py-5 space-y-5",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(In,{className:"h-3.5 w-3.5"}),"SKU / ID Externo"]}),t.jsx("p",{className:"font-mono text-xs text-slate-700 dark:text-slate-300 truncate",children:e.externalId||"—"})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(dt,{className:"h-3.5 w-3.5"}),"Catálogo"]}),t.jsx("p",{className:"text-sm font-bold text-slate-700 dark:text-slate-300",children:l})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(lr,{className:"h-3.5 w-3.5"}),"Precio"]}),t.jsx("p",{className:"text-sm font-black text-emerald-600 font-mono",children:zr(e.price,e.currency)})]}),t.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-1",children:[t.jsx(Ki,{className:"h-3.5 w-3.5"}),"Creado"]}),t.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:P(e.createdAt)})]})]}),t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-2",children:[t.jsx(Wr,{className:"h-3.5 w-3.5"}),"Descripción (Clave para IA)"]}),t.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300 leading-relaxed whitespace-pre-wrap",children:e.description||"Sin descripción"})]}),t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-3",children:[t.jsx(At,{className:"h-3.5 w-3.5"}),"Imagen del producto"]}),f?t.jsx("div",{className:"space-y-2.5",children:k&&_?t.jsxs("div",{className:"rounded-xl overflow-hidden border border-slate-200 dark:border-slate-700 shadow-sm relative",children:[t.jsx("img",{src:_,alt:e.name,className:"w-full h-auto max-h-[400px] object-contain bg-white dark:bg-slate-900"}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-white/90 dark:bg-slate-900/90 backdrop-blur-sm border-t border-slate-100 dark:border-slate-800",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[h?.name&&t.jsx("span",{className:"text-[11px] font-medium text-slate-500 dark:text-slate-400 truncate max-w-[180px]",children:h.name}),h?.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded shrink-0",children:E(h.fileSizeBytes)}),h?.mimeType&&t.jsx("span",{className:"text-[10px] font-bold uppercase text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded shrink-0",children:h.mimeType.split("/")[1]||h.mimeType})]}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>u(!1),className:"h-6 w-6 rounded-md text-slate-400 hover:text-slate-600 shrink-0",children:t.jsx(Ft,{className:"h-3.5 w-3.5"})})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"rounded-xl overflow-hidden border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900",children:[t.jsx("div",{className:"flex items-center justify-center p-3",children:t.jsx("div",{className:"w-24 h-24 rounded-lg overflow-hidden shrink-0",children:p?t.jsx("img",{src:p,alt:e.name,className:"w-full h-full object-contain"}):t.jsx("div",{className:"w-full h-full flex items-center justify-center bg-slate-50 dark:bg-slate-800 rounded-lg",children:t.jsx(At,{className:"h-6 w-6 text-slate-300"})})})}),h&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-t border-slate-100 dark:border-slate-800",children:[h.name&&t.jsx("span",{className:"text-[11px] font-medium text-slate-500 dark:text-slate-400 truncate min-w-0",children:h.name}),t.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[h.fileSizeBytes&&t.jsx("span",{className:"text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded",children:E(h.fileSizeBytes)}),h.mimeType&&t.jsx("span",{className:"text-[10px] font-bold uppercase text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded",children:h.mimeType.split("/")[1]||h.mimeType})]})]})]}),x&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:j,disabled:g,className:"w-full h-8 text-xs rounded-lg gap-1.5",children:[g?t.jsx(be,{className:"h-3 w-3 animate-spin"}):t.jsx(Dn,{className:"h-3 w-3"}),g?"Cargando imagen...":"Ver imagen completa"]})]})}):t.jsxs("div",{className:"flex flex-col items-center justify-center py-6 gap-2",children:[t.jsx("div",{className:"w-11 h-11 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:t.jsx(At,{className:"h-5 w-5 text-slate-300 dark:text-slate-600"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-xs font-medium text-slate-400 dark:text-slate-500",children:"Sin imagen"}),t.jsx("p",{className:"text-[11px] text-slate-300 dark:text-slate-600 mt-0.5",children:"Edita el producto para agregar una"})]})]})]}),e.media&&e.media.length>0&&t.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800/50 rounded-xl",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-slate-400 mb-3",children:[t.jsx(Fr,{className:"h-3.5 w-3.5"}),"Recursos de venta",t.jsx("span",{className:"ml-auto text-[10px] font-bold text-slate-400 bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded-full",children:e.media.length})]}),t.jsx("div",{className:"space-y-2",children:e.media.map((S,B)=>{const U=S.type==="image"?t.jsx(At,{className:"h-3.5 w-3.5 text-blue-500"}):S.type==="audio"?t.jsx(En,{className:"h-3.5 w-3.5 text-amber-500"}):S.type==="video"?t.jsx(Cn,{className:"h-3.5 w-3.5 text-purple-500"}):t.jsx(zn,{className:"h-3.5 w-3.5 text-slate-400"}),$=S.type==="image"?"Imagen":S.type==="audio"?"Audio":S.type==="video"?"Video":"Documento";return t.jsxs("div",{className:"flex items-start gap-2.5 p-2.5 bg-white dark:bg-slate-900 rounded-lg border border-slate-100 dark:border-slate-800",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-50 dark:bg-slate-800 flex items-center justify-center shrink-0 mt-0.5",children:U}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-200 truncate",children:S.name}),t.jsx("span",{className:"text-[9px] font-bold uppercase px-1.5 py-0.5 rounded bg-slate-100 dark:bg-slate-800 text-slate-500 shrink-0",children:$}),S.fileSizeBytes&&t.jsx("span",{className:"text-[9px] font-bold text-slate-400 shrink-0",children:E(S.fileSizeBytes)})]}),S.description&&t.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-0.5 leading-relaxed",children:S.description}),S.salesContext&&t.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[t.jsx(_n,{className:"h-2.5 w-2.5 text-violet-400 shrink-0"}),t.jsx("span",{className:"text-[10px] text-violet-500 dark:text-violet-400 italic",children:S.salesContext})]})]})]},S.id||B)})})]})]})}),t.jsxs("div",{className:"px-6 py-4 border-t border-slate-100 dark:border-slate-800 flex items-center gap-2 shrink-0",children:[t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>{a(!1),n(e)},className:"rounded-xl flex-1",children:[t.jsx($s,{className:"h-4 w-4 mr-2"}),"Editar"]}),t.jsx(ue,{variant:"outline",size:"sm",onClick:()=>{a(!1),i(e)},className:"rounded-xl text-rose-600 hover:text-rose-700 hover:bg-rose-50",children:t.jsx(bt,{className:"h-4 w-4"})})]})]}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"px-6 pt-6 pb-4 border-b border-slate-100 dark:border-slate-800 shrink-0",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(at,{className:"w-14 h-14 rounded-xl shrink-0"}),t.jsxs("div",{className:"flex-1 space-y-2",children:[t.jsx(at,{className:"h-6 w-3/4"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(at,{className:"h-5 w-20 rounded-full"}),t.jsx(at,{className:"h-5 w-20 rounded-full"})]})]})]})}),t.jsxs("div",{className:"flex-1 px-6 py-5 space-y-5",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"}),t.jsx(at,{className:"h-20 rounded-xl"})]}),t.jsx(at,{className:"h-[200px] w-full rounded-xl"})]})]})})})}const Xa={query:"",maxPrice:"",category:"",limit:"10",scoreThreshold:.3,filtersOpen:!1,results:null,currentLimit:10,isLoadingMore:!1},qe=Ts(e=>({...Xa,setQuery:r=>e({query:r}),setMaxPrice:r=>e({maxPrice:r}),setCategory:r=>e({category:r}),setLimit:r=>e({limit:r,currentLimit:parseInt(r,10)||10}),setScoreThreshold:r=>e({scoreThreshold:r}),setFiltersOpen:r=>e({filtersOpen:r}),setResults:r=>e({results:r}),setCurrentLimit:r=>e({currentLimit:r}),setIsLoadingMore:r=>e({isLoadingMore:r}),appendResults:r=>e(s=>{if(!s.results)return{results:r};const a=new Set(s.results.results.map(i=>i.id)),n=r.results.filter(i=>!a.has(i.id));return{results:{...r,results:[...s.results.results,...n],metadata:{...r.metadata,total_results:s.results.results.length+n.length}}}}),reset:()=>e(Xa)}));function am(e){return e>=.7?{label:"Excelente",className:"bg-emerald-100 text-emerald-700 border-emerald-200",barColor:"bg-emerald-500"}:e>=.5?{label:"Bueno",className:"bg-blue-100 text-blue-700 border-blue-200",barColor:"bg-blue-500"}:e>=.3?{label:"Regular",className:"bg-amber-100 text-amber-700 border-amber-200",barColor:"bg-amber-500"}:{label:"Bajo",className:"bg-red-100 text-red-700 border-red-200",barColor:"bg-red-400"}}function Ja(e){return e.pg_exists?e.pg_active===!1?{label:"Inactivo en PG",className:"bg-amber-100 text-amber-700 border-amber-200"}:{label:"OK en PG",className:"bg-emerald-100 text-emerald-700 border-emerald-200"}:{label:"No existe en PG",className:"bg-red-100 text-red-700 border-red-200"}}function en(e){return e?{label:"Activo",className:"bg-emerald-100 text-emerald-700 border-emerald-200"}:{label:"Inactivo",className:"bg-amber-100 text-amber-700 border-amber-200"}}function nm(){const e=qe(v=>v.query),r=qe(v=>v.setQuery),s=qe(v=>v.maxPrice),a=qe(v=>v.setMaxPrice),n=qe(v=>v.category),i=qe(v=>v.setCategory),o=qe(v=>v.limit),l=qe(v=>v.setLimit),h=qe(v=>v.scoreThreshold),p=qe(v=>v.setScoreThreshold),_=qe(v=>v.filtersOpen),w=qe(v=>v.setFiltersOpen),g=qe(v=>v.results),d=qe(v=>v.setResults),k=qe(v=>v.currentLimit),u=qe(v=>v.setCurrentLimit),x=qe(v=>v.isLoadingMore),f=qe(v=>v.setIsLoadingMore),j=qe(v=>v.appendResults),[E,P]=Y.useState(!1),S=Wo(),B=S.isPending&&!x,U=()=>{if(!e.trim())return;const v=parseInt(o,10)||10;u(v),S.mutate({query:e.trim(),...s?{maxPrice:parseFloat(s)}:{},...n?{category:n}:{},limit:v,scoreThreshold:h},{onSuccess:R=>d(R)})},$=parseInt(o,10)||10,T=()=>{if(!e.trim())return;const v=k+$;u(v),f(!0),S.mutate({query:e.trim(),...s?{maxPrice:parseFloat(s)}:{},...n?{category:n}:{},limit:v,scoreThreshold:h},{onSuccess:R=>{j(R),f(!1)},onError:()=>f(!1)})},G=v=>{v.key==="Enter"&&U()},se=async()=>{P(!0);try{await we.reindexProducts(),ne.success("Reindex iniciado. Los productos se sincronizaran a Qdrant en segundo plano.")}catch(v){const R=v instanceof Error?v.message:"Error al iniciar reindex";ne.error(R)}finally{P(!1)}};return t.jsxs("div",{className:"space-y-5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-purple-600 flex items-center justify-center shadow-md shadow-violet-200 dark:shadow-violet-900/30",children:t.jsx(Fr,{className:"h-5 w-5 text-white"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-bold text-slate-900 dark:text-slate-100",children:"Sandbox de Busqueda IA"}),t.jsx("p",{className:"text-xs text-slate-500",children:"Experimenta con la busqueda vectorial que usa el agente"})]})]}),t.jsxs(Ce,{variant:"outline",className:"text-violet-600 border-violet-200 bg-violet-50 dark:bg-violet-900/20 dark:border-violet-800 dark:text-violet-400 text-xs gap-1.5",children:[t.jsx(Wt,{className:"h-3 w-3"}),"Misma busqueda del agente"]})]}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm p-5",children:[t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx(Sr,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 h-4.5 w-4.5 text-slate-400"}),t.jsx(st,{value:e,onChange:v=>r(v.target.value),onKeyDown:G,placeholder:"Busca como lo haria un cliente... (ej: camiseta azul barata, laptop gaming)",className:"h-12 pl-11 pr-4 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-2xl text-base",disabled:B}),B&&t.jsx(be,{className:"absolute right-3.5 top-1/2 -translate-y-1/2 h-4.5 w-4.5 text-violet-500 animate-spin"})]}),t.jsx(ue,{onClick:U,disabled:!e.trim()||B,className:"rounded-2xl px-6 h-12 bg-gradient-to-r from-violet-600 to-purple-600 hover:from-violet-700 hover:to-purple-700 shadow-md shadow-violet-200 dark:shadow-violet-900/30",children:B?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"})," Buscando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Sr,{className:"h-4 w-4 mr-2"})," Buscar"]})})]}),t.jsxs(Hi,{open:_,onOpenChange:w,children:[t.jsx(Qi,{asChild:!0,children:t.jsxs("button",{className:"flex items-center gap-1.5 mt-3 text-xs font-medium text-slate-500 hover:text-slate-700 dark:hover:text-slate-300 transition-colors",children:[t.jsx(Nn,{className:"h-3.5 w-3.5"}),"Filtros avanzados",t.jsx(Dr,{className:le("h-3.5 w-3.5 transition-transform duration-200",_&&"rotate-180")})]})}),t.jsx(Yi,{children:t.jsx("div",{className:"mt-3 pt-3 border-t border-slate-100 dark:border-slate-800",children:t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Precio maximo"}),t.jsx(st,{value:s,onChange:v=>a(v.target.value),onKeyDown:G,placeholder:"Sin limite",type:"number",step:"0.01",min:"0",className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",disabled:B})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Categoria"}),t.jsx(st,{value:n,onChange:v=>i(v.target.value),onKeyDown:G,placeholder:"Todas",className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",disabled:B})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Limite de resultados"}),t.jsxs(sr,{value:o,onValueChange:l,disabled:B,children:[t.jsx(ar,{className:"h-9 bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700 rounded-xl text-sm",children:t.jsx(nr,{})}),t.jsx(ir,{children:[5,10,20,50].map(v=>t.jsxs(kt,{value:String(v),children:[v," resultados"]},v))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-slate-500",children:"Umbral de similitud"}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(dn,{className:"h-3 w-3 text-slate-400 cursor-help"})}),t.jsx(rt,{side:"top",className:"max-w-[220px]",children:"Score minimo de similitud coseno para incluir un resultado. Menor = mas resultados (menos precisos). El agente usa 0.3 por defecto."})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Gi,{value:[h],onValueChange:([v])=>p(v),min:0,max:1,step:.05,className:"flex-1",disabled:B}),t.jsx("span",{className:"text-xs font-mono font-bold text-violet-600 dark:text-violet-400 w-8 text-right",children:h.toFixed(2)})]})]})]})})})]})]}),!g&&!S.isError&&t.jsx(im,{}),S.isError&&t.jsx(om,{message:S.error?.message||"Error desconocido"}),g&&g.results.length===0&&t.jsx(t.Fragment,{children:g.diagnostics?t.jsx(lm,{diagnostics:g.diagnostics,metadata:g.metadata,query:g.query,scoreThreshold:h,isReindexing:E,onReindex:se}):t.jsx(cm,{query:g.query,metadata:g.metadata})}),g&&g.results.length>0&&t.jsx(dm,{data:g,scoreThreshold:h,onLoadMore:T,isLoadingMore:x,canLoadMore:g.results.length>=k,loadMoreCount:$})]})}function im(){return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-dashed border-slate-200 dark:border-slate-700 p-14 text-center",children:[t.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-violet-100 to-purple-100 dark:from-violet-900/30 dark:to-purple-900/30 flex items-center justify-center mx-auto mb-5",children:t.jsx(Sr,{className:"h-7 w-7 text-violet-500"})}),t.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-2",children:"Prueba la busqueda vectorial"}),t.jsx("p",{className:"text-sm text-slate-500 max-w-lg mx-auto mb-5",children:"Escribe una consulta en lenguaje natural para ver exactamente lo que el agente de IA obtiene al buscar productos. Veras scores de relevancia, imagenes, estado en Qdrant y verificacion contra PostgreSQL."}),t.jsx("div",{className:"flex flex-wrap justify-center gap-2",children:["camiseta azul","laptop gaming barata","zapatos de cuero"].map(e=>t.jsxs("span",{className:"text-xs bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400 px-3 py-1.5 rounded-full",children:['"',e,'"']},e))})]})}function om({message:e}){return t.jsxs("div",{className:"bg-red-50 dark:bg-red-900/10 rounded-[20px] border border-red-200 dark:border-red-800 p-6 text-center",children:[t.jsx(ct,{className:"h-8 w-8 text-red-400 mx-auto mb-2"}),t.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 font-medium",children:"Error en la busqueda"}),t.jsx("p",{className:"text-xs text-red-500 mt-1 font-mono",children:e})]})}function lm({diagnostics:e,metadata:r,query:s,scoreThreshold:a,isReindexing:n,onReindex:i}){const o=!e.collection_exists,l=e.collection_exists&&e.vectors_count===0,h=e.collection_exists&&e.vectors_count>0,p=e.pg_products_count>0;return t.jsx("div",{className:"bg-amber-50 dark:bg-amber-900/10 rounded-[20px] border border-amber-200 dark:border-amber-800 shadow-sm p-6",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center shrink-0 mt-0.5",children:t.jsx(ct,{className:"h-5 w-5 text-amber-600"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h4",{className:"font-semibold text-amber-800 dark:text-amber-200 mb-1",children:o?"Coleccion vectorial no existe":l?"Coleccion vectorial vacia":`Sin resultados para "${s}"`}),t.jsxs("p",{className:"text-sm text-amber-700 dark:text-amber-300 mb-3",children:[o&&p&&t.jsxs(t.Fragment,{children:["La coleccion ",t.jsx("code",{className:"bg-amber-200/50 px-1.5 py-0.5 rounded text-xs font-mono",children:r.collection})," no existe en Qdrant, pero tienes ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PostgreSQL. Los productos necesitan ser indexados."]}),o&&!p&&t.jsx(t.Fragment,{children:"La coleccion no existe y no hay productos en PostgreSQL. Crea productos primero."}),l&&p&&t.jsxs(t.Fragment,{children:["La coleccion ",t.jsx("code",{className:"bg-amber-200/50 px-1.5 py-0.5 rounded text-xs font-mono",children:r.collection})," existe pero tiene ",t.jsx("strong",{children:"0 vectores"}),". Tienes ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PostgreSQL que no han sido sincronizados."]}),l&&!p&&t.jsx(t.Fragment,{children:"La coleccion esta vacia y no hay productos en PostgreSQL. Crea productos primero."}),h&&t.jsxs(t.Fragment,{children:["La coleccion tiene ",t.jsxs("strong",{children:[e.vectors_count," vectores"]})," y ",t.jsxs("strong",{children:[e.pg_products_count," productos"]})," en PG, pero ninguno supero el umbral de similitud (",a.toFixed(2),') para "',s,'". Prueba bajando el umbral o con otra consulta.']})]}),e.raw_top_scores&&e.raw_top_scores.length>0&&t.jsxs("div",{className:"mb-3 bg-amber-100/50 dark:bg-amber-900/20 rounded-xl p-4",children:[t.jsx("p",{className:"text-xs font-semibold text-amber-700 dark:text-amber-300 mb-2.5",children:"Top scores reales (sin umbral, sin filtros):"}),t.jsx("div",{className:"space-y-2",children:e.raw_top_scores.map((_,w)=>t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"font-mono text-xs font-bold text-amber-700 dark:text-amber-300 w-14 shrink-0",children:_.score.toFixed(4)}),t.jsx("div",{className:"h-2 flex-1 max-w-40 bg-amber-200 dark:bg-amber-800 rounded-full overflow-hidden",children:t.jsx("div",{className:le("h-full rounded-full transition-all",_.score>=a?"bg-emerald-500":"bg-red-400"),style:{width:`${Math.min(_.score*100,100)}%`}})}),t.jsx("span",{className:"text-xs text-amber-600 dark:text-amber-400 truncate flex-1",children:_.product_name}),_.score<a&&t.jsx("span",{className:"text-[10px] text-red-500 font-medium shrink-0",children:"< umbral"})]},w))})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[{icon:Ot,text:e.collection_exists?"Coleccion existe":"Coleccion no existe"},{icon:it,text:`${e.vectors_count} vectores`},{icon:Ot,text:`${e.pg_products_count} en PG`},{icon:Pr,text:`${r.search_time_ms}ms`}].map((_,w)=>t.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-amber-600 dark:text-amber-400",children:[t.jsx(_.icon,{className:"h-3 w-3"})," ",_.text]},w))}),p&&t.jsx(ue,{onClick:i,disabled:n,variant:"outline",size:"sm",className:"rounded-full border-amber-300 text-amber-700 hover:bg-amber-100 hover:text-amber-800",children:n?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin mr-2"})," Reindexando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(hr,{className:"h-3.5 w-3.5 mr-2"})," Reindexar productos a Qdrant"]})})]})]})})}function cm({query:e,metadata:r}){return t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm p-10 text-center",children:[t.jsx(it,{className:"h-10 w-10 text-slate-300 mx-auto mb-3"}),t.jsx("h4",{className:"font-medium text-slate-700 dark:text-slate-300 mb-1",children:"Sin resultados"}),t.jsxs("p",{className:"text-sm text-slate-500",children:['No se encontraron productos para "',e,'"']}),t.jsxs("div",{className:"flex items-center justify-center gap-4 mt-3 text-xs text-slate-400",children:[t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Pr,{className:"h-3 w-3"})," ",r.search_time_ms,"ms"]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Ot,{className:"h-3 w-3"})," ",r.collection]})]})]})}function dm({data:e,scoreThreshold:r,onLoadMore:s,isLoadingMore:a,canLoadMore:n,loadMoreCount:i}){const{results:o,metadata:l}=e,h=o.length>0?o.reduce((g,d)=>g+d.score,0)/o.length:0,p=Object.keys(l.filters_applied).length,_=[];l.embedding_ms!=null&&_.push(`Embedding: ${l.embedding_ms}ms`),l.qdrant_ms!=null&&_.push(`Qdrant: ${l.qdrant_ms}ms`),l.pg_ms!=null&&_.push(`PG check: ${l.pg_ms}ms`),_.push(`Total: ${l.search_time_ms}ms`);const w=_.join(" · ");return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[t.jsx(gr,{icon:Ni,label:"Resultados",value:String(o.length),accent:"violet"}),t.jsx(gr,{icon:Pr,label:"Tiempo",value:`${l.search_time_ms}ms`,accent:"blue",title:w}),t.jsx(gr,{icon:Wt,label:"Score promedio",value:h.toFixed(3),accent:h>=.5?"emerald":h>=.3?"amber":"red"}),t.jsx(gr,{icon:Ot,label:"Coleccion",value:l.collection.replace("products_v2_","").substring(0,8)+"...",accent:"slate",title:l.collection,copyValue:l.collection}),t.jsx(gr,{icon:Nn,label:"Umbral",value:r.toFixed(2),accent:"purple",extra:p>0?`+${p} filtros`:void 0})]}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-slate-100 dark:border-slate-800 bg-slate-50/80 dark:bg-slate-800/50 text-[10px] font-semibold uppercase tracking-wider text-slate-400",children:[t.jsx("span",{className:"w-5 text-right",children:"#"}),t.jsx("span",{className:"w-8"}),t.jsx("span",{className:"flex-1",children:"Producto"}),t.jsx("span",{className:"shrink-0 w-24 text-right",children:"Precio"}),t.jsx("span",{className:"shrink-0 w-28 text-right",children:"Score"}),t.jsx("span",{className:"shrink-0 w-9 text-center",children:"Estado"}),t.jsx("span",{className:"w-3.5"})]}),t.jsx("div",{className:"divide-y divide-slate-50 dark:divide-slate-800/50",children:o.map((g,d)=>t.jsx(mm,{result:g,rank:d+1},g.id))}),n&&t.jsx("div",{className:"flex justify-center py-3 border-t border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30",children:t.jsx(ue,{variant:"ghost",size:"sm",onClick:s,disabled:a,className:"rounded-full px-5 text-xs text-violet-600 hover:text-violet-700 hover:bg-violet-50 dark:text-violet-400 dark:hover:bg-violet-900/20",children:a?t.jsxs(t.Fragment,{children:[t.jsx(be,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Cargando..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Dr,{className:"h-3.5 w-3.5 mr-1.5"})," Cargar mas resultados (+",i,")"]})})})]})]})}function gr({icon:e,label:r,value:s,accent:a,title:n,extra:i,copyValue:o}){const[l,h]=Y.useState(!1),p={violet:"bg-violet-50 dark:bg-violet-900/20 text-violet-600 dark:text-violet-400",blue:"bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400",emerald:"bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400",amber:"bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400",red:"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400",slate:"bg-slate-50 dark:bg-slate-800 text-slate-600 dark:text-slate-400",purple:"bg-purple-50 dark:bg-purple-900/20 text-purple-600 dark:text-purple-400"},_=()=>{o&&(navigator.clipboard.writeText(o),h(!0),setTimeout(()=>h(!1),1500))};return t.jsxs("div",{className:le("flex items-center gap-2.5 rounded-xl px-3.5 py-2.5 border border-transparent",p[a]||p.slate,o&&"cursor-pointer hover:opacity-80 active:scale-[0.98] transition-all"),title:n||(o?"Clic para copiar":void 0),onClick:o?_:void 0,children:[t.jsx(e,{className:"h-4 w-4 shrink-0 opacity-70"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider opacity-60",children:r}),t.jsxs("p",{className:"text-sm font-bold truncate",children:[l?"Copiado!":s,!l&&i&&t.jsx("span",{className:"text-[10px] font-normal opacity-60 ml-1",children:i})]})]})]})}function um(e){const r=e.pg_metadata?.media;if(r&&r.length>0){const a=r[0];if(a.type==="video"||a.mimeType?.startsWith("video/"))return"video";if(a.type==="document"||a.mimeType?.startsWith("application/"))return"document";if(a.type==="image"||a.mimeType?.startsWith("image/"))return"image"}const s=e.qdrant_metadata?.product_image_name?.toLowerCase();return s?/\.(mp4|webm|mov|avi|3gp)$/i.test(s)?"video":/\.(pdf|docx?|xlsx?|csv|txt|epub)$/i.test(s)?"document":"image":e.product_thumbnail||e.product_image?"image":"none"}function hm(e){switch(e){case"video":return Zi;case"document":return Wr;case"image":return At;default:return it}}function mm({result:e,rank:r}){const s=am(e.score),[a,n]=Y.useState(!1),[i,o]=Y.useState(!1),[l,h]=Y.useState(!1),[p,_]=Y.useState(!1),[w,g]=Y.useState(null),[d,k]=Y.useState(!1),u=e.pg_exists&&e.pg_active!==!1,x=e.is_active,f=um(e),j=hm(f),E=e.product_thumbnail_url,P=!!E&&!l,S=!!e.product_image,B=Y.useCallback(async U=>{if(U.stopPropagation(),!e.product_image){ne.error("Este producto no tiene imagen original (product_image es null)");return}if(w){_(!0);return}if(!e.product_image.startsWith("gs://")){g(e.product_image),_(!0);return}k(!0);try{const $=await Xi.getSignedUrl(e.product_image);if(!$){ne.error("La firma devolvio null. Path: "+e.product_image);return}g($),_(!0)}catch($){const T=$ instanceof Error?$.message:"Error desconocido";ne.error("Error al firmar imagen: "+T),console.warn("[handleViewFullImage] Failed to sign",e.product_image,$)}finally{k(!1)}},[e.product_image,w]);return t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>n(!a),className:le("w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors","hover:bg-slate-50 dark:hover:bg-slate-800/50",a&&"bg-slate-50/80 dark:bg-slate-800/30"),children:[t.jsx("span",{className:"text-[11px] font-mono text-slate-400 w-5 text-right shrink-0",children:r}),t.jsx("div",{className:"shrink-0",children:P?t.jsx("img",{src:E,alt:e.product_name,className:"w-8 h-8 rounded-lg object-cover border border-slate-200 dark:border-slate-700",onError:()=>h(!0)}):t.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-100 dark:bg-slate-800 flex items-center justify-center border border-slate-200 dark:border-slate-700",children:t.jsx(j,{className:"h-3.5 w-3.5 text-slate-300"})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100 truncate",children:e.product_name}),e.product_sku&&t.jsx("p",{className:"text-[10px] font-mono text-slate-400 truncate",children:e.product_sku})]}),t.jsx("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-300 shrink-0 w-24 text-right tabular-nums",children:zr(e.product_price,e.product_currency)}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 w-28 justify-end",children:[t.jsx("div",{className:"h-1.5 w-10 bg-slate-100 dark:bg-slate-800 rounded-full overflow-hidden",children:t.jsx("div",{className:le("h-full rounded-full",s.barColor),style:{width:`${Math.min(e.score*100,100)}%`}})}),t.jsx("span",{className:"text-[11px] font-mono font-bold text-slate-600 dark:text-slate-400 w-12 text-right",children:e.score.toFixed(3)})]}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 w-9 justify-center",children:[t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{className:le("w-2 h-2 rounded-full",u?"bg-emerald-500":e.pg_exists?"bg-amber-400":"bg-red-400")})}),t.jsxs(rt,{side:"top",className:"text-xs",children:["PG: ",e.pg_exists?e.pg_active===!1?"Inactivo":"OK":"No existe"]})]}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{className:le("w-2 h-2 rounded-full",x?"bg-emerald-500":"bg-amber-400")})}),t.jsxs(rt,{side:"top",className:"text-xs",children:["Qdrant: ",x?"Activo":"Inactivo"]})]})]}),t.jsx(Dr,{className:le("h-3.5 w-3.5 text-slate-400 shrink-0 transition-transform duration-200",a&&"rotate-180")})]}),a&&t.jsxs("div",{className:"px-4 pb-4 pt-2 bg-slate-50/50 dark:bg-slate-800/20",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[t.jsxs(Ce,{variant:"outline",className:le("text-[10px] px-2 py-0",en(e.is_active).className),children:["Qdrant: ",en(e.is_active).label]}),t.jsx(Ce,{variant:"outline",className:le("text-[10px] px-2 py-0",Ja(e).className),children:Ja(e).label}),t.jsxs(Ce,{className:le("text-[10px] px-2 py-0",s.className),children:["Score: ",s.label]}),e.catalog_id&&t.jsxs("span",{className:"text-[10px] text-slate-400",title:e.catalog_id,children:["Cat: ",e.catalog_id.substring(0,8),"..."]}),!e.pg_exists&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ct,{className:"h-3.5 w-3.5 text-red-400 cursor-help"})}),t.jsx(rt,{children:"Este producto existe en Qdrant pero no en PostgreSQL. Puede ser un producto eliminado que no se sincronizo."})]}),e.pg_exists&&e.pg_active!==e.is_active&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ct,{className:"h-3.5 w-3.5 text-amber-400 cursor-help"})}),t.jsxs(rt,{children:["Discrepancia: Qdrant dice ",e.is_active?"activo":"inactivo"," pero PG dice ",e.pg_active?"activo":"inactivo",". Necesita resincronizar."]})]}),t.jsx("span",{className:"flex-1"}),t.jsxs("button",{onClick:U=>{U.stopPropagation(),o(!i)},className:"flex items-center gap-1 text-[11px] text-slate-400 hover:text-slate-600 dark:hover:text-slate-300 transition-colors",children:[i?t.jsx(Cr,{className:"h-3 w-3"}):t.jsx(Fn,{className:"h-3 w-3"}),i?"Ocultar contenido":"Ver contenido vectorial"]}),S&&t.jsxs("button",{onClick:B,disabled:d,className:"flex items-center gap-1 text-[11px] text-violet-500 hover:text-violet-700 dark:hover:text-violet-300 transition-colors disabled:opacity-50",children:[d?t.jsx(be,{className:"h-3 w-3 animate-spin"}):t.jsx(Dn,{className:"h-3 w-3"}),"Ver imagen completa"]})]}),i&&t.jsx("p",{className:"mb-3 text-xs text-slate-500 bg-slate-100 dark:bg-slate-800 rounded-lg p-3 font-mono leading-relaxed border border-slate-200 dark:border-slate-700",children:e.content}),t.jsx(fm,{result:e})]}),p&&t.jsx(nn,{open:p,onOpenChange:_,children:t.jsxs(on,{className:"sm:max-w-3xl p-2 bg-black/95 border-none",children:[t.jsx(ln,{className:"sr-only",children:e.product_name}),t.jsx(cn,{className:"sr-only",children:"Imagen completa del producto"}),w?t.jsx("img",{src:w,alt:e.product_name,className:"w-full h-auto max-h-[80vh] object-contain rounded-lg"}):t.jsx("div",{className:"flex items-center justify-center h-48",children:t.jsx(be,{className:"h-8 w-8 text-white animate-spin"})}),t.jsxs("p",{className:"text-center text-xs text-slate-400 mt-2",children:[e.product_name,t.jsx("span",{className:"text-slate-600 ml-2 font-mono text-[10px]",children:"(firmada on-demand)"})]})]})})]})}function fm({result:e}){const r=e.pg_metadata,s=e.qdrant_metadata;return t.jsx("div",{className:"bg-slate-50 dark:bg-slate-800/50 rounded-xl border border-slate-100 dark:border-slate-700 overflow-hidden",children:t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-slate-200 dark:divide-slate-700",children:[t.jsxs("div",{className:"p-4",children:[t.jsxs("h5",{className:"text-[11px] font-semibold uppercase tracking-wider text-blue-600 dark:text-blue-400 mb-3 flex items-center gap-1.5",children:[t.jsx(Ot,{className:"h-3 w-3"})," PostgreSQL"]}),r?t.jsxs("div",{className:"space-y-2.5",children:[r.description&&t.jsx(Le,{label:"Descripcion",value:r.description,multiline:!0}),r.external_category&&t.jsx(Le,{label:"Categoria",children:t.jsx(Ce,{variant:"outline",className:"text-[10px] bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 border-blue-200",children:r.external_category})}),t.jsx(Le,{label:"Metadata (jsonb)",children:Object.keys(r.metadata).length===0?t.jsx("span",{className:"text-xs text-slate-400 italic",children:"Vacio"}):t.jsx("div",{className:"flex flex-wrap gap-1",children:Object.entries(r.metadata).map(([a,n])=>t.jsxs("span",{className:"text-[10px] bg-slate-200 dark:bg-slate-700 text-slate-600 dark:text-slate-300 px-2 py-0.5 rounded-md font-mono",title:typeof n=="object"?JSON.stringify(n):String(n),children:[a,": ",typeof n=="object"?JSON.stringify(n):String(n)]},a))})}),t.jsx(Le,{label:`Media (${r.media.length})`,children:r.media.length===0?t.jsx("span",{className:"text-xs text-slate-400 italic",children:"Sin archivos"}):t.jsx("div",{className:"space-y-1",children:r.media.map((a,n)=>t.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-slate-500",children:[t.jsx("span",{className:"bg-slate-200 dark:bg-slate-700 px-1.5 py-0.5 rounded text-slate-600 dark:text-slate-400 font-mono uppercase",children:a.type||"file"}),t.jsx("span",{className:"truncate",children:a.name||"Sin nombre"}),a.fileSizeBytes&&t.jsxs("span",{className:"text-slate-400 shrink-0",children:[(a.fileSizeBytes/1024).toFixed(0),"KB"]})]},n))})}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"Creado",value:tn(r.created_at)}),t.jsx(Le,{label:"Actualizado",value:tn(r.updated_at)})]}),(r.created_by||r.updated_by)&&t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.created_by&&t.jsx(Le,{label:"Creado por",value:r.created_by}),r.updated_by&&t.jsx(Le,{label:"Editado por",value:r.updated_by})]})]}):t.jsx("p",{className:"text-xs text-slate-400 italic",children:"Producto no existe en PostgreSQL"})]}),t.jsxs("div",{className:"p-4",children:[t.jsxs("h5",{className:"text-[11px] font-semibold uppercase tracking-wider text-purple-600 dark:text-purple-400 mb-3 flex items-center gap-1.5",children:[t.jsx(Wt,{className:"h-3 w-3"})," Qdrant Payload",t.jsx("span",{className:"font-normal normal-case tracking-normal text-slate-400 ml-1",children:"(lo que ve el agente)"})]}),t.jsxs("div",{className:"space-y-2.5",children:[t.jsx(Le,{label:"id",value:e.id,mono:!0}),t.jsx(Le,{label:"source_id",value:s.source_id,mono:!0}),t.jsx(Le,{label:"type",value:s.type}),t.jsx(Le,{label:"organization_id",value:s.organization_id,mono:!0}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsx("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:"Datos del producto"}),t.jsx(Le,{label:"product_name",value:e.product_name}),t.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"product_price",value:String(e.product_price),highlight:!0}),t.jsx(Le,{label:"product_currency",value:e.product_currency,highlight:!0})]}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_sku",value:e.product_sku||"—",mono:!0,highlight:!0})}),t.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2",children:[t.jsx(Le,{label:"is_active",value:String(e.is_active)}),t.jsx(Le,{label:"catalog_id",value:e.catalog_id||"—",mono:!0})]})]}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsx("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:"Media (paths raw)"}),t.jsx(Le,{label:"product_image",value:e.product_image||"—",mono:!0}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_thumbnail",value:e.product_thumbnail||"—",mono:!0})}),t.jsx("div",{className:"mt-1.5",children:t.jsx(Le,{label:"product_image_name",value:s.product_image_name||"—"})})]}),t.jsxs("div",{className:"pt-2 mt-2 border-t border-slate-200 dark:border-slate-600",children:[t.jsxs("p",{className:"text-[10px] font-medium text-slate-400 mb-1.5",children:["content ",t.jsx("span",{className:"normal-case",children:"(texto embebido)"})]}),t.jsx("p",{className:"text-xs text-slate-500 bg-purple-50 dark:bg-purple-900/20 rounded-lg p-2.5 font-mono leading-relaxed border border-purple-100 dark:border-purple-800 line-clamp-4",children:e.content})]})]})]})]})})}function Le({label:e,value:r,mono:s,multiline:a,highlight:n,children:i}){const[o,l]=Y.useState(!1),h=()=>{!s||!r||(navigator.clipboard.writeText(r),l(!0),setTimeout(()=>l(!1),1200))};return t.jsxs("div",{className:le(n&&"bg-violet-50 dark:bg-violet-900/20 rounded-lg px-2 py-1.5 ring-1 ring-violet-200/70 dark:ring-violet-700/50"),children:[t.jsx("p",{className:le("text-[10px] font-medium uppercase tracking-wider mb-0.5",n?"text-violet-500 dark:text-violet-400":"text-slate-400"),children:e}),i||t.jsx("p",{className:le("text-xs",n?"text-violet-700 dark:text-violet-200 font-semibold":"text-slate-600 dark:text-slate-300",s&&"font-mono text-[11px] break-all cursor-pointer hover:text-violet-600 dark:hover:text-violet-400 transition-colors",a&&"line-clamp-3"),title:s?o?"Copiado!":"Clic para copiar":r,onClick:s?h:void 0,children:o?t.jsx("span",{className:"text-violet-600 dark:text-violet-400",children:"Copiado!"}):r})]})}function tn(e){if(!e)return"—";try{return new Date(e).toLocaleDateString("es",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}const rn={catalogId:"",search:"",category:""},Zt=Ts(e=>({filters:rn,page:1,limit:50,sortBy:"createdAt",sortOrder:"DESC",selectedIds:[],density:"comfortable",selectedProductId:null,setFilters:r=>e(s=>({filters:{...s.filters,...r},page:1,selectedIds:[]})),setPage:r=>e({page:r,selectedIds:[]}),resetFilters:()=>e({filters:rn,page:1,selectedIds:[],sortBy:"createdAt",sortOrder:"DESC"}),setSorting:r=>e(s=>({sortBy:r,sortOrder:s.sortBy===r&&s.sortOrder==="DESC"?"ASC":"DESC",page:1})),toggleSelection:r=>e(s=>({selectedIds:s.selectedIds.includes(r)?s.selectedIds.filter(a=>a!==r):[...s.selectedIds,r]})),selectAll:r=>e({selectedIds:r}),clearSelection:()=>e({selectedIds:[]}),setDensity:r=>e({density:r}),setSelectedProduct:r=>e({selectedProductId:r})})),pm=()=>Zt($t(e=>e.filters)),xm=()=>Zt($t(e=>({page:e.page,limit:e.limit}))),gm=()=>Zt($t(e=>({sortBy:e.sortBy,sortOrder:e.sortOrder}))),bm=()=>Zt($t(e=>({selectedIds:e.selectedIds,toggleSelection:e.toggleSelection,selectAll:e.selectAll,clearSelection:e.clearSelection}))),vm=()=>Zt($t(e=>({setFilters:e.setFilters,setPage:e.setPage,resetFilters:e.resetFilters,setSorting:e.setSorting,setDensity:e.setDensity,setSelectedProduct:e.setSelectedProduct,clearSelection:e.clearSelection}))),sn={status:"idle",progress:0,synced:0,errors:0,total:0,jobId:null,message:null},ym=Ts(e=>({...sn,startReindex:r=>e({status:"processing",progress:0,synced:0,errors:0,total:0,jobId:r,message:"Iniciando reindex..."}),updateProgress:r=>e(s=>({...s,...r})),reset:()=>e(sn)}));function wm({status:e,isLoading:r,onReindex:s,isReindexing:a,canReindex:n}){const[i,o]=Y.useState(!1),[l,h]=Y.useState(!1),[p,_]=Y.useState(1),w=Mo(),{data:g,isLoading:d}=Vo(p,l&&(e?.orphanedCount??0)>0);if(r||!e||e.orphanedCount===0&&e.missingCount===0)return null;const k=async()=>{o(!1),h(!1),await w.mutateAsync()},u=e.orphanedCount,x=u!==1,f=e.missingCount,j=f!==1,E=g?Math.ceil(g.total/g.limit):1;return t.jsxs("div",{className:"flex flex-col gap-2",children:[u>0&&t.jsxs("div",{className:"rounded-2xl border border-amber-200 bg-amber-50/80 dark:bg-amber-950/20 dark:border-amber-800/50 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center shrink-0",children:t.jsx(ct,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("p",{className:"text-sm font-bold text-amber-800 dark:text-amber-300",children:[u," producto",x?"s":""," obsoleto",x?"s":""," en el índice de búsqueda IA"]}),t.jsxs("p",{className:"text-xs text-amber-600/80 dark:text-amber-400/70 mt-0.5",children:["El agente IA puede referenciar producto",x?"s":""," que ya no existe",x?"n":"","."]})]}),t.jsxs(ue,{variant:"ghost",size:"sm",onClick:()=>h(!l),className:"shrink-0 rounded-xl text-amber-700 hover:bg-amber-100 dark:text-amber-400 dark:hover:bg-amber-900/30",children:[l?t.jsx(yn,{className:"mr-1.5 h-3.5 w-3.5"}):t.jsx(Dr,{className:"mr-1.5 h-3.5 w-3.5"}),"Ver detalles"]}),t.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>o(!0),disabled:w.isPending,className:"shrink-0 rounded-xl border-amber-300 text-amber-700 hover:bg-amber-100 dark:border-amber-700 dark:text-amber-400 dark:hover:bg-amber-900/30",children:[w.isPending?t.jsx(be,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):t.jsx(bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Limpiar todo"]})]}),l&&t.jsx("div",{className:"border-t border-amber-200/60 dark:border-amber-800/40",children:d?t.jsxs("div",{className:"flex items-center justify-center py-6 gap-2 text-amber-600",children:[t.jsx(be,{className:"w-4 h-4 animate-spin"}),t.jsx("span",{className:"text-xs font-medium",children:"Cargando registros..."})]}):g&&g.items.length>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"divide-y divide-amber-100 dark:divide-amber-900/30",children:g.items.map(P=>t.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 hover:bg-amber-100/50 dark:hover:bg-amber-900/20 transition-colors",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100/80 dark:bg-amber-900/40 flex items-center justify-center shrink-0",children:t.jsx(it,{className:"w-3.5 h-3.5 text-amber-500"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-xs font-bold text-amber-800 dark:text-amber-300 truncate",children:P.payload.product_name||"Sin nombre"}),t.jsxs("p",{className:"text-[10px] text-amber-600/70 dark:text-amber-400/60 font-mono truncate",children:["ID: ",P.id]})]}),P.payload.product_price!=null&&t.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-bold text-amber-700 dark:text-amber-300 shrink-0",children:[t.jsx(lr,{className:"w-3 h-3"}),P.payload.product_currency," ",P.payload.product_price]}),P.payload.product_sku&&t.jsx("span",{className:"text-[10px] font-mono text-amber-600/70 dark:text-amber-400/60 bg-amber-100 dark:bg-amber-900/40 px-2 py-0.5 rounded-md shrink-0",children:P.payload.product_sku})]},P.id))}),E>1&&t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-t border-amber-200/60 dark:border-amber-800/40",children:[t.jsxs("span",{className:"text-[10px] font-bold text-amber-600/70 dark:text-amber-400/60 uppercase tracking-wider",children:["Página ",p," de ",E," · ",g.total," registros"]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(ue,{variant:"ghost",size:"sm",disabled:p<=1,onClick:()=>_(p-1),className:"h-7 px-2.5 text-xs rounded-lg text-amber-700 hover:bg-amber-100 dark:text-amber-400",children:"Anterior"}),t.jsx(ue,{variant:"ghost",size:"sm",disabled:p>=E,onClick:()=>_(p+1),className:"h-7 px-2.5 text-xs rounded-lg text-amber-700 hover:bg-amber-100 dark:text-amber-400",children:"Siguiente"})]})]})]}):t.jsx("p",{className:"text-center py-4 text-xs text-amber-600/70",children:"No se encontraron registros"})})]}),f>0&&t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-2xl border border-blue-200 bg-blue-50/80 dark:bg-blue-950/20 dark:border-blue-800/50",children:[t.jsx("div",{className:"w-9 h-9 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center shrink-0",children:t.jsx(Sr,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("p",{className:"text-sm font-bold text-blue-800 dark:text-blue-300",children:[f," producto",j?"s":""," sin indexar en la búsqueda IA"]}),t.jsxs("p",{className:"text-xs text-blue-600/80 dark:text-blue-400/70 mt-0.5",children:["Marcado",j?"s":""," en la tabla con",t.jsx(ct,{className:"w-3 h-3 inline mx-1 text-amber-500"}),"— puedes sincronizar individual o reindexar todo."]})]}),n&&t.jsxs(ue,{variant:"outline",size:"sm",onClick:s,disabled:a,className:"shrink-0 rounded-xl border-blue-300 text-blue-700 hover:bg-blue-100 dark:border-blue-700 dark:text-blue-400 dark:hover:bg-blue-900/30",children:[a?t.jsx(be,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):t.jsx(hr,{className:"mr-1.5 h-3.5 w-3.5"}),"Reindexar"]})]}),t.jsx(Kt,{open:i,onOpenChange:o,children:t.jsxs(Gt,{children:[t.jsxs(Ht,{children:[t.jsx(Qt,{children:"Limpiar índice de búsqueda IA"}),t.jsxs(Yt,{children:["Se eliminarán ",t.jsxs("strong",{children:[u," registro",x?"s":""," obsoleto",x?"s":""]})," del índice de búsqueda IA que ya no corresponden a productos existentes. Tus productos actuales no se verán afectados."]})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{children:"Cancelar"}),t.jsxs(er,{onClick:k,children:["Limpiar ",u," registro",x?"s":""]})]})]})})]})}const Et=({icon:e,label:r,value:s,bgClass:a})=>t.jsxs("div",{className:"bg-white dark:bg-slate-900 p-4 rounded-[20px] border border-slate-100 dark:border-slate-800 shadow-sm flex items-center gap-4 transition-all duration-300 group",children:[t.jsx("div",{className:le("w-11 h-11 rounded-xl flex items-center justify-center shrink-0 shadow-inner group-hover:scale-110 transition-transform duration-300",a),children:e}),t.jsxs("div",{children:[s!==void 0?t.jsx("p",{className:"text-2xl font-black text-slate-900 dark:text-white leading-none tracking-tighter",children:s}):t.jsx("p",{className:"text-sm font-black text-slate-400 leading-none",children:"—"}),t.jsx("p",{className:"text-[9px] uppercase font-black text-slate-400 mt-1 tracking-widest",children:r})]})]});function x0(){const{currentOrganization:e}=Os(),r=Ke(),[s,a]=Y.useState("products"),n=pm(),{page:i,limit:o}=xm(),{sortBy:l,sortOrder:h}=gm(),{selectedIds:p,toggleSelection:_,selectAll:w,clearSelection:g}=bm(),{setFilters:d,setPage:k,resetFilters:u,setSorting:x,setDensity:f,setSelectedProduct:j}=vm(),E=Zt(W=>W.density),P=Zt(W=>W.selectedProductId),[S,B]=Y.useState(n.search),U=eo(S,400);Y.useEffect(()=>{U!==n.search&&d({search:U})},[U,n.search,d]);const{data:$,isLoading:T,isFetching:G}=Io({search:n.search||void 0,catalogId:n.catalogId||void 0,page:i,limit:o,withDeleted:!1}),{data:se=[],isLoading:v}=Ao(),R=T||v,m=$?.data??[],V=n.category?m.filter(W=>W.externalCategory===n.category):m;$?.totalPages;const ie=n.category?V.length:$?.total??0,q=Y.useMemo(()=>{const W=new Set;return V.forEach(Ne=>{Ne.externalCategory&&W.add(Ne.externalCategory)}),Array.from(W).sort()},[V]),ce=Y.useMemo(()=>V.find(W=>W.id===P)??null,[V,P]),F=Po(),ee=Fo(),O=Do(),L=Oo(),ae=To(),te=Ro(),J=Zo(),ve=$o(),Se=Lo(),[fe,me]=Y.useState(!1),[ke,ye]=Y.useState(!1),[_e,Re]=Y.useState(null),[c,K]=Y.useState(null),[M,C]=Y.useState(null),[N,D]=Y.useState(null),[X,y]=Y.useState(!1),[b,A]=Y.useState({name:"",description:""}),I=async W=>{if(e)try{const Ne=Array.isArray(W.media)&&W.media.length>0,ta={name:W.name,description:W.description,price:W.price,currency:W.currency,externalId:W.externalId||void 0,externalCategory:W.externalCategory||void 0,catalogId:W.catalogId,imageUrl:W.imageUrl||void 0,media:Ne?W.media:[]};_e?await ee.mutateAsync({id:_e.id,dto:ta}):await F.mutateAsync(ta),me(!1),Re(null)}catch(Ne){console.warn("[Products] submit error (toast handled by hook):",Ne)}},z=Y.useCallback(W=>{Re(W),me(!0)},[]),Z=()=>{Re(null),me(!0)},H=Y.useCallback(W=>{C(W)},[]),re=Y.useCallback(async()=>{if(M)try{await O.mutateAsync(M.id),C(null)}catch(W){console.warn("[Products] delete error (toast handled by hook):",W)}},[M,O]),he=Y.useCallback(async W=>{try{await ae.mutateAsync({ids:p,isActive:W}),g()}catch(Ne){console.warn("[Products] bulk toggle error (toast handled by hook):",Ne)}},[p,ae,g]),ze=Y.useCallback(async()=>{try{await te.mutateAsync(p),g()}catch(W){console.warn("[Products] bulk delete error (toast handled by hook):",W)}y(!1)},[p,te,g]),je=Y.useMemo(()=>V.filter(W=>p.includes(W.id)),[V,p]),Fe=je.filter(W=>W.isActive).length,ge=je.filter(W=>!W.isActive).length,xe=Y.useCallback(W=>{j(W.id)},[j]),Ze=()=>{K(null),A({name:"",description:""}),ye(!0)},$e=W=>{K(W),A({name:W.name,description:W.description||""}),ye(!0)},Ae=async W=>{if(W.preventDefault(),!!e)try{c?await ve.mutateAsync({id:c.id,dto:{name:b.name,description:b.description||void 0}}):await J.mutateAsync({name:b.name,description:b.description||void 0}),ye(!1),K(null),A({name:"",description:""})}catch(Ne){console.warn("[Products] catalog save error (toast handled by hook):",Ne)}},He=Y.useCallback(async()=>{if(N)try{await Se.mutateAsync(N.id),D(null)}catch(W){console.warn("[Products] catalog delete error (toast handled by hook):",W)}},[N,Se]),Qe=Y.useCallback(()=>{u(),B(""),ne.success("Filtros reiniciados",{id:"filters-reset"})},[u]),[xt,mt]=Y.useState(!1),Nt=async()=>{mt(!0);try{await we.exportProducts({search:n.search||void 0,catalogId:n.catalogId||void 0}),ne.success("Exportación descargada")}catch{ne.error("Error al exportar productos")}finally{mt(!1)}},St=Si(W=>W.user?.isSuperAdmin),{can:Tr,esAdmin:fi}=Ci(),{data:hs,isLoading:pi}=Uo(Tr("manage:products")),xi=hs?.missingIds?.length?new Set(hs.missingIds):void 0,gi=qo(),ms=Bo(),Ye=ym(),Bt=Ye.status==="processing";Y.useEffect(()=>zi.onProductsReindexProgress(Ne=>{Ye.updateProgress({status:Ne.status,progress:Ne.progress,synced:Ne.synced,errors:Ne.errors,total:Ne.total,message:Ne.message||null}),Ne.status==="completed"?(ne.success(`Reindex completado: ${Ne.synced} productos sincronizados`),setTimeout(()=>Ye.reset(),5e3),r.invalidateQueries({queryKey:pe.all}),r.invalidateQueries({queryKey:pe.qdrantStatus()})):Ne.status==="failed"&&(ne.error(Ne.message||"Error durante el reindex"),setTimeout(()=>Ye.reset(),5e3))}),[]);const Js=async()=>{try{const W=await we.reindexProducts();Ye.startReindex(W.jobId)}catch(W){const Ne=W;Ne.response?.status===409?ne.warning("Ya hay un reindex en progreso para esta organización"):ne.error(Ne.message||"Error al iniciar reindex")}},bi=n.catalogId||n.category||S,vi=F.isPending||ee.isPending,ea=J.isPending||ve.isPending,yi=Y.useMemo(()=>se.reduce((W,Ne)=>W+(Ne.productCount??0),0),[se]);return t.jsxs(Ar,{children:[t.jsx(Ii,{children:t.jsxs("div",{className:"h-full overflow-y-auto no-scrollbar",children:[t.jsx(Ai,{title:"Gestión de Productos",description:"Administra tu inventario para que los Agentes puedan recomendar y vender",icon:it,actions:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("div",{className:"flex items-center bg-slate-100/60 dark:bg-slate-800/50 rounded-full p-1 gap-0.5",children:[Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ue,{onClick:()=>ms.mutate(),disabled:ms.isPending,variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(hr,{className:le("h-4 w-4 text-slate-500",ms.isPending&&"animate-spin text-primary")})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Verificar consistencia IA"})})]}),St&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsxs(ue,{onClick:Js,disabled:Bt||Ye.status==="completed",variant:"ghost",size:"icon",className:le("h-9 w-9 rounded-full transition-all relative overflow-hidden",Bt?"bg-amber-100 dark:bg-amber-900/30 ring-2 ring-amber-400/50":Ye.status==="completed"?"bg-green-100 dark:bg-green-900/30 ring-2 ring-green-400/50":"bg-amber-50 dark:bg-amber-900/20 ring-1 ring-amber-300/40 hover:ring-amber-400/60 hover:bg-amber-100 dark:hover:bg-amber-900/40"),children:[Bt&&t.jsx("div",{className:"absolute inset-0 bg-amber-300/30 dark:bg-amber-500/20 transition-all duration-500 ease-out rounded-full",style:{width:`${Ye.progress}%`}}),t.jsx("span",{className:"relative",children:Bt?t.jsx(be,{className:"h-4 w-4 text-amber-600 animate-spin"}):Ye.status==="completed"?t.jsx(fs,{className:"h-4 w-4 text-green-500"}):t.jsx(fs,{className:"h-4 w-4 text-amber-600"})})]})}),t.jsxs(rt,{side:"bottom",className:"max-w-[280px]",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx(fs,{className:"h-3 w-3 text-amber-500"}),t.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-amber-600",children:"Super Admin"})]}),t.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:Bt?`Reindexando… ${Ye.progress}% (${Ye.synced}/${Ye.total} · ${Ye.errors} errores)`:Ye.status==="completed"?`✓ ${Ye.synced} productos sincronizados`:"Reconstruye el índice de búsqueda IA completo. Regenera embeddings de todos los productos."})]})]}),fi&&V.length>0&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx(ue,{onClick:Nt,variant:"ghost",size:"icon",disabled:xt,className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:xt?t.jsx(be,{className:"h-4 w-4 text-slate-500 animate-spin"}):t.jsx(to,{className:"h-4 w-4 text-slate-500"})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Exportar productos"})})]}),t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(Co,{catalogs:se,onSuccess:()=>r.invalidateQueries({queryKey:pe.all}),trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(Hr,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar productos"})})]}),Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(tl,{trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(fn,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar desde API"})})]}),Tr("manage:products")&&t.jsxs(et,{children:[t.jsx(tt,{asChild:!0,children:t.jsx("span",{children:t.jsx(rl,{trigger:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-full hover:bg-white dark:hover:bg-slate-700 transition-all",children:t.jsx(kn,{className:"h-4 w-4 text-slate-500"})})})})}),t.jsx(rt,{side:"bottom",children:t.jsx("p",{className:"text-xs font-medium",children:"Importar desde Shopify"})})]})]}),se.length>0&&t.jsxs(ue,{onClick:Z,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-5 ml-1",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"}),"Nuevo Producto"]})]})}),t.jsx(Pi,{className:"space-y-6",children:t.jsxs(Ji,{defaultValue:"products",value:s,onValueChange:a,children:[t.jsx("div",{className:"flex items-center gap-1 mb-6 border-b border-slate-100 dark:border-slate-800",children:[{value:"products",label:"Productos",icon:it,count:ie},{value:"catalogs",label:"Catálogos",icon:dt,count:se.length},{value:"ai-search",label:"Búsqueda IA",icon:Fr}].map(W=>t.jsxs("button",{onClick:()=>a(W.value),className:le("flex items-center gap-2 px-4 py-2.5 text-sm font-bold transition-all relative -mb-[1px] border-b-2",s===W.value?"text-primary border-primary":"text-slate-400 border-transparent hover:text-slate-600 dark:hover:text-slate-300 hover:border-slate-200 dark:hover:border-slate-700"),children:[t.jsx(W.icon,{className:"h-4 w-4"}),W.label,W.count!==void 0&&t.jsx("span",{className:le("text-[10px] font-black px-1.5 py-0.5 rounded-full min-w-[20px] text-center leading-none",s===W.value?"bg-primary/10 text-primary":"bg-slate-100 text-slate-400 dark:bg-slate-800 dark:text-slate-500"),children:W.count})]},W.value))}),t.jsx(xs,{value:"products",className:"space-y-6",children:v?t.jsxs("div",{className:"space-y-4",children:[t.jsx(at,{className:"h-24 w-full rounded-[24px]"}),t.jsx(at,{className:"h-14 w-full rounded-[24px]"}),t.jsx(at,{className:"h-64 w-full rounded-[32px]"})]}):se.length===0?t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(dt,{className:"w-10 h-10 text-slate-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2",children:"No hay catálogos"}),t.jsx("p",{className:"text-slate-500 max-w-md mb-6",children:"Debes crear al menos un catálogo antes de agregar productos."}),t.jsx(ue,{onClick:()=>a("catalogs"),className:"rounded-full px-6",children:"Ir a Catálogos"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4 px-1",children:[t.jsx(na,{className:"h-4 w-4 text-slate-400"}),t.jsx("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:"Resumen"})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[t.jsx(Et,{icon:t.jsx(it,{className:"w-5 h-5 text-indigo-500"}),label:"Total Productos",value:ie,bgClass:"bg-indigo-50 dark:bg-indigo-900/10"}),t.jsx(Et,{icon:t.jsx(dt,{className:"w-5 h-5 text-violet-500"}),label:"Catálogos",value:se.length,bgClass:"bg-violet-50 dark:bg-violet-900/10"}),t.jsx(Et,{icon:t.jsx(ss,{className:"w-5 h-5 text-blue-500"}),label:"Categorías",value:q.length,bgClass:"bg-blue-50 dark:bg-blue-900/10"}),t.jsx(Et,{icon:t.jsx(lr,{className:"w-5 h-5 text-emerald-500"}),label:"Monedas",value:new Set(V.map(W=>W.currency)).size,bgClass:"bg-emerald-50 dark:bg-emerald-900/10"})]})]}),t.jsx(wm,{status:hs,isLoading:pi,onReindex:Js,isReindexing:Bt,canReindex:!!St}),t.jsxs("div",{className:"bg-white dark:bg-slate-900 p-3 rounded-[24px] border border-slate-100 dark:border-slate-800 shadow-sm flex flex-col xl:flex-row items-center justify-between gap-3 sticky top-[72px] z-10 backdrop-blur-md bg-opacity-95",children:[t.jsxs("div",{className:"flex items-center gap-3 w-full xl:w-auto",children:[t.jsxs("div",{className:"relative flex-1 xl:w-72",children:[G?t.jsx(be,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-primary animate-spin"}):t.jsx(Sr,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),t.jsx(st,{placeholder:"Buscar por nombre o SKU...",value:S,onChange:W=>B(W.target.value),className:"h-11 pl-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-sm focus-visible:ring-1 focus-visible:ring-primary/20 transition-all font-medium"}),S&&t.jsx(Ft,{className:"absolute right-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400 cursor-pointer hover:text-slate-600 transition-colors",onClick:()=>B("")})]}),bi&&t.jsxs(ue,{variant:"ghost",size:"sm",onClick:Qe,className:"text-[11px] font-bold uppercase tracking-tight text-rose-500 hover:text-rose-600 hover:bg-rose-50 dark:hover:bg-rose-900/10 whitespace-nowrap rounded-xl transition-all",children:[t.jsx(Ft,{className:"w-3.5 h-3.5 mr-1"}),"Limpiar"]})]}),t.jsxs("div",{className:"flex items-center gap-2 w-full xl:w-auto overflow-x-auto no-scrollbar pb-1 xl:pb-0",children:[t.jsxs(sr,{value:n.catalogId||"all",onValueChange:W=>d({catalogId:W==="all"?"":W}),children:[t.jsx(ar,{className:"h-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-[13px] font-medium w-full xl:w-[160px]",children:t.jsx(nr,{placeholder:"Catálogo"})}),t.jsxs(ir,{className:"rounded-2xl",children:[t.jsx(kt,{value:"all",className:"rounded-xl",children:"Todos"}),se.map(W=>t.jsx(kt,{value:W.id,className:"rounded-xl",children:W.name},W.id))]})]}),q.length>0&&t.jsxs(sr,{value:n.category||"all",onValueChange:W=>d({category:W==="all"?"":W}),children:[t.jsx(ar,{className:"h-11 bg-slate-50 dark:bg-slate-950 border-none rounded-2xl text-[13px] font-medium w-full xl:w-[160px]",children:t.jsx(nr,{placeholder:"Categoría"})}),t.jsxs(ir,{className:"rounded-2xl",children:[t.jsx(kt,{value:"all",className:"rounded-xl",children:"Todas"}),q.map(W=>t.jsx(kt,{value:W,className:"rounded-xl",children:W},W))]})]}),t.jsx("div",{className:"h-6 w-[1px] bg-slate-100 dark:bg-slate-800 hidden md:block shrink-0 mx-1"}),t.jsxs("div",{className:"flex bg-slate-100/50 dark:bg-slate-800/50 p-1 rounded-xl shrink-0",children:[t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>f("comfortable"),className:le("h-8 w-8 rounded-lg transition-all",E==="comfortable"?"bg-white dark:bg-slate-900 shadow-sm text-primary":"text-slate-400 hover:text-slate-600"),children:t.jsx(ro,{className:"h-4 w-4"})}),t.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>f("compact"),className:le("h-8 w-8 rounded-lg transition-all",E==="compact"?"bg-white dark:bg-slate-900 shadow-sm text-primary":"text-slate-400 hover:text-slate-600"),children:t.jsx(ao,{className:"h-4 w-4"})})]})]})]}),t.jsx(mi,{products:V,catalogs:se,isLoading:R,selectedIds:p,onSelect:_,onSelectAll:W=>w(W?V.map(Ne=>Ne.id):[]),onViewDetail:xe,onEdit:z,onDelete:H,onToggleActive:W=>L.mutate({id:W.id,isActive:!W.isActive}),onSyncProduct:W=>gi.mutate([W.id]),missingIds:xi,page:i,total:ie,limit:o,onPageChange:k,density:E,sortBy:l,sortOrder:h,onSort:x})]})}),t.jsx(xs,{value:"catalogs",className:"space-y-6",children:v?t.jsxs("div",{className:"space-y-4",children:[t.jsx(at,{className:"h-24 w-full rounded-[24px]"}),t.jsx(at,{className:"h-64 w-full rounded-[32px]"})]}):se.length===0?t.jsxs("div",{className:"w-full bg-white dark:bg-slate-900 rounded-[32px] border border-dashed border-slate-200 dark:border-slate-800 p-20 flex flex-col items-center justify-center text-center",children:[t.jsx("div",{className:"w-20 h-20 bg-violet-50 dark:bg-violet-900/20 rounded-[24px] flex items-center justify-center mb-6",children:t.jsx(dt,{className:"w-10 h-10 text-violet-300"})}),t.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2",children:"No hay catálogos"}),t.jsx("p",{className:"text-slate-500 max-w-md mb-6",children:"Crea tu primer catálogo para comenzar a organizar tus productos. Los catálogos ayudan a la IA a recomendar mejor."}),t.jsxs(ue,{onClick:Ze,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-6",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"})," Crear primer catálogo"]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4 px-1",children:[t.jsx(na,{className:"h-4 w-4 text-slate-400"}),t.jsx("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:"Resumen de catálogos"})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[t.jsx(Et,{icon:t.jsx(dt,{className:"w-5 h-5 text-violet-500"}),label:"Total Catálogos",value:se.length,bgClass:"bg-violet-50 dark:bg-violet-900/10"}),t.jsx(Et,{icon:t.jsx(it,{className:"w-5 h-5 text-indigo-500"}),label:"Productos Totales",value:yi,bgClass:"bg-indigo-50 dark:bg-indigo-900/10"}),t.jsx(Et,{icon:t.jsx(so,{className:"w-5 h-5 text-amber-500"}),label:"Catálogo Default",value:se.filter(W=>W.isDefault).length,bgClass:"bg-amber-50 dark:bg-amber-900/10"})]})]}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 px-1",children:[t.jsx(dt,{className:"h-4 w-4 text-slate-400"}),t.jsxs("h2",{className:"text-xs font-black uppercase tracking-widest text-slate-400",children:[se.length," catálogo",se.length!==1?"s":""]})]}),t.jsxs(ue,{onClick:Ze,className:"bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 rounded-full px-5",children:[t.jsx(ps,{className:"mr-2 h-4 w-4"})," Nuevo Catálogo"]})]}),t.jsx("div",{className:"bg-white dark:bg-slate-900 rounded-[32px] border border-slate-100 dark:border-slate-800 shadow-sm overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-500",children:t.jsxs(Qr,{children:[t.jsx(Yr,{children:t.jsxs(or,{className:"bg-slate-50/30 dark:bg-slate-800/20 hover:bg-slate-50/30 dark:hover:bg-slate-800/20 border-slate-100 dark:border-slate-800",children:[t.jsx(De,{className:"py-5 pl-6 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Nombre"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Descripción"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Productos"}),t.jsx(De,{className:"py-5 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Creación"}),t.jsx(De,{className:"w-[80px] pr-6"})]})}),t.jsx(wn,{children:se.map(W=>t.jsxs(or,{className:"group hover:bg-slate-50/80 dark:hover:bg-slate-800/50 border-slate-50/50 dark:border-slate-800/50 transition-all",children:[t.jsx(ut,{className:"py-4 pl-6",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-violet-50 dark:bg-violet-900/20 flex items-center justify-center shrink-0",children:t.jsx(dt,{className:"w-4 h-4 text-violet-500"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("span",{className:"font-black text-sm text-slate-900 dark:text-white truncate block",children:W.name}),W.isDefault&&t.jsx(Ce,{className:"mt-0.5 text-[9px] rounded-full bg-amber-50 text-amber-600 border-amber-200 px-1.5 py-0",children:"Default"})]})]})}),t.jsx(ut,{className:"py-4 text-sm max-w-[300px]",children:W.description?t.jsx("span",{className:"text-slate-600 dark:text-slate-400 line-clamp-2",children:W.description}):t.jsx("span",{className:"text-slate-300 dark:text-slate-600 italic text-xs",children:"Sin descripción"})}),t.jsx(ut,{className:"py-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-indigo-50 dark:bg-indigo-900/20 flex items-center justify-center",children:t.jsx(it,{className:"w-3.5 h-3.5 text-indigo-500"})}),t.jsx("span",{className:"text-[13px] font-bold text-slate-700 dark:text-slate-300",children:W.productCount??0})]})}),t.jsx(ut,{className:"py-4 text-sm text-slate-500",children:as(W.createdAt,{style:"date-only"})}),t.jsx(ut,{className:"text-right pr-6 py-4",onClick:Ne=>Ne.stopPropagation(),children:t.jsx("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity translate-x-4 group-hover:translate-x-0 duration-300",children:t.jsxs(pn,{children:[t.jsx(xn,{asChild:!0,children:t.jsx(ue,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-slate-200/50",children:t.jsx(Pn,{className:"h-4 w-4 text-slate-400"})})}),t.jsxs(gn,{align:"end",className:"w-48 p-2 rounded-2xl shadow-2xl border-slate-100",children:[t.jsx(bn,{className:"text-[10px] uppercase font-black tracking-widest text-slate-400 p-2",children:"Opciones"}),t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>$e(W),className:"rounded-xl p-2.5 font-bold text-sm cursor-pointer",children:[t.jsx($s,{className:"mr-3 h-4 w-4 text-slate-400"}),"Editar"]}),!W.isDefault&&t.jsxs(t.Fragment,{children:[t.jsx(Gr,{className:"bg-slate-50"}),t.jsxs(It,{onClick:()=>D(W),className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50 cursor-pointer",children:[t.jsx(bt,{className:"mr-3 h-4 w-4"}),"Eliminar"]})]})]})]})})})]},W.id))})]})})]})}),t.jsx(xs,{value:"ai-search",className:"space-y-6",children:t.jsx(nm,{})})]})})]})}),t.jsx(jr,{open:fe,onOpenChange:W=>{me(W),W||Re(null)},children:t.jsxs(kr,{className:"w-full sm:w-[540px] md:w-[620px] sm:max-w-none overflow-hidden p-0 flex flex-col",children:[t.jsx("div",{className:"px-5 py-3 bg-muted/20 border-b border-border/40 shrink-0",children:t.jsx(_r,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary/10 flex items-center justify-center shrink-0 border border-primary/20",children:t.jsx(it,{className:"h-5 w-5 text-primary"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(Nr,{className:"text-lg font-bold tracking-tight",children:_e?"Editar Producto":"Nuevo Producto"}),t.jsx(Ce,{variant:"outline",className:le("uppercase text-[9px] font-bold tracking-widest px-1.5",_e?"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20":"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20"),children:_e?"Editando":"Nuevo"})]}),t.jsx(Kr,{className:"text-[11px] text-muted-foreground/70 font-medium mt-0.5 leading-tight",children:_e?"Modifica los datos del producto. Los cambios se sincronizarán con la IA.":"Completa la información. La IA usará estos datos para recomendar."})]})]})})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-4 pb-5",children:t.jsx(Jh,{product:_e,catalogs:se,organizationId:e.id,isSubmitting:vi,onSubmit:I},_e?.id||"new")})]})}),t.jsx(jr,{open:ke,onOpenChange:W=>{ye(W),W||(K(null),A({name:"",description:""}))},children:t.jsxs(kr,{className:"w-full sm:w-[480px] sm:max-w-none overflow-hidden p-0 flex flex-col",children:[t.jsx("div",{className:"px-5 py-3 bg-muted/20 border-b border-border/40 shrink-0",children:t.jsx(_r,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"h-10 w-10 rounded-xl bg-violet-500/10 flex items-center justify-center shrink-0 border border-violet-500/20",children:t.jsx(dt,{className:"h-5 w-5 text-violet-500"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(Nr,{className:"text-lg font-bold tracking-tight",children:c?"Editar Catálogo":"Nuevo Catálogo"}),t.jsx(Ce,{variant:"outline",className:le("uppercase text-[9px] font-bold tracking-widest px-1.5",c?"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20":"bg-violet-500/10 text-violet-600 dark:text-violet-400 border-violet-500/20"),children:c?"Editando":"Nuevo"})]}),t.jsx(Kr,{className:"text-[11px] text-muted-foreground/70 font-medium mt-0.5 leading-tight",children:c?"Modifica el nombre y la descripción del catálogo.":"Los catálogos agrupan productos para que la IA pueda recomendarlos mejor."})]})]})})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-4 pb-5",children:t.jsxs("form",{onSubmit:Ae,className:"space-y-3 pb-2",children:[t.jsxs("div",{className:"border border-border/40 shadow-sm bg-background/50 rounded-lg overflow-hidden hover:border-violet-500/20 transition-all duration-200",children:[t.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5",children:[t.jsx("div",{className:"w-6 h-6 rounded-md flex items-center justify-center bg-violet-500/10",children:t.jsx(dt,{className:"h-3.5 w-3.5 text-violet-500"})}),t.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:"Información del catálogo"})]}),t.jsxs("div",{className:"px-4 pb-4 space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:["Nombre ",t.jsx("span",{className:"text-rose-500 ml-0.5",children:"*"})]}),t.jsx(st,{required:!0,value:b.name,onChange:W=>A({...b,name:W.target.value}),placeholder:"Ej: Ropa Verano 2025",className:"h-9 rounded-lg bg-muted/30 border-border/50 text-sm focus-visible:ring-1 focus-visible:ring-primary/30 font-medium"}),t.jsx("p",{className:"text-[10px] text-muted-foreground/50 leading-snug",children:"Usa un nombre descriptivo para agrupar productos similares."})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(yt,{className:"text-[10px] uppercase font-bold tracking-wider text-muted-foreground/70",children:"Descripción"}),t.jsx(Ce,{variant:"outline",className:"text-[9px] font-bold uppercase tracking-wider text-muted-foreground/50 border-border/50 rounded-md px-1.5 py-0",children:"Opcional"})]}),t.jsx(vn,{value:b.description,onChange:W=>A({...b,description:W.target.value}),placeholder:"Describe el propósito de este catálogo...",className:"min-h-[80px] rounded-lg bg-muted/30 border-border/50 text-sm focus-visible:ring-1 focus-visible:ring-primary/30 resize-none leading-relaxed font-medium"})]})]})]}),t.jsxs(ue,{type:"submit",className:"w-full h-10 rounded-lg bg-primary hover:bg-primary/90 text-white shadow-lg shadow-primary/25 font-bold text-sm transition-all",disabled:ea,children:[ea?t.jsx(be,{className:"h-4 w-4 animate-spin mr-2"}):t.jsx(An,{className:"h-4 w-4 mr-2"}),c?"Guardar cambios":"Crear Catálogo"]})]})})]})}),t.jsx(sm,{product:ce,catalogs:se,open:!!ce,onOpenChange:W=>{W||j(null)},onEdit:z,onDelete:H,onToggleActive:W=>L.mutate({id:W.id,isActive:!W.isActive})}),p.length>0&&t.jsx("div",{className:"fixed bottom-8 left-1/2 transform -translate-x-1/2 z-50 animate-in slide-in-from-bottom-5 fade-in duration-300",children:t.jsxs("div",{className:"bg-slate-900 text-white px-7 py-3.5 rounded-full shadow-[0_20px_50px_rgba(0,0,0,0.3)] flex items-center gap-5 border border-slate-800/50 backdrop-blur-xl bg-opacity-95",children:[t.jsxs("span",{className:"text-[13px] font-bold flex items-center gap-2.5",children:[t.jsx("div",{className:"bg-primary text-white w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-black shadow-lg shadow-primary/40",children:p.length}),"Seleccionados"]}),t.jsx("div",{className:"h-5 w-[1px] bg-white/10"}),t.jsxs("div",{className:"flex items-center gap-2",children:[ge>0&&t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:()=>he(!0),disabled:ae.isPending,children:[ae.isPending?t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}):t.jsx(Ls,{className:"w-4 h-4 mr-2 text-emerald-400"}),"Activar",ge<p.length?` (${ge})`:""]}),Fe>0&&t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:()=>he(!1),disabled:ae.isPending,children:[ae.isPending?t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}):t.jsx(Cr,{className:"w-4 h-4 mr-2 text-amber-400"}),"Desactivar",Fe<p.length?` (${Fe})`:""]}),t.jsx("div",{className:"h-5 w-[1px] bg-white/10"}),t.jsxs(ue,{size:"sm",variant:"ghost",className:"h-9 hover:bg-rose-500/20 text-white rounded-xl px-4 transition-all",onClick:()=>y(!0),disabled:te.isPending,children:[t.jsx(bt,{className:"w-4 h-4 mr-2 text-rose-400"}),"Eliminar"]})]}),t.jsx(ue,{size:"icon",variant:"ghost",className:"h-7 w-7 rounded-full hover:bg-white/10 transition-all text-slate-400 hover:text-white",onClick:()=>g(),children:t.jsx(Ft,{className:"w-4 h-4"})})]})}),t.jsx(Kt,{open:!!M,onOpenChange:W=>{W||C(null)},children:t.jsxs(Gt,{className:"rounded-2xl",children:[t.jsxs(Ht,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Qt,{className:"text-lg font-bold",children:['Eliminar "',M?.name,'"']})]}),t.jsxs(Yt,{className:"text-sm text-slate-500 leading-relaxed",children:["Esta acción es ",t.jsx("span",{className:"font-semibold text-rose-600",children:"permanente e irreversible"}),'. El producto será eliminado completamente del sistema y no podrá recuperarse. Si solo quieres que la IA deje de recomendarlo, usa la opción "Desactivar".']})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(er,{onClick:re,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[O.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar permanente"]})]})]})}),t.jsx(Kt,{open:X,onOpenChange:W=>{W||y(!1)},children:t.jsxs(Gt,{className:"rounded-2xl",children:[t.jsxs(Ht,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Qt,{className:"text-lg font-bold",children:["Eliminar ",p.length," producto",p.length>1?"s":""]})]}),t.jsxs(Yt,{className:"text-sm text-slate-500 leading-relaxed",children:["Esta acción es ",t.jsx("span",{className:"font-semibold text-rose-600",children:"permanente e irreversible"}),". Se eliminarán ",p.length," producto",p.length>1?"s":"",' completamente del sistema y no podrán recuperarse. Si solo quieres que la IA deje de recomendarlos, usa la opción "Desactivar".']})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(er,{onClick:ze,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[te.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar ",p.length," producto",p.length>1?"s":""]})]})]})}),t.jsx(Kt,{open:!!N,onOpenChange:W=>{W||D(null)},children:t.jsxs(Gt,{className:"rounded-2xl",children:[t.jsxs(Ht,{children:[t.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[t.jsx("div",{className:"w-10 h-10 bg-rose-50 dark:bg-rose-900/20 rounded-xl flex items-center justify-center",children:t.jsx(ct,{className:"w-5 h-5 text-rose-500"})}),t.jsxs(Qt,{className:"text-lg font-bold",children:['Eliminar "',N?.name,'"']})]}),t.jsx(Yt,{className:"text-sm text-slate-500 leading-relaxed",children:"El catálogo será eliminado permanentemente. Si contiene productos activos, deberás moverlos o desactivarlos primero."})]}),t.jsxs(Xt,{children:[t.jsx(Jt,{className:"rounded-xl",children:"Cancelar"}),t.jsxs(er,{onClick:He,className:"rounded-xl bg-rose-600 hover:bg-rose-700 text-white",children:[Se.isPending&&t.jsx(be,{className:"w-4 h-4 mr-2 animate-spin"}),t.jsx(bt,{className:"w-4 h-4 mr-2"}),"Eliminar"]})]})]})})]})}export{x0 as default};
|