adserver-dashboard 1.0.0

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.
Files changed (525) hide show
  1. package/.ci/staging.yml +191 -0
  2. package/.dockerignore +117 -0
  3. package/.env +40 -0
  4. package/.env.staging +38 -0
  5. package/.gitlab-ci.yml +16 -0
  6. package/DEMO_STATUS.md +579 -0
  7. package/Dockerfile +61 -0
  8. package/Influence-MW-AdServer-12-02-2026/client/index.html +17 -0
  9. package/Influence-MW-AdServer-12-02-2026/client/public/favicon.png +0 -0
  10. package/Influence-MW-AdServer-12-02-2026/client/src/App.tsx +91 -0
  11. package/Influence-MW-AdServer-12-02-2026/client/src/components/advanced-map-drawer.tsx +1131 -0
  12. package/Influence-MW-AdServer-12-02-2026/client/src/components/ai-recommendation-panel.tsx +379 -0
  13. package/Influence-MW-AdServer-12-02-2026/client/src/components/app-sidebar.tsx +183 -0
  14. package/Influence-MW-AdServer-12-02-2026/client/src/components/auto-optimize-button.tsx +184 -0
  15. package/Influence-MW-AdServer-12-02-2026/client/src/components/availability-drawer.tsx +385 -0
  16. package/Influence-MW-AdServer-12-02-2026/client/src/components/brand-insights-panel.tsx +87 -0
  17. package/Influence-MW-AdServer-12-02-2026/client/src/components/create-agency-drawer.tsx +198 -0
  18. package/Influence-MW-AdServer-12-02-2026/client/src/components/create-brand-drawer.tsx +275 -0
  19. package/Influence-MW-AdServer-12-02-2026/client/src/components/creative-assignment.tsx +526 -0
  20. package/Influence-MW-AdServer-12-02-2026/client/src/components/data-table-toolbar.tsx +148 -0
  21. package/Influence-MW-AdServer-12-02-2026/client/src/components/data-table.tsx +158 -0
  22. package/Influence-MW-AdServer-12-02-2026/client/src/components/filter-drawer.tsx +356 -0
  23. package/Influence-MW-AdServer-12-02-2026/client/src/components/form-insights-panel.tsx +82 -0
  24. package/Influence-MW-AdServer-12-02-2026/client/src/components/geography-selector.tsx +699 -0
  25. package/Influence-MW-AdServer-12-02-2026/client/src/components/header-user-menu.tsx +178 -0
  26. package/Influence-MW-AdServer-12-02-2026/client/src/components/history-drawer.tsx +313 -0
  27. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-availability-section.tsx +176 -0
  28. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-format-drawer.tsx +173 -0
  29. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-selector.tsx +401 -0
  30. package/Influence-MW-AdServer-12-02-2026/client/src/components/manual-inventory-drawer.tsx +368 -0
  31. package/Influence-MW-AdServer-12-02-2026/client/src/components/mapbox-map.tsx +368 -0
  32. package/Influence-MW-AdServer-12-02-2026/client/src/components/market-insights-panel.tsx +202 -0
  33. package/Influence-MW-AdServer-12-02-2026/client/src/components/media-owner-drawer.tsx +217 -0
  34. package/Influence-MW-AdServer-12-02-2026/client/src/components/metric-card.tsx +58 -0
  35. package/Influence-MW-AdServer-12-02-2026/client/src/components/page-header.tsx +27 -0
  36. package/Influence-MW-AdServer-12-02-2026/client/src/components/player-status-indicator.tsx +137 -0
  37. package/Influence-MW-AdServer-12-02-2026/client/src/components/poi-targeting-drawer.tsx +298 -0
  38. package/Influence-MW-AdServer-12-02-2026/client/src/components/recommendation-score-badge.tsx +102 -0
  39. package/Influence-MW-AdServer-12-02-2026/client/src/components/recommended-inventories-panel.tsx +248 -0
  40. package/Influence-MW-AdServer-12-02-2026/client/src/components/searchable-combobox.tsx +134 -0
  41. package/Influence-MW-AdServer-12-02-2026/client/src/components/signal-visualizations.tsx +407 -0
  42. package/Influence-MW-AdServer-12-02-2026/client/src/components/status-badge.tsx +35 -0
  43. package/Influence-MW-AdServer-12-02-2026/client/src/components/theme-provider.tsx +73 -0
  44. package/Influence-MW-AdServer-12-02-2026/client/src/components/theme-toggle.tsx +37 -0
  45. package/Influence-MW-AdServer-12-02-2026/client/src/components/traffic-slider.tsx +75 -0
  46. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/accordion.tsx +56 -0
  47. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/alert-dialog.tsx +139 -0
  48. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/alert.tsx +59 -0
  49. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/aspect-ratio.tsx +5 -0
  50. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/avatar.tsx +51 -0
  51. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/badge.tsx +38 -0
  52. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/breadcrumb.tsx +115 -0
  53. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/button.tsx +62 -0
  54. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/calendar.tsx +68 -0
  55. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/card.tsx +85 -0
  56. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/carousel.tsx +260 -0
  57. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/chart.tsx +365 -0
  58. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/checkbox.tsx +28 -0
  59. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/collapsible.tsx +11 -0
  60. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/command.tsx +151 -0
  61. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/context-menu.tsx +198 -0
  62. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/dialog.tsx +122 -0
  63. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/drawer.tsx +118 -0
  64. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/dropdown-menu.tsx +198 -0
  65. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/form.tsx +178 -0
  66. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/hover-card.tsx +29 -0
  67. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/input-otp.tsx +69 -0
  68. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/input.tsx +23 -0
  69. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/label.tsx +24 -0
  70. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/menubar.tsx +256 -0
  71. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/navigation-menu.tsx +128 -0
  72. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/pagination.tsx +117 -0
  73. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/popover.tsx +29 -0
  74. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/progress.tsx +28 -0
  75. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/radio-group.tsx +42 -0
  76. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/resizable.tsx +45 -0
  77. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/scroll-area.tsx +46 -0
  78. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/select.tsx +160 -0
  79. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/separator.tsx +29 -0
  80. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/sheet.tsx +140 -0
  81. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/sidebar.tsx +727 -0
  82. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/skeleton.tsx +15 -0
  83. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/slider.tsx +26 -0
  84. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/switch.tsx +27 -0
  85. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/table.tsx +117 -0
  86. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/tabs.tsx +53 -0
  87. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/textarea.tsx +22 -0
  88. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toast.tsx +127 -0
  89. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toaster.tsx +33 -0
  90. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toggle-group.tsx +61 -0
  91. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toggle.tsx +43 -0
  92. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/tooltip.tsx +30 -0
  93. package/Influence-MW-AdServer-12-02-2026/client/src/components/vendor-stores-modal.tsx +336 -0
  94. package/Influence-MW-AdServer-12-02-2026/client/src/components/venue-type-drawer.tsx +359 -0
  95. package/Influence-MW-AdServer-12-02-2026/client/src/components/venue-type-selector.tsx +436 -0
  96. package/Influence-MW-AdServer-12-02-2026/client/src/hooks/use-mobile.tsx +19 -0
  97. package/Influence-MW-AdServer-12-02-2026/client/src/hooks/use-toast.ts +191 -0
  98. package/Influence-MW-AdServer-12-02-2026/client/src/index.css +244 -0
  99. package/Influence-MW-AdServer-12-02-2026/client/src/lib/queryClient.ts +57 -0
  100. package/Influence-MW-AdServer-12-02-2026/client/src/lib/utils.ts +39 -0
  101. package/Influence-MW-AdServer-12-02-2026/client/src/lib/venue-taxonomy.ts +532 -0
  102. package/Influence-MW-AdServer-12-02-2026/client/src/main.tsx +5 -0
  103. package/Influence-MW-AdServer-12-02-2026/client/src/pages/assign-creative.tsx +781 -0
  104. package/Influence-MW-AdServer-12-02-2026/client/src/pages/content-hub.tsx +995 -0
  105. package/Influence-MW-AdServer-12-02-2026/client/src/pages/custom-pois.tsx +431 -0
  106. package/Influence-MW-AdServer-12-02-2026/client/src/pages/dashboard.tsx +620 -0
  107. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deal-detail.tsx +1062 -0
  108. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deal-form.tsx +1570 -0
  109. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deals.tsx +716 -0
  110. package/Influence-MW-AdServer-12-02-2026/client/src/pages/edit-creative-assignment.tsx +1051 -0
  111. package/Influence-MW-AdServer-12-02-2026/client/src/pages/geotargeting.tsx +675 -0
  112. package/Influence-MW-AdServer-12-02-2026/client/src/pages/integrations.tsx +425 -0
  113. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-item-creatives.tsx +622 -0
  114. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-item-form.tsx +3132 -0
  115. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-items.tsx +530 -0
  116. package/Influence-MW-AdServer-12-02-2026/client/src/pages/not-found.tsx +21 -0
  117. package/Influence-MW-AdServer-12-02-2026/client/src/pages/proof-of-play-upload.tsx +479 -0
  118. package/Influence-MW-AdServer-12-02-2026/client/src/pages/proof-of-play.tsx +880 -0
  119. package/Influence-MW-AdServer-12-02-2026/client/src/pages/reports.tsx +235 -0
  120. package/Influence-MW-AdServer-12-02-2026/client/src/pages/settings.tsx +652 -0
  121. package/Influence-MW-AdServer-12-02-2026/client/src/pages/signal-form.tsx +1117 -0
  122. package/Influence-MW-AdServer-12-02-2026/client/src/pages/signals.tsx +366 -0
  123. package/Influence-MW-AdServer-12-02-2026/client/src/pages/tags.tsx +332 -0
  124. package/Influence-MW-AdServer-12-02-2026/client/src/pages/venues.tsx +381 -0
  125. package/Influence-MW-AdServer-12-02-2026/client/src/types/mapbox-gl-draw.d.ts +37 -0
  126. package/Influence-MW-AdServer-12-02-2026/client/src/types/react-simple-maps.d.ts +57 -0
  127. package/Influence-MW-AdServer-12-02-2026/components.json +20 -0
  128. package/Influence-MW-AdServer-12-02-2026/docs/PRD.md +3373 -0
  129. package/Influence-MW-AdServer-12-02-2026/docs/influence-feature-mapping.csv +498 -0
  130. package/Influence-MW-AdServer-12-02-2026/drizzle.config.ts +14 -0
  131. package/Influence-MW-AdServer-12-02-2026/package-lock.json +9672 -0
  132. package/Influence-MW-AdServer-12-02-2026/package.json +118 -0
  133. package/Influence-MW-AdServer-12-02-2026/postcss.config.js +6 -0
  134. package/Influence-MW-AdServer-12-02-2026/replit.md +91 -0
  135. package/Influence-MW-AdServer-12-02-2026/script/build.ts +67 -0
  136. package/Influence-MW-AdServer-12-02-2026/scripts/create-miro-diagrams.cjs +318 -0
  137. package/Influence-MW-AdServer-12-02-2026/scripts/create-remaining-diagrams.cjs +270 -0
  138. package/Influence-MW-AdServer-12-02-2026/server/index.ts +103 -0
  139. package/Influence-MW-AdServer-12-02-2026/server/recommendation-service.ts +319 -0
  140. package/Influence-MW-AdServer-12-02-2026/server/routes.ts +1890 -0
  141. package/Influence-MW-AdServer-12-02-2026/server/static.ts +19 -0
  142. package/Influence-MW-AdServer-12-02-2026/server/storage.ts +2058 -0
  143. package/Influence-MW-AdServer-12-02-2026/server/vite.ts +58 -0
  144. package/Influence-MW-AdServer-12-02-2026/shared/schema.ts +1595 -0
  145. package/Influence-MW-AdServer-12-02-2026/tailwind.config.ts +107 -0
  146. package/Influence-MW-AdServer-12-02-2026/tsconfig.json +23 -0
  147. package/Influence-MW-AdServer-12-02-2026/vite.config.ts +40 -0
  148. package/LINE_ITEM_BUDGET_FIELD_MAPPING.md +178 -0
  149. package/PCM/.env.example +92 -0
  150. package/PCM/README.md +558 -0
  151. package/PCM/docs/TEST_CASES.md +422 -0
  152. package/PCM/index.js +106 -0
  153. package/PCM/package-lock.json +3282 -0
  154. package/PCM/package.json +32 -0
  155. package/PCM/replit.md +64 -0
  156. package/PCM/schema.sql +495 -0
  157. package/PCM/scripts/export-schema.js +183 -0
  158. package/PCM/scripts/seed-comprehensive.js +631 -0
  159. package/PCM/scripts/seed-production.js +477 -0
  160. package/PCM/src/config/db.js +56 -0
  161. package/PCM/src/config/swagger.js +5975 -0
  162. package/PCM/src/dto/EmailRequestDTO.js +166 -0
  163. package/PCM/src/middleware/errorHandler.js +52 -0
  164. package/PCM/src/middleware/logger.js +26 -0
  165. package/PCM/src/migrations/001_add_campaign_mode_fields.sql +36 -0
  166. package/PCM/src/migrations/002_create_deal_id_counters.sql +22 -0
  167. package/PCM/src/migrations/003_update_publishers_column.sql +15 -0
  168. package/PCM/src/migrations/004_add_direct_dealtype_and_advertiser.sql +5 -0
  169. package/PCM/src/migrations/005_add_programmatic_fields_and_update_enums.sql +31 -0
  170. package/PCM/src/migrations/006_add_line_item_programmatic_fields.sql +12 -0
  171. package/PCM/src/migrations/007_add_line_item_direct_fields.sql +15 -0
  172. package/PCM/src/migrations/008_add_inventory_fields.sql +45 -0
  173. package/PCM/src/migrations/009_move_inventory_fields_to_metadata.sql +32 -0
  174. package/PCM/src/migrations/010_add_draft_status_and_line_items_count.sql +23 -0
  175. package/PCM/src/migrations/011_add_planning_field.sql +21 -0
  176. package/PCM/src/migrations/012_fix_inventory_composite_pk.sql +17 -0
  177. package/PCM/src/migrations/013_make_external_id_optional.sql +3 -0
  178. package/PCM/src/migrations/014_create_change_history.sql +38 -0
  179. package/PCM/src/migrations/016_create_publisher_insertion_orders.sql +33 -0
  180. package/PCM/src/migrations/017_fix_line_item_id_fk_reference.sql +86 -0
  181. package/PCM/src/migrations/018_create_approval_tables.sql +44 -0
  182. package/PCM/src/migrations/019_add_encrypted_token_column.sql +2 -0
  183. package/PCM/src/migrations/020_add_rejection_reason_to_deals.sql +10 -0
  184. package/PCM/src/migrations/021_add_publisher_external_id_to_inventories.sql +12 -0
  185. package/PCM/src/migrations/022_add_line_item_extended_fields.sql +24 -0
  186. package/PCM/src/migrations/023_add_base_price_fields.sql +8 -0
  187. package/PCM/src/migrations/run-migrations.js +46 -0
  188. package/PCM/src/models/ApprovalOTP.js +51 -0
  189. package/PCM/src/models/ApprovalToken.js +79 -0
  190. package/PCM/src/models/ChangeHistory.js +107 -0
  191. package/PCM/src/models/Deal.js +186 -0
  192. package/PCM/src/models/DealIdCounter.js +28 -0
  193. package/PCM/src/models/LineItem.js +227 -0
  194. package/PCM/src/models/LineItemCreative.js +89 -0
  195. package/PCM/src/models/LineItemInventory.js +115 -0
  196. package/PCM/src/models/PublisherInsertionOrder.js +93 -0
  197. package/PCM/src/models/TransactionHistory.js +34 -0
  198. package/PCM/src/models/associations.js +81 -0
  199. package/PCM/src/routes/approval.js +321 -0
  200. package/PCM/src/routes/creatives.js +437 -0
  201. package/PCM/src/routes/deals.js +1638 -0
  202. package/PCM/src/routes/digitalSignage.js +242 -0
  203. package/PCM/src/routes/insertionOrders.js +380 -0
  204. package/PCM/src/routes/lineItems.js +926 -0
  205. package/PCM/src/routes/system.js +384 -0
  206. package/PCM/src/services/ApprovalService.js +885 -0
  207. package/PCM/src/services/CampaignImportConverter.js +631 -0
  208. package/PCM/src/services/CampaignModeService.js +273 -0
  209. package/PCM/src/services/CampaignStatusService.js +395 -0
  210. package/PCM/src/services/ChangeHistoryService.js +316 -0
  211. package/PCM/src/services/DealIdService.js +94 -0
  212. package/PCM/src/services/DealResponseFormatter.js +90 -0
  213. package/PCM/src/services/EmailNotificationService.js +315 -0
  214. package/PCM/src/services/LineItemResponseFormatter.js +122 -0
  215. package/PCM/src/services/LineItemStatusService.js +380 -0
  216. package/PCM/src/tests/comprehensiveTestRunner.js +360 -0
  217. package/PCM/src/tests/comprehensiveTests.js +1277 -0
  218. package/PCM/src/tests/dealTypeUnitTests.js +1058 -0
  219. package/PCM/src/tests/testRunner.js +248 -0
  220. package/PCM/src/utils/caseConverter.js +92 -0
  221. package/PCM/src/utils/dealCalculations.js +206 -0
  222. package/PCM/src/utils/lineItemPayloadNormalizer.js +41 -0
  223. package/PCM/src/utils/payloadNormalizer.js +34 -0
  224. package/PCM/src/utils/sourceNormalizer.js +56 -0
  225. package/PCM/src/validators/creativeValidator.js +27 -0
  226. package/PCM/src/validators/dealValidator.js +203 -0
  227. package/PCM/src/validators/lineItemValidator.js +489 -0
  228. package/PCM/tests/approval-flows.test.js +238 -0
  229. package/PCM/tests/approval-workflow.test.js +291 -0
  230. package/PCM/tests/campaign-import-converter.test.js +543 -0
  231. package/PCM/tests/campaign-import-e2e.test.js +520 -0
  232. package/PCM/tests/campaign-status.test.js +539 -0
  233. package/PCM/tests/direct-publisher-split-reimport.test.js +460 -0
  234. package/PCM/tests/e2e/digital-signage.test.js +145 -0
  235. package/PCM/tests/e2e/search-filter-pagination.test.js +399 -0
  236. package/PCM/tests/e2e-comprehensive.test.js +3446 -0
  237. package/PCM/tests/edge-cases.test.js +340 -0
  238. package/PCM/tests/line-item-status.test.js +340 -0
  239. package/PCM/tests/seller-account-external-ids.test.js +877 -0
  240. package/PCM/tests/source-validation.test.js +324 -0
  241. package/PRD.md +3373 -0
  242. package/README.md +186 -0
  243. package/client/index.html +35 -0
  244. package/client/public/DEMO_STATUS.md +579 -0
  245. package/client/public/img/MW-logo-trans_1754045676555.png +0 -0
  246. package/client/public/locales/ar/approval.json +144 -0
  247. package/client/public/locales/ar/buyer.json +61 -0
  248. package/client/public/locales/ar/campaigns.json +1 -0
  249. package/client/public/locales/ar/common.json +218 -0
  250. package/client/public/locales/ar/contentHub.json +266 -0
  251. package/client/public/locales/ar/creatives.json +79 -0
  252. package/client/public/locales/ar/dashboard.json +57 -0
  253. package/client/public/locales/ar/deals.json +886 -0
  254. package/client/public/locales/ar/dsp.json +131 -0
  255. package/client/public/locales/ar/inventory.json +201 -0
  256. package/client/public/locales/ar/lineItems.json +553 -0
  257. package/client/public/locales/ar/navigation.json +48 -0
  258. package/client/public/locales/ar/wizard.json +1 -0
  259. package/client/public/locales/en/approval.json +144 -0
  260. package/client/public/locales/en/buyer.json +65 -0
  261. package/client/public/locales/en/campaigns.json +1 -0
  262. package/client/public/locales/en/common.json +218 -0
  263. package/client/public/locales/en/contentHub.json +266 -0
  264. package/client/public/locales/en/creatives.json +79 -0
  265. package/client/public/locales/en/dashboard.json +57 -0
  266. package/client/public/locales/en/deals.json +886 -0
  267. package/client/public/locales/en/dsp.json +131 -0
  268. package/client/public/locales/en/inventory.json +201 -0
  269. package/client/public/locales/en/lineItems.json +659 -0
  270. package/client/public/locales/en/navigation.json +48 -0
  271. package/client/public/locales/en/wizard.json +1 -0
  272. package/client/public/locales/ja/approval.json +144 -0
  273. package/client/public/locales/ja/buyer.json +61 -0
  274. package/client/public/locales/ja/campaigns.json +1 -0
  275. package/client/public/locales/ja/common.json +218 -0
  276. package/client/public/locales/ja/contentHub.json +266 -0
  277. package/client/public/locales/ja/creatives.json +79 -0
  278. package/client/public/locales/ja/dashboard.json +57 -0
  279. package/client/public/locales/ja/deals.json +886 -0
  280. package/client/public/locales/ja/dsp.json +131 -0
  281. package/client/public/locales/ja/inventory.json +201 -0
  282. package/client/public/locales/ja/lineItems.json +553 -0
  283. package/client/public/locales/ja/navigation.json +48 -0
  284. package/client/public/locales/ja/wizard.json +1 -0
  285. package/client/public/locales/zh/approval.json +144 -0
  286. package/client/public/locales/zh/buyer.json +61 -0
  287. package/client/public/locales/zh/campaigns.json +1 -0
  288. package/client/public/locales/zh/common.json +218 -0
  289. package/client/public/locales/zh/contentHub.json +266 -0
  290. package/client/public/locales/zh/creatives.json +79 -0
  291. package/client/public/locales/zh/dashboard.json +57 -0
  292. package/client/public/locales/zh/deals.json +886 -0
  293. package/client/public/locales/zh/dsp.json +131 -0
  294. package/client/public/locales/zh/inventory.json +201 -0
  295. package/client/public/locales/zh/lineItems.json +553 -0
  296. package/client/public/locales/zh/navigation.json +48 -0
  297. package/client/public/locales/zh/wizard.json +1 -0
  298. package/client/public/manifest.json +36 -0
  299. package/client/src/App.tsx +464 -0
  300. package/client/src/components/app-sidebar.tsx +312 -0
  301. package/client/src/components/approval/approval-decision-form.test.tsx +294 -0
  302. package/client/src/components/approval/approval-decision-form.tsx +326 -0
  303. package/client/src/components/approval/approval-sheet.tsx +631 -0
  304. package/client/src/components/approval/line-item-details-sheet.tsx +371 -0
  305. package/client/src/components/approval/otp-verification.test.tsx +337 -0
  306. package/client/src/components/approval/otp-verification.tsx +180 -0
  307. package/client/src/components/content-hub/bulk-transcode-dialog.tsx +379 -0
  308. package/client/src/components/content-hub/content-hub-manager-v2.tsx +574 -0
  309. package/client/src/components/content-hub/content-hub-manager.tsx +330 -0
  310. package/client/src/components/content-hub/creative-card.tsx +456 -0
  311. package/client/src/components/content-hub/creative-detail-sheet.tsx +685 -0
  312. package/client/src/components/content-hub/creative-filters.tsx +457 -0
  313. package/client/src/components/content-hub/creative-grid.tsx +329 -0
  314. package/client/src/components/content-hub/creative-selector.tsx +415 -0
  315. package/client/src/components/content-hub/creative-upload.tsx +547 -0
  316. package/client/src/components/content-hub/folder-dialogs.tsx +445 -0
  317. package/client/src/components/content-hub/folder-list.tsx +280 -0
  318. package/client/src/components/content-hub/review-dialogs.tsx +268 -0
  319. package/client/src/components/content-hub/transcode-dialog.tsx +226 -0
  320. package/client/src/components/creative-library/creative-details-view.tsx +446 -0
  321. package/client/src/components/creative-library/creative-filters-panel.tsx +203 -0
  322. package/client/src/components/creative-library/creative-list.tsx +360 -0
  323. package/client/src/components/creative-library/creative-status-badge.tsx +71 -0
  324. package/client/src/components/creative-library/folder-card.tsx +78 -0
  325. package/client/src/components/creative-library/index.ts +27 -0
  326. package/client/src/components/creative-library/new-creative-card.tsx +211 -0
  327. package/client/src/components/creative-library/upload-creative-dialog.tsx +261 -0
  328. package/client/src/components/dashboard-overview.tsx +109 -0
  329. package/client/src/components/deals/approval-history-panel.test.tsx +240 -0
  330. package/client/src/components/deals/approval-history-panel.tsx +156 -0
  331. package/client/src/components/deals/deal-status-badge.tsx +92 -0
  332. package/client/src/components/deals/import-from-planner-dialog.tsx +399 -0
  333. package/client/src/components/deals/market-insights-panel.tsx +237 -0
  334. package/client/src/components/deals/reopen-deal-sheet.tsx +191 -0
  335. package/client/src/components/deals/request-approval-sheet.test.tsx +323 -0
  336. package/client/src/components/deals/request-approval-sheet.tsx +136 -0
  337. package/client/src/components/deals/resend-approval-sheet.tsx +201 -0
  338. package/client/src/components/direct-campaigns/campaign-card.tsx +283 -0
  339. package/client/src/components/direct-campaigns/deal-filter-panel.tsx +325 -0
  340. package/client/src/components/inventory/advanced-filters-panel.tsx +273 -0
  341. package/client/src/components/inventory/csv-upload-modal.tsx +639 -0
  342. package/client/src/components/inventory/inventory-availability-view.tsx +486 -0
  343. package/client/src/components/inventory/inventory-details-sheet.tsx +376 -0
  344. package/client/src/components/inventory/inventory-map-view.tsx +596 -0
  345. package/client/src/components/inventory/inventory-settings-menu.tsx +52 -0
  346. package/client/src/components/language-switcher.tsx +53 -0
  347. package/client/src/components/line-items/campaign-forecast-panel.tsx +138 -0
  348. package/client/src/components/line-items/form-insights.tsx +89 -0
  349. package/client/src/components/line-items/geofencing/LocationCsvUploadDrawer.tsx +100 -0
  350. package/client/src/components/line-items/geofencing/POIDropdown.tsx +379 -0
  351. package/client/src/components/line-items/geofencing/SelectedLocationsSidebar.tsx +436 -0
  352. package/client/src/components/line-items/geofencing/ViewFileLocationDrawer.tsx +199 -0
  353. package/client/src/components/line-items/geofencing/components/ExistingFilesTab.tsx +268 -0
  354. package/client/src/components/line-items/geofencing/components/TemplateDownloadSection.tsx +59 -0
  355. package/client/src/components/line-items/geofencing/components/UploadTab.tsx +215 -0
  356. package/client/src/components/line-items/geofencing-map.tsx +1270 -0
  357. package/client/src/components/line-items/inventory-availability-section.tsx +178 -0
  358. package/client/src/components/line-items/line-item-schedule-manager.tsx +313 -0
  359. package/client/src/components/line-items/manual-inventory-drawer.tsx +346 -0
  360. package/client/src/components/line-items/planner-inventory-card.tsx +495 -0
  361. package/client/src/components/line-items/planner-schedule-grid.tsx +495 -0
  362. package/client/src/components/line-items/schedule-rule-editor.tsx +649 -0
  363. package/client/src/components/line-items/schedule-rule-types.ts +122 -0
  364. package/client/src/components/line-items/steps/creatives-step.tsx +681 -0
  365. package/client/src/components/line-items/steps/inventory-schedule-step.tsx +1596 -0
  366. package/client/src/components/line-items/steps/inventory-step.tsx +1533 -0
  367. package/client/src/components/line-items/steps/line-item-details-step.tsx +916 -0
  368. package/client/src/components/line-items/steps/schedule-step.tsx +273 -0
  369. package/client/src/components/line-items/steps/summary-step.tsx +680 -0
  370. package/client/src/components/line-items/steps/targeting-step.tsx +1708 -0
  371. package/client/src/components/product-switcher.tsx +105 -0
  372. package/client/src/components/protected-route.tsx +49 -0
  373. package/client/src/components/skip-link.tsx +22 -0
  374. package/client/src/components/stat-card.tsx +53 -0
  375. package/client/src/components/status-badge.tsx +96 -0
  376. package/client/src/components/ui/hierarchical-venue-selector.tsx +389 -0
  377. package/client/src/components/ui/toaster.tsx +111 -0
  378. package/client/src/contexts/auth-context.tsx +181 -0
  379. package/client/src/contexts/sidebar-state.tsx +50 -0
  380. package/client/src/contexts/theme-context.tsx +66 -0
  381. package/client/src/data/campaign-data.json +107 -0
  382. package/client/src/data/countries.json +22 -0
  383. package/client/src/hooks/use-approval.ts +366 -0
  384. package/client/src/hooks/use-keyboard-shortcuts.ts +74 -0
  385. package/client/src/hooks/use-media-query.ts +46 -0
  386. package/client/src/hooks/use-mobile.tsx +19 -0
  387. package/client/src/hooks/use-page-title.ts +21 -0
  388. package/client/src/hooks/use-toast.ts +195 -0
  389. package/client/src/index.css +694 -0
  390. package/client/src/lib/__tests__/accessibility.test.ts +104 -0
  391. package/client/src/lib/__tests__/date-utils.test.ts +199 -0
  392. package/client/src/lib/__tests__/dsp-buyer-api.test.ts +127 -0
  393. package/client/src/lib/__tests__/dsp-buyer-integration.test.ts +247 -0
  394. package/client/src/lib/__tests__/storage-utils.test.ts +167 -0
  395. package/client/src/lib/__tests__/utils.test.ts +57 -0
  396. package/client/src/lib/accessibility.ts +141 -0
  397. package/client/src/lib/api-config.ts +9 -0
  398. package/client/src/lib/auth-service.ts +209 -0
  399. package/client/src/lib/campaign-creative-api.ts +82 -0
  400. package/client/src/lib/company-api.ts +61 -0
  401. package/client/src/lib/content-hub-api.ts +407 -0
  402. package/client/src/lib/creative-mapper.ts +61 -0
  403. package/client/src/lib/date-utils.ts +119 -0
  404. package/client/src/lib/deal-helpers.ts +220 -0
  405. package/client/src/lib/dsp-buyer-api.ts +196 -0
  406. package/client/src/lib/geo-import-api.ts +151 -0
  407. package/client/src/lib/google-poi-api.ts +305 -0
  408. package/client/src/lib/i18n/__tests__/formatting.test.ts +202 -0
  409. package/client/src/lib/i18n/formatting.ts +130 -0
  410. package/client/src/lib/i18n/index.ts +8 -0
  411. package/client/src/lib/i18n-compat.ts +76 -0
  412. package/client/src/lib/influence-deals-api.ts +896 -0
  413. package/client/src/lib/inventory-api.ts +399 -0
  414. package/client/src/lib/oauth-service.ts +678 -0
  415. package/client/src/lib/poi-types.ts +75 -0
  416. package/client/src/lib/queryClient.ts +144 -0
  417. package/client/src/lib/recommendation-api.ts +380 -0
  418. package/client/src/lib/storage-utils.ts +104 -0
  419. package/client/src/lib/tolgee.ts +85 -0
  420. package/client/src/lib/utils.ts +0 -0
  421. package/client/src/main.tsx +67 -0
  422. package/client/src/mapbox-draw-modes.d.ts +32 -0
  423. package/client/src/pages/all-folders.tsx +203 -0
  424. package/client/src/pages/auth-callback.tsx +115 -0
  425. package/client/src/pages/buyer-form.tsx +339 -0
  426. package/client/src/pages/buyer-list.tsx +622 -0
  427. package/client/src/pages/content-hub.tsx +1358 -0
  428. package/client/src/pages/create-deal.tsx +2093 -0
  429. package/client/src/pages/creative-assignment-page.tsx +548 -0
  430. package/client/src/pages/creatives.tsx +5 -0
  431. package/client/src/pages/custom-pois.tsx +425 -0
  432. package/client/src/pages/dashboard.tsx +615 -0
  433. package/client/src/pages/deal-history.tsx +434 -0
  434. package/client/src/pages/deal-line-items.tsx +1703 -0
  435. package/client/src/pages/demo-status.tsx +113 -0
  436. package/client/src/pages/direct-campaign-details.tsx +361 -0
  437. package/client/src/pages/direct-campaigns-new.tsx +824 -0
  438. package/client/src/pages/dsp-form.tsx +803 -0
  439. package/client/src/pages/dsp-list.tsx +239 -0
  440. package/client/src/pages/folder-content.tsx +336 -0
  441. package/client/src/pages/integrations.tsx +429 -0
  442. package/client/src/pages/line-item-creatives.tsx +789 -0
  443. package/client/src/pages/line-item-detail-page.tsx +684 -0
  444. package/client/src/pages/line-item-form-page.tsx +3261 -0
  445. package/client/src/pages/line-item-wizard.tsx +1207 -0
  446. package/client/src/pages/login.tsx +154 -0
  447. package/client/src/pages/not-found.tsx +23 -0
  448. package/client/src/pages/proof-of-play.tsx +397 -0
  449. package/client/src/pages/public-approval.tsx +551 -0
  450. package/client/src/pages/reports.tsx +231 -0
  451. package/client/src/pages/settings.tsx +760 -0
  452. package/client/src/pages/signals.tsx +389 -0
  453. package/client/src/pages/tags.tsx +318 -0
  454. package/client/src/pages/test-results.tsx +328 -0
  455. package/client/src/store/hooks.ts +5 -0
  456. package/client/src/store/index.ts +15 -0
  457. package/client/src/store/mapMarkerLocationsSlice.ts +241 -0
  458. package/client/src/styles/design-tokens.css +324 -0
  459. package/client/src/test/setup.ts +261 -0
  460. package/client/src/test/test-utils.tsx +40 -0
  461. package/client/src/types/approval.ts +221 -0
  462. package/client/src/types/content-hub.ts +209 -0
  463. package/client/src/types/geofencing.ts +67 -0
  464. package/client/src/types/transcoding.ts +140 -0
  465. package/client/src/vite-env.d.ts +18 -0
  466. package/components.json +20 -0
  467. package/creative-api.json +1 -0
  468. package/docs/AI_REFERENCE.md +459 -0
  469. package/docs/MWDesign-Prompt.md +132 -0
  470. package/docs/MWDesign-System.md +344 -0
  471. package/docs/test-plan.md +277 -0
  472. package/e2e/AUTONOMOUS-TESTING.md +406 -0
  473. package/e2e/README.md +219 -0
  474. package/e2e/autonomous-flow.spec.ts +308 -0
  475. package/e2e/debug-sso.spec.ts +163 -0
  476. package/e2e/direct-campaigns.spec.ts +219 -0
  477. package/e2e/explore-sso.spec.ts +149 -0
  478. package/e2e/fixtures/auth.ts +26 -0
  479. package/e2e/fixtures/enhanced-test.ts +331 -0
  480. package/e2e/pagination.spec.ts +280 -0
  481. package/e2e/view-toggle.spec.ts +312 -0
  482. package/generated-icon.png +0 -0
  483. package/i18next-scanner.config.cjs +46 -0
  484. package/package.json +141 -0
  485. package/playwright.config.ts +93 -0
  486. package/postcss.config.js +6 -0
  487. package/replit.md +196 -0
  488. package/screenshot-after-login.png +0 -0
  489. package/screenshot-contenthub-grid.png +0 -0
  490. package/screenshot-contenthub-list-fixed.png +0 -0
  491. package/screenshot-contenthub-list.png +0 -0
  492. package/screenshot-create-deal.png +0 -0
  493. package/screenshot-dashboard.png +0 -0
  494. package/screenshot-deals.png +0 -0
  495. package/screenshot-login-filled.png +0 -0
  496. package/screenshot-login.png +0 -0
  497. package/screenshot.mjs +24 -0
  498. package/scripts/deploy-stg.sh +185 -0
  499. package/shared/direct-io-schema.ts +383 -0
  500. package/shared/schema.ts +439 -0
  501. package/shared/screen-types.ts +149 -0
  502. package/springdocDefault.json +1 -0
  503. package/swagger-ui-bundle.js +2 -0
  504. package/swagger-ui-init.js +10316 -0
  505. package/tailwind.config.ts +282 -0
  506. package/terraform/README.md +306 -0
  507. package/terraform/cloudfront.tf +289 -0
  508. package/terraform/ecs.tf +727 -0
  509. package/terraform/environments/dev.tfvars +59 -0
  510. package/terraform/environments/production.tfvars +60 -0
  511. package/terraform/main.tf +47 -0
  512. package/terraform/outputs.tf +145 -0
  513. package/terraform/s3.tf +192 -0
  514. package/terraform/variables.tf +226 -0
  515. package/terraform/waf.tf +165 -0
  516. package/terraform-frontend/.terraform.lock.hcl +25 -0
  517. package/terraform-frontend/README.md +85 -0
  518. package/terraform-frontend/cloudfront.tf +125 -0
  519. package/terraform-frontend/main.tf +31 -0
  520. package/terraform-frontend/outputs.tf +24 -0
  521. package/terraform-frontend/terraform.tfvars +12 -0
  522. package/terraform-frontend/variables.tf +53 -0
  523. package/tsconfig.json +23 -0
  524. package/vite.config.ts +226 -0
  525. package/vitest.config.ts +56 -0
@@ -0,0 +1,1270 @@
1
+ import { useEffect, useRef, useState, useCallback } from 'react';
2
+ import { useTranslation } from '@/lib/i18n';
3
+ import mapboxgl from 'mapbox-gl';
4
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
5
+ import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
6
+ import 'mapbox-gl/dist/mapbox-gl.css';
7
+ import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
8
+ import '@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css';
9
+ import { cn } from '@moving-walls/design-system';
10
+ import { POIDropdown } from './geofencing/POIDropdown';
11
+ import { fetchNearbyPlaces, type PlaceResult } from '@/lib/google-poi-api';
12
+ import { getPOILabel } from '@/lib/poi-types';
13
+
14
+ let DragCircleMode: any = null;
15
+ let DirectMode: any = null;
16
+ let SimpleSelectMode: any = null;
17
+ let RectangleMode: any = null;
18
+
19
+ const loadDrawModes = async () => {
20
+ if (!DragCircleMode) {
21
+ const circleModule = await import('mapbox-gl-draw-circle');
22
+ DragCircleMode = circleModule.DragCircleMode;
23
+ DirectMode = circleModule.DirectMode;
24
+ SimpleSelectMode = circleModule.SimpleSelectMode;
25
+ }
26
+ if (!RectangleMode) {
27
+ const rectModule = await import('mapbox-gl-draw-rectangle-mode');
28
+ RectangleMode = rectModule.default;
29
+ }
30
+ return { DragCircleMode, DirectMode, SimpleSelectMode, RectangleMode };
31
+ };
32
+ import {
33
+ MapPin,
34
+ Layers,
35
+ Circle,
36
+ Square,
37
+ Trash2,
38
+ Mountain,
39
+ Sun,
40
+ Moon,
41
+ RotateCcw,
42
+ Maximize2,
43
+ Pentagon,
44
+ Search,
45
+ X,
46
+ AlertTriangle,
47
+ Route,
48
+ Map,
49
+ Satellite,
50
+ TreePine,
51
+ } from 'lucide-react';
52
+ import {
53
+ Dialog,
54
+ DialogContent,
55
+ DialogHeader,
56
+ DialogTitle,
57
+ DialogFooter,
58
+ DialogDescription,
59
+ } from '@moving-walls/design-system';
60
+ import { Button } from '@moving-walls/design-system';
61
+ import { Badge } from '@moving-walls/design-system';
62
+
63
+ const COUNTRY_DATA = [
64
+ { name: "Malaysia", code: "my", center: [101.6869, 3.1390] as [number, number], zoom: 11 },
65
+ { name: "Singapore", code: "sg", center: [103.8198, 1.3521] as [number, number], zoom: 12 },
66
+ { name: "Indonesia", code: "id", center: [106.8456, -6.2088] as [number, number], zoom: 11 },
67
+ { name: "Thailand", code: "th", center: [100.5018, 13.7563] as [number, number], zoom: 11 },
68
+ { name: "Philippines", code: "ph", center: [121.0244, 14.5995] as [number, number], zoom: 11 },
69
+ { name: "Vietnam", code: "vn", center: [106.6297, 10.8231] as [number, number], zoom: 11 },
70
+ { name: "India", code: "in", center: [77.2090, 28.6139] as [number, number], zoom: 11 },
71
+ { name: "Japan", code: "jp", center: [139.6917, 35.6895] as [number, number], zoom: 11 },
72
+ { name: "South Korea", code: "kr", center: [126.9780, 37.5665] as [number, number], zoom: 11 },
73
+ { name: "Australia", code: "au", center: [151.2093, -33.8688] as [number, number], zoom: 10 },
74
+ { name: "Hong Kong", code: "hk", center: [114.1694, 22.3193] as [number, number], zoom: 12 },
75
+ { name: "Taiwan", code: "tw", center: [121.5654, 25.0330] as [number, number], zoom: 11 },
76
+ { name: "United Arab Emirates", code: "ae", center: [55.2708, 25.2048] as [number, number], zoom: 11 },
77
+ { name: "Saudi Arabia", code: "sa", center: [46.6753, 24.7136] as [number, number], zoom: 10 },
78
+ { name: "United Kingdom", code: "gb", center: [-0.1276, 51.5074] as [number, number], zoom: 10 },
79
+ ];
80
+
81
+ const DEFAULT_COUNTRY = COUNTRY_DATA[0];
82
+
83
+ const getCountryData = (country?: string) => {
84
+ if (!country) return DEFAULT_COUNTRY;
85
+ const lowerCountry = country.toLowerCase();
86
+ const found = COUNTRY_DATA.find(c =>
87
+ c.name.toLowerCase() === lowerCountry ||
88
+ c.code.toLowerCase() === lowerCountry
89
+ );
90
+ return found || DEFAULT_COUNTRY;
91
+ };
92
+
93
+ interface POIMarker {
94
+ id: string;
95
+ name: string;
96
+ coordinates: [number, number];
97
+ category: string;
98
+ locationId: string;
99
+ }
100
+
101
+ interface SelectedLocationForPOI {
102
+ id: string;
103
+ geometry?: {
104
+ type: string;
105
+ coordinates: any;
106
+ };
107
+ properties?: {
108
+ name?: string;
109
+ center?: [number, number];
110
+ };
111
+ poi?: string[];
112
+ }
113
+
114
+ interface GeofencingMapProps {
115
+ onLocationsChange: (locations: any[]) => void;
116
+ initialLocations?: any[];
117
+ radiusKm?: number;
118
+ country?: string;
119
+ onSearch?: (query: string) => void;
120
+ poisToRender?: POIMarker[];
121
+ onDeleteLocation?: (locationId: string) => void;
122
+ locationToDelete?: string | null;
123
+ onPOIsRendered?: (pois: POIMarker[]) => void;
124
+ hasLocations?: boolean;
125
+ addPOI?: boolean;
126
+ selectedLocation?: SelectedLocationForPOI | null;
127
+ onUpdateLocationPOIMetadata?: (id: string, metadata: Record<string, string>, pois: string[]) => void;
128
+ onAddPOIChange?: (addPOI: boolean) => void;
129
+ onCenterOnLocation?: boolean;
130
+ onLocationSelectFromMap?: (location: any) => void;
131
+ }
132
+
133
+ const RADIUS_OPTIONS = [
134
+ { value: 0.5, label: '500m' },
135
+ { value: 1, label: '1km' },
136
+ { value: 2, label: '2km' },
137
+ { value: 5, label: '5km' },
138
+ { value: 10, label: '10km' },
139
+ { value: 15, label: '15km' },
140
+ { value: 20, label: '20km' },
141
+ ];
142
+
143
+ type DrawMode = 'simple_select' | 'draw_point' | 'draw_polygon' | 'draw_circle' | 'draw_rectangle';
144
+
145
+ export function GeofencingMap({
146
+ onLocationsChange,
147
+ initialLocations = [],
148
+ radiusKm = 5,
149
+ country,
150
+ poisToRender = [],
151
+ locationToDelete = null,
152
+ onPOIsRendered,
153
+ hasLocations = false,
154
+ addPOI = false,
155
+ selectedLocation = null,
156
+ onUpdateLocationPOIMetadata,
157
+ onAddPOIChange,
158
+ onCenterOnLocation = false,
159
+ onLocationSelectFromMap,
160
+ }: GeofencingMapProps) {
161
+ const { t } = useTranslation('lineItems');
162
+ const mapContainer = useRef<HTMLDivElement>(null);
163
+ const map = useRef<mapboxgl.Map | null>(null);
164
+ const draw = useRef<MapboxDraw | null>(null);
165
+ const geocoder = useRef<MapboxGeocoder | null>(null);
166
+ const [isMapLoaded, setIsMapLoaded] = useState(false);
167
+ const [activeMode, setActiveMode] = useState<DrawMode>('simple_select');
168
+ const [isFullscreen, setIsFullscreen] = useState(false);
169
+ const [mapStyle, setMapStyle] = useState<'streets' | 'satellite' | 'outdoors' | 'light' | 'dark'>('streets');
170
+
171
+ const [selectedPOIs, setSelectedPOIs] = useState<string[]>([]);
172
+ const [isLoadingPOIs, setIsLoadingPOIs] = useState(false);
173
+ const [internalPOIs, setInternalPOIs] = useState<POIMarker[]>([]);
174
+ const [isPOIDropdownOpen, setIsPOIDropdownOpen] = useState(false);
175
+ const [selectedRadius, setSelectedRadius] = useState(1450);
176
+ const [showRadiusToolbar, setShowRadiusToolbar] = useState(false);
177
+ const [searchQuery, setSearchQuery] = useState('');
178
+ const [searchSuggestions, setSearchSuggestions] = useState<any[]>([]);
179
+ const [showSuggestions, setShowSuggestions] = useState(false);
180
+ const searchContainerRef = useRef<HTMLDivElement>(null);
181
+ const debounceTimerRef = useRef<NodeJS.Timeout | null>(null);
182
+ const [locationPopover, setLocationPopover] = useState<{
183
+ coordinates: [number, number];
184
+ name: string;
185
+ address: string;
186
+ included: boolean;
187
+ } | null>(null);
188
+ const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
189
+ const [selectedFeatureToDelete, setSelectedFeatureToDelete] = useState<any>(null);
190
+ const popupRef = useRef<mapboxgl.Popup | null>(null);
191
+ const shapeCountersRef = useRef<{ circle: number; rectangle: number; polygon: number; point: number }>({
192
+ circle: 0,
193
+ rectangle: 0,
194
+ polygon: 0,
195
+ point: 0,
196
+ });
197
+ const processedFeaturesRef = useRef<Set<string>>(new Set());
198
+
199
+ const getMapCenter = useCallback((): { lat: number; lng: number } | null => {
200
+ if (!draw.current) return null;
201
+
202
+ const features = draw.current.getAll();
203
+ if (features.features.length === 0) return null;
204
+
205
+ const firstFeature = features.features[0];
206
+ if (firstFeature.geometry.type === 'Point') {
207
+ const coords = firstFeature.geometry.coordinates as [number, number];
208
+ return { lng: coords[0], lat: coords[1] };
209
+ }
210
+
211
+ if (firstFeature.geometry.type === 'Polygon') {
212
+ const coords = firstFeature.geometry.coordinates[0] as [number, number][];
213
+ const sumLng = coords.reduce((acc, c) => acc + c[0], 0);
214
+ const sumLat = coords.reduce((acc, c) => acc + c[1], 0);
215
+ return { lng: sumLng / coords.length, lat: sumLat / coords.length };
216
+ }
217
+
218
+ return null;
219
+ }, []);
220
+
221
+ const getSelectedLocationCenter = useCallback((): { lat: number; lng: number } | null => {
222
+ if (!selectedLocation) return null;
223
+
224
+ if (selectedLocation.properties?.center) {
225
+ const center = selectedLocation.properties.center;
226
+ return { lng: center[0], lat: center[1] };
227
+ }
228
+
229
+ if (selectedLocation.geometry?.type === 'Point' && selectedLocation.geometry.coordinates) {
230
+ const coords = selectedLocation.geometry.coordinates;
231
+ return { lng: coords[0], lat: coords[1] };
232
+ }
233
+
234
+ if (selectedLocation.geometry?.type === 'Polygon' && selectedLocation.geometry.coordinates?.[0]) {
235
+ const coords = selectedLocation.geometry.coordinates[0];
236
+ if (Array.isArray(coords) && coords.length > 0) {
237
+ const sumLng = coords.reduce((acc: number, c: any) => acc + (c[0] || 0), 0);
238
+ const sumLat = coords.reduce((acc: number, c: any) => acc + (c[1] || 0), 0);
239
+ return { lng: sumLng / coords.length, lat: sumLat / coords.length };
240
+ }
241
+ }
242
+
243
+ return getMapCenter();
244
+ }, [selectedLocation, getMapCenter]);
245
+
246
+ const handleRenderPOIs = useCallback(async (pois?: string[], metadata?: Record<string, string>) => {
247
+ const poiList = pois || selectedPOIs;
248
+ if (poiList.length === 0) return;
249
+
250
+ const center = addPOI && selectedLocation ? getSelectedLocationCenter() : getMapCenter();
251
+ if (!center) {
252
+ console.warn('No location selected to render POIs around');
253
+ return;
254
+ }
255
+
256
+ setIsLoadingPOIs(true);
257
+ const allPOIMarkers: POIMarker[] = [];
258
+ const locationId = selectedLocation?.id || 'map-location';
259
+
260
+ try {
261
+ for (const poiType of poiList) {
262
+ const places = await fetchNearbyPlaces({
263
+ location: center,
264
+ searchType: poiType,
265
+ radius: radiusKm * 1000,
266
+ maxResults: 10,
267
+ });
268
+
269
+ places.forEach((place, index) => {
270
+ allPOIMarkers.push({
271
+ id: `${poiType}-${place.id || index}`,
272
+ name: place.name || getPOILabel(poiType),
273
+ coordinates: place.coordinates,
274
+ category: poiType,
275
+ locationId: locationId,
276
+ });
277
+ });
278
+ }
279
+
280
+ setInternalPOIs(allPOIMarkers);
281
+
282
+ if (onUpdateLocationPOIMetadata && selectedLocation) {
283
+ onUpdateLocationPOIMetadata(
284
+ selectedLocation.id,
285
+ metadata || { poiCount: String(poiList.length), timestamp: new Date().toISOString() },
286
+ poiList
287
+ );
288
+ }
289
+
290
+ if (onPOIsRendered) {
291
+ onPOIsRendered(allPOIMarkers);
292
+ }
293
+ } catch (error) {
294
+ console.error('Error fetching POIs:', error);
295
+ } finally {
296
+ setIsLoadingPOIs(false);
297
+ }
298
+ }, [selectedPOIs, getMapCenter, getSelectedLocationCenter, radiusKm, onPOIsRendered, addPOI, selectedLocation, onUpdateLocationPOIMetadata]);
299
+
300
+ const effectivePOIs = poisToRender.length > 0 ? poisToRender : internalPOIs;
301
+ const isPOIDropdownEnabled = addPOI ? (selectedLocation !== null) : (hasLocations || initialLocations.length > 0);
302
+
303
+ const initializeMap = useCallback(async () => {
304
+ if (!mapContainer.current || map.current) return;
305
+
306
+ const mapboxToken = "pk.eyJ1IjoibWF4aW5mbyIsImEiOiJjbWV2M2l6ZDMwZ2ZqMmtzaHUyMXc3bGl2In0.ttPa9Es1LK2herlw4ZM0Hw";
307
+
308
+ if (!mapboxToken) {
309
+ console.error('Mapbox token not found.');
310
+ return;
311
+ }
312
+
313
+ const modes = await loadDrawModes();
314
+
315
+ mapboxgl.accessToken = mapboxToken;
316
+
317
+ const countryData = getCountryData(country);
318
+
319
+ map.current = new mapboxgl.Map({
320
+ container: mapContainer.current,
321
+ style: 'mapbox://styles/mapbox/streets-v12',
322
+ center: countryData.center,
323
+ zoom: countryData.zoom,
324
+ });
325
+
326
+ draw.current = new MapboxDraw({
327
+ displayControlsDefault: false,
328
+ controls: {},
329
+ defaultMode: 'simple_select',
330
+ modes: {
331
+ ...MapboxDraw.modes,
332
+ draw_circle: modes.DragCircleMode,
333
+ direct_select: modes.DirectMode,
334
+ simple_select: modes.SimpleSelectMode,
335
+ draw_rectangle: modes.RectangleMode,
336
+ },
337
+ styles: [
338
+ {
339
+ 'id': 'gl-draw-polygon-fill',
340
+ 'type': 'fill',
341
+ 'filter': ['all', ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
342
+ 'paint': {
343
+ 'fill-color': '#2176cc',
344
+ 'fill-outline-color': '#2176cc',
345
+ 'fill-opacity': 0.2
346
+ }
347
+ },
348
+ {
349
+ 'id': 'gl-draw-polygon-stroke',
350
+ 'type': 'line',
351
+ 'filter': ['all', ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
352
+ 'layout': {
353
+ 'line-cap': 'round',
354
+ 'line-join': 'round'
355
+ },
356
+ 'paint': {
357
+ 'line-color': '#2176cc',
358
+ 'line-width': 2
359
+ }
360
+ },
361
+ {
362
+ 'id': 'gl-draw-line',
363
+ 'type': 'line',
364
+ 'filter': ['all', ['==', '$type', 'LineString'], ['!=', 'mode', 'static']],
365
+ 'layout': {
366
+ 'line-cap': 'round',
367
+ 'line-join': 'round'
368
+ },
369
+ 'paint': {
370
+ 'line-color': '#2176cc',
371
+ 'line-width': 2
372
+ }
373
+ },
374
+ {
375
+ 'id': 'gl-draw-point',
376
+ 'type': 'circle',
377
+ 'filter': ['all', ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
378
+ 'paint': {
379
+ 'circle-radius': 6,
380
+ 'circle-color': '#2176cc'
381
+ }
382
+ },
383
+ {
384
+ 'id': 'gl-draw-point-stroke',
385
+ 'type': 'circle',
386
+ 'filter': ['all', ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
387
+ 'paint': {
388
+ 'circle-radius': 8,
389
+ 'circle-color': '#fff'
390
+ }
391
+ }
392
+ ]
393
+ });
394
+
395
+ geocoder.current = new MapboxGeocoder({
396
+ accessToken: mapboxToken,
397
+ mapboxgl: mapboxgl as any,
398
+ marker: false,
399
+ placeholder: 'Search locations...',
400
+ countries: countryData.code,
401
+ });
402
+
403
+ map.current.addControl(draw.current);
404
+ map.current.addControl(new mapboxgl.NavigationControl(), 'bottom-right');
405
+
406
+ geocoder.current.on('result', (e: any) => {
407
+ const { result } = e;
408
+ if (result && result.center && draw.current) {
409
+ const feature = {
410
+ type: 'Feature' as const,
411
+ properties: {
412
+ name: result.place_name || result.text || 'Search Result',
413
+ address: result.place_name || '',
414
+ included: true,
415
+ pois: [],
416
+ },
417
+ geometry: {
418
+ type: 'Point' as const,
419
+ coordinates: result.center,
420
+ },
421
+ };
422
+ draw.current.add(feature);
423
+ const data = draw.current.getAll();
424
+ onLocationsChange(data.features);
425
+ }
426
+ });
427
+
428
+ map.current.on('load', () => {
429
+ setIsMapLoaded(true);
430
+ });
431
+
432
+ const handleDrawCreate = (e: any) => {
433
+ if (draw.current && e.features && e.features.length > 0) {
434
+ const feature = e.features[0];
435
+ const featureId = feature.id;
436
+
437
+ // Skip if this feature was already processed (prevents infinite loop)
438
+ if (processedFeaturesRef.current.has(featureId)) {
439
+ return;
440
+ }
441
+
442
+ // Skip if feature already has a name (was added programmatically)
443
+ if (feature.properties?.name) {
444
+ const data = draw.current.getAll();
445
+ onLocationsChange(data.features);
446
+ return;
447
+ }
448
+
449
+ let shapeName = 'Location';
450
+ let shapeType = 'point';
451
+
452
+ // Determine shape type based on geometry and properties
453
+ if (feature.properties?.isCircle || (feature.geometry?.type === 'Polygon' && feature.properties?.center)) {
454
+ shapeType = 'circle';
455
+ shapeCountersRef.current.circle += 1;
456
+ shapeName = `Circle ${shapeCountersRef.current.circle}`;
457
+ } else if (feature.properties?.isRectangle) {
458
+ shapeType = 'rectangle';
459
+ shapeCountersRef.current.rectangle += 1;
460
+ shapeName = `Rectangle ${shapeCountersRef.current.rectangle}`;
461
+ } else if (feature.geometry?.type === 'Polygon') {
462
+ // Check if it's a rectangle by coordinates count
463
+ const coords = feature.geometry?.coordinates?.[0];
464
+ if (coords && coords.length === 5) {
465
+ shapeType = 'rectangle';
466
+ shapeCountersRef.current.rectangle += 1;
467
+ shapeName = `Rectangle ${shapeCountersRef.current.rectangle}`;
468
+ } else {
469
+ shapeType = 'polygon';
470
+ shapeCountersRef.current.polygon += 1;
471
+ shapeName = `Polygon ${shapeCountersRef.current.polygon}`;
472
+ }
473
+ } else if (feature.geometry?.type === 'Point') {
474
+ shapeType = 'point';
475
+ shapeCountersRef.current.point += 1;
476
+ shapeName = `Point ${shapeCountersRef.current.point}`;
477
+ }
478
+
479
+ // Mark as processed before updating
480
+ processedFeaturesRef.current.add(featureId);
481
+
482
+ // Use setFeatureProperty to update properties without triggering draw.create
483
+ draw.current.setFeatureProperty(featureId, 'name', shapeName);
484
+ draw.current.setFeatureProperty(featureId, 'locationType', shapeType);
485
+ draw.current.setFeatureProperty(featureId, 'included', true);
486
+
487
+ const data = draw.current.getAll();
488
+ onLocationsChange(data.features);
489
+ }
490
+ };
491
+
492
+ const handleDrawUpdate = () => {
493
+ if (draw.current) {
494
+ const data = draw.current.getAll();
495
+ onLocationsChange(data.features);
496
+ }
497
+ };
498
+
499
+ const handleDrawDelete = () => {
500
+ if (draw.current) {
501
+ const data = draw.current.getAll();
502
+ onLocationsChange(data.features);
503
+ }
504
+ };
505
+
506
+ const handleDrawSelectionChange = () => {
507
+ if (draw.current && onLocationSelectFromMap) {
508
+ const selected = draw.current.getSelected();
509
+ if (selected.features && selected.features.length > 0) {
510
+ const selectedFeature = selected.features[0];
511
+ onLocationSelectFromMap(selectedFeature);
512
+ }
513
+ }
514
+ };
515
+
516
+ map.current.on('draw.create', handleDrawCreate);
517
+ map.current.on('draw.update', handleDrawUpdate);
518
+ map.current.on('draw.delete', handleDrawDelete);
519
+ map.current.on('draw.selectionchange', handleDrawSelectionChange);
520
+
521
+ return () => {
522
+ if (map.current) {
523
+ map.current.remove();
524
+ map.current = null;
525
+ }
526
+ };
527
+ }, [onLocationsChange, country, onLocationSelectFromMap]);
528
+
529
+ useEffect(() => {
530
+ initializeMap();
531
+ }, [initializeMap]);
532
+
533
+ useEffect(() => {
534
+ if (!isMapLoaded || !draw.current) return;
535
+
536
+ const existingFeatures = draw.current.getAll();
537
+ if (existingFeatures.features.length > 0) {
538
+ const featureIds = existingFeatures.features.map((f: any) => f.id);
539
+ featureIds.forEach((id: string) => draw.current?.delete(id));
540
+ }
541
+
542
+ // Reset counters and initialize based on initial locations
543
+ shapeCountersRef.current = { circle: 0, rectangle: 0, polygon: 0, point: 0 };
544
+ processedFeaturesRef.current.clear();
545
+
546
+ if (initialLocations.length > 0) {
547
+ initialLocations.forEach((location) => {
548
+ if (location.geometry) {
549
+ // Count existing shapes to continue numbering
550
+ const locationType = location.properties?.locationType || '';
551
+ const name = location.properties?.name || '';
552
+
553
+ if (locationType === 'circle' || name.toLowerCase().startsWith('circle')) {
554
+ const match = name.match(/Circle (\d+)/i);
555
+ if (match) {
556
+ const num = parseInt(match[1], 10);
557
+ if (num > shapeCountersRef.current.circle) {
558
+ shapeCountersRef.current.circle = num;
559
+ }
560
+ }
561
+ } else if (locationType === 'rectangle' || name.toLowerCase().startsWith('rectangle')) {
562
+ const match = name.match(/Rectangle (\d+)/i);
563
+ if (match) {
564
+ const num = parseInt(match[1], 10);
565
+ if (num > shapeCountersRef.current.rectangle) {
566
+ shapeCountersRef.current.rectangle = num;
567
+ }
568
+ }
569
+ } else if (locationType === 'polygon' || name.toLowerCase().startsWith('polygon')) {
570
+ const match = name.match(/Polygon (\d+)/i);
571
+ if (match) {
572
+ const num = parseInt(match[1], 10);
573
+ if (num > shapeCountersRef.current.polygon) {
574
+ shapeCountersRef.current.polygon = num;
575
+ }
576
+ }
577
+ } else if (locationType === 'point' || name.toLowerCase().startsWith('point')) {
578
+ const match = name.match(/Point (\d+)/i);
579
+ if (match) {
580
+ const num = parseInt(match[1], 10);
581
+ if (num > shapeCountersRef.current.point) {
582
+ shapeCountersRef.current.point = num;
583
+ }
584
+ }
585
+ }
586
+
587
+ // Mark as processed so we don't rename it
588
+ if (location.id) {
589
+ processedFeaturesRef.current.add(location.id);
590
+ }
591
+
592
+ draw.current?.add(location);
593
+ }
594
+ });
595
+ }
596
+ }, [isMapLoaded, initialLocations]);
597
+
598
+ useEffect(() => {
599
+ if (!isMapLoaded || !draw.current || !locationToDelete) return;
600
+ draw.current.delete(locationToDelete);
601
+ const data = draw.current.getAll();
602
+ onLocationsChange(data.features);
603
+ }, [locationToDelete, isMapLoaded, onLocationsChange]);
604
+
605
+ useEffect(() => {
606
+ if (!addPOI || !selectedLocation) {
607
+ if (isPOIDropdownOpen) {
608
+ setIsPOIDropdownOpen(false);
609
+ setSelectedPOIs([]);
610
+ }
611
+ return;
612
+ }
613
+ if (selectedLocation.poi && selectedLocation.poi.length > 0) {
614
+ setSelectedPOIs(selectedLocation.poi);
615
+ } else {
616
+ setSelectedPOIs([]);
617
+ }
618
+ setIsPOIDropdownOpen(true);
619
+ }, [addPOI, selectedLocation]);
620
+
621
+ useEffect(() => {
622
+ if (!isMapLoaded || !map.current || !selectedLocation || !onCenterOnLocation) return;
623
+
624
+ const center = getSelectedLocationCenter();
625
+ if (center) {
626
+ map.current.flyTo({
627
+ center: [center.lng, center.lat],
628
+ zoom: 14,
629
+ duration: 1000,
630
+ });
631
+
632
+ if (popupRef.current) {
633
+ popupRef.current.remove();
634
+ }
635
+
636
+ const name = selectedLocation.properties?.name || 'Location';
637
+ const address = (selectedLocation as any).properties?.address || '';
638
+ const included = (selectedLocation as any).properties?.included !== false;
639
+
640
+ setLocationPopover({
641
+ coordinates: [center.lng, center.lat],
642
+ name,
643
+ address,
644
+ included,
645
+ });
646
+ }
647
+ }, [isMapLoaded, selectedLocation, onCenterOnLocation, getSelectedLocationCenter]);
648
+
649
+ useEffect(() => {
650
+ if (!isMapLoaded || !map.current || !locationPopover) return;
651
+
652
+ if (popupRef.current) {
653
+ popupRef.current.remove();
654
+ }
655
+
656
+ const popupContent = document.createElement('div');
657
+ popupContent.className = 'location-popover-content';
658
+ popupContent.innerHTML = `
659
+ <div style="padding: 12px; min-width: 200px; max-width: 280px;">
660
+ <div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px;">
661
+ <h3 style="font-weight: 600; font-size: 14px; color: #1f2937; margin: 0; flex: 1;">${locationPopover.name}</h3>
662
+ <button class="popover-close-btn" style="background: none; border: none; cursor: pointer; padding: 2px; margin-left: 8px;">
663
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
664
+ <line x1="18" y1="6" x2="6" y2="18"></line>
665
+ <line x1="6" y1="6" x2="18" y2="18"></line>
666
+ </svg>
667
+ </button>
668
+ </div>
669
+ ${locationPopover.address ? `<p style="font-size: 12px; color: #6b7280; margin: 0 0 8px 0; line-height: 1.4;">${locationPopover.address}</p>` : ''}
670
+ ${locationPopover.included ? `
671
+ <span style="display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; background-color: #dcfce7; color: #166534; font-size: 11px; font-weight: 500; border-radius: 4px;">
672
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
673
+ <polyline points="20,6 9,17 4,12"></polyline>
674
+ </svg>
675
+ Included
676
+ </span>
677
+ ` : ''}
678
+ </div>
679
+ `;
680
+
681
+ popupRef.current = new mapboxgl.Popup({
682
+ closeButton: false,
683
+ closeOnClick: false,
684
+ anchor: 'bottom',
685
+ offset: [0, -10],
686
+ })
687
+ .setLngLat(locationPopover.coordinates)
688
+ .setDOMContent(popupContent)
689
+ .addTo(map.current);
690
+
691
+ const closeBtn = popupContent.querySelector('.popover-close-btn');
692
+ if (closeBtn) {
693
+ closeBtn.addEventListener('click', () => {
694
+ if (popupRef.current) {
695
+ popupRef.current.remove();
696
+ popupRef.current = null;
697
+ }
698
+ setLocationPopover(null);
699
+ });
700
+ }
701
+
702
+ return () => {
703
+ if (popupRef.current) {
704
+ popupRef.current.remove();
705
+ popupRef.current = null;
706
+ }
707
+ };
708
+ }, [isMapLoaded, locationPopover]);
709
+
710
+ const handleSearchSubmit = useCallback(async () => {
711
+ if (!map.current || !searchQuery.trim()) return;
712
+
713
+ const mapboxToken = "pk.eyJ1IjoibWF4aW5mbyIsImEiOiJjbWV2M2l6ZDMwZ2ZqMmtzaHUyMXc3bGl2In0.ttPa9Es1LK2herlw4ZM0Hw";
714
+
715
+ // Build URL - only add country filter if country prop is provided
716
+ let apiUrl = `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent(searchQuery)}.json?access_token=${mapboxToken}&limit=1`;
717
+ if (country) {
718
+ const countryData = getCountryData(country);
719
+ apiUrl += `&country=${countryData.code}`;
720
+ }
721
+
722
+ try {
723
+ const response = await fetch(apiUrl);
724
+ const data = await response.json();
725
+
726
+ if (data.features && data.features.length > 0 && draw.current) {
727
+ const result = data.features[0];
728
+ const feature = {
729
+ type: 'Feature' as const,
730
+ properties: {
731
+ name: result.place_name || result.text || 'Search Result',
732
+ address: result.place_name || '',
733
+ included: true,
734
+ pois: [],
735
+ locationType: 'address',
736
+ },
737
+ geometry: {
738
+ type: 'Point' as const,
739
+ coordinates: result.center,
740
+ },
741
+ };
742
+ draw.current.add(feature);
743
+ const allFeatures = draw.current.getAll();
744
+ onLocationsChange(allFeatures.features);
745
+
746
+ map.current.flyTo({
747
+ center: result.center,
748
+ zoom: 14,
749
+ duration: 1000,
750
+ });
751
+
752
+ setSearchQuery('');
753
+ }
754
+ } catch (error) {
755
+ console.error('Geocoding error:', error);
756
+ }
757
+ }, [searchQuery, country, onLocationsChange]);
758
+
759
+ const handleSearchKeyDown = useCallback((e: React.KeyboardEvent) => {
760
+ if (e.key === 'Enter') {
761
+ setShowSuggestions(false);
762
+ handleSearchSubmit();
763
+ } else if (e.key === 'Escape') {
764
+ setShowSuggestions(false);
765
+ }
766
+ }, [handleSearchSubmit]);
767
+
768
+ const fetchSearchSuggestions = useCallback(async (query: string) => {
769
+ if (!query.trim() || query.length < 2) {
770
+ setSearchSuggestions([]);
771
+ setShowSuggestions(false);
772
+ return;
773
+ }
774
+
775
+ const mapboxToken = "pk.eyJ1IjoibWF4aW5mbyIsImEiOiJjbWV2M2l6ZDMwZ2ZqMmtzaHUyMXc3bGl2In0.ttPa9Es1LK2herlw4ZM0Hw";
776
+
777
+ let apiUrl = `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent(query)}.json?access_token=${mapboxToken}&limit=5`;
778
+ if (country) {
779
+ const countryData = getCountryData(country);
780
+ apiUrl += `&country=${countryData.code}`;
781
+ }
782
+
783
+ try {
784
+ const response = await fetch(apiUrl);
785
+ const data = await response.json();
786
+
787
+ if (data.features && data.features.length > 0) {
788
+ setSearchSuggestions(data.features);
789
+ setShowSuggestions(true);
790
+ } else {
791
+ setSearchSuggestions([]);
792
+ setShowSuggestions(false);
793
+ }
794
+ } catch (error) {
795
+ console.error('Geocoding suggestion error:', error);
796
+ setSearchSuggestions([]);
797
+ setShowSuggestions(false);
798
+ }
799
+ }, [country]);
800
+
801
+ const handleSearchInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
802
+ const value = e.target.value;
803
+ setSearchQuery(value);
804
+
805
+ if (debounceTimerRef.current) {
806
+ clearTimeout(debounceTimerRef.current);
807
+ }
808
+
809
+ debounceTimerRef.current = setTimeout(() => {
810
+ fetchSearchSuggestions(value);
811
+ }, 300);
812
+ }, [fetchSearchSuggestions]);
813
+
814
+ const handleSuggestionClick = useCallback((suggestion: any) => {
815
+ if (!map.current || !draw.current) return;
816
+
817
+ const feature = {
818
+ type: 'Feature' as const,
819
+ properties: {
820
+ name: suggestion.text || suggestion.place_name || 'Search Result',
821
+ address: suggestion.place_name || '',
822
+ included: true,
823
+ pois: [],
824
+ locationType: 'address',
825
+ },
826
+ geometry: {
827
+ type: 'Point' as const,
828
+ coordinates: suggestion.center,
829
+ },
830
+ };
831
+ draw.current.add(feature);
832
+ const allFeatures = draw.current.getAll();
833
+ onLocationsChange(allFeatures.features);
834
+
835
+ map.current.flyTo({
836
+ center: suggestion.center,
837
+ zoom: 14,
838
+ duration: 1000,
839
+ });
840
+
841
+ setSearchQuery('');
842
+ setSearchSuggestions([]);
843
+ setShowSuggestions(false);
844
+ }, [onLocationsChange]);
845
+
846
+ useEffect(() => {
847
+ const handleClickOutside = (event: MouseEvent) => {
848
+ if (searchContainerRef.current && !searchContainerRef.current.contains(event.target as Node)) {
849
+ setShowSuggestions(false);
850
+ }
851
+ };
852
+
853
+ document.addEventListener('mousedown', handleClickOutside);
854
+ return () => {
855
+ document.removeEventListener('mousedown', handleClickOutside);
856
+ if (debounceTimerRef.current) {
857
+ clearTimeout(debounceTimerRef.current);
858
+ }
859
+ };
860
+ }, []);
861
+
862
+ useEffect(() => {
863
+ if (!isMapLoaded || !map.current) return;
864
+
865
+ const mapInstance = map.current;
866
+ const sourceId = 'poi-markers-source';
867
+ const layerId = 'poi-markers-layer';
868
+ const labelLayerId = 'poi-labels-layer';
869
+
870
+ if (mapInstance.getLayer(labelLayerId)) {
871
+ mapInstance.removeLayer(labelLayerId);
872
+ }
873
+ if (mapInstance.getLayer(layerId)) {
874
+ mapInstance.removeLayer(layerId);
875
+ }
876
+ if (mapInstance.getSource(sourceId)) {
877
+ mapInstance.removeSource(sourceId);
878
+ }
879
+
880
+ if (effectivePOIs.length > 0) {
881
+ const geojsonData: GeoJSON.FeatureCollection<GeoJSON.Point> = {
882
+ type: 'FeatureCollection',
883
+ features: effectivePOIs.map((poi) => ({
884
+ type: 'Feature',
885
+ properties: {
886
+ id: poi.id,
887
+ name: poi.name,
888
+ category: poi.category,
889
+ locationId: poi.locationId,
890
+ },
891
+ geometry: {
892
+ type: 'Point',
893
+ coordinates: poi.coordinates,
894
+ },
895
+ })),
896
+ };
897
+
898
+ mapInstance.addSource(sourceId, {
899
+ type: 'geojson',
900
+ data: geojsonData,
901
+ });
902
+
903
+ mapInstance.addLayer({
904
+ id: layerId,
905
+ type: 'circle',
906
+ source: sourceId,
907
+ paint: {
908
+ 'circle-radius': 8,
909
+ 'circle-color': '#22c55e',
910
+ 'circle-stroke-width': 2,
911
+ 'circle-stroke-color': '#ffffff',
912
+ },
913
+ });
914
+
915
+ mapInstance.addLayer({
916
+ id: labelLayerId,
917
+ type: 'symbol',
918
+ source: sourceId,
919
+ layout: {
920
+ 'text-field': ['get', 'name'],
921
+ 'text-size': 11,
922
+ 'text-offset': [0, 1.5],
923
+ 'text-anchor': 'top',
924
+ },
925
+ paint: {
926
+ 'text-color': '#374151',
927
+ 'text-halo-color': '#ffffff',
928
+ 'text-halo-width': 1,
929
+ },
930
+ });
931
+ }
932
+ }, [isMapLoaded, effectivePOIs]);
933
+
934
+ const handleSetMode = (mode: DrawMode) => {
935
+ if (!draw.current) return;
936
+
937
+ setActiveMode(mode);
938
+ setShowRadiusToolbar(mode === 'draw_circle');
939
+
940
+ switch (mode) {
941
+ case 'draw_point':
942
+ draw.current.changeMode('draw_point');
943
+ break;
944
+ case 'draw_polygon':
945
+ draw.current.changeMode('draw_polygon');
946
+ break;
947
+ case 'draw_circle':
948
+ draw.current.changeMode('draw_circle');
949
+ break;
950
+ case 'draw_rectangle':
951
+ draw.current.changeMode('draw_rectangle');
952
+ break;
953
+ default:
954
+ draw.current.changeMode('simple_select');
955
+ }
956
+ };
957
+
958
+ const handleDeleteClick = () => {
959
+ if (!draw.current) return;
960
+ const selectedFeatures = draw.current.getSelected();
961
+ if (selectedFeatures.features && selectedFeatures.features.length > 0) {
962
+ setSelectedFeatureToDelete(selectedFeatures.features);
963
+ setDeleteConfirmOpen(true);
964
+ }
965
+ };
966
+
967
+ const handleConfirmDelete = () => {
968
+ if (!draw.current || !selectedFeatureToDelete || selectedFeatureToDelete.length === 0) return;
969
+ const idsToDelete = selectedFeatureToDelete.map((f: any) => f.id);
970
+ draw.current.delete(idsToDelete);
971
+ const data = draw.current.getAll();
972
+ onLocationsChange(data.features);
973
+ setDeleteConfirmOpen(false);
974
+ setSelectedFeatureToDelete(null);
975
+ };
976
+
977
+ const handleClearAll = () => {
978
+ if (!draw.current) return;
979
+ draw.current.deleteAll();
980
+ onLocationsChange([]);
981
+ };
982
+
983
+ const handleFullscreen = () => {
984
+ if (!mapContainer.current) return;
985
+
986
+ if (!isFullscreen) {
987
+ if (mapContainer.current.requestFullscreen) {
988
+ mapContainer.current.requestFullscreen();
989
+ }
990
+ } else {
991
+ if (document.exitFullscreen) {
992
+ document.exitFullscreen();
993
+ }
994
+ }
995
+ setIsFullscreen(!isFullscreen);
996
+ };
997
+
998
+ const handleMapStyleChange = (style: 'streets' | 'satellite' | 'outdoors' | 'light' | 'dark') => {
999
+ if (!map.current || !draw.current) return;
1000
+ const styleUrls: Record<string, string> = {
1001
+ streets: 'mapbox://styles/mapbox/streets-v12',
1002
+ satellite: 'mapbox://styles/mapbox/satellite-streets-v12',
1003
+ outdoors: 'mapbox://styles/mapbox/outdoors-v12',
1004
+ light: 'mapbox://styles/mapbox/light-v11',
1005
+ dark: 'mapbox://styles/mapbox/dark-v11',
1006
+ };
1007
+
1008
+ const currentFeatures = draw.current.getAll();
1009
+
1010
+ map.current.setStyle(styleUrls[style]);
1011
+ setMapStyle(style);
1012
+
1013
+ map.current.once('style.load', () => {
1014
+ if (draw.current && currentFeatures.features.length > 0) {
1015
+ draw.current.set(currentFeatures);
1016
+ }
1017
+ });
1018
+ };
1019
+
1020
+ const toolbarButtons = [
1021
+ { id: 'draw_point', icon: MapPin, tooltip: t('geofencing.map.tools.drawPoint'), mode: 'draw_point' as DrawMode },
1022
+ { id: 'draw_rectangle', icon: Square, tooltip: t('geofencing.map.tools.drawRectangle'), mode: 'draw_rectangle' as DrawMode },
1023
+ { id: 'draw_circle', icon: Circle, tooltip: t('geofencing.map.tools.drawCircle'), mode: 'draw_circle' as DrawMode },
1024
+ { id: 'draw_line', icon: Route, tooltip: t('geofencing.map.tools.drawLine'), mode: 'draw_polygon' as DrawMode },
1025
+ { id: 'delete', icon: Trash2, tooltip: t('geofencing.map.tools.deleteSelected'), action: handleDeleteClick },
1026
+ { id: 'divider1', divider: true },
1027
+ { id: 'terrain', icon: Mountain, tooltip: t('geofencing.map.tools.toggleTerrain') },
1028
+ { id: 'layers', icon: Layers, tooltip: t('geofencing.map.tools.toggleLayers'), mode: 'simple_select' as DrawMode },
1029
+ { id: 'divider2', divider: true },
1030
+ { id: 'streets', icon: Map, tooltip: t('geofencing.map.tools.streets'), styleAction: () => handleMapStyleChange('streets') },
1031
+ { id: 'satellite', icon: Satellite, tooltip: t('geofencing.map.tools.satellite'), styleAction: () => handleMapStyleChange('satellite') },
1032
+ { id: 'outdoors', icon: TreePine, tooltip: t('geofencing.map.tools.outdoors'), styleAction: () => handleMapStyleChange('outdoors') },
1033
+ { id: 'light', icon: Sun, tooltip: t('geofencing.map.tools.light'), styleAction: () => handleMapStyleChange('light') },
1034
+ { id: 'dark', icon: Moon, tooltip: t('geofencing.map.tools.dark'), styleAction: () => handleMapStyleChange('dark') },
1035
+ ];
1036
+
1037
+ return (
1038
+ <div className="relative w-full h-full">
1039
+ <div
1040
+ ref={mapContainer}
1041
+ className="w-full h-full rounded-lg"
1042
+ data-testid="map-geofencing"
1043
+ />
1044
+
1045
+ {!isMapLoaded && (
1046
+ <div className="absolute inset-0 flex items-center justify-center bg-mw-neutral-100/80 dark:bg-mw-neutral-800/80 rounded-lg">
1047
+ <div className="flex flex-col items-center gap-2">
1048
+ <div className="w-8 h-8 border-2 border-mw-primary-500 border-t-transparent rounded-full animate-spin" />
1049
+ <p className="text-sm text-mw-neutral-600 dark:text-mw-neutral-400">{t('geofencing.map.loading')}</p>
1050
+ </div>
1051
+ </div>
1052
+ )}
1053
+
1054
+ <div className="absolute top-3 left-3 right-3 z-20">
1055
+ <div className="flex items-stretch gap-3">
1056
+ <div className="flex-1 relative" ref={searchContainerRef}>
1057
+ <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-mw-neutral-400 z-10" />
1058
+ <input
1059
+ type="text"
1060
+ placeholder={t('geofencing.map.searchLocations')}
1061
+ value={searchQuery}
1062
+ onChange={handleSearchInputChange}
1063
+ onKeyDown={handleSearchKeyDown}
1064
+ onFocus={() => {
1065
+ if (searchSuggestions.length > 0) {
1066
+ setShowSuggestions(true);
1067
+ }
1068
+ }}
1069
+ className={cn(
1070
+ 'w-full h-10 pl-10 pr-10 text-sm',
1071
+ 'bg-white',
1072
+ 'border border-mw-neutral-200',
1073
+ 'rounded-md shadow-sm outline-none',
1074
+ 'focus:ring-2 focus:ring-mw-primary-500 focus:border-transparent',
1075
+ 'placeholder:text-mw-neutral-400'
1076
+ )}
1077
+ />
1078
+ {searchQuery && (
1079
+ <button
1080
+ type="button"
1081
+ onClick={() => {
1082
+ setSearchQuery('');
1083
+ setSearchSuggestions([]);
1084
+ setShowSuggestions(false);
1085
+ }}
1086
+ className="absolute right-3 top-1/2 -translate-y-1/2 p-1 hover:bg-mw-neutral-100 rounded-full z-10"
1087
+ >
1088
+ <X className="h-3 w-3 text-mw-neutral-400" />
1089
+ </button>
1090
+ )}
1091
+ {showSuggestions && searchSuggestions.length > 0 && (
1092
+ <div className="absolute top-full left-0 right-0 mt-1 bg-white border border-mw-neutral-200 rounded-md shadow-lg overflow-hidden z-30">
1093
+ {searchSuggestions.map((suggestion, index) => {
1094
+ const placeName = suggestion.text || suggestion.place_name?.split(',')[0] || 'Location';
1095
+ const address = suggestion.place_name || '';
1096
+ const briefAddress = address.split(',').slice(1, 3).join(',').trim();
1097
+
1098
+ return (
1099
+ <button
1100
+ key={suggestion.id || index}
1101
+ type="button"
1102
+ onClick={() => handleSuggestionClick(suggestion)}
1103
+ className={cn(
1104
+ 'w-full px-3 py-2 text-left hover:bg-mw-neutral-50 transition-colors',
1105
+ 'flex flex-col gap-0.5',
1106
+ index !== searchSuggestions.length - 1 && 'border-b border-mw-neutral-100'
1107
+ )}
1108
+ >
1109
+ <span className="text-sm font-medium text-mw-neutral-800 truncate">
1110
+ {placeName}
1111
+ </span>
1112
+ {briefAddress && (
1113
+ <span className="text-xs text-mw-neutral-500 truncate">
1114
+ {briefAddress}
1115
+ </span>
1116
+ )}
1117
+ </button>
1118
+ );
1119
+ })}
1120
+ </div>
1121
+ )}
1122
+ </div>
1123
+ <div className="flex-1">
1124
+ <POIDropdown
1125
+ selectedPOIs={selectedPOIs}
1126
+ onPOIsChange={setSelectedPOIs}
1127
+ onRenderPOIs={handleRenderPOIs}
1128
+ disabled={!isPOIDropdownEnabled}
1129
+ isLoading={isLoadingPOIs}
1130
+ maxSelections={5}
1131
+ selectedLocation={addPOI ? selectedLocation : null}
1132
+ useDynamicCategories={addPOI}
1133
+ isOpen={isPOIDropdownOpen}
1134
+ onOpenChange={(open) => {
1135
+ setIsPOIDropdownOpen(open);
1136
+ if (!open && onAddPOIChange) {
1137
+ onAddPOIChange(false);
1138
+ }
1139
+ }}
1140
+ showChipsInTrigger={true}
1141
+ />
1142
+ </div>
1143
+ </div>
1144
+ </div>
1145
+
1146
+ {showRadiusToolbar && (
1147
+ <div className="absolute bottom-20 left-1/2 -translate-x-1/2 z-20" style={{ width: '300px' }}>
1148
+ <div className="flex flex-col gap-2 px-4 py-3 bg-white dark:bg-mw-neutral-800 rounded-lg shadow-lg border border-mw-neutral-200 dark:border-mw-neutral-700">
1149
+ <div className="flex items-center justify-between">
1150
+ <span className="text-sm font-medium text-mw-neutral-700 dark:text-mw-neutral-300">{t('geofencing.map.targetRadius')}</span>
1151
+ <span className="text-sm font-semibold text-mw-primary-600 dark:text-mw-primary-400">
1152
+ {selectedRadius >= 1000 ? `${(selectedRadius / 1000).toFixed(1)}km` : `${selectedRadius}m`}
1153
+ </span>
1154
+ </div>
1155
+ <div className="flex items-center gap-2">
1156
+ <span className="text-xs text-mw-neutral-500">200m</span>
1157
+ <input
1158
+ type="range"
1159
+ min={200}
1160
+ max={5000}
1161
+ step={50}
1162
+ value={selectedRadius}
1163
+ onChange={(e) => setSelectedRadius(Number(e.target.value))}
1164
+ className="flex-1 h-2 bg-mw-neutral-200 dark:bg-mw-neutral-600 rounded-lg appearance-none cursor-pointer accent-mw-primary-500"
1165
+ />
1166
+ <span className="text-xs text-mw-neutral-500">5km</span>
1167
+ </div>
1168
+ </div>
1169
+ </div>
1170
+ )}
1171
+
1172
+ {/* Expand icon above zoom controls (bottom-right) - matches Mapbox zoom control styling */}
1173
+ <button
1174
+ type="button"
1175
+ onClick={handleFullscreen}
1176
+ className="absolute bottom-[120px] right-[10px] z-10 w-[29px] h-[29px] flex items-center justify-center bg-white rounded shadow hover:bg-mw-neutral-100 transition-colors border-0"
1177
+ title={t('geofencing.map.toggleFullscreen')}
1178
+ >
1179
+ <Maximize2 className="h-[18px] w-[18px] text-[#333]" />
1180
+ </button>
1181
+
1182
+ <div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-10">
1183
+ <div className="flex items-center gap-1 px-2 py-1.5 bg-white dark:bg-mw-neutral-800 rounded-lg shadow-lg border border-mw-neutral-200 dark:border-mw-neutral-700">
1184
+ {toolbarButtons.map((button) => {
1185
+ if (button.divider) {
1186
+ return (
1187
+ <div
1188
+ key={button.id}
1189
+ className="w-px h-6 bg-mw-neutral-200 dark:bg-mw-neutral-600 mx-1"
1190
+ />
1191
+ );
1192
+ }
1193
+
1194
+ const Icon = button.icon!;
1195
+ const isActive = button.mode && activeMode === button.mode;
1196
+ const isStyleActive = button.styleAction && mapStyle === button.id;
1197
+
1198
+ return (
1199
+ <button
1200
+ type="button"
1201
+ key={button.id}
1202
+ onClick={() => {
1203
+ if (button.action) {
1204
+ button.action();
1205
+ } else if (button.styleAction) {
1206
+ button.styleAction();
1207
+ } else if (button.mode) {
1208
+ handleSetMode(button.mode);
1209
+ }
1210
+ }}
1211
+ className={cn(
1212
+ 'p-2 rounded-md transition-all duration-200',
1213
+ isActive || isStyleActive
1214
+ ? 'bg-mw-primary-500 text-white shadow-sm'
1215
+ : 'text-mw-neutral-600 dark:text-mw-neutral-400 hover:bg-mw-neutral-100 dark:hover:bg-mw-neutral-700 hover:text-mw-neutral-900 dark:hover:text-white'
1216
+ )}
1217
+ title={button.tooltip}
1218
+ >
1219
+ <Icon className="h-4 w-4" />
1220
+ </button>
1221
+ );
1222
+ })}
1223
+ </div>
1224
+ </div>
1225
+
1226
+ {/* Delete Confirmation Dialog */}
1227
+ <Dialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
1228
+ <DialogContent className="sm:max-w-md">
1229
+ <DialogHeader>
1230
+ <DialogTitle className="flex items-center gap-2">
1231
+ <AlertTriangle className="h-5 w-5 text-mw-error-500" />
1232
+ {t('geofencing.map.deleteLocation')}
1233
+ </DialogTitle>
1234
+ <DialogDescription>
1235
+ {t('geofencing.map.deleteConfirmation')}
1236
+ </DialogDescription>
1237
+ </DialogHeader>
1238
+ <div className="py-4">
1239
+ {selectedFeatureToDelete && selectedFeatureToDelete.length > 0 && (
1240
+ <div className="p-3 bg-mw-neutral-50 dark:bg-mw-neutral-800 rounded-md">
1241
+ <p className="font-medium text-sm">
1242
+ {selectedFeatureToDelete.length === 1
1243
+ ? selectedFeatureToDelete[0].properties?.name || t('geofencing.map.selectedLocation')
1244
+ : `${selectedFeatureToDelete.length} ${t('geofencing.map.locationsSelected')}`}
1245
+ </p>
1246
+ </div>
1247
+ )}
1248
+ </div>
1249
+ <DialogFooter className="flex gap-2 sm:gap-0">
1250
+ <Button
1251
+ type="button"
1252
+ variant="outline"
1253
+ onClick={() => setDeleteConfirmOpen(false)}
1254
+ >
1255
+ {t('geofencing.locations.cancel')}
1256
+ </Button>
1257
+ <Button
1258
+ type="button"
1259
+ variant="primary"
1260
+ className="bg-mw-error-500 hover:bg-mw-error-600 text-white"
1261
+ onClick={handleConfirmDelete}
1262
+ >
1263
+ {t('geofencing.locations.delete')}
1264
+ </Button>
1265
+ </DialogFooter>
1266
+ </DialogContent>
1267
+ </Dialog>
1268
+ </div>
1269
+ );
1270
+ }