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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ay as o}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";const t=o;export{t as PublicFormPage,o as default};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{c as C,j as e,i as V,n as Q,I as D,o as P,B as U,V as R,a9 as W,t as j}from"./index-43NA2pdZ.js";import{b as d}from"./recharts-DrC5kNsx.js";import{s as G,i as K}from"./storage.api-C0ZJBoSz.js";import{a as T}from"./agent.service-BE2rJG_o.js";import{M as J,v as X}from"./mediaValidation-Bg0xHQrv.js";import{b as O,a as Y}from"./mediaLimits-CAYdWqeQ.js";import{T as Z}from"./textarea-B1anutjq.js";import{C as ee}from"./code-C-UH-ZD-.js";import{L as te}from"./list-B0uLKf1b.js";import{P as se}from"./pencil-aqjc7AWb.js";import{E as ae}from"./eye-CR5C6hVv.js";import{M as re}from"./music-CgtkroYi.js";import{P as ie}from"./paperclip-DVRbzE7C.js";import{U as ne}from"./upload-CQg4_W5r.js";import{S as oe}from"./save-mwkHDnDL.js";const le=[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]],de=C("bold",le);const ce=[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]],me=C("italic",ce);const ue=[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]],pe=C("list-ordered",ue);const xe=[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]],he=C("quote",xe);const ge=[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]],fe=C("strikethrough",ge),be={whatsapp:{bold:"*",italic:"_",strike:"~",mono:"```"},markdown:{bold:"**",italic:"_",strike:"~~",mono:"`"}};function je(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ve(s,i){let t=je(s);return i==="whatsapp"?(t=t.replace(/```([\s\S]+?)```/g,"<code>$1</code>"),t=t.replace(/\*([^*\n]+)\*/g,"<strong>$1</strong>"),t=t.replace(/_([^_\n]+)_/g,"<em>$1</em>"),t=t.replace(/~([^~\n]+)~/g,"<del>$1</del>")):(t=t.replace(/`([^`\n]+)`/g,"<code>$1</code>"),t=t.replace(/\*\*([^*\n]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/~~([^~\n]+)~~/g,"<del>$1</del>"),t=t.replace(/_([^_\n]+)_/g,"<em>$1</em>")),t=t.replace(/\n/g,"<br/>"),t}function ye({id:s,value:i,onChange:t,placeholder:w,minHeight:A="140px",defaultMode:$="whatsapp"}){const N=d.useRef(null),[x,k]=d.useState($),[h,E]=d.useState(!1),l=be[x],g=a=>{const n=N.current;if(!n)return;const o=n.selectionStart??i.length,c=n.selectionEnd??i.length,b=i.slice(o,c),m=i.slice(0,o)+a+b+a+i.slice(c);t(m),requestAnimationFrame(()=>{n.focus(),n.setSelectionRange(o+a.length,c+a.length)})},v=a=>{const n=N.current;if(!n)return;const o=n.selectionStart??0,c=n.selectionEnd??0,b=i.lastIndexOf(`
|
|
2
|
+
`,o-1)+1,m=i.indexOf(`
|
|
3
|
+
`,c),S=m===-1?i.length:m,u=i.slice(b,S).split(`
|
|
4
|
+
`).map((M,y)=>a(y)+M).join(`
|
|
5
|
+
`);t(i.slice(0,b)+u+i.slice(S)),requestAnimationFrame(()=>n.focus())},f=({onClick:a,title:n,children:o})=>e.jsx("button",{type:"button",title:n,"aria-label":n,onMouseDown:c=>c.preventDefault(),onClick:a,disabled:h,className:"h-7 w-7 inline-flex items-center justify-center rounded text-slate-500 hover:text-foreground hover:bg-muted transition-colors disabled:opacity-40",children:o});return e.jsxs("div",{className:"rounded-lg border border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-900 overflow-hidden focus-within:ring-2 focus-within:ring-violet-500/30",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-slate-200 dark:border-slate-700 bg-white/60 dark:bg-slate-950/30",children:[e.jsx(f,{onClick:()=>g(l.bold),title:"Negrita",children:e.jsx(de,{className:"h-3.5 w-3.5"})}),e.jsx(f,{onClick:()=>g(l.italic),title:"Cursiva",children:e.jsx(me,{className:"h-3.5 w-3.5"})}),e.jsx(f,{onClick:()=>g(l.strike),title:"Tachado",children:e.jsx(fe,{className:"h-3.5 w-3.5"})}),e.jsx(f,{onClick:()=>g(l.mono),title:"Monoespaciado",children:e.jsx(ee,{className:"h-3.5 w-3.5"})}),e.jsx("span",{className:"w-px h-4 bg-slate-200 dark:bg-slate-700 mx-1"}),e.jsx(f,{onClick:()=>v(()=>"- "),title:"Lista",children:e.jsx(te,{className:"h-3.5 w-3.5"})}),e.jsx(f,{onClick:()=>v(a=>`${a+1}. `),title:"Lista numerada",children:e.jsx(pe,{className:"h-3.5 w-3.5"})}),e.jsx(f,{onClick:()=>v(()=>"> "),title:"Cita",children:e.jsx(he,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsxs("div",{className:"inline-flex rounded-md border border-slate-200 dark:border-slate-700 overflow-hidden text-[11px]",children:[e.jsx("button",{type:"button",onClick:()=>k("whatsapp"),className:`px-2 py-0.5 transition-colors ${x==="whatsapp"?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400 font-medium":"text-slate-500 hover:text-foreground"}`,children:"WhatsApp"}),e.jsx("button",{type:"button",onClick:()=>k("markdown"),className:`px-2 py-0.5 transition-colors ${x==="markdown"?"bg-slate-200 dark:bg-slate-700 text-foreground font-medium":"text-slate-500 hover:text-foreground"}`,children:"Markdown"})]}),e.jsx("button",{type:"button",onClick:()=>E(a=>!a),title:h?"Editar":"Vista previa","aria-label":h?"Editar":"Vista previa",className:"h-7 w-7 inline-flex items-center justify-center rounded text-slate-500 hover:text-foreground hover:bg-muted transition-colors",children:h?e.jsx(se,{className:"h-3.5 w-3.5"}):e.jsx(ae,{className:"h-3.5 w-3.5"})})]})]}),h?e.jsx("div",{className:"px-3 py-2 text-sm leading-relaxed [&_code]:bg-muted [&_code]:px-1 [&_code]:rounded [&_code]:text-[13px]",style:{minHeight:A},dangerouslySetInnerHTML:{__html:ve(i,x)||'<span class="opacity-40">Nada que previsualizar</span>'}}):e.jsx(Z,{ref:N,id:s,value:i,onChange:a=>t(a.target.value),placeholder:w,className:"border-0 bg-transparent focus-visible:ring-0 resize-y rounded-none",style:{minHeight:A}}),e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-muted-foreground border-t border-slate-200 dark:border-slate-700",children:x==="whatsapp"?"Formato WhatsApp: *negrita* _cursiva_ ~tachado~ ```mono```":"Markdown: **negrita** _cursiva_ ~~tachado~~ `mono`"})]})}function Qe({item:s,organizationId:i,onSaved:t,onCancel:w,compact:A,submitLabel:$}){const N=V(),[x,k]=d.useState(s?.question||""),[h,E]=d.useState(s?.answer||""),[l,g]=d.useState(null),[v,f]=d.useState(!1),[a,n]=d.useState(!1),[o,c]=d.useState(null),[b,m]=d.useState(!1),[S,I]=d.useState(!1),u=s?.mediaUrl?decodeURIComponent(s.mediaUrl.split("?")[0].split("/").pop()||"Adjunto"):"",M=u.split(".").pop()?.toLowerCase()||"",y=["jpg","jpeg","png","gif","webp","bmp","svg"].includes(M),F=["mp4","mov","avi","webm","mkv","m4v"].includes(M),_=["mp3","ogg","oga","m4a","wav","opus","aac"].includes(M);d.useEffect(()=>{let r=!0;return c(null),m(!1),s?.mediaUrl&&(y||F||_)&&(s.mediaSignedUrl?c(s.mediaSignedUrl):G.getSignedUrl(s.mediaUrl).then(p=>{r&&(p?c(p):m(!0))}).catch(()=>r&&m(!0))),()=>{r=!1}},[s?.mediaUrl,s?.mediaSignedUrl,y,F,_]);const B=async r=>{if(!r){g(null);return}const p=X(r,O);if(!p.isValid){j.error(p.userMessage||"Archivo no válido",{description:p.suggestion});return}const q=Y(r.type),z=q?O[q].maxBytes:0;if(q==="image"&&z&&r.size>z){I(!0);try{const L=await K(r,{maxSizeMB:z/1048576,maxWidthOrHeight:1920,useWebWorker:!0,initialQuality:.9});if(L.size>z){j.error("La imagen sigue siendo muy grande tras optimizar.",{description:"Usa una imagen de menor resolución."});return}g(L),j.success("Imagen optimizada")}catch{j.error("No se pudo optimizar la imagen")}finally{I(!1)}return}g(r)},H=async r=>{if(r?.preventDefault(),!x.trim()||!h.trim()){j.error("Pregunta y respuesta son requeridas");return}n(!0);try{let p;s?(await T.updateQa(s.id,{question:x,answer:h,media:l||void 0,removeMedia:v&&!l}),j.success("Q&A actualizado")):(p=(await T.uploadQa({question:x,answer:h,organizationId:i,media:l||void 0}))?.sourceId,j.success("Q&A agregado"),k(""),E(""),g(null)),await N.invalidateQueries({queryKey:["knowledge","sources","all"]}),t(p)}catch(p){console.error(p),j.error("Error guardando Q&A")}finally{n(!1)}};return e.jsxs("form",{onSubmit:H,className:A?"space-y-3":"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{htmlFor:"qa-question",className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:"Pregunta o intención"}),e.jsxs("div",{className:"relative",children:[e.jsx(J,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-violet-500"}),e.jsx(D,{id:"qa-question",placeholder:"Ej. ¿Cuál es el horario de atención?",className:"pl-9 bg-slate-50 dark:bg-slate-900 border-slate-200 dark:border-slate-700 focus-visible:ring-violet-500/30",value:x,onChange:r=>k(r.target.value)})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{htmlFor:"qa-answer",className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:"Respuesta del agente"}),e.jsx(ye,{id:"qa-answer",value:h,onChange:E,placeholder:"Ej. *Atendemos* de lunes a viernes de 9am a 6pm.",minHeight:"120px",defaultMode:"whatsapp"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:"Material adjunto (opcional)"}),u&&!v&&!l?e.jsxs("div",{className:"border border-slate-200 dark:border-slate-700 rounded-lg p-3 bg-slate-50 dark:bg-slate-900 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[y&&o&&!b?e.jsx("img",{src:o,alt:u,onError:()=>m(!0),className:"h-12 w-12 rounded-md object-cover border border-slate-200 dark:border-slate-700 shrink-0"}):F&&o&&!b?e.jsx("video",{src:`${o}#t=0.1`,muted:!0,preload:"metadata","aria-label":u,onError:()=>m(!0),className:"h-12 w-12 rounded-md object-cover border border-slate-200 dark:border-slate-700 shrink-0 bg-black"}):e.jsx("span",{className:"h-12 w-12 rounded-md bg-violet-500/10 flex items-center justify-center text-violet-500 shrink-0",children:(y||F||_)&&!o&&!b?e.jsx(P,{className:"h-4 w-4 animate-spin"}):_&&!b?e.jsx(re,{className:"h-5 w-5"}):e.jsx(ie,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",title:u,children:u}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Adjunto actual"})]})]}),e.jsx(U,{type:"button",size:"sm",variant:"ghost",className:"h-7 text-xs text-destructive hover:text-destructive shrink-0",onClick:()=>f(!0),children:"Quitar"})]}),_&&o&&!b&&e.jsx("audio",{src:o,controls:!0,preload:"metadata","aria-label":u,onError:()=>m(!0),className:"w-full h-9"})]}):e.jsxs(e.Fragment,{children:[u&&v&&!l&&e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground mb-1.5",children:[e.jsx("span",{children:"Se quitará el adjunto al guardar."}),e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>f(!1),children:"Deshacer"})]}),e.jsxs("div",{className:"border-2 border-dashed border-slate-200 dark:border-slate-700 rounded-lg p-4 flex items-center justify-center hover:border-violet-300 dark:hover:border-violet-800 hover:bg-violet-50/40 dark:hover:bg-violet-950/10 transition-colors relative",children:[e.jsx("input",{type:"file",className:"absolute inset-0 opacity-0 cursor-pointer disabled:cursor-not-allowed",accept:"image/*,video/*,audio/*,.pdf",disabled:S,onChange:r=>B(r.target.files?.[0]||null)}),S?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4 animate-spin text-violet-500"}),"Optimizando imagen..."]}):l?e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(R,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium truncate max-w-[220px]",children:l.name}),e.jsx(U,{type:"button",size:"sm",variant:"ghost",className:"h-6 text-xs",onClick:r=>{r.preventDefault(),g(null)},children:"Cambiar"})]}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"h-7 w-7 rounded-full bg-violet-500/10 flex items-center justify-center text-violet-500",children:e.jsx(ne,{className:"h-3.5 w-3.5"})}),u?"Subir un archivo nuevo":"Imagen, video, audio o PDF"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[w&&e.jsx(U,{type:"button",variant:"ghost",className:"flex-1",onClick:w,disabled:a,children:"Cancelar"}),e.jsx(U,{type:"submit",className:w?"flex-[2] font-medium":"w-full font-medium",disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"mr-2 h-4 w-4 animate-spin"})," Guardando..."]}):e.jsxs(e.Fragment,{children:[s?e.jsx(oe,{className:"mr-2 h-4 w-4"}):e.jsx(W,{className:"mr-2 h-4 w-4"}),$||(s?"Guardar":"Agregar Q&A")]})})]})]})}export{Qe as Q};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ay as e}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";const o=e;export{o as SelectPlanPage,e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as r,l as f}from"./index-43NA2pdZ.js";import{b as g}from"./recharts-DrC5kNsx.js";const p=[{key:"agent.name",label:"Tu nombre"},{key:"agent.email",label:"Tu email"},{key:"org.name",label:"Organización"},{key:"contact.firstName",label:"Nombre del cliente"},{key:"date.today",label:"Fecha"}];function k({value:t,onChange:a,placeholder:i="Saludos cordiales,<br>{{agent.name}}<br>{{org.name}}",className:u,disabled:s}){const l=g.useRef(null),b=e=>{const n=`{{${e}}}`,o=l.current;if(!o){a(t+n);return}const c=o.selectionStart??t.length,m=o.selectionEnd??t.length,x=t.slice(0,c)+n+t.slice(m);a(x),requestAnimationFrame(()=>{o.focus();const d=c+n.length;o.setSelectionRange(d,d)})};return r.jsxs("div",{className:f("space-y-2",u),children:[r.jsx("textarea",{ref:l,value:t,onChange:e=>a(e.target.value),placeholder:i,disabled:s,rows:4,className:"w-full resize-y rounded-md border border-border bg-card px-3 py-2 font-mono text-xs text-foreground placeholder:text-muted-foreground focus:border-blue-300 dark:focus:border-blue-900 focus:outline-none focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900/50 disabled:opacity-50"}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"text-[11px] text-muted-foreground/70",children:"Insertar variable:"}),p.map(e=>r.jsx("button",{type:"button",disabled:s,onClick:()=>b(e.key),className:"rounded-full border border-border bg-muted/30 px-2 py-0.5 text-[11px] text-muted-foreground transition-colors hover:border-blue-200 dark:hover:border-blue-900 hover:bg-blue-50 dark:hover:bg-blue-950/40 hover:text-blue-700 dark:hover:text-blue-300 disabled:opacity-50",title:`{{${e.key}}}`,children:e.label},e.key))]}),r.jsxs("p",{className:"text-[11px] leading-relaxed text-muted-foreground/70",children:["Admite HTML simple (",r.jsx("code",{children:"<br>"}),", ",r.jsx("code",{children:"<b>"}),", enlaces). Se añade automáticamente al final de cada correo que envíes; las variables se completan al enviar."]})]})}export{k as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as
|
|
1
|
+
import{c as I,j as e,B as o,a9 as L,S as G,I as N,l as c,D as d,ai as J,a7 as Q,X as P}from"./index-43NA2pdZ.js";import{b as r}from"./recharts-DrC5kNsx.js";import{P as Y,a as U,b as ee}from"./popover-cWIhNmod.js";import{F as O}from"./folder-DxTHNhQ_.js";const se=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],ae=I("folder-plus",se);const te=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],ce=I("minimize-2",te),D=["#3B82F6","#10B981","#F59E0B","#EF4444","#8B5CF6","#EC4899","#06B6D4","#F97316"];function ie({selectedTags:v,folders:i,onToggleTag:b,onCreateTag:m,onCreateFolder:p,disabled:_=!1,trigger:R,showUntaggedOption:A=!1,isUntaggedSelected:g=!1,onToggleUntagged:K,showSystemTags:w=!1}){const[T,V]=r.useState(!1),[l,H]=r.useState(""),[y,W]=r.useState(new Set),[X,u]=r.useState(!1),[Z,h]=r.useState(!1),[j,C]=r.useState(""),[f,k]=r.useState(""),[F,S]=r.useState(void 0),E=r.useMemo(()=>new Set(v.map(s=>s.id)),[v]),M=r.useMemo(()=>{const s=i.map(a=>({...a,tags:w?a.tags:a.tags.filter(t=>!t.readOnly&&!t.isSystem)})).filter(a=>a.tags.length>0||a.id==="unassigned");return l.trim()?s.map(a=>({...a,tags:a.tags.filter(t=>t.name.toLowerCase().includes(l.toLowerCase()))})).filter(a=>a.tags.length>0||a.id==="unassigned"):s},[i,l,w]),z=r.useMemo(()=>i.filter(s=>s.id!=="unassigned"),[i]),$=r.useCallback(s=>{W(a=>{const t=new Set(a);return t.has(s)?t.delete(s):t.add(s),t})},[]),q=async()=>{if(!(!j.trim()||!m))try{await m(j.trim(),F),C(""),S(void 0),u(!1)}catch(s){console.error("Error creating tag:",s)}},B=async()=>{if(!(!f.trim()||!p))try{const s=D[Math.floor(Math.random()*D.length)];await p(f.trim(),s),k(""),h(!1)}catch(s){console.error("Error creating folder:",s)}};return e.jsxs(Y,{open:T,onOpenChange:V,children:[e.jsx(U,{asChild:!0,disabled:_,children:R||e.jsxs(o,{variant:"outline",size:"sm",className:"text-primary hover:text-primary/80 border-dashed",children:[e.jsx(L,{className:"h-3 w-3 mr-1"}),"Añadir etiqueta"]})}),e.jsxs(ee,{className:"w-80 flex flex-col max-h-[450px] p-0 overflow-hidden shadow-xl",align:"start",sideOffset:8,children:[e.jsx("div",{className:"p-2 border-b",children:e.jsxs("div",{className:"relative",children:[e.jsx(G,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(N,{placeholder:"Buscar etiqueta...",value:l,onChange:s=>H(s.target.value),className:"pl-8 h-8"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 max-h-[300px] scrollbar-thin scrollbar-thumb-muted-foreground/20 pointer-events-auto",onWheel:s=>s.stopPropagation(),children:e.jsx("div",{className:"p-1",children:l.trim()?e.jsx(e.Fragment,{children:(()=>{const s=l.toLowerCase(),a=[];return i.forEach(t=>{t.tags.filter(n=>n.name.toLowerCase().includes(s)).forEach(n=>a.push({tag:n,folder:t}))}),a.length===0?e.jsxs("div",{className:"py-8 text-center text-sm text-muted-foreground",children:[e.jsx("p",{children:"No se encontraron etiquetas"}),m&&e.jsxs("p",{className:"text-xs opacity-70 mt-1",children:['Puedes crear "',l,'" abajo']})]}):a.map(({tag:t,folder:x})=>{const n=E.has(t.id);return e.jsxs("button",{onClick:()=>b(t),className:c("flex items-center gap-2 w-full px-2 py-2 text-sm rounded-md hover:bg-accent transition-colors group mb-0.5",n&&"bg-accent/80"),children:[e.jsx("div",{className:c("w-4 h-4 rounded-sm flex items-center justify-center border transition-all flex-shrink-0",n?"border-transparent text-white shadow-sm":"border-muted-foreground/30 bg-muted/10 group-hover:border-muted-foreground/50"),style:n?{backgroundColor:t.color}:{},children:n&&e.jsx(d,{className:"h-3 w-3"})}),e.jsxs("div",{className:"flex-1 text-left flex items-center justify-between min-w-0 gap-3",children:[e.jsx("span",{className:c("truncate font-medium",n?"text-foreground":"text-muted-foreground group-hover:text-foreground"),children:t.name}),x.id!=="unassigned"&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0 bg-muted/50 px-2 py-0.5 rounded-full border border-border/50",children:[e.jsx(O,{className:"h-2.5 w-2.5",style:{color:x.color}}),e.jsx("span",{className:"text-[10px] text-muted-foreground truncate max-w-[80px]",children:x.name})]})]})]},t.id)})})()}):e.jsxs(e.Fragment,{children:[A&&e.jsxs("div",{className:"mb-1",children:[e.jsxs("button",{onClick:()=>K?.(!g),className:c("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent transition-colors",g&&"bg-accent font-medium"),children:[e.jsx("div",{className:"w-3 h-3 rounded-sm flex items-center justify-center border border-dashed border-muted-foreground/50 bg-muted/20",children:g&&e.jsx(d,{className:"h-2.5 w-2.5 text-primary"})}),e.jsx("span",{className:"flex-1 text-left text-muted-foreground/80",children:"Sin etiquetas"})]}),e.jsx("div",{className:"px-2 py-1",children:e.jsx("div",{className:"h-px bg-border/40"})})]}),M.map(s=>e.jsxs("div",{className:"mb-1",children:[s.id!=="unassigned"&&e.jsxs("button",{onClick:()=>$(s.id),className:"flex items-center gap-2 w-full px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent rounded",children:[y.has(s.id)?e.jsx(J,{className:"h-3 w-3"}):e.jsx(Q,{className:"h-3 w-3"}),e.jsx(O,{className:"h-3 w-3",style:{color:s.color}}),e.jsx("span",{className:"font-medium truncate",children:s.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-auto bg-muted/50 px-1.5 rounded-sm",children:s.tags?.length||0})]}),(s.id==="unassigned"||y.has(s.id))&&s.tags.map(a=>{const t=E.has(a.id);return e.jsxs("button",{onClick:()=>b(a),className:c("flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded hover:bg-accent group",s.id!=="unassigned"&&"pl-7",t&&"bg-accent"),children:[e.jsx("div",{className:c("w-3 h-3 rounded-sm flex items-center justify-center transition-all",t?"text-white shadow-sm":"border border-muted-foreground/30 bg-muted/10 group-hover:border-muted-foreground/50"),style:t?{backgroundColor:a.color}:{},children:t&&e.jsx(d,{className:"h-2.5 w-2.5"})}),e.jsx("span",{className:"flex-1 text-left truncate",children:a.name})]},a.id)})]},s.id)),M.every(s=>s.tags.length===0)&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-4",children:"No hay etiquetas disponibles"})]})})}),e.jsx("div",{className:"p-2 border-t space-y-2",children:X?e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{placeholder:"Nombre de etiqueta...",value:j,onChange:s=>C(s.target.value),className:"h-8 text-sm",autoFocus:!0,onKeyDown:s=>{s.key==="Enter"&&q(),s.key==="Escape"&&u(!1)}}),z.length>0&&e.jsxs("select",{value:F||"",onChange:s=>S(s.target.value||void 0),className:"w-full h-8 text-sm border rounded-md px-2 bg-background",children:[e.jsx("option",{value:"",children:"Sin carpeta"}),z.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(o,{size:"sm",className:"flex-1 h-8",onClick:q,children:[e.jsx(d,{className:"h-3 w-3 mr-1"}),"Crear"]}),e.jsx(o,{size:"sm",variant:"ghost",className:"h-8",onClick:()=>u(!1),children:e.jsx(P,{className:"h-3 w-3"})})]})]}):Z?e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{placeholder:"Nombre de carpeta...",value:f,onChange:s=>k(s.target.value),className:"h-8 text-sm",autoFocus:!0,onKeyDown:s=>{s.key==="Enter"&&B(),s.key==="Escape"&&h(!1)}}),e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(o,{size:"sm",className:"flex-1 h-8",onClick:B,children:[e.jsx(d,{className:"h-3 w-3 mr-1"}),"Crear carpeta"]}),e.jsx(o,{size:"sm",variant:"ghost",className:"h-8",onClick:()=>h(!1),children:e.jsx(P,{className:"h-3 w-3"})})]})]}):e.jsxs("div",{className:"space-y-1",children:[m&&e.jsxs(o,{variant:"ghost",size:"sm",className:"w-full justify-start text-primary",onClick:()=>u(!0),children:[e.jsx(L,{className:"h-3 w-3 mr-2"}),"Crear nueva etiqueta"]}),p&&e.jsxs(o,{variant:"ghost",size:"sm",className:"w-full justify-start text-muted-foreground",onClick:()=>h(!0),children:[e.jsx(ae,{className:"h-3 w-3 mr-2"}),"Crear nueva carpeta"]})]})})]})]})}export{ce as M,ie as T};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as Is,i as re,O as q,t as E,j as e,a1 as J,a2 as ee,a3 as se,a4 as z,a5 as Q,n as B,I as ae,l as S,aa as _,B as p,o as F,w as ye,aB as Ps,a as Se,g as be,S as Ve,Z as Le,T as Oe,s as Re,ar as Je,v as Ue,r as Ce,al as Be,am as _e,ai as Ls,an as Ge,ao as es,ap as ss,aq as Z,X as Os,a8 as Rs,bi as ds,b5 as Us,R as zs,A as ze,q as cs,U as as,a0 as Bs,aC as _s,a7 as Gs,a9 as xs,E as $s}from"./index-43NA2pdZ.js";import{b as d,g as Ks,A as Vs,C as Qs,X as Hs,Y as Ws,T as Xs,h as Ys}from"./recharts-DrC5kNsx.js";import{T as Zs,a as Js,b as je,c as Ne}from"./tabs-BGCKrmVw.js";import{P as ea,a as sa,b as aa}from"./page-components-DXOKtt_M.js";import{u as I}from"./useMutation-0ypmz8SO.js";import{C as ts}from"./checkbox-CuJh5AMO.js";import{S as qe,a as De,b as Ae,c as Fe,d as R}from"./select-DCY_lg9j.js";import{T as ta,a as ra,b as rs,c as xe,d as la,e as me}from"./table-7NGq0kRw.js";import{S as H}from"./skeleton-CN6xlRXP.js";import{T as na}from"./textarea-B1anutjq.js";import{P as ms,a as hs,b as us}from"./popover-cWIhNmod.js";import{T as te,M as $e,A as ia}from"./tags-HU2fuPFH.js";import{G as gs}from"./grip-vertical-CS-dU0tJ.js";import{T as Ee}from"./trending-up-BnHeLWFs.js";import{P as Ke}from"./pencil-aqjc7AWb.js";import{E as oa}from"./eye-CR5C6hVv.js";import{T as O}from"./trash-2-D_kmHMwn.js";import{F as Te}from"./folder-DxTHNhQ_.js";import{F as Qe}from"./folder-open-BM4rA96e.js";import{A as da,b as ca}from"./alert-seLKo73M.js";import{E as xa}from"./ellipsis-vertical-CskGwbgN.js";import{a as L}from"./datetime-D72Uxhjs.js";import{C as K,a as V}from"./card-DdbmSh-v.js";import{C as ls}from"./calendar-Bu0aDtW1.js";import{D as ma}from"./download-CyfdxFCW.js";import{H as ha}from"./hash-ByrjK6gt.js";import{T as ua}from"./target-CG_g4_Fj.js";import{H as ps}from"./history-97D1GT_9.js";import{A as ns}from"./arrow-up-down-DkSCsCjR.js";import{P as is}from"./pen-line-Cr0YFjAs.js";import"./index-KbFmSzBE.js";const ga=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],bs=Is("palette",ga),ve=[{value:"#3B82F6",label:"Azul"},{value:"#10B981",label:"Verde"},{value:"#F59E0B",label:"Ámbar"},{value:"#EF4444",label:"Rojo"},{value:"#8B5CF6",label:"Púrpura"},{value:"#EC4899",label:"Rosa"},{value:"#06B6D4",label:"Cian"},{value:"#F97316",label:"Naranja"},{value:"#64748B",label:"Slate"},{value:"#000000",label:"Negro"}],we=["#3B82F6","#10B981","#F59E0B","#EF4444","#8B5CF6","#EC4899","#06B6D4","#F97316"];function fs({open:u,onOpenChange:x,tag:i,folders:j}){const v=re(),l=!!i,[N,a]=d.useState(""),[m,g]=d.useState(""),[h,w]=d.useState("#3B82F6"),[k,r]=d.useState("");d.useEffect(()=>{u&&(i?(a(i.name),g(i.description||""),w(i.color||"#3B82F6"),r(i.folderId||"")):(a(""),g(""),w("#3B82F6"),r("")))},[u,i]);const y=I({mutationFn:o=>q.createTag(o),onSuccess:()=>{v.invalidateQueries({queryKey:["tags"]}),E.success("Etiqueta creada"),x(!1)},onError:()=>{E.error("Error al crear la etiqueta. El nombre ya existe.")}}),C=I({mutationFn:o=>q.updateTag(i.id,o),onSuccess:()=>{v.invalidateQueries({queryKey:["tags"]}),E.success("Etiqueta actualizada"),x(!1)},onError:()=>{E.error("Error al actualizar la etiqueta")}}),t=()=>{if(!N.trim()){E.error("El nombre es requerido");return}const o={name:N.trim(),description:m.trim()||void 0,color:h,folderId:k||void 0};l?C.mutate({...o,description:o.description||null,folderId:o.folderId||null}):y.mutate(o)},b=y.isPending||C.isPending;return e.jsx(J,{open:u,onOpenChange:x,children:e.jsxs(ee,{className:"sm:max-w-[450px]",children:[e.jsxs(se,{children:[e.jsx(z,{children:l?"Editar etiqueta":"Nueva etiqueta"}),e.jsx(Q,{children:l?"Modifica los datos de la etiqueta.":"Crea una nueva etiqueta para organizar tus contactos."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"tag-name",children:"Nombre *"}),e.jsx(ae,{id:"tag-name",value:N,onChange:o=>a(o.target.value),placeholder:"Ej: VIP, Reclamo, Nuevo",maxLength:100}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Puedes usar emojis: "🔥 VIP", "⚠️ Reclamo"'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"tag-description",children:"Descripción (opcional)"}),e.jsx(na,{id:"tag-description",value:m,onChange:o=>g(o.target.value),placeholder:"Explica cuándo usar esta etiqueta...",rows:3,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[m.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:"Color"}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[ve.map(o=>e.jsx("button",{type:"button",onClick:()=>w(o.value),className:S("w-8 h-8 rounded-md border-2 transition-all",h===o.value?"border-slate-900 dark:border-white scale-110":"border-transparent hover:scale-105"),style:{backgroundColor:o.value},title:o.label},o.value)),e.jsxs(ms,{children:[e.jsx(hs,{asChild:!0,children:e.jsx("button",{type:"button",className:S("w-8 h-8 rounded-md border-2 transition-all flex items-center justify-center",ve.find(o=>o.value===h)?"border-dashed border-slate-300 hover:border-slate-400":"border-slate-900 dark:border-white scale-110"),style:{backgroundColor:ve.find(o=>o.value===h)?"transparent":h},children:ve.find(o=>o.value===h)&&e.jsx(bs,{className:"h-4 w-4 text-slate-400"})})}),e.jsx(us,{className:"w-auto p-3",align:"start",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{className:"text-xs",children:"Color personalizado"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:h,onChange:o=>w(o.target.value),className:"w-10 h-10 rounded cursor-pointer border-0 p-0"}),e.jsx(ae,{value:h,onChange:o=>{const A=o.target.value;/^#[0-9A-Fa-f]{0,6}$/.test(A)&&w(A)},placeholder:"#3B82F6",className:"w-24 font-mono text-sm",maxLength:7})]})]})})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:"Carpeta (opcional)"}),e.jsxs(qe,{value:k,onValueChange:r,children:[e.jsx(De,{children:e.jsx(Ae,{placeholder:"Sin carpeta"})}),e.jsxs(Fe,{children:[e.jsx(R,{value:"none",children:"Sin carpeta"}),j.map(o=>e.jsx(R,{value:o.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:o.color}}),o.name]})},o.id))]})]})]})]}),e.jsxs(_,{children:[e.jsx(p,{variant:"outline",onClick:()=>x(!1),children:"Cancelar"}),e.jsxs(p,{onClick:t,disabled:b||!N.trim(),children:[b&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),l?"Guardar cambios":"Crear etiqueta"]})]})]})})}function pa({open:u,onOpenChange:x,sourceTag:i,allTags:j}){const v=re(),[l,N]=d.useState(""),a=I({mutationFn:({sourceId:h,targetId:w})=>q.mergeTags(h,w),onSuccess:h=>{v.invalidateQueries({queryKey:["tags"]}),E.success(`Fusión exitosa: ${h.transferred} contactos transferidos`),x(!1),N("")},onError:h=>{E.error(h.response?.data?.message||"Error al fusionar etiquetas")}}),m=()=>{!i||!l||a.mutate({sourceId:i.id,targetId:l})},g=j.filter(h=>h.id!==i?.id);return e.jsx(J,{open:u,onOpenChange:x,children:e.jsxs(ee,{className:"sm:max-w-[450px]",children:[e.jsxs(se,{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(ye,{className:"h-5 w-5 text-amber-500"}),"Fusionar etiquetas"]}),e.jsx(Q,{children:"Esta acción transferirá todos los contactos de una etiqueta a otra y luego eliminará la etiqueta original."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex flex-col items-center flex-1 text-center",children:[e.jsx("span",{className:"text-[10px] uppercase text-muted-foreground font-semibold mb-1",children:"Origen"}),e.jsx("div",{className:"px-3 py-1 rounded-full text-white text-sm font-medium w-full truncate",style:{backgroundColor:i?.color},children:i?.name})]}),e.jsx(Ps,{className:"h-5 w-5 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"flex flex-col items-center flex-1 text-center",children:[e.jsx("span",{className:"text-[10px] uppercase text-muted-foreground font-semibold mb-1",children:"Destino"}),l?e.jsx("div",{className:"px-3 py-1 rounded-full text-white text-sm font-medium w-full truncate",style:{backgroundColor:j.find(h=>h.id===l)?.color},children:j.find(h=>h.id===l)?.name}):e.jsx("div",{className:"px-3 py-1 rounded-full border-2 border-dashed border-slate-300 text-slate-400 text-sm w-full",children:"Seleccionar..."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:"Selecciona la etiqueta de destino"}),e.jsxs(qe,{value:l,onValueChange:N,children:[e.jsx(De,{children:e.jsx(Ae,{placeholder:"Buscar etiqueta de destino..."})}),e.jsx(Fe,{children:g.map(h=>e.jsx(R,{value:h.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:h.color}}),h.name]})},h.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Los contactos que ya tengan ambas etiquetas no se duplicarán."})]})]}),e.jsxs(_,{children:[e.jsx(p,{variant:"outline",onClick:()=>x(!1),children:"Cancelar"}),e.jsxs(p,{onClick:m,disabled:!l||a.isPending,children:[a.isPending&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),"Fusionar etiquetas"]})]})]})})}const ba=({totalTags:u,foldersCount:x,totalUsage:i,isLoading:j,isLoadingUsage:v,onFetchUsage:l})=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-white dark:bg-slate-900 p-5 rounded-[24px] border border-slate-100 dark:border-slate-800 shadow-sm flex items-center gap-5 group hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-indigo-50 dark:bg-indigo-900/10 flex items-center justify-center shrink-0 group-hover:scale-110 transition-transform duration-300",children:e.jsx(te,{className:"w-6 h-6 text-indigo-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-black text-slate-900 dark:text-white leading-none tracking-tighter",children:j?"...":u}),e.jsx("p",{className:"text-[11px] uppercase font-black text-slate-400 mt-2 tracking-widest",children:"Total Etiquetas"})]})]}),e.jsxs("div",{className:"bg-white dark:bg-slate-900 p-5 rounded-[24px] border border-slate-100 dark:border-slate-800 shadow-sm flex items-center justify-between group hover:shadow-lg transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-purple-50 dark:bg-purple-900/10 flex items-center justify-center shrink-0 group-hover:scale-110 transition-transform duration-300",children:e.jsx(Ee,{className:"w-6 h-6 text-purple-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-black text-slate-900 dark:text-white leading-none tracking-tighter",children:v?e.jsx(F,{className:"w-6 h-6 animate-spin text-slate-300"}):i?i.toLocaleString():"---"}),e.jsx("p",{className:"text-[11px] uppercase font-black text-slate-400 mt-2 tracking-widest",children:"Uso Total"})]})]}),!i&&!v&&e.jsx(p,{variant:"ghost",size:"sm",onClick:l,className:"rounded-xl font-bold text-[10px] uppercase tracking-wider text-primary hover:bg-primary/5 px-3",children:"Calcular"}),i>0&&e.jsx(p,{variant:"ghost",size:"icon",onClick:l,disabled:v,className:"h-8 w-8 rounded-full text-slate-400 hover:text-primary transition-colors",children:e.jsx(F,{className:S("w-4 h-4",v&&"animate-spin")})})]}),e.jsxs("div",{className:"bg-white dark:bg-slate-900 p-5 rounded-[24px] border border-slate-100 dark:border-slate-800 shadow-sm flex items-center gap-5 group hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-emerald-50 dark:bg-emerald-900/10 flex items-center justify-center shrink-0 group-hover:scale-110 transition-transform duration-300",children:e.jsx(Qe,{className:"w-6 h-6 text-emerald-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-black text-slate-900 dark:text-white leading-none tracking-tighter",children:j?"...":x}),e.jsx("p",{className:"text-[11px] uppercase font-black text-slate-400 mt-2 tracking-widest",children:"Carpetas"})]})]})]});function fa(){const u=re(),[x,i]=d.useState(""),[j,v]=d.useState("all"),[l,N]=d.useState(null),[a,m]=d.useState(!1),[g,h]=d.useState(new Set),[w,k]=d.useState(!1),[r,y]=d.useState(null),[C,t]=d.useState(null),[b,o]=d.useState(null),[A,D]=d.useState(null),[n,T]=d.useState(10),[W,G]=d.useState(!1),[le,ne]=d.useState(!1),[ie,M]=d.useState(null),[P,oe]=d.useState(1),Me=15,He=Se(s=>s.user),de=He?.role==="OWNER"||He?.role==="ADMIN",{data:ce=[],isLoading:Ie}=be({queryKey:["tags","folders"],queryFn:()=>q.getFoldersWithTags(),staleTime:300*1e3});d.useEffect(()=>{C?(l?.[C.id]||0)>0?(T(10),G(!0)):G(!1):w&&Array.from(g).some(c=>(l?.[c]||0)>0)?(T(10),G(!0)):G(!1)},[C,w,g,l]),d.useEffect(()=>{let s;return W&&n>0&&(s=setTimeout(()=>T(c=>c-1),1e3)),()=>clearTimeout(s)},[W,n]);const Ns=async()=>{m(!0);try{const s=await q.getTagUsageCounts();N(s),E.success("Estadísticas actualizadas")}catch(s){console.error("Error fetching usage counts",s),E.error("Error al calcular estadísticas")}finally{m(!1)}},he=d.useMemo(()=>ce.flatMap(s=>s.tags||[]),[ce]),vs=d.useMemo(()=>l?Object.values(l).reduce((s,c)=>s+c,0):0,[l]),U=d.useMemo(()=>{let s=he;if(x){const c=x.toLowerCase();s=s.filter(f=>f.name.toLowerCase().includes(c)||f.description?.toLowerCase().includes(c))}return j!=="all"&&(j==="unassigned"?s=s.filter(c=>!c.folderId):s=s.filter(c=>c.folderId===j)),x?s.sort((c,f)=>c.name.localeCompare(f.name)):s.sort((c,f)=>(c.position||0)-(f.position||0)||c.name.localeCompare(f.name))},[he,x,j]),ue=d.useMemo(()=>{const s=(P-1)*Me;return U.slice(s,s+Me)},[U,P]),$=Math.ceil(U.length/Me);d.useEffect(()=>{P>$&&$>0?oe($):P<1&&oe(1)},[$,P]);const fe=d.useMemo(()=>ce.filter(s=>s.id!=="unassigned").sort((s,c)=>(s.position||0)-(c.position||0)||s.name.localeCompare(c.name)),[ce]),X=I({mutationFn:s=>q.deleteTag(s),onSuccess:()=>{u.invalidateQueries({queryKey:["tags"]}),E.success("Etiqueta eliminada"),t(null)},onError:()=>{E.error("Error al eliminar la etiqueta")}}),Y=I({mutationFn:s=>q.deleteTags(s),onSuccess:s=>{u.invalidateQueries({queryKey:["tags"]}),E.success(`${s.deleted} etiquetas eliminadas`),h(new Set),k(!1)},onError:()=>{E.error("Error al eliminar las etiquetas")}}),ws=I({mutationFn:s=>q.reorderTags(s),onSuccess:()=>{u.invalidateQueries({queryKey:["tags"]})},onError:()=>{E.error("Error al reordenar etiquetas")}}),We=I({mutationFn:({tagIds:s,folderId:c})=>q.bulkMoveTags(s,c),onSuccess:s=>{u.invalidateQueries({queryKey:["tags"]}),E.success(`${s.moved} etiquetas movidas`),h(new Set)},onError:()=>{E.error("Error al mover las etiquetas")}}),ks=(s,c)=>{x||(M(c),s.dataTransfer.effectAllowed="move")},ys=s=>{s.preventDefault(),s.dataTransfer.dropEffect="move"},Cs=(s,c)=>{if(s.preventDefault(),!ie||ie===c){M(null);return}const f=U.findIndex(ge=>ge.id===ie),Ze=U.findIndex(ge=>ge.id===c);if(f===-1||Ze===-1){M(null);return}const Pe=[...U],[As]=Pe.splice(f,1);Pe.splice(Ze,0,As);const Fs=Pe.map((ge,Ms)=>({id:ge.id,position:Ms}));ws.mutate(Fs),M(null)},Es=()=>{M(null)},Ts=()=>{const s=ue.filter(f=>!f.readOnly);s.filter(f=>g.has(f.id)).length===s.length&&s.length>0?h(new Set):h(new Set(s.map(f=>f.id)))},Ss=s=>{const c=new Set(g);c.has(s)?c.delete(s):c.add(s),h(c)},qs=async s=>{ne(!0),t(s);try{const{count:c}=await q.getTagUsage(s.id);N(f=>({...f||{},[s.id]:c}))}catch(c){console.error("Error fetching tag usage",c)}finally{ne(!1)}},Ds=async()=>{const s=Array.from(g);ne(!0),k(!0);try{const c=await q.getBulkTagUsage(s);N(f=>({...f||{},...c}))}catch(c){console.error("Error fetching bulk tag usage",c)}finally{ne(!1)}},Xe=s=>s&&ce.find(f=>f.id===s)?.name||"Sin carpeta",Ye=s=>s&&ce.find(f=>f.id===s)?.color||"#94a3b8";return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ba,{totalTags:he.length,foldersCount:fe.length,totalUsage:vs,isLoading:Ie,isLoadingUsage:a,onFetchUsage:Ns}),e.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 transition-all duration-300",children:[e.jsx("div",{className:"p-4 bg-slate-50/30 dark:bg-slate-800/20 backdrop-blur-md border-b border-slate-100 dark:border-slate-800",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ve,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(ae,{placeholder:"Buscar etiquetas por nombre o descripción...",value:x,onChange:s=>{i(s.target.value),oe(1)},className:"h-11 pl-11 bg-white dark:bg-slate-950 border-none rounded-2xl text-sm focus-visible:ring-1 focus-visible:ring-primary/20 transition-all font-medium"})]}),e.jsx("div",{className:"flex gap-3 items-center",children:e.jsxs(qe,{value:j,onValueChange:s=>{v(s),oe(1)},children:[e.jsx(De,{className:"h-11 w-full md:w-[220px] bg-white dark:bg-slate-950 border-none rounded-2xl text-[13px] font-medium shadow-sm transition-all",children:e.jsx(Ae,{placeholder:"Filtrar por carpeta"})}),e.jsxs(Fe,{className:"rounded-2xl border-slate-100 shadow-2xl",children:[e.jsx(R,{value:"all",className:"rounded-xl",children:"Todas las carpetas"}),e.jsx(R,{value:"unassigned",className:"rounded-xl",children:"Sin carpeta"}),fe.map(s=>e.jsx(R,{value:s.id,className:"rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:s.color}}),s.name]})},s.id))]})]})})]})}),e.jsx("div",{className:"overflow-x-auto no-scrollbar",children:Ie?e.jsx("div",{className:"p-8 space-y-4 animate-pulse",children:Array.from({length:6}).map((s,c)=>e.jsx(H,{className:"h-16 w-full rounded-2xl"},c))}):U.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center animate-in fade-in duration-500",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:e.jsx(te,{className:"h-10 w-10 text-slate-300"})}),e.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2 tracking-tight",children:"Sin etiquetas"}),e.jsx("p",{className:"text-slate-500 max-w-sm mx-auto text-sm leading-relaxed",children:"No encontramos ninguna etiqueta que coincida con tus filtros."}),e.jsx(p,{variant:"outline",className:"mt-8 rounded-full px-8 font-bold border-slate-200",onClick:()=>{i(""),v("all")},children:"Resetear Filtros"})]}):e.jsxs(ta,{children:[e.jsx(ra,{children:e.jsxs(rs,{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:[e.jsx(xe,{className:"w-[50px] pl-6 py-6"}),de&&e.jsx(xe,{className:"w-[50px] py-6",children:e.jsx(ts,{checked:g.size===ue.length&&ue.length>0,onCheckedChange:Ts,className:"data-[state=checked]:bg-primary rounded-[6px]"})}),e.jsx(xe,{className:"py-6 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Etiqueta"}),e.jsx(xe,{className:"py-6 font-black uppercase text-[10px] tracking-widest text-slate-400",children:"Carpeta"}),e.jsx(xe,{className:"py-6 font-black uppercase text-[10px] tracking-widest text-slate-400 text-center",children:"Uso Total"}),de&&e.jsx(xe,{className:"w-[80px] pr-6"})]})}),e.jsx(la,{children:ue.map((s,c)=>e.jsxs(rs,{className:S("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",g.has(s.id)&&"bg-primary/5 dark:bg-primary/10 hover:bg-primary/10",ie===s.id&&"opacity-50 ring-2 ring-primary ring-inset"),draggable:!x&&de&&!s.readOnly,onDragStart:f=>ks(f,s.id),onDragOver:ys,onDrop:f=>Cs(f,s.id),onDragEnd:Es,onClick:()=>o(s),children:[e.jsx(me,{className:"pl-6 py-4",onClick:f=>f.stopPropagation(),children:de&&!s.readOnly&&e.jsx(gs,{className:"h-4 w-4 text-slate-300 opacity-0 group-hover:opacity-100 transition-opacity cursor-grab active:cursor-grabbing"})}),de&&e.jsx(me,{className:"py-4",onClick:f=>f.stopPropagation(),children:e.jsx(ts,{checked:g.has(s.id),onCheckedChange:()=>Ss(s.id),disabled:s.readOnly,className:S("data-[state=checked]:bg-primary rounded-[6px]",s.readOnly&&"opacity-50 cursor-not-allowed")})}),e.jsx(me,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-[14px] shadow-sm flex items-center justify-center text-white shrink-0 group-hover:scale-105 transition-transform duration-300",style:{backgroundColor:s.color},children:e.jsx(te,{className:"h-5 w-5 opacity-90"})}),e.jsxs("div",{className:"min-w-0 flex flex-col",children:[e.jsxs("span",{className:"font-black text-slate-900 dark:text-white truncate text-sm leading-tight group-hover:text-primary transition-colors flex items-center gap-2",children:[s.name,s.isSystem&&e.jsx(Le,{children:e.jsxs(Oe,{children:[e.jsx(Re,{children:e.jsx(Je,{className:"w-3 h-3 text-amber-500/70"})}),e.jsx(Ue,{children:"Etiqueta del sistema"})]})})]}),e.jsx("span",{className:"text-[11px] text-slate-400 font-bold tracking-tight truncate max-w-[280px] mt-1",children:s.description||"Sin descripción"})]})]})}),e.jsx(me,{className:"py-4",children:e.jsxs(Ce,{variant:"outline",className:"h-7 gap-2 px-3 rounded-full bg-white dark:bg-slate-900 font-bold border-slate-100 dark:border-slate-800 shadow-sm",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shadow-sm",style:{backgroundColor:Ye(s.folderId)}}),e.jsx("span",{className:"text-[11px] text-slate-600 dark:text-slate-300 capitalize",children:Xe(s.folderId)})]})}),e.jsx(me,{className:"text-center py-4",children:e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 bg-indigo-50/50 dark:bg-indigo-900/20 rounded-lg group/usage",children:[e.jsx(Ee,{className:"w-3.5 h-3.5 text-indigo-500 group-hover/usage:translate-y-[-1px] transition-transform"}),e.jsx("span",{className:"font-black text-sm text-indigo-600 dark:text-indigo-400",children:l&&typeof l[s.id]=="number"?l[s.id]:"---"})]})}),de&&e.jsx(me,{className:"py-4 text-right pr-6",onClick:f=>f.stopPropagation(),children:s.readOnly?e.jsx("div",{className:"flex items-center justify-end pr-2 opacity-50",children:e.jsx(Le,{children:e.jsxs(Oe,{children:[e.jsx(Re,{children:e.jsx(Je,{className:"w-4 h-4 text-slate-300"})}),e.jsx(Ue,{children:e.jsx("p",{children:"Etiqueta de sistema protegida"})})]})})}):e.jsxs("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:[e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-primary hover:text-white transition-all shadow-sm",onClick:()=>y(s),title:"Editar",children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsxs(Be,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-slate-200/50",children:e.jsx(Ls,{className:"h-4 w-4 text-slate-400"})})}),e.jsxs(Ge,{align:"end",className:"w-52 p-2 rounded-2xl shadow-2xl border-slate-100",children:[e.jsx(es,{className:"text-[10px] uppercase font-black tracking-widest text-slate-400 p-2",children:"Más Opciones"}),e.jsx(ss,{className:"bg-slate-50"}),e.jsxs(Z,{onClick:()=>o(s),className:"rounded-xl p-2.5 font-bold text-sm",children:[e.jsx(oa,{className:"mr-3 h-4 w-4 text-slate-400"})," Ver Detalles"]}),e.jsxs(Z,{onClick:()=>D(s),className:"rounded-xl p-2.5 font-bold text-sm text-amber-600 focus:text-amber-700 focus:bg-amber-50",children:[e.jsx($e,{className:"mr-3 h-4 w-4"})," Fusionar Etiqueta"]}),e.jsxs(Z,{onClick:f=>{f.stopPropagation(),qs(s)},className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50",children:[e.jsx(O,{className:"mr-3 h-4 w-4"})," Eliminar Definitivamente"]})]})]})]})})]},s.id))})]})}),!Ie&&U.length>0&&e.jsxs("div",{className:"px-8 py-5 bg-slate-50/40 dark:bg-slate-800/30 border-t border-slate-100 dark:border-slate-800 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest",children:["Página ",e.jsx("span",{className:"text-slate-900 dark:text-white",children:P})," de ",e.jsx("span",{className:"text-slate-900 dark:text-white",children:$||1})]}),e.jsx("div",{className:"h-4 w-[1px] bg-slate-200 dark:bg-slate-700"}),e.jsxs("span",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest",children:["Mostrando ",e.jsx("span",{className:"text-primary",children:ue.length})," / ",e.jsx("span",{className:"text-slate-900 dark:text-white",children:U.length})," Etiquetas"]})]}),$>1&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx(p,{variant:"outline",size:"sm",onClick:()=>oe(s=>Math.max(1,s-1)),disabled:P===1,className:"h-10 px-5 rounded-xl font-black text-[11px] uppercase tracking-wider border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 transition-all shadow-sm",children:"Anterior"}),e.jsx(p,{variant:"outline",size:"sm",onClick:()=>oe(s=>Math.min($,s+1)),disabled:P===$,className:"h-10 px-5 rounded-xl font-black text-[11px] uppercase tracking-wider border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 transition-all shadow-sm",children:"Siguiente"})]})]})]}),e.jsx(fs,{open:!!r,onOpenChange:s=>!s&&y(null),tag:r,folders:fe}),e.jsx(pa,{open:!!A,onOpenChange:s=>!s&&D(null),sourceTag:A,allTags:he}),e.jsx(J,{open:!!C,onOpenChange:s=>!s&&!X.isPending&&t(null),children:e.jsx(ee,{className:S("sm:max-w-[480px] p-0 overflow-hidden border-none shadow-2xl rounded-3xl transition-all duration-300",W?"scale-[1.02]":"scale-100"),children:le?e.jsxs("div",{className:"p-20 flex flex-col items-center justify-center bg-white dark:bg-slate-900",children:[e.jsx(F,{className:"w-12 h-12 animate-spin text-rose-500 mb-6"}),e.jsx("p",{className:"text-sm font-black text-slate-400 uppercase tracking-widest animate-pulse",children:"Verificando uso de etiqueta..."})]}):l&&C&&l[C.id]>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-rose-500 p-8 text-white flex flex-col items-center gap-4 text-center",children:[e.jsx("div",{className:"p-4 bg-white/20 rounded-2xl backdrop-blur-md animate-pulse",children:e.jsx(ye,{className:"w-10 h-10 text-white"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(z,{className:"text-2xl font-black tracking-tight text-white uppercase italic",children:"¡Atención Crítica!"}),e.jsx(Q,{className:"text-white/90 font-medium",children:"Esta etiqueta está en uso activo por tus contactos."})]})]}),e.jsxs("div",{className:"p-8 space-y-6 bg-white dark:bg-slate-900",children:[e.jsx("div",{className:"p-5 rounded-2xl border-2 border-rose-100 dark:border-rose-900/30 bg-rose-50/30 dark:bg-rose-950/20 space-y-4",children:e.jsxs("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 leading-relaxed text-center",children:["Eliminar ",e.jsxs("strong",{className:"text-rose-600 dark:text-rose-400",children:['"',C.name,'"']})," afectará a",e.jsx("span",{className:"mx-1.5 px-2 py-0.5 bg-rose-100 dark:bg-rose-900 text-rose-700 dark:text-rose-300 rounded-lg font-black",children:l[C.id]}),"contactos permanentemente."]})}),e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2",children:[e.jsxs("div",{className:"relative flex items-center justify-center h-20 w-20",children:[e.jsxs("svg",{className:"absolute w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"40",cy:"40",r:"36",fill:"transparent",stroke:"currentColor",strokeWidth:"5",className:"text-slate-100 dark:text-slate-800"}),e.jsx("circle",{cx:"40",cy:"40",r:"36",fill:"transparent",stroke:"currentColor",strokeWidth:"5",strokeDasharray:226,strokeDashoffset:226-n/10*226,className:S("text-rose-500 transition-all duration-1000",n===0&&"text-emerald-500")})]}),e.jsx("span",{className:S("text-3xl font-black transition-colors duration-300",n>0?"text-rose-600":"text-emerald-600"),children:n})]}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mt-2",children:n>0?"Bloqueo de seguridad activo":"Confirmación habilitada"})]})]}),e.jsxs(_,{className:"p-6 bg-slate-50 dark:bg-slate-800/50 border-t border-slate-100 dark:border-slate-800 gap-3 flex-col sm:flex-row",children:[e.jsx(p,{variant:"ghost",onClick:()=>t(null),className:"h-12 rounded-2xl font-bold text-slate-500 hover:bg-slate-100 sm:flex-1",children:"CANCELAR"}),e.jsx(p,{variant:"destructive",onClick:()=>X.mutate(C.id),disabled:n>0||X.isPending,className:S("h-12 rounded-2xl font-black gap-2 transition-all transform sm:flex-1",n===0&&"bg-rose-600 hover:bg-rose-700 shadow-lg shadow-rose-200"),children:X.isPending?e.jsx(F,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:["ELIMINAR AHORA",e.jsx(O,{className:"w-4 h-4 ml-1"})]})})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-6 pb-2",children:e.jsxs(se,{children:[e.jsxs(z,{className:"flex items-center gap-2 text-slate-900 dark:text-white text-xl font-black",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:e.jsx(O,{className:"h-5 w-5 text-slate-500"})}),"Eliminar etiqueta"]}),e.jsxs(Q,{className:"pt-3 text-slate-500 font-medium",children:["¿Estás seguro de que deseas eliminar la etiqueta ",e.jsxs("strong",{children:['"',C?.name,'"']}),"? Esta acción no se puede deshacer."]})]})}),e.jsxs(_,{className:"p-6 pt-2 gap-2 sm:gap-3",children:[e.jsx(p,{variant:"ghost",onClick:()=>t(null),className:"rounded-xl font-bold",children:"Cancelar"}),e.jsxs(p,{variant:"destructive",onClick:()=>C&&X.mutate(C.id),disabled:X.isPending,className:"rounded-xl font-bold px-6 shadow-sm shadow-red-200",children:[X.isPending&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),"Eliminar"]})]})]})})}),e.jsx(J,{open:w,onOpenChange:s=>!s&&!Y.isPending&&k(!1),children:e.jsx(ee,{className:S("sm:max-w-[480px] p-0 overflow-hidden border-none shadow-2xl rounded-3xl transition-all duration-300",W?"scale-[1.02]":"scale-100"),children:le?e.jsxs("div",{className:"p-20 flex flex-col items-center justify-center bg-white dark:bg-slate-900",children:[e.jsx(F,{className:"w-12 h-12 animate-spin text-rose-500 mb-6"}),e.jsx("p",{className:"text-sm font-black text-slate-400 uppercase tracking-widest animate-pulse",children:"Verificando etiquetas..."})]}):Array.from(g).some(s=>(l?.[s]||0)>0)?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-rose-500 p-8 text-white flex flex-col items-center gap-4 text-center",children:[e.jsx("div",{className:"p-4 bg-white/20 rounded-2xl backdrop-blur-md animate-pulse",children:e.jsx(ye,{className:"w-10 h-10 text-white"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(z,{className:"text-2xl font-black tracking-tight text-white uppercase italic",children:"¡Atención Masiva!"}),e.jsx(Q,{className:"text-white/90 font-medium",children:"Varios de las etiquetas seleccionadas están en uso."})]})]}),e.jsxs("div",{className:"p-8 space-y-6 bg-white dark:bg-slate-900",children:[e.jsx("div",{className:"p-5 rounded-2xl border-2 border-rose-100 dark:border-rose-900/30 bg-rose-50/30 dark:bg-rose-950/20 space-y-4",children:e.jsxs("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 leading-relaxed text-center",children:["Estás a punto de eliminar ",e.jsxs("strong",{className:"text-rose-600 dark:text-rose-400",children:[g.size," etiquetas"]}),". Esto afectará a múltiples contactos permanentemente."]})}),e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2",children:[e.jsxs("div",{className:"relative flex items-center justify-center h-20 w-20",children:[e.jsxs("svg",{className:"absolute w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"40",cy:"40",r:"36",fill:"transparent",stroke:"currentColor",strokeWidth:"5",className:"text-slate-100 dark:text-slate-800"}),e.jsx("circle",{cx:"40",cy:"40",r:"36",fill:"transparent",stroke:"currentColor",strokeWidth:"5",strokeDasharray:226,strokeDashoffset:226-n/10*226,className:S("text-rose-500 transition-all duration-1000",n===0&&"text-emerald-500")})]}),e.jsx("span",{className:S("text-3xl font-black transition-colors duration-300",n>0?"text-rose-600":"text-emerald-600"),children:n})]}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mt-2",children:n>0?"Bloqueo de seguridad activo":"Confirmación habilitada"})]})]}),e.jsxs(_,{className:"p-6 bg-slate-50 dark:bg-slate-800/50 border-t border-slate-100 dark:border-slate-800 gap-3 flex-col sm:flex-row",children:[e.jsx(p,{variant:"ghost",onClick:()=>k(!1),className:"h-12 rounded-2xl font-bold text-slate-500 hover:bg-slate-100 sm:flex-1",children:"CANCELAR"}),e.jsx(p,{variant:"destructive",onClick:()=>Y.mutate(Array.from(g)),disabled:n>0||Y.isPending,className:S("h-12 rounded-2xl font-black gap-2 transition-all transform sm:flex-1",n===0&&"bg-rose-600 hover:bg-rose-700 shadow-lg shadow-rose-200"),children:Y.isPending?e.jsx(F,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:["ELIMINAR TODO",e.jsx(O,{className:"w-4 h-4 ml-1"})]})})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-6 pb-2",children:e.jsxs(se,{children:[e.jsxs(z,{className:"flex items-center gap-2 text-slate-900 dark:text-white text-xl font-black",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:e.jsx(O,{className:"h-5 w-5 text-slate-500"})}),"Eliminar etiquetas"]}),e.jsxs(Q,{className:"pt-3 text-slate-500 font-medium",children:["¿Estás seguro de eliminar las ",e.jsxs("strong",{children:[g.size," etiquetas"]})," seleccionadas? Esta acción no se puede deshacer."]})]})}),e.jsxs(_,{className:"p-6 pt-2 gap-2 sm:gap-3",children:[e.jsx(p,{variant:"ghost",onClick:()=>k(!1),className:"rounded-xl font-bold",children:"Cancelar"}),e.jsxs(p,{variant:"destructive",onClick:()=>Y.mutate(Array.from(g)),disabled:Y.isPending,className:"rounded-xl font-bold px-6 shadow-sm shadow-red-200",children:[Y.isPending&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),"Eliminar etiquetas"]})]})]})})}),e.jsx(J,{open:!!b,onOpenChange:s=>!s&&o(null),children:e.jsxs(ee,{className:"sm:max-w-[420px]",children:[e.jsx(se,{children:e.jsx(z,{children:"Detalles de etiqueta"})}),b&&e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl shadow-lg flex items-center justify-center text-white text-2xl font-bold",style:{backgroundColor:b.color},children:b.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground",children:b.name}),e.jsxs(Ce,{variant:"outline",className:"bg-muted/50 font-normal",children:[e.jsx("div",{className:"w-2 h-2 rounded-full mr-2",style:{backgroundColor:Ye(b.folderId)}}),Xe(b.folderId)]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-3 bg-muted/40 rounded-xl border border-border/50",children:[e.jsx("p",{className:"text-[10px] uppercase text-muted-foreground font-semibold mb-1",children:"Color HEX"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:b.color}}),e.jsx("span",{className:"font-mono text-xs",children:b.color})]})]}),e.jsxs("div",{className:"p-3 bg-muted/40 rounded-xl border border-border/50",children:[e.jsx("p",{className:"text-[10px] uppercase text-muted-foreground font-semibold mb-1",children:"Uso Actual"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ee,{className:"w-3 h-3 text-primary"}),e.jsx("span",{className:"text-xs font-bold",children:l&&typeof l[b.id]=="number"?`${l[b.id]} contactos`:"Pendiente de calcular"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] uppercase text-muted-foreground font-semibold",children:"Descripción"}),e.jsx("p",{className:"text-sm p-3 bg-muted/30 rounded-lg text-foreground min-h-[60px]",children:b.description||"Sin descripción disponible."})]})]}),e.jsxs(_,{className:"border-t pt-4",children:[e.jsx(p,{variant:"ghost",onClick:()=>o(null),children:"Cerrar"}),e.jsxs(p,{onClick:()=>{y(b),o(null)},className:"gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"}),"Editar"]})]})]})}),g.size>0&&e.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:e.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-7 border border-slate-800/50 backdrop-blur-xl bg-opacity-95",children:[e.jsxs("span",{className:"text-[13px] font-bold flex items-center gap-2.5",children:[e.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:g.size}),e.jsx("span",{className:"hidden sm:inline",children:"Etiquetas Seleccionadas"}),e.jsx("span",{className:"sm:hidden",children:"Selección"})]}),e.jsx("div",{className:"h-5 w-[1px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(p,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:Ds,children:[e.jsx(O,{className:"w-4 h-4 mr-2 text-rose-400"}),e.jsx("span",{className:"hidden sm:inline",children:"Eliminar"})]}),e.jsxs(Be,{children:[e.jsx(_e,{asChild:!0,children:e.jsxs(p,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",children:[e.jsx(Te,{className:"w-4 h-4 mr-2 text-emerald-400"}),e.jsx("span",{className:"hidden sm:inline",children:"Mover a"}),e.jsx("span",{className:"sm:hidden",children:"Mover"})]})}),e.jsxs(Ge,{className:"w-60 p-2 rounded-2xl shadow-2xl",align:"center",side:"top",children:[e.jsx(es,{className:"text-[10px] uppercase font-bold tracking-widest text-slate-400 p-2",children:"Mover a Carpeta"}),fe.map(s=>e.jsxs(Z,{onClick:()=>We.mutate({tagIds:Array.from(g),folderId:s.id}),className:"rounded-xl flex items-center gap-3 p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shadow-sm",style:{backgroundColor:s.color}}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]},s.id)),e.jsx(ss,{className:"bg-slate-100 dark:bg-slate-800"}),e.jsxs(Z,{onClick:()=>We.mutate({tagIds:Array.from(g),folderId:"unassigned"}),className:"rounded-xl flex items-center gap-3 p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shadow-sm bg-slate-400"}),e.jsx("span",{className:"text-sm font-medium text-slate-400",children:"Sin Carpeta"})]})]})]}),g.size===2&&e.jsx(Le,{children:e.jsxs(Oe,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(p,{size:"sm",variant:"ghost",className:"h-9 hover:bg-white/10 text-white rounded-xl px-4 transition-all",onClick:()=>{const s=Array.from(g),c=he.find(f=>f.id===s[0]);D(c||null)},children:[e.jsx($e,{className:"w-4 h-4 mr-2 text-amber-400"}),e.jsx("span",{className:"hidden sm:inline",children:"Fusionar"})]})}),e.jsx(Ue,{className:"bg-slate-900 text-white border-slate-800",children:e.jsx("p",{className:"text-xs",children:"Fusionar las 2 etiquetas seleccionadas"})})]})})]}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-7 w-7 rounded-full hover:bg-white/10 transition-all text-slate-400 hover:text-white",onClick:()=>h(new Set),children:e.jsx(Os,{className:"w-4 h-4"})})]})})]})}function js({open:u,onOpenChange:x,folder:i}){const j=re(),v=!!i,[l,N]=d.useState(""),[a,m]=d.useState("#3B82F6");d.useEffect(()=>{u&&(i?(N(i.name),m(i.color)):(N(""),m("#3B82F6")))},[u,i]);const g=I({mutationFn:r=>q.createFolder(r),onSuccess:()=>{j.invalidateQueries({queryKey:["tags"]}),E.success("Carpeta creada"),x(!1)},onError:()=>{E.error("Error al crear la carpeta")}}),h=I({mutationFn:r=>q.updateFolder(i.id,r),onSuccess:()=>{j.invalidateQueries({queryKey:["tags"]}),E.success("Carpeta actualizada"),x(!1)},onError:()=>{E.error("Error al actualizar la carpeta")}}),w=()=>{if(!l.trim()){E.error("El nombre es requerido");return}const r={name:l.trim(),color:a};v?h.mutate(r):g.mutate(r)},k=g.isPending||h.isPending;return e.jsx(J,{open:u,onOpenChange:x,children:e.jsxs(ee,{className:"sm:max-w-[400px]",children:[e.jsxs(se,{children:[e.jsx(z,{children:v?"Editar carpeta":"Nueva carpeta"}),e.jsx(Q,{children:"Las carpetas te ayudan a organizar tus etiquetas por temas."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"folder-name",children:"Nombre *"}),e.jsx(ae,{id:"folder-name",value:l,onChange:r=>N(r.target.value),placeholder:"Ej: Ventas, Soporte, Urgente",maxLength:50})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:"Color visual"}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[we.map(r=>e.jsx("button",{type:"button",onClick:()=>m(r),className:S("w-8 h-8 rounded-full border-2 transition-all",a===r?"border-slate-900 dark:border-white scale-110":"border-transparent hover:scale-105"),style:{backgroundColor:r}},r)),e.jsxs(ms,{children:[e.jsx(hs,{asChild:!0,children:e.jsx("button",{type:"button",className:S("w-8 h-8 rounded-full border-2 transition-all flex items-center justify-center",we.includes(a)?"border-dashed border-slate-300 hover:border-slate-400":"border-slate-900 dark:border-white scale-110"),style:{backgroundColor:we.includes(a)?"transparent":a},children:we.includes(a)&&e.jsx(bs,{className:"h-4 w-4 text-slate-400"})})}),e.jsx(us,{className:"w-auto p-3",align:"start",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{className:"text-xs",children:"Color personalizado"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:a,onChange:r=>m(r.target.value),className:"w-10 h-10 rounded-full cursor-pointer border-0 p-0 overflow-hidden"}),e.jsx(ae,{value:a,onChange:r=>{const y=r.target.value;/^#[0-9A-Fa-f]{0,6}$/.test(y)&&m(y)},placeholder:"#3B82F6",className:"w-24 font-mono text-sm",maxLength:7})]})]})})]})]})]})]}),e.jsxs(_,{children:[e.jsx(p,{variant:"outline",onClick:()=>x(!1),children:"Cancelar"}),e.jsxs(p,{onClick:w,disabled:k||!l.trim(),children:[k&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),v?"Guardar cambios":"Crear carpeta"]})]})]})})}function ja(){const u=re(),[x,i]=d.useState(""),[j,v]=d.useState(null),[l,N]=d.useState(null),[a,m]=d.useState(null),g=Se(n=>n.user),h=g?.role==="OWNER"||g?.role==="ADMIN",{data:w=[],isLoading:k}=be({queryKey:["tags","folders"],queryFn:()=>q.getFoldersWithTags(),staleTime:300*1e3}),r=d.useMemo(()=>w.filter(n=>n.id!=="unassigned"),[w]),y=d.useMemo(()=>{if(!x)return r;const n=x.toLowerCase();return r.filter(T=>T.name.toLowerCase().includes(n))},[r,x]),C=I({mutationFn:n=>q.reorderFolders(n),onSuccess:()=>{u.invalidateQueries({queryKey:["tags"]})},onError:()=>{E.error("Error al reordenar carpetas")}}),t=(n,T)=>{x||(m(T),n.dataTransfer.effectAllowed="move")},b=n=>{n.preventDefault(),n.dataTransfer.dropEffect="move"},o=(n,T)=>{if(n.preventDefault(),!a||a===T){m(null);return}const W=r.findIndex(M=>M.id===a),G=r.findIndex(M=>M.id===T);if(W===-1||G===-1){m(null);return}const le=[...r],[ne]=le.splice(W,1);le.splice(G,0,ne);const ie=le.map((M,P)=>({id:M.id,position:P}));C.mutate(ie),m(null)},A=()=>{m(null)},D=I({mutationFn:n=>q.deleteFolder(n),onSuccess:()=>{u.invalidateQueries({queryKey:["tags"]}),E.success("Carpeta eliminada. Las etiquetas quedan sin carpeta."),N(null)},onError:()=>{E.error("Error al eliminar la carpeta")}});return e.jsxs("div",{className:"space-y-6",children:[e.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 transition-all duration-300",children:[e.jsx("div",{className:"p-4 bg-slate-50/30 dark:bg-slate-800/20 backdrop-blur-md border-b border-slate-100 dark:border-slate-800",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 items-center justify-between",children:[e.jsxs("div",{className:"relative flex-1 w-full max-w-sm",children:[e.jsx(Ve,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(ae,{placeholder:"Buscar carpetas por nombre...",value:x,onChange:n=>i(n.target.value),className:"h-11 pl-11 bg-white dark:bg-slate-950 border-none rounded-2xl text-sm focus-visible:ring-1 focus-visible:ring-primary/20 transition-all font-medium"})]}),e.jsxs("div",{className:"text-[10px] uppercase font-black tracking-widest text-slate-400",children:["Mostrando ",e.jsx("span",{className:"text-primary",children:y.length})," / ",r.length," carpetas"]})]})}),e.jsx("div",{className:"p-8 bg-slate-50/20 dark:bg-slate-900/10 min-h-[400px]",children:k?e.jsx("div",{className:"grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 animate-pulse",children:Array.from({length:8}).map((n,T)=>e.jsx(H,{className:"h-44 w-full rounded-[28px]"},T))}):y.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center animate-in fade-in duration-500",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 dark:bg-slate-800 rounded-[24px] flex items-center justify-center mb-6",children:e.jsx(Te,{className:"h-10 w-10 text-slate-300"})}),e.jsx("h3",{className:"text-2xl font-black text-slate-900 dark:text-white mb-2 tracking-tight",children:"Sin carpetas"}),e.jsx("p",{className:"text-slate-500 max-w-sm mx-auto text-sm leading-relaxed",children:x?"No encontramos ninguna carpeta que coincida con tu búsqueda.":"Aún no has creado ninguna carpeta para organizar tus etiquetas."}),x&&e.jsx(p,{variant:"outline",className:"mt-8 rounded-full px-8 font-bold border-slate-200",onClick:()=>i(""),children:"Resetear Búsqueda"})]}):e.jsx("div",{className:"grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:y.map(n=>e.jsxs("div",{className:S("group relative bg-white dark:bg-slate-900 rounded-[28px] border border-slate-100 dark:border-slate-800 shadow-sm transition-all duration-300 hover:shadow-xl hover:border-primary/20 hover:-translate-y-1 p-6 flex flex-col justify-between",a===n.id?"opacity-50 ring-2 ring-primary ring-inset":"",!x&&"cursor-grab active:cursor-grabbing"),draggable:!x,onDragStart:T=>t(T,n.id),onDragOver:b,onDrop:T=>o(T,n.id),onDragEnd:A,children:[h&&e.jsx("div",{className:"flex items-start justify-between absolute top-4 right-4",children:e.jsxs(Be,{children:[e.jsx(_e,{asChild:!0,onClick:T=>T.stopPropagation(),children:e.jsx(p,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity bg-slate-50/50 dark:bg-slate-800/50",children:e.jsx(xa,{className:"h-4 w-4 text-slate-400"})})}),e.jsxs(Ge,{align:"end",className:"w-48 p-2 rounded-2xl shadow-2xl border-slate-100",children:[e.jsxs(Z,{onClick:()=>v(n),className:"rounded-xl p-2.5 font-bold text-sm",children:[e.jsx(Ke,{className:"h-4 w-4 mr-3 text-slate-400"})," Editar Carpeta"]}),e.jsxs(Z,{onClick:()=>N(n),className:"rounded-xl p-2.5 font-bold text-sm text-rose-600 focus:text-rose-700 focus:bg-rose-50",children:[e.jsx(O,{className:"h-4 w-4 mr-3"})," Eliminar Carpeta"]})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center shadow-inner group-hover:scale-110 transition-transform duration-300",style:{backgroundColor:n.color+"15",border:`1px solid ${n.color}30`},children:e.jsx(Te,{className:"h-7 w-7",style:{color:n.color}})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900 dark:text-white truncate text-base leading-tight",children:n.name}),e.jsx("div",{className:"flex items-center gap-2 mt-2",children:e.jsx("div",{className:"px-2 py-0.5 bg-slate-50 dark:bg-slate-800 rounded-md border border-slate-100 dark:border-slate-700",children:e.jsxs("span",{className:"text-[10px] font-black text-slate-500 uppercase tracking-tight",children:[n.tags?.length||0," Etiquetas"]})})})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-6 mt-6 border-t border-slate-50 dark:border-slate-800",children:[e.jsxs("div",{className:"flex -space-x-2 overflow-hidden",children:[n.tags?.slice(0,4).map(T=>e.jsx("div",{className:"h-5 w-5 rounded-full ring-2 ring-white dark:ring-slate-900 shadow-sm border border-black/5",style:{backgroundColor:T.color},title:T.name},T.id)),(n.tags?.length||0)>4&&e.jsx("div",{className:"h-5 w-5 rounded-full bg-slate-50 dark:bg-slate-800 flex items-center justify-center ring-2 ring-white dark:ring-slate-900 border border-slate-100 dark:border-slate-700",children:e.jsxs("span",{className:"text-[8px] font-black text-slate-500",children:["+",n.tags.length-4]})})]}),!x&&e.jsx(gs,{className:"h-4 w-4 text-slate-200 opacity-0 group-hover:opacity-100 transition-opacity"})]})]},n.id))})})]}),e.jsx(js,{open:!!j,onOpenChange:n=>!n&&v(null),folder:j}),e.jsx(J,{open:!!l,onOpenChange:n=>!n&&N(null),children:e.jsxs(ee,{children:[e.jsxs(se,{children:[e.jsxs(z,{className:"flex items-center gap-2 text-red-600",children:[e.jsx(ye,{className:"h-5 w-5"}),"Eliminar carpeta"]}),e.jsxs(Q,{className:"space-y-3 pt-2",children:[e.jsxs("p",{children:["¿Estás seguro de eliminar la carpeta ",e.jsxs("strong",{children:['"',l?.name,'"']}),"?"]}),l&&(l.tags?.length||0)>0&&e.jsxs(da,{variant:"default",className:"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-900 shadow-none",children:[e.jsx(Rs,{className:"h-4 w-4 text-amber-600"}),e.jsxs(ca,{className:"text-amber-800 dark:text-amber-200",children:["Las ",e.jsxs("strong",{children:[l.tags?.length," etiquetas"]})," de esta carpeta no se eliminarán, pero quedarán sin carpeta asignada."]})]})]})]}),e.jsxs(_,{className:"gap-2 sm:gap-0",children:[e.jsx(p,{variant:"outline",onClick:()=>N(null),children:"Cancelar"}),e.jsxs(p,{variant:"destructive",onClick:()=>l&&D.mutate(l.id),disabled:D.isPending,className:"shadow-lg shadow-red-500/20",children:[D.isPending&&e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}),"Eliminar carpeta"]})]})]})})]})}function Na(){re();const[u,x]=d.useState(7),[i,j]=d.useState(!1),v=ds(),l=Se(t=>t.user?.organizationId),N=Us(t=>t.fetchMembers),{data:a,isLoading:m,isFetching:g,refetch:h}=be({queryKey:["tags","stats",u],queryFn:()=>q.getTagAssignmentStats(u),enabled:i,staleTime:300*1e3,gcTime:600*1e3,refetchOnWindowFocus:!1});d.useEffect(()=>{l&&N(l)},[l,N]);const w=t=>v.get(t)?.user.name||t,k=()=>{i?h():j(!0),E.success("Generando análisis...")};d.useEffect(()=>{i&&h()},[u,i,h]);const r=()=>{if(!a)return;const t=[];t.push("Reporte de Asignaciones de Etiquetas"),t.push(`Período: ${L(a.period.from,{style:"date-only"})} - ${L(a.period.to,{style:"date-only"})}`),t.push(`Total asignaciones: ${a.total}`),t.push(""),t.push("ASIGNACIONES POR ETIQUETA"),t.push("Etiqueta,Color,Cantidad"),a.byTag.forEach(D=>{t.push(`"${D.tagName}",${D.tagColor},${D.count}`)}),t.push(""),t.push("TOP ASIGNADORES"),t.push("Usuario,Cantidad"),a.byUser.forEach(D=>{t.push(`"${w(D.userId)}",${D.count}`)}),t.push(""),t.push("TENDENCIA DIARIA"),t.push("Fecha,Cantidad"),a.timeline.forEach(D=>{t.push(`${D.date},${D.count}`)});const b=t.join(`
|
|
2
|
+
`),o=new Blob([b],{type:"text/csv;charset=utf-8;"}),A=document.createElement("a");A.href=URL.createObjectURL(o),A.download=`reporte-etiquetas-${new Date().toISOString().split("T")[0]}.csv`,A.click(),URL.revokeObjectURL(A.href),E.success("Reporte exportado correctamente")},y=d.useMemo(()=>a?a.timeline.map(t=>({name:t.date,count:t.count})):[],[a]),C=d.useMemo(()=>{if(!a)return null;const t=a.total/(u||1),b=a.byTag[0],o=a.byUser[0];return{avgPerDay:Math.round(t*10)/10,topTagName:b?.tagName||"-",topTagCount:b?.count||0,topUserName:o?w(o.userId):"-",topUserCount:o?.count||0,uniqueTags:a.byTag.length,activeUsers:a.byUser.length}},[a,u,w]);return e.jsxs("div",{className:"space-y-6 animate-in fade-in duration-500",children:[e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900",children:e.jsx(V,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 w-full sm:w-auto",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-slate-50 dark:bg-slate-800 rounded-xl border border-slate-200/50 dark:border-slate-700",children:[e.jsx(ls,{className:"h-4 w-4 text-slate-400"}),e.jsxs(qe,{value:u.toString(),onValueChange:t=>x(parseInt(t)),children:[e.jsx(De,{className:"w-[140px] border-none bg-transparent h-8 focus:ring-0 text-sm font-semibold p-0 shadow-none text-slate-700 dark:text-slate-200",children:e.jsx(Ae,{})}),e.jsxs(Fe,{className:"rounded-xl border-slate-200 shadow-xl",children:[e.jsx(R,{value:"7",className:"rounded-lg font-medium",children:"Últimos 7 días"}),e.jsx(R,{value:"30",className:"rounded-lg font-medium",children:"Últimos 30 días"}),e.jsx(R,{value:"90",className:"rounded-lg font-medium",children:"Últimos 90 días"}),e.jsx(R,{value:"365",className:"rounded-lg font-medium",children:"Último año"})]})]})]}),a?.cachedAt&&e.jsx("div",{className:"hidden sm:flex items-center gap-2 text-xs text-slate-400",children:e.jsxs("span",{children:["Actualizado: ",L(a.cachedAt,{style:"time-only"})]})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[a&&e.jsxs(p,{variant:"outline",onClick:r,className:"h-10 px-4 rounded-xl font-semibold text-sm border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 hover:bg-slate-50 dark:hover:bg-slate-700 text-slate-600 dark:text-slate-300 flex-1 sm:flex-none",children:[e.jsx(ma,{className:"h-4 w-4 mr-2"}),"Exportar"]}),e.jsxs(p,{onClick:k,disabled:m||g,className:"h-10 px-6 rounded-xl font-semibold text-sm bg-indigo-600 hover:bg-indigo-700 text-white shadow-lg shadow-indigo-500/20 flex-1 sm:flex-none",children:[m||g?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):i?e.jsx(zs,{className:"h-4 w-4 mr-2"}):e.jsx(ze,{className:"h-4 w-4 mr-2"}),i?"Actualizar":"Generar Análisis"]})]})]})})}),!a&&!m&&!g?e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900",children:e.jsx(V,{className:"py-20",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-indigo-50 dark:bg-indigo-900/20 rounded-2xl flex items-center justify-center mb-6",children:e.jsx(cs,{className:"h-10 w-10 text-indigo-500"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-900 dark:text-white mb-2",children:"Módulo de Estadísticas"}),e.jsx("p",{className:"text-slate-500 max-w-sm mx-auto text-sm mb-6",children:"Analiza el rendimiento de tus etiquetas y el comportamiento de tus agentes en tiempo real."}),e.jsxs(p,{onClick:k,className:"rounded-xl px-8 h-11 font-semibold bg-indigo-600 hover:bg-indigo-700 text-white shadow-lg shadow-indigo-500/20",children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Iniciar Análisis"]})]})})}):e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-bottom-2 duration-500",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-4",children:[e.jsx(pe,{icon:e.jsx(ha,{className:"h-5 w-5"}),value:m?null:a?.total,label:"TOTAL",sublabel:"Asignaciones",color:"indigo",isLoading:m}),e.jsx(pe,{icon:e.jsx(te,{className:"h-5 w-5"}),value:m?null:C?.uniqueTags,label:"ETIQUETAS",sublabel:"Utilizadas",color:"emerald",isLoading:m}),e.jsx(pe,{icon:e.jsx(as,{className:"h-5 w-5"}),value:m?null:C?.activeUsers,label:"USUARIOS",sublabel:"Activos",color:"amber",isLoading:m}),e.jsx(pe,{icon:e.jsx(Ee,{className:"h-5 w-5"}),value:m?null:C?.avgPerDay,label:"PROMEDIO",sublabel:"Por día",color:"rose",isLoading:m}),e.jsx(pe,{icon:e.jsx(ls,{className:"h-5 w-5"}),value:m?null:u,label:"PERÍODO",sublabel:"Días",color:"violet",isLoading:m})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(ke,{icon:e.jsx(ia,{className:"h-5 w-5"}),title:"Top Etiqueta",value:C?.topTagName||"-",subtitle:`${C?.topTagCount||0} asignaciones`,color:"emerald",isLoading:m}),e.jsx(ke,{icon:e.jsx(Bs,{className:"h-5 w-5"}),title:"Top Usuario",value:C?.topUserName||"-",subtitle:`${C?.topUserCount||0} asignaciones`,color:"amber",isLoading:m}),e.jsx(ke,{icon:e.jsx(ua,{className:"h-5 w-5"}),title:"Agregación",value:a?.aggregation==="daily"?"Diaria":a?.aggregation==="weekly"?"Semanal":a?.aggregation==="monthly"?"Mensual":"Diaria",subtitle:"Nivel de detalle",color:"indigo",isLoading:m}),e.jsx(ke,{icon:e.jsx(ze,{className:"h-5 w-5"}),title:"Puntos de Datos",value:a?.timeline.length.toString()||"0",subtitle:"En el período",color:"rose",isLoading:m})]}),e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden",children:e.jsxs(V,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-slate-900 dark:text-white",children:"Actividad en el Tiempo"}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Tendencia de asignaciones de etiquetas"})]}),e.jsx(Ce,{variant:"outline",className:"rounded-lg px-3 py-1 text-xs font-medium bg-indigo-50 dark:bg-indigo-900/30 border-indigo-200 dark:border-indigo-800 text-indigo-600 dark:text-indigo-400",children:a?.aggregation==="daily"?"Por día":a?.aggregation==="weekly"?"Por semana":a?.aggregation==="monthly"?"Por mes":"Por día"})]}),e.jsx("div",{className:"h-[280px] w-full",children:m?e.jsx(H,{className:"h-full w-full rounded-xl"}):e.jsx(Ks,{width:"100%",height:"100%",children:e.jsxs(Vs,{data:y,margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"colorGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#6366f1",stopOpacity:.3}),e.jsx("stop",{offset:"100%",stopColor:"#6366f1",stopOpacity:.05})]})}),e.jsx(Qs,{strokeDasharray:"3 3",vertical:!1,stroke:"#e2e8f0",opacity:.5}),e.jsx(Hs,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:"#94a3b8",fontSize:11,fontWeight:500},dy:10,tickFormatter:t=>a?.aggregation==="monthly"?L(t,{style:"month-year"}):a?.aggregation==="weekly"?L(t,{style:"chart-axis"}):L(t,{style:"chart-axis"})}),e.jsx(Ws,{axisLine:!1,tickLine:!1,tick:{fill:"#94a3b8",fontSize:11,fontWeight:500}}),e.jsx(Xs,{contentStyle:{borderRadius:"12px",border:"1px solid #e2e8f0",boxShadow:"0 10px 40px -10px rgba(0, 0, 0, 0.1)",padding:"12px 16px",backgroundColor:"white"},cursor:{stroke:"#6366f1",strokeWidth:1,strokeDasharray:"4 4"},labelFormatter:t=>a?.aggregation==="monthly"?L(t,{style:"month-long"}):a?.aggregation==="weekly"?`Semana del ${L(t,{style:"day-month"})}`:L(t,{style:"chart-tooltip"})}),e.jsx(Ys,{type:"monotone",dataKey:"count",name:"Asignaciones",stroke:"#6366f1",strokeWidth:2.5,fillOpacity:1,fill:"url(#colorGradient)",animationDuration:1500})]})})})]})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-5",children:[e.jsx(K,{className:"lg:col-span-3 border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden",children:e.jsxs(V,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-slate-900 dark:text-white",children:"Distribución por Etiqueta"}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Top etiquetas más asignadas"})]}),e.jsx(Ce,{variant:"outline",className:"rounded-lg px-3 py-1 text-xs font-medium bg-slate-50 dark:bg-slate-800 border-slate-200 dark:border-slate-700",children:"TOP 10"})]}),m?e.jsx("div",{className:"space-y-4",children:Array.from({length:6}).map((t,b)=>e.jsx(H,{className:"h-10 w-full rounded-lg"},b))}):(a?.byTag.length||0)===0?e.jsx(os,{icon:e.jsx(te,{className:"h-10 w-10"}),label:"Sin asignaciones registradas"}):e.jsx("div",{className:"space-y-3",children:a?.byTag.slice(0,10).map((t,b)=>{const o=a.byTag[0]?.count||1,A=t.count/o*100,D=Math.round(t.count/a.total*100);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shadow-sm",style:{backgroundColor:t.tagColor}}),e.jsx("span",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 group-hover:text-indigo-600 dark:group-hover:text-indigo-400 transition-colors",children:t.tagName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-bold text-slate-900 dark:text-white",children:t.count}),e.jsxs("span",{className:"text-xs text-slate-400 font-medium",children:["(",D,"%)"]})]})]}),e.jsx("div",{className:"w-full h-2 bg-slate-100 dark:bg-slate-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${A}%`,backgroundColor:t.tagColor,opacity:.8}})})]},t.tagId)})})]})}),e.jsx(K,{className:"lg:col-span-2 border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden",children:e.jsxs(V,{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-base font-bold text-slate-900 dark:text-white",children:"Top Colaboradores"}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Usuarios más activos"})]}),m?e.jsx("div",{className:"space-y-3",children:Array.from({length:6}).map((t,b)=>e.jsx(H,{className:"h-14 w-full rounded-xl"},b))}):(a?.byUser.length||0)===0?e.jsx(os,{icon:e.jsx(as,{className:"h-10 w-10"}),label:"Sin actividad de agentes"}):e.jsx("div",{className:"space-y-2",children:a?.byUser.map((t,b)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-slate-50/80 dark:bg-slate-800/50 rounded-xl border border-slate-100 dark:border-slate-700/50 hover:bg-white dark:hover:bg-slate-800 hover:shadow-md hover:border-slate-200 dark:hover:border-slate-600 transition-all duration-200 group",children:[e.jsx("div",{className:S("w-8 h-8 rounded-lg flex items-center justify-center text-xs font-bold transition-all",b===0?"bg-amber-100 text-amber-600 dark:bg-amber-900/30 dark:text-amber-400":b===1?"bg-slate-200 text-slate-600 dark:bg-slate-700 dark:text-slate-300":b===2?"bg-orange-100 text-orange-600 dark:bg-orange-900/30 dark:text-orange-400":"bg-slate-100 dark:bg-slate-700 text-slate-500 dark:text-slate-400"),children:b+1}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("span",{className:"text-sm font-semibold text-slate-800 dark:text-slate-100 block truncate",children:w(t.userId)})}),e.jsx("div",{className:"px-2.5 py-1 bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-400 rounded-lg text-xs font-bold",children:t.count})]},t.userId))})]})})]})]})]})}function pe({icon:u,value:x,label:i,sublabel:j,color:v,isLoading:l}){const a={indigo:{bg:"bg-indigo-50 dark:bg-indigo-900/20",icon:"text-indigo-500 dark:text-indigo-400",border:"border-indigo-100 dark:border-indigo-800/50"},emerald:{bg:"bg-emerald-50 dark:bg-emerald-900/20",icon:"text-emerald-500 dark:text-emerald-400",border:"border-emerald-100 dark:border-emerald-800/50"},amber:{bg:"bg-amber-50 dark:bg-amber-900/20",icon:"text-amber-500 dark:text-amber-400",border:"border-amber-100 dark:border-amber-800/50"},rose:{bg:"bg-rose-50 dark:bg-rose-900/20",icon:"text-rose-500 dark:text-rose-400",border:"border-rose-100 dark:border-rose-800/50"},violet:{bg:"bg-violet-50 dark:bg-violet-900/20",icon:"text-violet-500 dark:text-violet-400",border:"border-violet-100 dark:border-violet-800/50"}}[v];return e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden hover:shadow-md transition-shadow",children:e.jsxs(V,{className:"p-4",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsx("div",{className:S("w-10 h-10 rounded-xl flex items-center justify-center",a.bg,a.border,"border"),children:e.jsx("span",{className:a.icon,children:u})})}),e.jsxs("div",{children:[l?e.jsx(H,{className:"h-8 w-16 mb-1"}):e.jsx("div",{className:"text-2xl font-bold text-slate-900 dark:text-white tracking-tight",children:x?.toLocaleString()??"-"}),e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider mt-1",children:i}),e.jsx("div",{className:"text-xs text-slate-500 font-medium",children:j})]})]})})}function ke({icon:u,title:x,value:i,subtitle:j,color:v,isLoading:l}){const N={indigo:"bg-indigo-50 dark:bg-indigo-900/20 text-indigo-500 dark:text-indigo-400",emerald:"bg-emerald-50 dark:bg-emerald-900/20 text-emerald-500 dark:text-emerald-400",amber:"bg-amber-50 dark:bg-amber-900/20 text-amber-500 dark:text-amber-400",rose:"bg-rose-50 dark:bg-rose-900/20 text-rose-500 dark:text-rose-400"};return e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden",children:e.jsx(V,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:S("w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",N[v]),children:u}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:x}),l?e.jsx(H,{className:"h-5 w-24 mt-1"}):e.jsx("div",{className:"text-sm font-bold text-slate-900 dark:text-white truncate",children:i}),e.jsx("div",{className:"text-xs text-slate-500 font-medium",children:j})]})]})})})}function os({icon:u,label:x}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-slate-300 dark:text-slate-600",children:[e.jsx("div",{className:"mb-3 opacity-50",children:u}),e.jsx("p",{className:"text-xs font-semibold text-slate-400 dark:text-slate-500",children:x})]})}const va={TAG_CREATE:{label:"Creada",icon:e.jsx(xs,{className:"w-3 h-3"}),color:"text-emerald-600 dark:text-emerald-400",bgColor:"bg-emerald-100 dark:bg-emerald-900/30"},TAG_UPDATE:{label:"Editada",icon:e.jsx(is,{className:"w-3 h-3"}),color:"text-blue-600 dark:text-blue-400",bgColor:"bg-blue-100 dark:bg-blue-900/30"},TAG_DELETE:{label:"Eliminada",icon:e.jsx(O,{className:"w-3 h-3"}),color:"text-red-600 dark:text-red-400",bgColor:"bg-red-100 dark:bg-red-900/30"},TAG_BULK_DELETE:{label:"Eliminación masiva",icon:e.jsx(O,{className:"w-3 h-3"}),color:"text-red-600 dark:text-red-400",bgColor:"bg-red-100 dark:bg-red-900/30"},TAG_MERGE:{label:"Fusionadas",icon:e.jsx($e,{className:"w-3 h-3"}),color:"text-violet-600 dark:text-violet-400",bgColor:"bg-violet-100 dark:bg-violet-900/30"},TAG_REORDER:{label:"Reordenadas",icon:e.jsx(ns,{className:"w-3 h-3"}),color:"text-amber-600 dark:text-amber-400",bgColor:"bg-amber-100 dark:bg-amber-900/30"},TAG_FOLDER_CREATE:{label:"Carpeta creada",icon:e.jsx(Qe,{className:"w-3 h-3"}),color:"text-emerald-600 dark:text-emerald-400",bgColor:"bg-emerald-100 dark:bg-emerald-900/30"},TAG_FOLDER_UPDATE:{label:"Carpeta editada",icon:e.jsx(is,{className:"w-3 h-3"}),color:"text-blue-600 dark:text-blue-400",bgColor:"bg-blue-100 dark:bg-blue-900/30"},TAG_FOLDER_DELETE:{label:"Carpeta eliminada",icon:e.jsx(O,{className:"w-3 h-3"}),color:"text-red-600 dark:text-red-400",bgColor:"bg-red-100 dark:bg-red-900/30"},TAG_FOLDER_REORDER:{label:"Carpetas reordenadas",icon:e.jsx(ns,{className:"w-3 h-3"}),color:"text-amber-600 dark:text-amber-400",bgColor:"bg-amber-100 dark:bg-amber-900/30"}},wa={label:"Acción",icon:e.jsx($s,{className:"w-3 h-3"}),color:"text-slate-600 dark:text-slate-400",bgColor:"bg-slate-100 dark:bg-slate-800"};function ka(){const[u,x]=d.useState(""),[i,j]=d.useState(1),v=ds(),{data:l,isLoading:N,isFetching:a}=be({queryKey:["tags","audit",i,u],queryFn:()=>q.getAuditLogs({page:i,limit:20,resource:"ContactTag,TagFolder",search:u||void 0}),staleTime:30*1e3}),m=r=>v.get(r)?.user.name||"Usuario",g=r=>va[r]||{...wa,label:r},h=r=>{const y=new Date(r),t=new Date().getTime()-y.getTime(),b=Math.floor(t/6e4),o=Math.floor(t/36e5),A=Math.floor(t/864e5);return b<1?"Ahora":b<60?`${b}m`:o<24?`${o}h`:A<7?`${A}d`:L(y,{style:"day-month"})},w=l?.data||[],k=l?.pagination?.totalPages||1;return e.jsxs("div",{className:"space-y-4 animate-in fade-in duration-300",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(Ve,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(ae,{placeholder:"Buscar...",value:u,onChange:r=>{x(r.target.value),j(1)},className:"h-9 pl-9 bg-white dark:bg-slate-900 border-slate-200 dark:border-slate-800 rounded-xl text-sm"})]}),a&&e.jsx(F,{className:"h-4 w-4 animate-spin text-primary"})]}),e.jsx(K,{className:"border border-slate-200/60 dark:border-slate-800 shadow-sm rounded-2xl bg-white dark:bg-slate-900 overflow-hidden",children:e.jsx(V,{className:"p-0",children:N&&i===1?e.jsx("div",{className:"p-3 space-y-1",children:Array.from({length:10}).map((r,y)=>e.jsx(H,{className:"h-10 w-full rounded-lg"},y))}):w.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-slate-100 dark:bg-slate-800 rounded-xl flex items-center justify-center mb-3",children:e.jsx(ps,{className:"h-6 w-6 text-slate-400"})}),e.jsx("p",{className:"text-sm font-medium text-slate-600 dark:text-slate-400",children:u?"Sin resultados":"Sin actividad"}),u&&e.jsx(p,{variant:"ghost",size:"sm",className:"mt-2 text-xs",onClick:()=>x(""),children:"Limpiar"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-12 gap-2 px-4 py-2 bg-slate-50 dark:bg-slate-800/50 border-b border-slate-100 dark:border-slate-800 text-[10px] font-bold uppercase tracking-wider text-slate-500",children:[e.jsx("div",{className:"col-span-4",children:"Acción"}),e.jsx("div",{className:"col-span-3",children:"Usuario"}),e.jsx("div",{className:"col-span-3",children:"Detalles"}),e.jsx("div",{className:"col-span-2 text-right",children:"Fecha"})]}),e.jsx("div",{className:"divide-y divide-slate-100 dark:divide-slate-800/50",children:w.map(r=>{const y=g(r.action);return e.jsxs("div",{className:"grid grid-cols-12 gap-2 px-4 py-2.5 items-center hover:bg-slate-50/50 dark:hover:bg-slate-800/20 transition-colors",children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:S("w-6 h-6 rounded-lg flex items-center justify-center flex-shrink-0",y.bgColor,y.color),children:y.icon}),e.jsx("span",{className:"text-sm font-medium text-slate-800 dark:text-slate-200 truncate",children:y.label})]}),e.jsx("div",{className:"col-span-3 min-w-0",children:e.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400 truncate block",children:m(r.userId)})}),e.jsxs("div",{className:"col-span-3 flex items-center gap-1 flex-wrap min-w-0",children:[r.metadata?.name&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-slate-100 dark:bg-slate-800 rounded text-slate-600 dark:text-slate-400 truncate max-w-[120px]",children:r.metadata.name}),r.metadata?.transferredContacts!==void 0&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-violet-100 dark:bg-violet-900/30 rounded text-violet-600 dark:text-violet-400",children:[r.metadata.transferredContacts," contactos"]}),r.metadata?.tagIds?.length>0&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-900/30 rounded text-indigo-600 dark:text-indigo-400",children:[r.metadata.tagIds.length," tags"]}),r.metadata?.deletedCount!==void 0&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-red-100 dark:bg-red-900/30 rounded text-red-600 dark:text-red-400",children:[r.metadata.deletedCount," eliminadas"]})]}),e.jsx("div",{className:"col-span-2 text-right",children:e.jsx("span",{className:"text-xs text-slate-400 font-medium",children:h(r.createdAt)})})]},r.id)})}),!N&&w.length>0&&e.jsxs("div",{className:"px-6 py-4 bg-slate-50/50 dark:bg-slate-800/30 border-t border-slate-100 dark:border-slate-800 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex flex-col",children:e.jsxs("span",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest leading-none",children:["Página ",e.jsx("span",{className:"text-slate-900 dark:text-white",children:i})," de ",e.jsx("span",{className:"text-slate-900 dark:text-white",children:k})]})}),e.jsx("div",{className:"h-4 w-[1px] bg-slate-200 dark:bg-slate-700"}),e.jsxs("span",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest",children:["Logs: ",e.jsx("span",{className:"text-primary",children:w.length})," / ",l?.pagination?.total||0]})]}),k>1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>j(r=>Math.max(1,r-1)),disabled:i===1||a,className:"h-8 px-3 rounded-lg font-black text-[10px] uppercase tracking-wider border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-800 transition-all shadow-sm disabled:opacity-50",children:[e.jsx(_s,{className:"h-3 w-3 mr-1"}),"Anterior"]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>j(r=>Math.min(k,r+1)),disabled:i===k||a,className:"h-8 px-3 rounded-lg font-black text-[10px] uppercase tracking-wider border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-800 transition-all shadow-sm disabled:opacity-50",children:["Siguiente",e.jsx(Gs,{className:"h-3 w-3 ml-1"})]})]})]})]})})})]})}function st(){const u=re(),[x,i]=d.useState("tags"),[j,v]=d.useState(!1),[l,N]=d.useState(!1),a=Se(k=>k.user),m=a?.role==="OWNER"||a?.role==="ADMIN",{data:g=[]}=be({queryKey:["tags","folders"],queryFn:()=>q.getFoldersWithTags()}),h=g.filter(k=>k.id!=="unassigned"),w=d.useCallback(k=>{k==="stats"&&u.prefetchQuery({queryKey:["tags","stats",7],queryFn:()=>q.getTagAssignmentStats(7),staleTime:300*1e3})},[u]);return e.jsxs(ea,{children:[e.jsx(sa,{title:"Gestión de Etiquetas",description:"Organiza y categoriza tus contactos con etiquetas y carpetas de forma estratégica.",icon:te,actions:m?e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(p,{variant:"outline",className:"rounded-xl font-bold border-slate-200 dark:border-slate-800 hover:bg-slate-50 dark:hover:bg-slate-800 transition-all shadow-sm",onClick:()=>N(!0),children:[e.jsx(Qe,{className:"h-4 w-4 sm:mr-2 text-indigo-500"}),e.jsx("span",{className:"hidden sm:inline",children:"Carpetas"})]}),e.jsxs(p,{onClick:()=>v(!0),className:"rounded-xl font-bold bg-primary text-white shadow-lg shadow-primary/20 hover:shadow-primary/30 active:scale-95 transition-all px-6",children:[e.jsx(xs,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Nueva Etiqueta"})]})]}):null}),e.jsx(aa,{className:"space-y-6",children:e.jsxs(Zs,{value:x,onValueChange:i,className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs(Js,{className:"bg-slate-100/50 dark:bg-slate-800/50 p-1 rounded-2xl h-11 border border-slate-200/50 dark:border-slate-700/50 backdrop-blur-sm",children:[e.jsxs(je,{value:"tags",className:"rounded-xl px-6 data-[state=active]:bg-white dark:data-[state=active]:bg-slate-900 data-[state=active]:shadow-sm transition-all font-bold text-xs uppercase tracking-wider",children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Etiquetas"]}),e.jsxs(je,{value:"folders",className:"rounded-xl px-6 data-[state=active]:bg-white dark:data-[state=active]:bg-slate-900 data-[state=active]:shadow-sm transition-all font-bold text-xs uppercase tracking-wider",children:[e.jsx(Te,{className:"h-4 w-4 mr-2"}),"Carpetas"]}),e.jsxs(je,{value:"stats",className:"rounded-xl px-6 data-[state=active]:bg-white dark:data-[state=active]:bg-slate-900 data-[state=active]:shadow-sm transition-all font-bold text-xs uppercase tracking-wider",onMouseEnter:()=>w("stats"),children:[e.jsx(cs,{className:"h-4 w-4 mr-2"}),"Estadísticas"]}),e.jsxs(je,{value:"history",className:"rounded-xl px-6 data-[state=active]:bg-white dark:data-[state=active]:bg-slate-900 data-[state=active]:shadow-sm transition-all font-bold text-xs uppercase tracking-wider",children:[e.jsx(ps,{className:"h-4 w-4 mr-2"}),"Historial"]})]})}),e.jsx(Ne,{value:"tags",className:"space-y-4 m-0 border-none p-0 outline-none animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsx(fa,{})}),e.jsx(Ne,{value:"folders",className:"space-y-4 m-0 border-none p-0 outline-none animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsx(ja,{})}),e.jsx(Ne,{value:"stats",className:"space-y-4 m-0 border-none p-0 outline-none animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsx(Na,{})}),e.jsx(Ne,{value:"history",className:"space-y-4 m-0 border-none p-0 outline-none animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsx(ka,{})})]})}),e.jsx(fs,{open:j,onOpenChange:v,tag:null,folders:h}),e.jsx(js,{open:l,onOpenChange:N,folder:null})]})}export{st as TagsSettingsPage,st as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as vs,a as re,h as F,j as e,a1 as oe,a2 as de,a3 as ce,a4 as me,a5 as ue,n as $,I as pe,B as w,r as te,X as Ps,D as zs,l as O,aa as xe,aW as q,t as y,Z as Ls,T as B,s as Y,v as K,al as Ke,am as Xe,an as Ze,ao as Qe,aq as H,o as Je,az as xs,R as Me,aC as qs,a7 as ks,aT as ys,b4 as ws,a6 as Ee,Q as Z,b5 as ge,b6 as Fs,b7 as Gs,y as fe,a8 as J,d as Us,p as Ws,e as $s,f as Cs,i as Vs,b as Le,g as es,k as ss,x as _s,C as as,U as be,q as je,A as hs,u as Ts,aw as Hs,a9 as Bs,aD as Ys,aK as Ks}from"./index-43NA2pdZ.js";import{b as u,g as Se,P as Xs,i as Zs,j as Qs,S as ps,A as gs,C as qe,X as Fe,Y as Ge,T as Ue,h as fs,B as Js,l as ea}from"./recharts-DrC5kNsx.js";import{C as A,a as R,b as X,c as ee,d as We}from"./card-DdbmSh-v.js";import{T as sa,a as aa,b as $e,c as Ve}from"./tabs-BGCKrmVw.js";import{S as Ne}from"./switch-C7XmAU1c.js";import{A as ve,a as ke,b as ye}from"./avatar-BXhSKQGY.js";import{C as ta,a as ra,b as na,c as la,d as ia,e as oa}from"./command-aHRTWaYV.js";import{P as Ae,a as Re,b as Ie}from"./popover-cWIhNmod.js";import{C as da}from"./chevrons-up-down-DNNdNhV8.js";import{T as Oe,a as Pe,b as V,c as E,d as ze,e as N}from"./table-7NGq0kRw.js";import{C as ts}from"./ConfirmModal-B27OBQdm.js";import{E as rs}from"./ellipsis-GLu0u4ze.js";import{S as ca}from"./settings-2-PhKPMrsj.js";import{T as De}from"./trash-2-D_kmHMwn.js";import{S as ns,a as ls,b as is,c as os,d as ie}from"./select-DCY_lg9j.js";import{u as Ss}from"./useOrgSyncedFetch-FSgwRhpR.js";import{a as Es}from"./datetime-D72Uxhjs.js";import{P as Ds}from"./pencil-aqjc7AWb.js";import{A as ma,b as ua}from"./alert-seLKo73M.js";import{u as xa,h as ha}from"./creditErrors-DSbswjsG.js";import{C as pa}from"./CreditLimitBanner-j72L7jgK.js";import{C as ga}from"./calendar-days-CXtOZxOF.js";import{c as fa,t as js,d as Ms,h as As,f as ne}from"./format-BG1mN6C0.js";import{e as le}from"./es-BDgg6unH.js";import{S as z}from"./skeleton-CN6xlRXP.js";import{M as ja}from"./message-square-B1_OirdW.js";import{T as Rs}from"./trending-up-BnHeLWFs.js";import{A as ba}from"./arrow-up-down-DkSCsCjR.js";import{A as Na,a as va}from"./arrow-up-DJzXCc8_.js";import{A as bs}from"./arrow-left-CI7mH7bD.js";import{T as ka}from"./target-CG_g4_Fj.js";import{U as ya}from"./user-l48WDfDH.js";import{M as wa}from"./minus-vh4a51Mn.js";import{P as Ca,a as Ta,b as Sa}from"./page-components-DXOKtt_M.js";import{U as Ea}from"./user-plus-CWaaUP-O.js";import"./index-KbFmSzBE.js";const Da=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],Ma=vs("trending-down",Da);const Aa=[["path",{d:"M10 14.66v1.626a2 2 0 0 1-.976 1.696A5 5 0 0 0 7 21.978",key:"1n3hpd"}],["path",{d:"M14 14.66v1.626a2 2 0 0 0 .976 1.696A5 5 0 0 1 17 21.978",key:"rfe1zi"}],["path",{d:"M18 9h1.5a1 1 0 0 0 0-5H18",key:"7xy6bh"}],["path",{d:"M4 22h16",key:"57wxv0"}],["path",{d:"M6 9a6 6 0 0 0 12 0V3a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1z",key:"1mhfuq"}],["path",{d:"M6 9H4.5a1 1 0 0 1 0-5H6",key:"tex48p"}]],Ns=vs("trophy",Aa);function we(a,t){const n=()=>fa(t?.in,NaN),l=Pa(a);let d;if(l.date){const h=za(l.date,2);d=La(h.restDateString,h.year)}if(!d||isNaN(+d))return n();const x=+d;let i=0,c;if(l.time&&(i=qa(l.time),isNaN(i)))return n();if(l.timezone){if(c=Fa(l.timezone),isNaN(c))return n()}else{const h=new Date(x+i),p=js(0,t?.in);return p.setFullYear(h.getUTCFullYear(),h.getUTCMonth(),h.getUTCDate()),p.setHours(h.getUTCHours(),h.getUTCMinutes(),h.getUTCSeconds(),h.getUTCMilliseconds()),p}return js(x+i+c,t?.in)}const Ce={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},Ra=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,Ia=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,Oa=/^([+-])(\d{2})(?::?(\d{2}))?$/;function Pa(a){const t={},n=a.split(Ce.dateTimeDelimiter);let r;if(n.length>2)return t;if(/:/.test(n[0])?r=n[0]:(t.date=n[0],r=n[1],Ce.timeZoneDelimiter.test(t.date)&&(t.date=a.split(Ce.timeZoneDelimiter)[0],r=a.substr(t.date.length,a.length))),r){const l=Ce.timezone.exec(r);l?(t.time=r.replace(l[1],""),t.timezone=l[1]):t.time=r}return t}function za(a,t){const n=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+t)+"})|(\\d{2}|[+-]\\d{"+(2+t)+"})$)"),r=a.match(n);if(!r)return{year:NaN,restDateString:""};const l=r[1]?parseInt(r[1]):null,d=r[2]?parseInt(r[2]):null;return{year:d===null?l:d*100,restDateString:a.slice((r[1]||r[2]).length)}}function La(a,t){if(t===null)return new Date(NaN);const n=a.match(Ra);if(!n)return new Date(NaN);const r=!!n[4],l=he(n[1]),d=he(n[2])-1,x=he(n[3]),i=he(n[4]),c=he(n[5])-1;if(r)return Va(t,i,c)?Ga(t,i,c):new Date(NaN);{const h=new Date(0);return!Wa(t,d,x)||!$a(t,l)?new Date(NaN):(h.setUTCFullYear(t,d,Math.max(l,x)),h)}}function he(a){return a?parseInt(a):1}function qa(a){const t=a.match(Ia);if(!t)return NaN;const n=_e(t[1]),r=_e(t[2]),l=_e(t[3]);return _a(n,r,l)?n*Ms+r*As+l*1e3:NaN}function _e(a){return a&&parseFloat(a.replace(",","."))||0}function Fa(a){if(a==="Z")return 0;const t=a.match(Oa);if(!t)return 0;const n=t[1]==="+"?-1:1,r=parseInt(t[2]),l=t[3]&&parseInt(t[3])||0;return Ha(r,l)?n*(r*Ms+l*As):NaN}function Ga(a,t,n){const r=new Date(0);r.setUTCFullYear(a,0,4);const l=r.getUTCDay()||7,d=(t-1)*7+n+1-l;return r.setUTCDate(r.getUTCDate()+d),r}const Ua=[31,null,31,30,31,30,31,31,30,31,30,31];function Is(a){return a%400===0||a%4===0&&a%100!==0}function Wa(a,t,n){return t>=0&&t<=11&&n>=1&&n<=(Ua[t]||(Is(a)?29:28))}function $a(a,t){return t>=1&&t<=(Is(a)?366:365)}function Va(a,t,n){return t>=1&&t<=53&&n>=0&&n<=6}function _a(a,t,n){return a===24?t===0&&n===0:n>=0&&n<60&&t>=0&&t<60&&a>=0&&a<25}function Ha(a,t){return t>=0&&t<=59}const Os=[{id:"mon",label:"Lunes"},{id:"tue",label:"Martes"},{id:"wed",label:"Miércoles"},{id:"thu",label:"Jueves"},{id:"fri",label:"Viernes"},{id:"sat",label:"Sábado"},{id:"sun",label:"Domingo"}],He=Os.reduce((a,t)=>({...a,[t.id]:{enabled:!0,start:"09:00",end:"17:00"}}),{});function Ba({open:a,onOpenChange:t,onSuccess:n,teamToEdit:r}){const l=!!r,[d,x]=u.useState(""),[i,c]=u.useState(""),[h,p]=u.useState(!1);re(s=>s.user);const{addTeam:m,updateTeamInStore:o,members:f,fetchMembers:v,currentOrganization:k}=F(),[C,M]=u.useState([]),[G,I]=u.useState(!1),[D,P]=u.useState(He);u.useEffect(()=>{a&&k?.id&&(console.log("Fetching fresh members for team creation..."),v(k.id),r?(x(r.name),c(r.description||""),r.schedule?.days?P(r.schedule.days):P(He),r.members?M(r.members.map(s=>s.user.id)):M([])):(x(""),c(""),P(He),M([])))},[a,r,k?.id,f.length,v]);const b=async s=>{if(s.preventDefault(),!!k?.id){p(!0);try{const g={name:d,description:i,schedule:{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,days:D},memberIds:C};if(l&&r){const j=await q.updateTeam(k.id,r.id,g);o(j),y.success("Equipo actualizado correctamente")}else{const j=await q.createTeam(k.id,g);m(j),y.success("Equipo creado correctamente")}n(),t(!1)}catch(g){y.error(l?"Error al actualizar el equipo":"Error al crear el equipo"),console.error(g)}finally{p(!1)}}},S=(s,g,j)=>{P(T=>({...T,[s]:{...T[s],[g]:j}}))},U=s=>{M(g=>g.includes(s)?g.filter(j=>j!==s):[...g,s])},se=f.filter(s=>s&&s.user);return e.jsx(oe,{open:a,onOpenChange:t,children:e.jsxs(de,{className:"sm:max-w-[600px] max-h-[85vh] overflow-y-auto",children:[e.jsxs(ce,{children:[e.jsx(me,{children:l?"Editar Equipo":"Crear Nuevo Equipo"}),e.jsx(ue,{children:l?"Modifique los detalles y horarios del equipo.":"Configure los detalles y horarios del equipo."})]}),e.jsxs("form",{onSubmit:b,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx($,{htmlFor:"name",children:"Nombre del equipo"}),e.jsx(pe,{id:"name",value:d,onChange:s=>x(s.target.value),placeholder:"Ej: Ventas, Soporte...",required:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx($,{htmlFor:"description",children:"Descripción"}),e.jsx(pe,{id:"description",value:i,onChange:s=>c(s.target.value),placeholder:"Breve descripción del propósito del equipo"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx($,{children:"Miembros del Equipo"}),e.jsxs(Ae,{open:G,onOpenChange:I,children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"outline",role:"combobox","aria-expanded":G,className:"w-full justify-between h-auto min-h-10 py-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:C.length>0?C.map(s=>{const g=f.find(j=>j.user.id===s);return e.jsxs(te,{variant:"secondary",className:"mr-1 gap-1.5 pl-1",children:[e.jsxs(ve,{className:"h-5 w-5",children:[e.jsx(ke,{src:g?.user.avatarUrl||""}),e.jsx(ye,{className:"text-[10px]",children:(g?.user.name||g?.user.email||"U").slice(0,2).toUpperCase()})]}),g?.user.name||g?.user.email||"Usuario",e.jsx("span",{"aria-label":`Quitar a ${g?.user.name||g?.user.email||"este miembro"} del equipo`,className:"pointer-events-auto ml-1 flex cursor-pointer items-center rounded-full hover:text-destructive",onClick:j=>{j.preventDefault(),j.stopPropagation(),U(s)},children:e.jsx(Ps,{className:"h-3 w-3"})})]},s)}):e.jsx("span",{className:"text-muted-foreground",children:"Seleccionar miembros..."})}),e.jsx(da,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Ie,{className:"w-[var(--radix-popover-trigger-width)] p-0",children:e.jsxs(ta,{children:[e.jsx(ra,{placeholder:"Buscar miembro...",autoComplete:"off","data-lpignore":"true","data-form-type":"other"}),e.jsxs(na,{children:[e.jsx(la,{children:"No se encontraron miembros."}),e.jsx(ia,{children:se.map(s=>e.jsxs(oa,{value:s.user?.email,onSelect:()=>U(s.user?.id),children:[e.jsx(zs,{className:O("mr-2 h-4 w-4",C.includes(s.user?.id)?"opacity-100":"opacity-0")}),e.jsxs(ve,{className:"h-8 w-8 mr-2",children:[e.jsx(ke,{src:s.user?.avatarUrl||""}),e.jsx(ye,{className:"text-xs",children:(s.user?.name||s.user?.email||"U").slice(0,2).toUpperCase()})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.user?.name||"Sin nombre"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.user?.email})]})]},s.user?.id))})]})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Asigna miembros a este equipo. Solo se muestran miembros activos."})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{children:"Horario de Atención"}),e.jsx("div",{className:"border rounded-md p-4 space-y-4",children:Os.map(s=>e.jsxs("div",{className:"flex items-center justify-between space-x-4",children:[e.jsxs("div",{className:"flex items-center space-x-2 w-32",children:[e.jsx(Ne,{checked:D[s.id]?.enabled??!1,onCheckedChange:g=>S(s.id,"enabled",g)}),e.jsx("span",{className:"text-sm",children:s.label})]}),D[s.id]?.enabled&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(pe,{type:"time",className:"w-24 h-8",value:D[s.id]?.start||"09:00",onChange:g=>S(s.id,"start",g.target.value)}),e.jsx("span",{className:"text-muted-foreground",children:"-"}),e.jsx(pe,{type:"time",className:"w-24 h-8",value:D[s.id]?.end||"17:00",onChange:g=>S(s.id,"end",g.target.value)})]})]},s.id))})]}),e.jsx(xe,{children:e.jsx(w,{type:"submit",disabled:h,children:h?"Guardando...":l?"Guardar Cambios":"Crear Equipo"})})]})]})})}function Ya({onEdit:a}){const{teams:t,fetchTeams:n,removeTeamFromStore:r,currentOrganization:l}=F(),d=re(o=>o.user),[x,i]=u.useState(null),[c,h]=u.useState(!1);u.useEffect(()=>{l?.id&&n(l.id)},[l?.id,n]);const p=o=>{i(o)},m=async()=>{if(!(!l?.id||!x)){h(!0);try{await q.deleteTeam(l.id,x),y.success("Equipo eliminado"),r(x),i(null)}catch{y.error("Error al eliminar equipo")}finally{h(!1)}}};return e.jsxs("div",{className:"rounded-md border relative",children:[e.jsxs(Oe,{children:[e.jsx(Pe,{children:e.jsxs(V,{children:[e.jsx(E,{children:"Nombre"}),e.jsx(E,{children:"Descripción"}),e.jsx(E,{children:"Horario"}),e.jsx(E,{children:"Miembros"}),(d?.role==="OWNER"||d?.role==="ADMIN")&&e.jsx(E,{className:"text-right",children:"Acciones"})]})}),e.jsx(ze,{children:t.length===0?e.jsx(V,{children:e.jsx(N,{colSpan:5,className:"text-center h-24 text-muted-foreground",children:"No hay equipos registrados."})}):t.map(o=>e.jsxs(V,{children:[e.jsx(N,{className:"font-medium",children:o.name}),e.jsx(N,{children:o.description||"-"}),e.jsx(N,{children:o.schedule?.timezone?e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Configurado (",o.schedule.timezone,")"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No configurado"})}),e.jsx(N,{children:e.jsx("div",{className:"flex -space-x-2 overflow-hidden",children:o.members&&o.members.length>0?e.jsxs(e.Fragment,{children:[o.members.slice(0,3).map(f=>e.jsx(Ls,{children:e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{className:"relative inline-block cursor-pointer",children:e.jsxs(ve,{className:"h-6 w-6 ring-2 ring-background",children:[e.jsx(ke,{src:f.user.avatarUrl}),e.jsx(ye,{className:"text-[10px] bg-primary/10 text-primary",children:(f.user?.name||f.user?.email||"?").substring(0,2).toUpperCase()})]})})}),e.jsx(K,{children:e.jsx("p",{children:f.user?.name||f.user?.email||"Sin nombre"})})]})},f.id)),o.members.length>3&&e.jsxs("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-muted ring-2 ring-background text-[10px] font-medium",children:["+",o.members.length-3]})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Sin miembros"})})}),(d?.role==="OWNER"||d?.role==="ADMIN")&&e.jsx(N,{className:"text-right",children:e.jsxs(Ke,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(w,{variant:"ghost",className:"h-8 w-8 p-0",children:[e.jsx("span",{className:"sr-only",children:"Open menu"}),e.jsx(rs,{className:"h-4 w-4"})]})}),e.jsxs(Ze,{align:"end",children:[e.jsx(Qe,{children:"Acciones"}),e.jsxs(H,{onClick:()=>a?.(o),children:[e.jsx(ca,{className:"mr-2 h-4 w-4"}),"Configurar"]}),e.jsxs(H,{onClick:()=>p(o.id),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Eliminar"]})]})]})})]},o.id))})]}),e.jsx(ts,{open:!!x,onOpenChange:o=>!o&&i(null),onConfirm:m,title:"Eliminar Equipo",description:"¿Estás seguro que deseas eliminar este equipo? Esta acción no se puede deshacer.",confirmText:"Eliminar",variant:"destructive",loading:c})]})}function Ka({open:a,onOpenChange:t,onSuccess:n,invitation:r}){const[l,d]=u.useState("AGENT"),[x,i]=u.useState(!1);re(p=>p.user);const c=F(p=>p.currentOrganization);u.useEffect(()=>{r&&d(r.role)},[r]);const h=async p=>{if(p.preventDefault(),!(!c?.id||!r)){i(!0);try{await q.updateInvitation(c.id,r.id,l),y.success("Invitación actualizada correctamente"),n(),t(!1)}catch(m){y.error("Error al actualizar la invitación"),console.error(m)}finally{i(!1)}}};return e.jsx(oe,{open:a,onOpenChange:t,children:e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ce,{children:[e.jsx(me,{children:"Editar Invitación"}),e.jsx(ue,{children:"Modifica el rol asignado a este usuario."})]}),e.jsxs("form",{onSubmit:h,className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Email del usuario"}),e.jsx("div",{className:"p-2 bg-muted rounded-md text-sm text-muted-foreground",children:r?.email})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"role",children:"Rol"}),e.jsxs(ns,{value:l,onValueChange:d,children:[e.jsx(ls,{children:e.jsx(is,{placeholder:"Selecciona un rol"})}),e.jsxs(os,{children:[e.jsx(ie,{value:"ADMIN",children:"Administrador"}),e.jsx(ie,{value:"AGENT",children:"Agente"})]})]})]}),e.jsxs(xe,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>t(!1),children:"Cancelar"}),e.jsxs(w,{type:"submit",disabled:x,children:[x&&e.jsx(Je,{className:"mr-2 h-4 w-4 animate-spin"}),"Guardar Cambios"]})]})]})]})})}function Xa(){const{invitations:a,fetchInvitations:t,removeInvitationFromStore:n}=F(),{currentOrganization:r}=F(),l=r?.role,d=r?.id,[x,i]=u.useState(null),[c,h]=u.useState(null),[p,m]=u.useState(!1),[o,f]=u.useState(1),v=10;Ss(t);const k=[...a].sort((s,g)=>new Date(g.createdAt).getTime()-new Date(s.createdAt).getTime()),C=Math.ceil(k.length/v),M=k.slice((o-1)*v,o*v),G=s=>{const g=`${window.location.origin}/register?token=${s}`;navigator.clipboard.writeText(g),y.success("Enlace copiado al portapapeles")},I=s=>{h(s)},D=async()=>{if(!(!d||!c)){m(!0);try{await q.revokeInvitation(d,c),y.success("Invitación revocada"),n(c),h(null)}catch{y.error("Error al revocar invitación")}finally{m(!1)}}},P=async s=>{if(d)try{const g=await q.resendInvitation(d,s);if(ys){const j=await ws(g);y.success(j?"Copiamos el enlace de invitación":"Invitación renovada",{description:j?"Compártelo con la persona invitada. Vence en 7 días.":g.inviteUrl})}}catch{y.error("Error al reenviar invitación")}},b=s=>{switch(s){case"OWNER":return"Propietario";case"ADMIN":return"Administrador";case"AGENT":return"Agente";default:return s}},S=s=>{switch(s){case"ACCEPTED":return"Aceptada";case"PENDING":return"Pendiente";case"REVOKED":return"Cancelada";case"EXPIRED":return"Expirada";default:return s}},U=s=>{switch(s){case"OWNER":return"bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-900/20 dark:text-purple-300 dark:border-purple-800";case"ADMIN":return"bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-900/20 dark:text-blue-300 dark:border-blue-800";case"AGENT":return"bg-slate-50 text-slate-600 border-slate-200 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-700";default:return"bg-gray-50 text-gray-600 border-gray-200"}},se=s=>{switch(s){case"ACCEPTED":return"bg-green-50 text-green-700 border-green-200 dark:bg-green-900/20 dark:text-green-300 dark:border-green-800";case"PENDING":return"bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-900/20 dark:text-amber-300 dark:border-amber-800";case"REVOKED":return"bg-gray-50 text-gray-500 border-gray-200 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-700";case"EXPIRED":return"bg-red-50 text-red-600 border-red-200 dark:bg-red-900/20 dark:text-red-400 dark:border-red-800";default:return"bg-gray-50 text-gray-600 border-gray-200"}};return e.jsxs("div",{className:"rounded-md border relative overflow-hidden",children:[e.jsxs(Oe,{children:[e.jsx(Pe,{children:e.jsxs(V,{className:"bg-muted/30",children:[e.jsx(E,{className:"text-[11px] font-bold uppercase tracking-wider",children:"Email"}),e.jsx(E,{className:"text-[11px] font-bold uppercase tracking-wider",children:"Rol"}),e.jsx(E,{className:"text-[11px] font-bold uppercase tracking-wider",children:"Estado"}),e.jsx(E,{className:"text-[11px] font-bold uppercase tracking-wider",children:"Expira"}),(l==="OWNER"||l==="ADMIN")&&e.jsx(E,{className:"text-[11px] font-bold uppercase tracking-wider text-right",children:"Acciones"})]})}),e.jsx(ze,{children:M.length===0&&a.length===0?e.jsx(V,{children:e.jsx(N,{colSpan:5,className:"text-center h-24 text-muted-foreground",children:"No hay invitaciones registradas."})}):M.map(s=>e.jsxs(V,{className:`transition-opacity duration-200 ${s.status!=="PENDING"?"opacity-60 bg-muted/10":""}`,children:[e.jsx(N,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"w-3 h-3 text-muted-foreground cursor-pointer hover:text-primary transition-colors",onClick:()=>G(s.token)}),e.jsx("span",{className:s.status!=="PENDING"?"line-through decoration-muted-foreground/30":"",children:s.email}),s.isExternal&&e.jsx(te,{variant:"outline",className:"bg-sky-50 text-sky-700 border-sky-200 dark:bg-sky-900/20 dark:text-sky-300 dark:border-sky-800 text-[9px] font-bold uppercase py-0 px-1.5 h-4",children:"Externo"})]})}),e.jsx(N,{children:e.jsx(te,{variant:"outline",className:`${U(s.role)} text-[10px] font-bold uppercase py-0 px-2 h-5`,children:b(s.role)})}),e.jsx(N,{children:e.jsx(te,{variant:"outline",className:`${se(s.status)} text-[10px] font-bold uppercase py-0 px-2 h-5`,children:S(s.status)})}),e.jsx(N,{className:"text-xs text-muted-foreground",children:Es(s.expiresAt,{style:"date-only"})}),(l==="OWNER"||l==="ADMIN")&&e.jsx(N,{className:"text-right",children:e.jsxs(Ke,{children:[e.jsx(Xe,{asChild:!0,children:e.jsx(w,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted",children:e.jsx(rs,{className:"h-4 w-4"})})}),e.jsxs(Ze,{align:"end",className:"w-40",children:[e.jsx(Qe,{className:"text-[10px] uppercase text-muted-foreground",children:"Acciones"}),s.status==="PENDING"?e.jsxs(e.Fragment,{children:[e.jsxs(H,{onClick:()=>i(s),children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Editar Rol"]}),e.jsxs(H,{onClick:()=>G(s.token),children:[e.jsx(xs,{className:"mr-2 h-4 w-4"}),"Copiar Link"]}),e.jsxs(H,{onClick:()=>P(s.id),children:[e.jsx(Me,{className:"mr-2 h-4 w-4"}),"Reenviar"]}),e.jsxs(H,{onClick:()=>I(s.id),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Cancelar"]})]}):e.jsxs(H,{onClick:()=>I(s.id),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Eliminar"]})]})]})})]},s.id))})]}),C>1&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t bg-muted/5",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground font-medium",children:["Mostrando ",(o-1)*v+1," - ",Math.min(o*v,k.length)," de ",k.length]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"outline",size:"sm",className:"h-7 px-2",onClick:()=>f(s=>Math.max(1,s-1)),disabled:o===1,children:e.jsx(qs,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-[11px] font-medium min-w-[80px] text-center",children:["Pág. ",o," de ",C]}),e.jsx(w,{variant:"outline",size:"sm",className:"h-7 px-2",onClick:()=>f(s=>Math.min(C,s+1)),disabled:o===C,children:e.jsx(ks,{className:"h-4 w-4"})})]})]}),e.jsx(Ka,{open:!!x,onOpenChange:s=>!s&&i(null),invitation:x,onSuccess:()=>{i(null),t(d)}}),e.jsx(ts,{open:!!c,onOpenChange:s=>!s&&h(null),onConfirm:D,title:c&&a.find(s=>s.id===c)?.status==="PENDING"?"Cancelar Invitación":"Eliminar del Historial",description:c&&a.find(s=>s.id===c)?.status==="PENDING"?"¿Estás seguro que deseas cancelar esta invitación? El enlace dejará de ser válido inmediatamente.":"¿Deseas eliminar este registro del historial?",confirmText:c&&a.find(s=>s.id===c)?.status==="PENDING"?"Cancelar":"Eliminar",variant:"destructive",loading:p})]})}function Za({open:a,onOpenChange:t,onSuccess:n,member:r}){const[l,d]=u.useState("AGENT"),[x,i]=u.useState(!1);re(p=>p.user);const c=F(p=>p.currentOrganization);u.useEffect(()=>{r&&d(r.role)},[r]);const h=async p=>{if(p.preventDefault(),!(!c?.id||!r)){i(!0);try{await q.updateMember(c.id,r.id,l),y.success("Rol de miembro actualizado correctamente"),n(),t(!1)}catch(m){y.error("Error al actualizar el rol"),console.error(m)}finally{i(!1)}}};return e.jsx(oe,{open:a,onOpenChange:t,children:e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ce,{children:[e.jsx(me,{children:"Editar Miembro"}),e.jsx(ue,{children:"Modifica el rol asignado a este miembro del equipo."})]}),e.jsxs("form",{onSubmit:h,className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Usuario"}),e.jsxs("div",{className:"p-2 bg-muted rounded-md text-sm text-muted-foreground flex justify-between items-center",children:[e.jsx("span",{children:r?.name}),e.jsx("span",{className:"text-xs opacity-70",children:r?.email})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{htmlFor:"role",children:"Rol"}),e.jsxs(ns,{value:l,onValueChange:d,children:[e.jsx(ls,{children:e.jsx(is,{placeholder:"Selecciona un rol"})}),e.jsxs(os,{children:[e.jsx(ie,{value:"ADMIN",children:"Administrador"}),e.jsx(ie,{value:"AGENT",children:"Agente"})]})]})]}),e.jsxs(xe,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>t(!1),children:"Cancelar"}),e.jsxs(w,{type:"submit",disabled:x,children:[x&&e.jsx(Je,{className:"mr-2 h-4 w-4 animate-spin"}),"Guardar Cambios"]})]})]})]})})}function Qa({open:a,onOpenChange:t,member:n,onSuccess:r}){const l=F(m=>m.currentOrganization),[d,x]=u.useState(!1),[i,c]=u.useState([]);u.useEffect(()=>{a&&n&&c(n.permissions||[])},[a,n]);const h=async()=>{if(!(!l?.id||!n)){x(!0);try{await q.updateMemberPermissions(l.id,n.id,i),y.success("Permisos actualizados correctamente"),ge.getState().clearMembers(),r?.(),t(!1)}catch(m){console.error(m),y.error("Error al actualizar permisos")}finally{x(!1)}}},p=m=>{c(o=>o.includes(m)?o.filter(f=>f!==m):[...o,m])};return n?e.jsx(oe,{open:a,onOpenChange:t,children:e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ce,{children:[e.jsx(me,{children:"Permisos de Usuario"}),e.jsxs(ue,{children:["Administra los permisos granulares para ",n.user.name,"."]})]}),e.jsx("div",{className:"py-4 space-y-4",children:e.jsxs("div",{className:"flex items-center space-x-2 p-4 border rounded-lg bg-muted/20",children:[e.jsx(Ee,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx($,{htmlFor:"manage-credits",className:"font-medium",children:"Comprar Créditos"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Permite comprar paquetes de créditos adicionales."})]}),e.jsx(Ne,{id:"manage-credits",checked:i.includes(Z.MANAGE_CREDITS),onCheckedChange:()=>p(Z.MANAGE_CREDITS)})]})}),e.jsxs(xe,{children:[e.jsx(w,{variant:"outline",onClick:()=>t(!1),disabled:d,children:"Cancelar"}),e.jsx(w,{onClick:h,disabled:d,children:d?"Guardando...":"Guardar Cambios"})]})]})}):null}function Ja(){const a=Fs(),t=Gs(),n=ge(s=>s.fetchMembers),r=ge(s=>s.initWebSocketListeners),[l,d]=u.useState(null),[x,i]=u.useState(null),c=re(s=>s.user);c?.role==="OWNER"||c?.role;const h=c?.role==="OWNER",p=F(s=>s.currentOrganization),[m,o]=u.useState(new Set),[f,v]=u.useState(new Set),k=ge(s=>s.setMemberPermissions),C=u.useCallback(async(s,g)=>{const j=p?.id;if(!j)return;const T=s.permissions??[],_=g?T.filter(L=>L!==Z.DENY_INBOX_WAITING):[...T,Z.DENY_INBOX_WAITING];o(L=>new Set(L).add(s.id)),k(s.id,_);try{await q.updateMemberPermissions(j,s.id,_)}catch{k(s.id,T),y.error('No se pudo actualizar el acceso a "En Espera"')}finally{o(L=>{const ae=new Set(L);return ae.delete(s.id),ae})}},[p?.id,k]),M=u.useCallback(async(s,g)=>{const j=p?.id;if(!j)return;const T=s.permissions??[],_=g?[...T,Z.VIEW_ALL_CONVERSATIONS]:T.filter(L=>L!==Z.VIEW_ALL_CONVERSATIONS);v(L=>new Set(L).add(s.id)),k(s.id,_);try{await q.updateMemberPermissions(j,s.id,_)}catch{k(s.id,T),y.error("No se pudo actualizar el acceso a todas las conversaciones")}finally{v(L=>{const ae=new Set(L);return ae.delete(s.id),ae})}},[p?.id,k]),G=u.useCallback(s=>{n(s),r()},[n,r]);Ss(G);const I=async()=>{p?.id&&(ge.getState().clearMembers(),await n(p.id))},D=s=>s?s.split(" ").map(g=>g[0]).join("").toUpperCase().substring(0,2):"??",P=s=>{switch(s){case"OWNER":return"bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 border-purple-200 dark:border-purple-800";case"ADMIN":return"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800";case"AGENT":return"bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300 border-slate-200 dark:border-slate-700";default:return"bg-gray-100 text-gray-700"}},b=s=>{switch(s){case"AVAILABLE":return{color:"bg-green-500",label:"Disponible",textColor:"text-green-600 dark:text-green-400"};case"AWAY":return{color:"bg-yellow-500",label:"Ausente",textColor:"text-yellow-600 dark:text-yellow-400"};case"UNAVAILABLE":return{color:"bg-red-500",label:"No disponible",textColor:"text-red-600 dark:text-red-400"};default:return{color:"bg-gray-400",label:"Sin estado",textColor:"text-gray-500"}}},S=s=>{if(!s)return"Sin actividad";const g=new Date,j=new Date(s),T=g.getTime()-j.getTime(),_=Math.floor(T/6e4),L=Math.floor(T/36e5),ae=Math.floor(T/864e5);return _<1?"Activo ahora":_<5?"Hace unos minutos":_<60?`Hace ${_} min`:L<24?`Hace ${L}h`:`Hace ${ae} días`},U=s=>s?Date.now()-new Date(s).getTime()<600*1e3:!1,se=async s=>{if(p?.id)try{await q.removeMember(p.id,s),y.success("Miembro eliminado — 1 credito de Agentes liberado"),await I()}catch(g){console.error(g),y.error("No se pudo eliminar al miembro")}};return t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Cargando miembros..."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs(w,{variant:"outline",size:"sm",onClick:I,className:"gap-2",children:[e.jsx(Me,{className:`h-4 w-4 ${t?"animate-spin":""}`}),"Actualizar"]})}),e.jsxs("div",{className:"rounded-md border",children:[e.jsxs(Oe,{children:[e.jsx(Pe,{children:e.jsxs(V,{children:[e.jsx(E,{children:"Miembro"}),e.jsx(E,{children:"Email"}),e.jsx(E,{children:"Rol"}),e.jsx(E,{children:"Estado"}),e.jsx(E,{className:"text-center",children:'Ve "En Espera"'}),e.jsx(E,{className:"text-center",children:"Ve Todas las Conversaciones"}),e.jsx(E,{children:"Última Actividad"}),e.jsx(E,{className:"text-right",children:"Fecha de Ingreso"})]})}),e.jsx(ze,{children:a.length===0?e.jsx(V,{children:e.jsx(N,{colSpan:8,className:"text-center h-24 text-muted-foreground",children:"No se encontraron miembros."})}):a.map(s=>{const g=b(s.user.availabilityStatus),j=U(s.user.lastActivityAt);return e.jsxs(V,{className:s.user.isActive===!1?"opacity-50":"",children:[e.jsxs(N,{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsxs(ve,{className:"h-8 w-8",children:[e.jsx(ke,{src:s.user.avatarUrl}),e.jsx(ye,{children:D(s.user.name)})]}),j&&e.jsx("span",{className:"absolute bottom-0 right-0 w-2.5 h-2.5 bg-green-500 border-2 border-white dark:border-gray-900 rounded-full"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium",children:s.user.name||"Sin nombre"}),s.isExternal&&e.jsx(te,{variant:"outline",className:"bg-sky-50 text-sky-700 border-sky-200 dark:bg-sky-900/20 dark:text-sky-300 dark:border-sky-800 text-[9px] font-bold uppercase py-0 px-1.5 h-4",children:"Externo"})]}),s.user.isActive===!1&&e.jsx("span",{className:"text-xs text-red-500",children:"Desactivado"})]})]}),e.jsx(N,{className:"text-muted-foreground",children:s.user.email}),e.jsx(N,{children:e.jsx(te,{variant:"outline",className:`${P(s.role)} border shadow-sm`,children:s.role})}),e.jsx(N,{children:e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${g.color}`}),e.jsx("span",{className:`text-sm ${g.textColor}`,children:g.label})]})}),e.jsx(K,{children:e.jsx("p",{children:"Estado de disponibilidad manual"})})]})}),e.jsx(N,{className:"text-center",children:s.role==="AGENT"?e.jsx(Ne,{checked:!(s.permissions??[]).includes(Z.DENY_INBOX_WAITING),disabled:m.has(s.id)||!h,onCheckedChange:T=>C(s,T),"aria-label":`Permitir que ${s.user.name} vea la cola En Espera`}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx(N,{className:"text-center",children:s.role==="AGENT"?e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:e.jsx(Ne,{checked:(s.permissions??[]).includes(Z.VIEW_ALL_CONVERSATIONS),disabled:f.has(s.id)||!h,onCheckedChange:T=>M(s,T),"aria-label":`Permitir que ${s.user.name} vea las conversaciones de otros asesores`})})}),e.jsx(K,{children:e.jsx("p",{className:"max-w-[260px]",children:"Apagado, el asesor ve sólo sus conversaciones, las sin asignar y las que atiende la IA. El cambio se aplica de inmediato."})})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx(N,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:`text-sm ${j?"text-green-600 dark:text-green-400 font-medium":"text-muted-foreground"}`,children:S(s.user.lastActivityAt)})]})}),e.jsx(N,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground mr-4",children:Es(s.joinedAt,{style:"date-only"})}),(c?.role==="OWNER"||c?.role==="ADMIN")&&s.role!=="OWNER"&&s.user.id!==c?.id&&e.jsxs(Ke,{children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(w,{variant:"ghost",className:"h-8 w-8 p-0",children:[e.jsx("span",{className:"sr-only",children:"Open menu"}),e.jsx(rs,{className:"h-4 w-4"})]})}),e.jsxs(Ze,{align:"end",children:[e.jsx(Qe,{children:"Acciones"}),e.jsxs(H,{onClick:()=>d(s),children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Editar Rol"]}),s.role==="ADMIN"&&c?.role==="OWNER"&&e.jsxs(H,{onClick:()=>i(s),children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"Gestionar Permisos"]}),e.jsxs(H,{onClick:()=>se(s.id),className:"text-destructive focus:text-destructive",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Eliminar de la organización"]})]})]})]})})]},s.id)})})]}),e.jsx(Za,{open:!!l,onOpenChange:s=>!s&&d(null),member:l?{id:l.id,userId:l.user.id,name:l.user.name,email:l.user.email,role:l.role}:null,onSuccess:()=>{d(null),I()}}),e.jsx(Qa,{open:!!x,onOpenChange:s=>!s&&i(null),member:x,onSuccess:I})]})]})}function et({open:a,onOpenChange:t,onSuccess:n}){const[r,l]=u.useState(""),[d,x]=u.useState("AGENT"),[i,c]=u.useState(!1),[h,p]=u.useState(!1);re(b=>b.user);const{addInvitation:m,currentOrganization:o}=F(),f=o?.authPolicy==="domain_restricted",v=o?.role==="OWNER",k=f&&v,{pool:C,limitReached:M,blocked:G,refetch:I}=xa({resourceType:"AGENTS",enabled:a}),D=()=>{l(""),x("AGENT"),c(!1)},P=async b=>{if(b.preventDefault(),!!o?.id){p(!0);try{const S=await q.createInvitation(o.id,{email:r,role:d,...i&&{isExternal:!0}});if(m(S),ys){const U=await ws(S);y.success(U?"Copiamos el enlace de invitación":"Invitación creada",{description:U?`Envíaselo a ${r} por WhatsApp o correo. Vence en 7 días.`:S.inviteUrl})}I(),n(),t(!1),D()}catch(S){if(console.error(S),!ha(S,{title:"Limite de Agentes Alcanzado",fallbackDescription:"Tu plan no permite agregar mas agentes."})){const U=S?.response?.data?.message||S?.message||"Error al enviar la invitacion";y.error(U)}}finally{p(!1)}}};return e.jsx(oe,{open:a,onOpenChange:b=>{b||D(),t(b)},children:e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ce,{children:[e.jsx(me,{children:"Invitar usuario"}),e.jsx(ue,{children:"Envia una invitacion por correo electronico para unirte a tu organizacion."})]}),e.jsx(pa,{pool:C,lowThreshold:2}),e.jsxs("form",{onSubmit:P,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx($,{htmlFor:"email",className:"text-right",children:"Email"}),e.jsx(pe,{id:"email",type:"email",value:r,onChange:b=>l(b.target.value),className:"col-span-3",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx($,{htmlFor:"role",className:"text-right",children:"Rol"}),e.jsxs(ns,{value:d,onValueChange:x,children:[e.jsx(ls,{className:"col-span-3",children:e.jsx(is,{placeholder:"Selecciona un rol"})}),e.jsxs(os,{children:[e.jsx(ie,{value:"AGENT",children:"Agente"}),e.jsx(ie,{value:"ADMIN",children:"Administrador"})]})]})]}),k&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx($,{htmlFor:"isExternal",className:"text-sm font-medium cursor-pointer",children:"Usuario externo"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Permite invitar usuarios fuera del dominio corporativo"})]}),e.jsx(Ne,{id:"isExternal",checked:i,onCheckedChange:c})]}),i&&e.jsxs(ma,{className:"border-blue-200 bg-blue-50 dark:border-blue-800 dark:bg-blue-950/30",children:[e.jsx(J,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),e.jsx(ua,{className:"text-xs text-blue-700 dark:text-blue-300",children:"Este usuario no necesita pertenecer a los dominios registrados de la organizacion. Sera protegido contra las restricciones de dominio."})]})]})]}),e.jsx(xe,{children:e.jsx(w,{type:"submit",disabled:h||!!M||!!G,children:h?"Enviando...":"Enviar invitacion"})})]})]})})}const W=Us()(Ws((a,t)=>({dateRangePreset:"7d",customStartDate:null,customEndDate:null,selectedMemberId:null,_forceRefresh:!1,setDateRangePreset:n=>a({dateRangePreset:n}),setCustomDateRange:(n,r)=>a({customStartDate:n,customEndDate:r,dateRangePreset:"custom"}),setSelectedMember:n=>a({selectedMemberId:n}),getDateRange:()=>{const n=t(),r=new Date;if(n.dateRangePreset==="custom"&&n.customStartDate&&n.customEndDate)return{startDate:n.customStartDate,endDate:n.customEndDate};let l=7;n.dateRangePreset==="today"&&(l=0),n.dateRangePreset==="30d"&&(l=30);const d=new Date(r);return d.setDate(d.getDate()-l),d.setHours(0,0,0,0),{startDate:d.toISOString(),endDate:r.toISOString()}},getTimezone:()=>Cs.getState().getEffectiveTimezone(),requestForceRefresh:()=>a({_forceRefresh:!0}),clearForceRefresh:()=>a({_forceRefresh:!1}),clearFilters:()=>a({dateRangePreset:"7d",customStartDate:null,customEndDate:null,selectedMemberId:null})}),{name:"member-stats-filters",storage:$s(()=>localStorage),partialize:a=>({dateRangePreset:a.dateRangePreset,customStartDate:a.customStartDate,customEndDate:a.customEndDate})})),st=[{value:"today",label:"Hoy"},{value:"7d",label:"7 días"},{value:"30d",label:"30 días"}],at=10;function tt(){const{dateRangePreset:a,setDateRangePreset:t,setCustomDateRange:n,getDateRange:r}=W(),l=Cs(b=>b.getEffectiveTimezone()),d=Vs(),[x,i]=u.useState(!1),[c,h]=u.useState(""),[p,m]=u.useState(""),[o,f]=u.useState(!1),[v,k]=u.useState(0),C=u.useRef(null);u.useEffect(()=>()=>{C.current&&clearInterval(C.current)},[]);const M=o||v>0,G=u.useCallback(async()=>{M||(f(!0),W.getState().requestForceRefresh(),await d.invalidateQueries({queryKey:["member-stats"]}),W.getState().clearForceRefresh(),y.success("Estadísticas actualizadas"),f(!1),k(at),C.current=setInterval(()=>{k(b=>b<=1?(C.current&&clearInterval(C.current),C.current=null,0):b-1)},1e3))},[M,d]),I=()=>{if(c&&p){const b=new Date(c+"T00:00:00"),S=new Date(p+"T23:59:59");b<=S?(n(b.toISOString(),S.toISOString()),i(!1)):y.error("La fecha de inicio debe ser anterior a la fecha de fin")}},D=r(),P=a==="custom"?`${ne(new Date(D.startDate),"dd MMM",{locale:le})} - ${ne(new Date(D.endDate),"dd MMM yyyy",{locale:le})}`:null;return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("div",{className:"flex items-center rounded-lg border border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/50 p-0.5",children:st.map(b=>e.jsx("button",{onClick:()=>t(b.value),className:O("px-3 py-1.5 text-[11px] font-bold uppercase tracking-wider rounded-md transition-all duration-200",a===b.value?"bg-white dark:bg-slate-700 text-foreground shadow-sm border border-slate-200 dark:border-slate-600":"text-muted-foreground hover:text-foreground"),children:b.label},b.value))}),e.jsxs(Ae,{open:x,onOpenChange:i,children:[e.jsx(Re,{asChild:!0,children:e.jsxs("button",{className:O("flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-bold uppercase tracking-wider rounded-lg border transition-all duration-200",a==="custom"?"bg-white dark:bg-slate-700 text-foreground shadow-sm border-slate-200 dark:border-slate-600":"border-slate-200 dark:border-slate-700 text-muted-foreground hover:text-foreground hover:border-slate-300 bg-slate-50 dark:bg-slate-800/50"),children:[e.jsx(ga,{className:"w-3.5 h-3.5"}),P||"Personalizado"]})}),e.jsx(Ie,{className:"w-auto p-4 rounded-xl border-slate-200 dark:border-slate-700 shadow-lg",align:"start",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-[11px] font-bold text-muted-foreground uppercase tracking-widest",children:["Rango personalizado (",l,")"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider mb-1 block",children:"Desde"}),e.jsx("input",{type:"date",className:"flex h-9 w-full rounded-lg border border-slate-200 dark:border-slate-700 bg-transparent px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50",value:c,max:p||void 0,onChange:b=>h(b.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider mb-1 block",children:"Hasta"}),e.jsx("input",{type:"date",className:"flex h-9 w-full rounded-lg border border-slate-200 dark:border-slate-700 bg-transparent px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50",value:p,min:c||void 0,onChange:b=>m(b.target.value)})]})]}),e.jsx(w,{size:"sm",className:"w-full rounded-lg",onClick:I,disabled:!c||!p,children:"Aplicar"})]})})]}),e.jsxs("button",{onClick:G,disabled:M,className:O("flex items-center gap-1 px-1.5 py-1.5 rounded-lg border transition-all duration-200 ml-1",M?"border-slate-200 dark:border-slate-700 bg-slate-100 dark:bg-slate-800/80 text-muted-foreground/40 cursor-not-allowed":"border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/50 text-muted-foreground hover:text-foreground hover:border-slate-300"),title:v>0?`Disponible en ${v}s`:"Actualizar",children:[e.jsx(Me,{className:O("w-3.5 h-3.5",o&&"animate-spin")}),v>0&&e.jsxs("span",{className:"text-[10px] font-bold tabular-nums text-muted-foreground/50 pr-0.5",children:[v,"s"]})]})]})}const ds={getTeamOverview:async a=>(await Le.get("/analytics/members/overview",{params:a})).data,getMemberLeaderboard:async a=>(await Le.get("/analytics/members/leaderboard",{params:a})).data,getMemberDetail:async(a,t)=>(await Le.get(`/analytics/members/${a}/details`,{params:t})).data},cs=60*1e3,ms=180*1e3;function us(){const a=W(c=>c.getDateRange),t=W(c=>c.getTimezone),n=W(c=>c.dateRangePreset),r=W(c=>c.customStartDate),l=W(c=>c.customEndDate),d=W(c=>c._forceRefresh),x=a(),i=t();return{params:{...x,timezone:i,forceRefresh:d||void 0},keyDeps:[n,r,l,i]}}function rt(){const a=F(r=>r.currentOrganization?.id),{params:t,keyDeps:n}=us();return es({queryKey:["member-stats","overview",a,...n],queryFn:()=>ds.getTeamOverview(t),enabled:!!a,staleTime:cs,gcTime:ms,placeholderData:ss})}function nt(){const a=F(r=>r.currentOrganization?.id),{params:t,keyDeps:n}=us();return es({queryKey:["member-stats","leaderboard",a,...n],queryFn:()=>ds.getMemberLeaderboard(t),enabled:!!a,staleTime:cs,gcTime:ms,placeholderData:ss})}function lt(a){const t=F(l=>l.currentOrganization?.id),{params:n,keyDeps:r}=us();return es({queryKey:["member-stats","detail",t,a,...r],queryFn:()=>ds.getMemberDetail(a,n),enabled:!!t&&!!a,staleTime:cs,gcTime:ms,placeholderData:ss})}function Q(a){if(a==null)return"-";if(a<60)return`${Math.round(a)}s`;if(a<3600)return`${Math.round(a/60)}m`;const t=Math.floor(a/3600),n=Math.round(a%3600/60);return n>0?`${t}h ${n}m`:`${t}h`}const Te=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#6366f1","#f43f5e","#14b8a6"];function it({title:a,value:t,subtext:n,icon:r,color:l,bg:d,gradient:x,tooltip:i}){return e.jsxs(A,{className:"h-full border-slate-100 dark:border-slate-800 transition-all duration-300 hover:shadow-lg group relative overflow-hidden bg-white dark:bg-slate-900",children:[x&&e.jsx("div",{className:O("absolute inset-0 bg-gradient-to-br opacity-50 group-hover:opacity-100 transition-opacity",x)}),e.jsxs(R,{className:"p-5 relative z-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("div",{className:O("p-2.5 rounded-xl backdrop-blur-sm transition-transform group-hover:scale-110 duration-300",d),children:e.jsx("span",{className:l,children:r})}),i&&e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(J,{className:"w-3.5 h-3.5 text-slate-400"})})}),e.jsx(K,{side:"top",className:"max-w-[220px] text-center",children:i})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest",children:a}),e.jsxs("div",{className:"flex items-baseline gap-1.5 mt-1",children:[e.jsx("p",{className:O("text-3xl font-bold tracking-tight",l),children:t}),e.jsx("span",{className:"text-[10px] text-slate-400 font-medium whitespace-nowrap",children:n})]})]})]})]})}const ot=a=>{const{cx:t,cy:n,innerRadius:r,outerRadius:l,startAngle:d,endAngle:x,fill:i}=a;return e.jsxs("g",{children:[e.jsx(ps,{cx:t,cy:n,innerRadius:r-3,outerRadius:l+8,startAngle:d,endAngle:x,fill:i,opacity:.15,cornerRadius:4}),e.jsx(ps,{cx:t,cy:n,innerRadius:r-2,outerRadius:l+6,startAngle:d,endAngle:x,fill:i,opacity:.95,cornerRadius:4})]})};function dt(){const{data:a,isLoading:t,error:n,refetch:r}=rt(),[l,d]=u.useState(-1),x=u.useCallback((o,f)=>{d(f)},[]),i=u.useCallback(()=>{d(-1)},[]),c=u.useMemo(()=>[{title:"Total Tickets",value:(a?.totalTickets??0).toLocaleString(),subtext:`${a?.resolvedTickets??0} resueltos`,icon:e.jsx(ja,{className:"w-4 h-4"}),color:"text-blue-600 dark:text-blue-400",bg:"bg-blue-500/10",gradient:"from-blue-500/5 to-blue-500/10",tooltip:"Cantidad total de tickets asignados a agentes humanos en el período. Te permite dimensionar la carga de trabajo del equipo."},{title:"Tiempo de Respuesta",value:Q(a?.avgFirstResponseSeconds??null),subtext:"Primera respuesta",icon:e.jsx(fe,{className:"w-4 h-4"}),color:"text-amber-600 dark:text-amber-400",bg:"bg-amber-500/10",gradient:"from-amber-500/5 to-amber-500/10",tooltip:"Tiempo promedio desde que llega un ticket hasta la primera respuesta de un agente. Mientras más bajo, mejor experiencia para el cliente. Lo ideal es menos de 5 minutos."},{title:"Tiempo de Resolución",value:Q(a?.avgResolutionSeconds??null),subtext:"Promedio equipo",icon:e.jsx(_s,{className:"w-4 h-4"}),color:"text-emerald-600 dark:text-emerald-400",bg:"bg-emerald-500/10",gradient:"from-emerald-500/5 to-emerald-500/10",tooltip:"Tiempo promedio que toma resolver completamente un ticket. Ayuda a identificar si el equipo necesita más recursos o capacitación."},{title:"Tasa de Resolución",value:`${a?.resolutionRate??0}%`,subtext:"Resueltos",icon:e.jsx(Rs,{className:"w-4 h-4"}),color:"text-violet-600 dark:text-violet-400",bg:"bg-violet-500/10",gradient:"from-violet-500/5 to-violet-500/10",tooltip:"Porcentaje de tickets que fueron resueltos del total asignado. Una tasa mayor a 85% indica buena eficiencia operativa."}],[a]),h=a?.agentWorkload??[],p=u.useMemo(()=>h.length>0?Math.max(...h.map(o=>o.ticketCount)):1,[h]),m=a?.totalTickets??0;return n?e.jsx(A,{className:"border-rose-200/50 bg-rose-50/30 dark:bg-rose-950/10",children:e.jsxs(R,{className:"flex flex-col items-center justify-center py-8 gap-4",children:[e.jsx(as,{className:"h-10 w-10 text-rose-500/70"}),e.jsx("p",{className:"text-rose-600 dark:text-rose-400 text-sm font-medium",children:"Error al cargar estadísticas del equipo"}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>r(),children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),"Reintentar"]})]})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[1,2,3,4].map(o=>e.jsx(A,{className:"border-slate-100 dark:border-slate-800 bg-white dark:bg-slate-900",children:e.jsxs(R,{className:"p-5",children:[e.jsx(z,{className:"h-10 w-10 rounded-xl mb-4"}),e.jsx(z,{className:"h-3 w-20 mb-2"}),e.jsx(z,{className:"h-8 w-28"})]})},o))}),e.jsx(A,{className:"border-slate-100 dark:border-slate-800 bg-white dark:bg-slate-900",children:e.jsxs(R,{className:"p-6",children:[e.jsx(z,{className:"h-5 w-56 mb-4"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(z,{className:"h-[260px] w-full rounded-xl"}),e.jsx("div",{className:"space-y-4",children:[1,2,3].map(o=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{className:"h-4 w-full"}),e.jsx(z,{className:"h-2 w-full rounded-full"})]},o))})]})]})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:c.map(o=>e.jsx(it,{...o},o.title))}),h.length>0&&e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsx(X,{className:"pb-2",children:e.jsxs(ee,{className:"text-sm font-bold text-slate-500 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-violet-500/10",children:e.jsx(be,{className:"w-4 h-4 text-violet-600 dark:text-violet-400"})}),"Distribución de Carga de Trabajo",e.jsxs(Ae,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(w,{variant:"ghost",className:"h-6 w-6 p-0 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(J,{className:"h-4 w-4 text-violet-500 cursor-help"})})}),e.jsx(Ie,{className:"w-80 p-4 shadow-2xl border-violet-100 dark:border-violet-900/30",side:"right",align:"start",children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b border-slate-100 dark:border-slate-800",children:[e.jsx(be,{className:"h-4 w-4 text-violet-500"}),e.jsx("span",{className:"font-bold text-slate-900 dark:text-white",children:"Carga de Trabajo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-semibold text-violet-600 dark:text-violet-400",children:"¿Qué muestra este gráfico?"}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 text-xs leading-relaxed",children:"Muestra cómo se reparten los tickets entre los agentes del equipo. Te ayuda a detectar si la carga está equilibrada o si algún agente está sobrecargado."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-semibold text-slate-800 dark:text-slate-200 text-xs",children:"Cómo aprovecharlo:"}),e.jsxs("ul",{className:"list-disc pl-4 space-y-1 text-[11px] text-slate-600 dark:text-slate-400",children:[e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Distribución pareja:"})," Indica buena asignación de trabajo."]}),e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Un agente con muchos más:"})," Puede necesitar apoyo o reasignación."]}),e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Agente con pocos tickets:"})," Oportunidad para asignar más o capacitar."]})]})]})]})})]})]})}),e.jsx(R,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Se,{width:"100%",height:280,children:e.jsxs(Xs,{children:[e.jsx("defs",{children:Te.map((o,f)=>e.jsxs("linearGradient",{id:`donutGrad-${f}`,x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:o,stopOpacity:1}),e.jsx("stop",{offset:"100%",stopColor:o,stopOpacity:.7})]},`grad-${f}`))}),e.jsx(Zs,{data:h,dataKey:"ticketCount",nameKey:"agentName",cx:"50%",cy:"50%",outerRadius:105,innerRadius:68,paddingAngle:h.length>1?4:0,cornerRadius:4,strokeWidth:0,activeIndex:l>=0?l:void 0,activeShape:ot,onMouseEnter:x,onMouseLeave:i,children:h.map((o,f)=>e.jsx(Qs,{fill:`url(#donutGrad-${f%Te.length})`,className:"transition-opacity duration-200",opacity:l>=0&&l!==f?.4:1},`cell-${f}`))})]})}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center pointer-events-none",children:[e.jsx("span",{className:"text-4xl font-bold tracking-tight text-foreground",children:m}),e.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mt-0.5",children:"Total"})]})]}),e.jsx("div",{className:"space-y-4 py-2",children:h.map((o,f)=>{const v=Te[f%Te.length],k=o.ticketCount/p*100,C=l===f;return e.jsxs("div",{className:"group cursor-default",onMouseEnter:()=>d(f),onMouseLeave:()=>d(-1),children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:O("w-3 h-3 rounded-full shadow-sm transition-transform duration-200",C&&"scale-125"),style:{backgroundColor:v}}),e.jsx("span",{className:O("text-sm font-semibold transition-colors duration-200",C?"text-foreground":"text-slate-600 dark:text-slate-300"),children:o.agentName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-bold text-foreground tabular-nums",children:o.ticketCount}),e.jsxs("span",{className:"text-[11px] text-slate-400 font-medium tabular-nums",children:["(",o.percentage,"%)"]})]})]}),e.jsx("div",{className:"w-full h-2 bg-slate-100 dark:bg-slate-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 ease-out",style:{width:`${k}%`,backgroundColor:v,opacity:C?1:.75}})})]},o.agentId)})})]})})]})]})}function ct(a){return a>=90?"text-emerald-600 dark:text-emerald-400":a>=70?"text-amber-600 dark:text-amber-400":"text-rose-600 dark:text-rose-400"}function mt(a){return a>=90?"bg-emerald-50 dark:bg-emerald-500/10":a>=70?"bg-amber-50 dark:bg-amber-500/10":"bg-rose-50 dark:bg-rose-500/10"}function ut(a){return a.split(" ").map(t=>t[0]).join("").toUpperCase().substring(0,2)}const xt=["bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border-amber-200 dark:border-amber-500/30","bg-slate-100 dark:bg-slate-500/20 text-slate-600 dark:text-slate-400 border-slate-200 dark:border-slate-500/30","bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-200 dark:border-orange-500/30"];function ht({field:a,sortField:t,sortDir:n}){return t!==a?e.jsx(ba,{className:"w-3 h-3 ml-1 opacity-30"}):n==="desc"?e.jsx(Na,{className:"w-3 h-3 ml-1 text-primary"}):e.jsx(va,{className:"w-3 h-3 ml-1 text-primary"})}function pt({onSelectMember:a}){const{data:t,isLoading:n,error:r}=nt(),[l,d]=u.useState("ticketsAssigned"),[x,i]=u.useState("desc"),c=u.useMemo(()=>t?[...t].sort((m,o)=>{const f=m[l]??0,v=o[l]??0;return x==="desc"?v-f:f-v}):[],[t,l,x]),h=u.useCallback(m=>{l===m?i(o=>o==="desc"?"asc":"desc"):(d(m),i("desc"))},[l]);if(r)return e.jsx(A,{className:"border-rose-200/50 bg-rose-50/30 dark:bg-rose-950/10",children:e.jsxs(R,{className:"flex flex-col items-center justify-center py-8 gap-4",children:[e.jsx(as,{className:"h-10 w-10 text-rose-500/70"}),e.jsx("p",{className:"text-rose-600 dark:text-rose-400 text-sm font-medium",children:"Error al cargar la tabla de rendimiento"})]})});if(n)return e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm",children:[e.jsx(X,{className:"pb-2",children:e.jsx(z,{className:"h-5 w-48"})}),e.jsx(R,{children:e.jsx("div",{className:"space-y-3",children:[1,2,3].map(m=>e.jsx(z,{className:"h-16 w-full rounded-xl"},m))})})]});if(!c.length)return e.jsx(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm",children:e.jsxs(R,{className:"flex flex-col items-center justify-center py-12 gap-3",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-slate-500/10",children:e.jsx(be,{className:"h-8 w-8 text-slate-400"})}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"No hay datos de rendimiento disponibles"}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:"para el período seleccionado"})]})});const p=[{field:"ticketsAssigned",label:"Tickets",tooltip:"Total de tickets asignados al agente en el período."},{field:"ticketsResolved",label:"Resueltos",tooltip:"Tickets que el agente marcó como resueltos."},{field:"resolutionRate",label:"Tasa Res.",tooltip:"Porcentaje de tickets resueltos del total asignado. Verde (≥90%) es excelente, amarillo (70-89%) es aceptable, rojo (<70%) necesita atención."},{field:"avgFirstResponseSeconds",label:"T. Respuesta",tooltip:"Tiempo promedio hasta la primera respuesta del agente. Menos es mejor."},{field:"avgResolutionSeconds",label:"T. Resolución",tooltip:"Tiempo promedio para resolver un ticket completamente."},{field:"messagesSent",label:"Mensajes",tooltip:"Total de mensajes enviados por el agente en el período."}];return e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm hover:shadow-md transition-all duration-300 overflow-hidden",children:[e.jsxs(X,{className:"pb-3",children:[e.jsxs(ee,{className:"text-sm font-bold text-slate-500 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-500/10",children:e.jsx(Ns,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),"Tabla de Rendimiento",e.jsxs(Ae,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(w,{variant:"ghost",className:"h-6 w-6 p-0 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(J,{className:"h-4 w-4 text-blue-500 cursor-help"})})}),e.jsx(Ie,{className:"w-80 p-4 shadow-2xl border-blue-100 dark:border-blue-900/30",side:"right",align:"start",children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b border-slate-100 dark:border-slate-800",children:[e.jsx(Ns,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-bold text-slate-900 dark:text-white",children:"Ranking del Equipo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-semibold text-blue-600 dark:text-blue-400",children:"¿Qué muestra esta tabla?"}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 text-xs leading-relaxed",children:"Compara el rendimiento individual de cada agente. Puedes ordenar por cualquier columna haciendo click en el encabezado."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-semibold text-slate-800 dark:text-slate-200 text-xs",children:"Cómo aprovecharlo:"}),e.jsxs("ul",{className:"list-disc pl-4 space-y-1 text-[11px] text-slate-600 dark:text-slate-400",children:[e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Ordena por Tasa Res.:"})," Identifica quién necesita apoyo."]}),e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Ordena por T. Respuesta:"})," Encuentra oportunidades de mejora en atención."]}),e.jsxs("li",{children:[e.jsx("span",{className:"font-bold text-slate-700 dark:text-slate-300",children:"Haz click en un agente:"})," Ve su detalle completo con tendencias."]})]})]}),e.jsx("div",{className:"bg-slate-50 dark:bg-slate-800/50 p-2 rounded-lg text-[10px] text-slate-500 italic",children:"Tip: Pasa el mouse sobre cada columna para ver qué mide."})]})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Click en un miembro para ver sus estadísticas detalladas"})]}),e.jsx(R,{className:"px-0 pb-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Oe,{children:[e.jsx(Pe,{children:e.jsxs(V,{className:"border-slate-100 dark:border-slate-800 hover:bg-transparent",children:[e.jsx(E,{className:"w-12 pl-6 text-[10px] font-bold uppercase tracking-widest text-slate-400",children:"#"}),e.jsx(E,{className:"text-[10px] font-bold uppercase tracking-widest text-slate-400",children:"Miembro"}),p.map(m=>e.jsx(E,{className:"text-center cursor-pointer select-none hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors text-[10px] font-bold uppercase tracking-widest text-slate-400",onClick:()=>h(m.field),children:e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs("div",{className:"flex items-center justify-center",children:[m.label,e.jsx(ht,{field:m.field,sortField:l,sortDir:x})]})}),e.jsx(K,{side:"top",className:"max-w-[200px] text-center",children:m.tooltip})]})},m.field)),e.jsx(E,{className:"w-10 pr-6"})]})}),e.jsx(ze,{children:c.map((m,o)=>e.jsxs(V,{className:"cursor-pointer border-slate-50 dark:border-slate-800/50 hover:bg-slate-50/80 dark:hover:bg-slate-800/30 transition-colors group",onClick:()=>a(m.userId),children:[e.jsx(N,{className:"pl-6",children:o<3?e.jsx("span",{className:O("inline-flex items-center justify-center w-7 h-7 rounded-lg text-[11px] font-bold border",xt[o]),children:o+1}):e.jsx("span",{className:"inline-flex items-center justify-center w-7 h-7 text-xs font-medium text-muted-foreground",children:o+1})}),e.jsx(N,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(ve,{className:"h-9 w-9 border-2 border-white dark:border-slate-800 shadow-sm",children:[e.jsx(ke,{src:m.avatarUrl||void 0}),e.jsx(ye,{className:"text-xs font-bold bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400",children:ut(m.name)})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm text-foreground truncate",children:m.name}),m.openTickets>0&&e.jsxs(te,{variant:"outline",className:"mt-0.5 text-[9px] font-bold px-1.5 py-0 border-blue-200 text-blue-600 dark:border-blue-800 dark:text-blue-400",children:[m.openTickets," abiertos"]})]})]})}),e.jsx(N,{className:"text-center",children:e.jsx("span",{className:"text-sm font-bold text-foreground tabular-nums",children:m.ticketsAssigned})}),e.jsx(N,{className:"text-center",children:e.jsx("span",{className:"text-sm font-medium text-foreground/80 tabular-nums",children:m.ticketsResolved})}),e.jsx(N,{className:"text-center",children:e.jsxs("span",{className:O("inline-flex items-center px-2 py-0.5 rounded-md text-xs font-bold tabular-nums",ct(m.resolutionRate),mt(m.resolutionRate)),children:[m.resolutionRate,"%"]})}),e.jsx(N,{className:"text-center",children:e.jsx("span",{className:"text-sm font-mono text-muted-foreground tabular-nums",children:Q(m.avgFirstResponseSeconds)})}),e.jsx(N,{className:"text-center",children:e.jsx("span",{className:"text-sm font-mono text-muted-foreground tabular-nums",children:Q(m.avgResolutionSeconds)})}),e.jsx(N,{className:"text-center",children:e.jsx("span",{className:"text-sm font-medium text-foreground/80 tabular-nums",children:m.messagesSent})}),e.jsx(N,{className:"pr-6",children:e.jsx(ks,{className:"w-4 h-4 text-muted-foreground/40 group-hover:text-foreground group-hover:translate-x-0.5 transition-all duration-200"})})]},m.userId))})]})})})]})}const Be={borderRadius:"12px",border:"1px solid hsl(var(--border))",backgroundColor:"hsl(var(--card))",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)",fontSize:"12px",padding:"8px 12px"};function Ye({title:a,displayValue:t,comparisonPercent:n,teamLabel:r,tooltipText:l,icon:d,color:x,bg:i,gradient:c,invertColors:h=!1,teamAgentCount:p}){const m=p<=1,o=h?n<0:n>0,f=n===0,v=f||m?"text-slate-500 bg-slate-100 dark:bg-slate-800":o?"text-emerald-700 bg-emerald-50 dark:bg-emerald-500/10 dark:text-emerald-400":"text-rose-700 bg-rose-50 dark:bg-rose-500/10 dark:text-rose-400";return e.jsxs(A,{className:"h-full border-slate-100 dark:border-slate-800 transition-all duration-300 hover:shadow-lg group relative overflow-hidden bg-white dark:bg-slate-900",children:[e.jsx("div",{className:O("absolute inset-0 bg-gradient-to-br opacity-50 group-hover:opacity-100 transition-opacity",c)}),e.jsxs(R,{className:"p-5 relative z-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:O("p-2.5 rounded-xl backdrop-blur-sm transition-transform group-hover:scale-110 duration-300",i),children:e.jsx("span",{className:x,children:d})}),e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(J,{className:"w-3.5 h-3.5 text-slate-400"})})}),e.jsx(K,{side:"top",className:"max-w-[220px] text-center",children:l})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest",children:a}),e.jsx("p",{className:O("text-2xl font-bold tracking-tight mt-1",x),children:t}),e.jsxs("div",{className:"flex items-center justify-between mt-2.5",children:[e.jsx("span",{className:O("inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-bold",v),children:m?e.jsxs(e.Fragment,{children:[e.jsx(ya,{className:"w-3 h-3"}),"Único agente"]}):f?e.jsxs(e.Fragment,{children:[e.jsx(wa,{className:"w-3 h-3"}),"Igual al equipo"]}):o?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-3 h-3"}),"+",n,"%"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ma,{className:"w-3 h-3"}),n,"%"]})}),e.jsx("span",{className:"text-[10px] text-slate-400 font-medium truncate ml-2",children:r})]})]})]})]})}function gt({userId:a,onBack:t,backLabel:n="Volver"}){const{data:r,isLoading:l,error:d}=lt(a),x=u.useMemo(()=>Array.from({length:24},(i,c)=>{const p=(r?.activityHeatmap.filter(m=>m.hour===c)||[]).reduce((m,o)=>m+o.count,0);return{hour:`${c}:00`,count:p}}),[r?.activityHeatmap]);return d?e.jsx(A,{className:"border-rose-200/50 bg-rose-50/30 dark:bg-rose-950/10",children:e.jsxs(R,{className:"flex flex-col items-center justify-center py-8 gap-4",children:[e.jsx(as,{className:"h-10 w-10 text-rose-500/70"}),e.jsx("p",{className:"text-rose-600 dark:text-rose-400 text-sm font-medium",children:"Error al cargar estadísticas detalladas"}),e.jsxs(w,{onClick:t,variant:"outline",size:"sm",className:"rounded-lg",children:[e.jsx(bs,{className:"w-4 h-4 mr-2"}),n]})]})}):l?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:"h-9 w-20 rounded-lg"}),e.jsx(z,{className:"h-7 w-48"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[1,2,3].map(i=>e.jsx(A,{className:"border-slate-100 dark:border-slate-800 bg-white dark:bg-slate-900",children:e.jsxs(R,{className:"p-5",children:[e.jsx(z,{className:"h-10 w-10 rounded-xl mb-4"}),e.jsx(z,{className:"h-3 w-20 mb-2"}),e.jsx(z,{className:"h-8 w-28"})]})},i))}),e.jsx(A,{className:"border-slate-100 dark:border-slate-800 bg-white dark:bg-slate-900",children:e.jsx(R,{className:"p-6",children:e.jsx(z,{className:"h-[240px] w-full rounded-xl"})})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(w,{onClick:t,variant:"outline",size:"sm",className:"rounded-lg border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800",children:[e.jsx(bs,{className:"w-4 h-4 mr-2"}),n]}),e.jsx("h2",{className:"text-lg font-bold text-foreground tracking-tight",children:r?.name})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(Ye,{title:"Volumen de Tickets",displayValue:String(r?.comparisonToTeam.memberTickets??0),comparisonPercent:r?.comparisonToTeam.ticketsVsAvg??0,teamLabel:`Equipo: ${r?.comparisonToTeam.teamAvgTickets??0}`,tooltipText:"Total de tickets asignados a este miembro en el período. Se compara con el promedio de tickets por agente del equipo.",icon:e.jsx(je,{className:"w-4 h-4"}),color:"text-blue-600 dark:text-blue-400",bg:"bg-blue-500/10",gradient:"from-blue-500/5 to-blue-500/10",teamAgentCount:r?.comparisonToTeam.teamAgentCount??0}),e.jsx(Ye,{title:"Tiempo de Respuesta",displayValue:Q(r?.comparisonToTeam.memberFrtSeconds??null),comparisonPercent:r?.comparisonToTeam.responseTimeVsAvg??0,teamLabel:`Equipo: ${Q(r?.comparisonToTeam.teamAvgFrtSeconds??null)}`,tooltipText:"Tiempo promedio desde que se crea un ticket hasta la primera respuesta del agente. Un valor menor es mejor. Se compara con el promedio del equipo.",icon:e.jsx(fe,{className:"w-4 h-4"}),color:"text-amber-600 dark:text-amber-400",bg:"bg-amber-500/10",gradient:"from-amber-500/5 to-amber-500/10",invertColors:!0,teamAgentCount:r?.comparisonToTeam.teamAgentCount??0}),e.jsx(Ye,{title:"Tasa de Resolución",displayValue:`${r?.comparisonToTeam.memberResolutionRate??0}%`,comparisonPercent:r?.comparisonToTeam.resolutionRateVsAvg??0,teamLabel:`Equipo: ${r?.comparisonToTeam.teamAvgResolutionRate??0}%`,tooltipText:"Porcentaje de tickets resueltos sobre el total asignado. Indica la efectividad del agente para cerrar tickets. Se compara con el promedio del equipo.",icon:e.jsx(ka,{className:"w-4 h-4"}),color:"text-emerald-600 dark:text-emerald-400",bg:"bg-emerald-500/10",gradient:"from-emerald-500/5 to-emerald-500/10",teamAgentCount:r?.comparisonToTeam.teamAgentCount??0})]}),e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs(X,{className:"pb-2",children:[e.jsxs(ee,{className:"text-sm font-bold text-slate-500 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-500/10",children:e.jsx(je,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),"Volumen de Tickets",e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(J,{className:"w-3.5 h-3.5 text-slate-400"})})}),e.jsx(K,{side:"top",className:"max-w-[240px] text-center",children:"Muestra la cantidad de tickets asignados por día. Picos altos indican días de alta demanda. Útil para planificar turnos y recursos."})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Tendencia diaria de tickets asignados"})]}),e.jsx(R,{children:r?.ticketVolumeTrend&&r.ticketVolumeTrend.length>0?e.jsx(Se,{width:"100%",height:250,children:e.jsxs(gs,{data:r.ticketVolumeTrend,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"ticketGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#3b82f6",stopOpacity:.15}),e.jsx("stop",{offset:"95%",stopColor:"#3b82f6",stopOpacity:0})]})}),e.jsx(qe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",strokeOpacity:.5}),e.jsx(Fe,{dataKey:"date",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickFormatter:i=>{try{return ne(we(i),"dd MMM",{locale:le})}catch{return i}},axisLine:!1,tickLine:!1}),e.jsx(Ge,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},allowDecimals:!1,axisLine:!1,tickLine:!1}),e.jsx(Ue,{contentStyle:Be,labelFormatter:i=>{try{return ne(we(i),"dd MMM yyyy",{locale:le})}catch{return i}},formatter:i=>[`${i} tickets`,"Tickets"]}),e.jsx(fs,{type:"monotone",dataKey:"count",stroke:"#3b82f6",strokeWidth:2.5,fill:"url(#ticketGradient)",dot:{r:3,fill:"#3b82f6",strokeWidth:0},activeDot:{r:5,fill:"#3b82f6",strokeWidth:2,stroke:"#fff"}})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-slate-500/10",children:e.jsx(je,{className:"h-6 w-6 text-slate-400"})}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Sin datos en el período seleccionado"})]})})]}),e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs(X,{className:"pb-2",children:[e.jsxs(ee,{className:"text-sm font-bold text-slate-500 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-500/10",children:e.jsx(fe,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"})}),"Tiempo de Respuesta",e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(J,{className:"w-3.5 h-3.5 text-slate-400"})})}),e.jsx(K,{side:"top",className:"max-w-[240px] text-center",children:"Evolución diaria del tiempo promedio de primera respuesta. Una tendencia a la baja es positiva. Ayuda a detectar días problemáticos."})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Evolución del tiempo promedio de primera respuesta"})]}),e.jsx(R,{children:r?.responseTimeTrend&&r.responseTimeTrend.length>0?e.jsx(Se,{width:"100%",height:250,children:e.jsxs(gs,{data:r.responseTimeTrend,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"responseGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#10b981",stopOpacity:.15}),e.jsx("stop",{offset:"95%",stopColor:"#10b981",stopOpacity:0})]})}),e.jsx(qe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",strokeOpacity:.5}),e.jsx(Fe,{dataKey:"date",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickFormatter:i=>{try{return ne(we(i),"dd MMM",{locale:le})}catch{return i}},axisLine:!1,tickLine:!1}),e.jsx(Ge,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickFormatter:i=>Q(i),axisLine:!1,tickLine:!1}),e.jsx(Ue,{contentStyle:Be,labelFormatter:i=>{try{return ne(we(i),"dd MMM yyyy",{locale:le})}catch{return i}},formatter:i=>[Q(Number(i)||0),"Tiempo"]}),e.jsx(fs,{type:"monotone",dataKey:"avgSeconds",stroke:"#10b981",strokeWidth:2.5,fill:"url(#responseGradient)",dot:{r:3,fill:"#10b981",strokeWidth:0},activeDot:{r:5,fill:"#10b981",strokeWidth:2,stroke:"#fff"}})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-slate-500/10",children:e.jsx(fe,{className:"h-6 w-6 text-slate-400"})}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Sin datos en el período seleccionado"})]})})]}),e.jsxs(A,{className:"bg-white dark:bg-slate-900 border-slate-100 dark:border-slate-800 shadow-sm hover:shadow-md transition-all duration-300",children:[e.jsxs(X,{className:"pb-2",children:[e.jsxs(ee,{className:"text-sm font-bold text-slate-500 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-violet-500/10",children:e.jsx(hs,{className:"w-4 h-4 text-violet-600 dark:text-violet-400"})}),"Actividad por Hora",e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("button",{type:"button",className:"p-1 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(J,{className:"w-3.5 h-3.5 text-slate-400"})})}),e.jsx(K,{side:"top",className:"max-w-[240px] text-center",children:"Distribución de mensajes enviados según la hora del día. Identifica las horas de mayor actividad del agente para optimizar su horario."})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Distribución de mensajes enviados por hora del día"})]}),e.jsx(R,{children:x.some(i=>i.count>0)?e.jsx(Se,{width:"100%",height:250,children:e.jsxs(Js,{data:x,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"barGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#8b5cf6",stopOpacity:1}),e.jsx("stop",{offset:"100%",stopColor:"#8b5cf6",stopOpacity:.6})]})}),e.jsx(qe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",strokeOpacity:.5,vertical:!1}),e.jsx(Fe,{dataKey:"hour",tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},interval:1,axisLine:!1,tickLine:!1}),e.jsx(Ge,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},allowDecimals:!1,axisLine:!1,tickLine:!1}),e.jsx(Ue,{contentStyle:Be,formatter:i=>[`${i} mensajes`,"Actividad"]}),e.jsx(ea,{dataKey:"count",fill:"url(#barGradient)",radius:[6,6,0,0],maxBarSize:24})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-slate-500/10",children:e.jsx(hs,{className:"h-6 w-6 text-slate-400"})}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Sin datos en el período seleccionado"})]})})]})]})}function ft({fromDashboard:a=!1}){const t=W(d=>d.selectedMemberId),n=W(d=>d.setSelectedMember),r=Ts(),l=()=>{a?(n(null),r("/dashboard")):n(null)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-white dark:bg-slate-900 rounded-3xl border border-slate-100 dark:border-slate-800 p-6 shadow-sm",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-blue-500/10",children:e.jsx(je,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Rendimiento del Equipo"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Analiza el rendimiento de los miembros de tu organización"})]})]}),e.jsx(tt,{})]})}),t?e.jsx(gt,{userId:t,onBack:l,backLabel:a?"Volver al Dashboard":void 0}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{}),e.jsx(pt,{onSelectMember:n})]})]})}const er=()=>{re(j=>j.user);const{currentOrganization:a}=F(),t=a?.role,n=a?.id,[r,l]=u.useState(!1),[d,x]=u.useState(!1),[i,c]=u.useState("members"),[h,p]=u.useState(void 0),[m,o]=Hs();Ts();const f=m.get("from")==="dashboard";u.useEffect(()=>{const j=m.get("tab"),T=m.get("memberId");j==="stats"&&(c("stats"),T&&W.getState().setSelectedMember(T))},[]);const[v,k]=u.useState(!1),[C,M]=u.useState(!1),[G,I]=u.useState(!1),[D,P]=u.useState(""),[b,S]=u.useState(!1),U=async()=>{if(!(!n||!D)){S(!0);try{await q.transferOwnership(n,D),y.success("Invitación de transferencia enviada"),I(!1),P(""),F.getState().fetchInvitations(n)}catch(j){const T=j.message||j.response?.data?.message||"Error al iniciar transferencia";y.error(typeof T=="string"?T:Array.isArray(T)?T[0]:"Error desconocido")}finally{S(!1)}}},se=async()=>{if(n){M(!0);try{await q.leaveOrganization(n),y.success("Has abandonado la organización"),window.location.href="/login"}catch(j){console.error(j),y.error("Error al abandonar la organización"),M(!1),k(!1)}}},s=j=>{p(j),l(!0)},g=()=>{p(void 0),l(!0)};return e.jsxs(Ca,{children:[e.jsx(Ta,{title:"Gestión de Equipo",description:"Administra los miembros de tu organización, roles y equipos.",icon:be,actions:e.jsxs("div",{className:"flex gap-2",children:[(t==="OWNER"||t==="ADMIN")&&e.jsxs(e.Fragment,{children:[i==="teams"?e.jsxs(w,{onClick:g,size:"sm",className:"gap-2",children:[e.jsx(Bs,{className:"w-4 h-4"}),"Crear Equipo"]}):i==="members"?e.jsxs(w,{onClick:()=>x(!0),size:"sm",className:"gap-2",children:[e.jsx(Ea,{className:"w-4 h-4"}),"Invitar Miembro"]}):null,t==="OWNER"&&e.jsxs(w,{variant:"outline",size:"sm",className:"gap-2 border-orange-500/20 text-orange-600 hover:bg-orange-50 hover:text-orange-700",onClick:()=>I(!0),children:[e.jsx(Ee,{className:"w-4 h-4"}),"Transferir Propiedad"]})]}),t!=="OWNER"&&e.jsxs(w,{variant:"destructive",size:"sm",className:"gap-2",onClick:()=>k(!0),children:[e.jsx(Ys,{className:"w-4 h-4"}),"Salir"]})]})}),e.jsx(Sa,{className:"space-y-8",children:e.jsxs(sa,{value:i,onValueChange:j=>{c(j),f&&o({},{replace:!0})},className:"w-full",children:[e.jsxs(aa,{className:`grid w-full max-w-[500px] ${t==="OWNER"||t==="ADMIN"?"grid-cols-3":"grid-cols-2"}`,children:[e.jsxs($e,{value:"members",className:"gap-2",children:[e.jsx(be,{className:"w-4 h-4"}),"Miembros"]}),e.jsxs($e,{value:"teams",className:"gap-2",children:[e.jsx(Ks,{className:"w-4 h-4"}),"Equipos"]}),(t==="OWNER"||t==="ADMIN")&&e.jsxs($e,{value:"stats",className:"gap-2",children:[e.jsx(je,{className:"w-4 h-4"}),"Estadísticas"]})]}),e.jsxs(Ve,{value:"members",className:"mt-6 space-y-6",children:[e.jsxs(A,{children:[e.jsxs(X,{children:[e.jsx(ee,{className:"text-lg",children:"Miembros Activos"}),e.jsx(We,{children:"Usuarios que forman parte de su organización."})]}),e.jsx(R,{children:e.jsx(Ja,{})})]}),(t==="OWNER"||t==="ADMIN")&&e.jsxs(A,{children:[e.jsxs(X,{children:[e.jsx(ee,{className:"text-lg",children:"Gestión de Invitaciones"}),e.jsx(We,{children:"Gestione las invitaciones enviadas a nuevos usuarios."})]}),e.jsx(R,{children:e.jsx(Xa,{})})]})]}),e.jsx(Ve,{value:"teams",className:"mt-6",children:e.jsxs(A,{children:[e.jsxs(X,{children:[e.jsx(ee,{className:"text-lg",children:"Equipos Registrados"}),e.jsx(We,{children:"Organice a sus agentes en equipos funcionales con horarios definidos."})]}),e.jsx(R,{children:e.jsx(Ya,{onEdit:s})})]})}),(t==="OWNER"||t==="ADMIN")&&e.jsx(Ve,{value:"stats",className:"mt-6",children:e.jsx(ft,{fromDashboard:f})})]})}),e.jsx(Ba,{open:r,onOpenChange:l,onSuccess:()=>{},teamToEdit:h}),e.jsx(et,{open:d,onOpenChange:x,onSuccess:()=>{}}),e.jsx(ts,{open:v,onOpenChange:k,onConfirm:se,title:"Abandonar Organización",description:"¿Estás seguro que deseas abandonar esta organización? Esta acción no se puede deshacer y perderás acceso inmediato a todos los recursos.",confirmText:"Abandonar",variant:"destructive",loading:C}),e.jsx(oe,{open:G,onOpenChange:I,children:e.jsxs(de,{className:"sm:max-w-[425px]",children:[e.jsxs(ce,{children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-orange-500/10 flex items-center justify-center mb-2",children:e.jsx(Ee,{className:"h-5 w-5 text-orange-500"})}),e.jsx(me,{children:"Transferir Propiedad"}),e.jsxs(ue,{className:"text-sm",children:["Esta acción enviará una ",e.jsx("span",{className:"font-bold text-orange-600",children:"invitación de PROPIETARIO"})," al correo ingresado.",e.jsx("br",{}),e.jsx("br",{}),"Al aceptar, ",e.jsx("span",{className:"font-semibold text-foreground",children:"TÚ perderás el rol de propietario"})," y pasarás a ser Administrador. Esta acción es irreversible por tu parte una vez aceptada."]})]}),e.jsxs("div",{className:"py-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-muted-foreground mb-1.5 block",children:"Correo del Nuevo Propietario"}),e.jsx("input",{type:"email",className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",placeholder:"nuevo.dueno@ejemplo.com",value:D,onChange:j=>P(j.target.value)}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"El usuario debe aceptar la invitación para que el cambio sea efectivo."})]}),e.jsxs(xe,{className:"gap-2 sm:gap-0",children:[e.jsx(w,{variant:"ghost",onClick:()=>I(!1),children:"Cancelar"}),e.jsxs(w,{onClick:U,className:"bg-orange-600 hover:bg-orange-700 text-white font-bold",disabled:b||!D,children:[b?e.jsx(Je,{className:"h-4 w-4 animate-spin mr-2"}):null,"Enviar Invitación"]})]})]})})]})};export{er as TeamsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ay as e}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ay as e}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ay as t}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";const o=t,s=t,c=t,n=t,i=t;export{n as BuyCreditsPage,i as CheckoutPlanPage,o as SubscriptionPage,s as TransactionsPage,c as WalletsPage,t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ay as a}from"./index-43NA2pdZ.js";import"./recharts-DrC5kNsx.js";const e=a,n=a,s=a,c=a,g=a,r=a,P=a,i=a,m=a,d=a,p=a,b=a,l=a;export{e as AdminDashboard,g as AdminUsersPage,d as BackupsPage,m as CouponsPage,s as CreditManager,p as CronJobsPage,c as OrganizationsPage,i as PaymentsPage,n as PlanManager,r as StorageManagement,b as SystemHealthPage,P as TraceabilityPage,l as WebhookMonitorPage,a as default};
|