@census-ai/census-sdk 0.2.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +457 -74
- package/dist/index.d.ts +457 -74
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +27 -2
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1170 -79
- package/dist/react/index.d.ts +1170 -79
- package/dist/react/index.js +27 -2
- package/dist/react/index.js.map +1 -1
- package/dist/server/server.cjs +3 -0
- package/dist/server/server.cjs.map +1 -0
- package/dist/server/server.d.cts +322 -0
- package/dist/server/server.d.ts +322 -0
- package/dist/server/server.js +3 -0
- package/dist/server/server.js.map +1 -0
- package/package.json +11 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":["DEFAULT_BASE_URL","CensusClient","config","prefix","user","options","validTypes","response","params","queryString","url","slugOrId","error","eventType","properties","events","event","guideId","path","method","body","headers","errorMessage","args","createCensus"],"mappings":"AAmBA,IAAMA,CAAAA,CAAmB,wBAkBZC,CAAAA,CAAN,KAAmB,CAMxB,WAAA,CAAYC,CAAAA,CAAsB,CAFlC,IAAA,CAAQ,aAAA,CAA+B,IAAA,CAGrC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,4BAA4B,CAAA,CAIxB,CAAC,UAAA,CAAY,UAAA,CAAY,UAAA,CAAY,UAAU,EAClD,IAAA,CAAKC,CAAAA,EAAUD,EAAO,MAAA,CAAO,UAAA,CAAWC,CAAM,CAAC,CAAA,EAChE,OAAA,CAAQ,IAAA,CAAK,4DAA4D,CAAA,CAG3E,KAAK,MAAA,CAASD,CAAAA,CAAO,MAAA,CACrB,IAAA,CAAK,OAAA,CAAUA,CAAAA,CAAO,SAAWF,CAA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CAAkC,CACtC,cAAA,CAAgB,KAAK,MACvB,CAAA,CAEID,CAAAA,GACFC,CAAAA,CAAQ,cAAc,CAAA,CAAI,oBAG5B,IAAA,CAAK,GAAA,CAAI,CAAA,EAAGF,CAAM,CAAA,CAAA,EAAID,CAAI,GAAIE,CAAI,CAAA,CAElC,IAAMb,CAAAA,CAAW,MAAM,MAAMG,CAAAA,CAAK,CAChC,MAAA,CAAAS,CAAAA,CACA,OAAA,CAAAE,CAAAA,CACA,KAAMD,CAAAA,CAAO,IAAA,CAAK,SAAA,CAAUA,CAAI,CAAA,CAAI,MACtC,CAAC,CAAA,CAED,GAAI,CAACb,CAAAA,CAAS,EAAA,CAAI,CAChB,IAAIe,CAAAA,CAAe,CAAA,2BAAA,EAA8Bf,EAAS,MAAM,CAAA,CAAA,CAChE,GAAI,CAEFe,CAAAA,CAAAA,CADkB,MAAMf,CAAAA,CAAS,IAAA,EAAK,EACb,OAASe,EACpC,CAAA,KAAQ,CAER,CAMA,MAJ2B,CACzB,MAAOA,CAAAA,CACP,MAAA,CAAQf,CAAAA,CAAS,MACnB,CAEF,CAEA,OAAOA,CAAAA,CAAS,IAAA,EAClB,CAKQ,GAAA,CAAA,GAAOgB,CAAAA,CAAuB,CAChC,IAAA,CAAK,KAAA,EACP,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAY,GAAGA,CAAI,EAEnC,CACF,EAkBO,SAASC,CAAAA,CAAatB,CAAAA,CAAoC,CAC/D,OAAO,IAAID,CAAAA,CAAaC,CAAM,CAChC","file":"index.js","sourcesContent":["import type {\n CensusConfig,\n UserIdentity,\n FeedbackOptions,\n ArticlesOptions,\n ArticlesResponse,\n Article,\n RequestsOptions,\n RequestsResponse,\n BatchEventsOptions,\n CensusError,\n Guide,\n GuidesResponse,\n GuideAnalyticsEvent,\n} from './types';\n\n/**\n * Default API base URL\n */\nconst DEFAULT_BASE_URL = 'https://api.census.ai';\n\n/**\n * Census SDK Client\n *\n * The main client for interacting with the Census API.\n * Use `createCensus()` to create an instance.\n *\n * @example\n * ```typescript\n * import { createCensus } from '@census-ai/census-sdk';\n *\n * const census = createCensus({ apiKey: 'cs_live_xxx' });\n *\n * await census.identify({ userId: 'user_123', email: 'user@example.com' });\n * await census.submitFeedback({ type: 'bug_report', message: 'Button is broken' });\n * ```\n */\nexport class CensusClient {\n private apiKey: string;\n private baseUrl: string;\n private debug: boolean;\n private currentUserId: string | null = null;\n\n constructor(config: CensusConfig) {\n if (!config.apiKey) {\n throw new Error('Census: apiKey is required');\n }\n\n // Support both new (cs_) and legacy (op_) key prefixes\n const validPrefixes = ['cs_live_', 'cs_test_', 'op_live_', 'op_test_'];\n if (!validPrefixes.some(prefix => config.apiKey.startsWith(prefix))) {\n console.warn('Census: API key should start with \"cs_live_\" or \"cs_test_\"');\n }\n\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;\n this.debug = config.debug || false;\n\n this.log('Initialized with base URL:', this.baseUrl);\n }\n\n /**\n * Identify a user for tracking purposes.\n * Call this when a user logs in or when you have user information.\n *\n * @param user - User identity information\n *\n * @example\n * ```typescript\n * await census.identify({\n * userId: 'user_123',\n * email: 'john@example.com',\n * name: 'John Doe',\n * organizationId: 'org_456',\n * organizationName: 'Acme Inc',\n * });\n * ```\n */\n async identify(user: UserIdentity): Promise<void> {\n if (!user.userId) {\n throw new Error('Census: userId is required for identify()');\n }\n\n this.currentUserId = user.userId;\n\n await this.request('/api/sdk/identify', 'POST', {\n userId: user.userId,\n email: user.email,\n name: user.name,\n avatarUrl: user.avatarUrl,\n metadata: user.metadata,\n organizationId: user.organizationId,\n organizationName: user.organizationName,\n organizationDomain: user.organizationDomain,\n organizationPlan: user.organizationPlan,\n });\n\n this.log('User identified:', user.userId);\n }\n\n /**\n * Clear the current user identity.\n * Call this when a user logs out.\n */\n reset(): void {\n this.currentUserId = null;\n this.log('User identity reset');\n }\n\n /**\n * Submit feedback, bug report, or feature request.\n *\n * @param options - Feedback options\n *\n * @example\n * ```typescript\n * // Submit a bug report\n * await census.submitFeedback({\n * type: 'bug_report',\n * message: 'The submit button is not working on Firefox',\n * });\n *\n * // Submit a feature request\n * await census.submitFeedback({\n * type: 'feature_request',\n * message: 'It would be great to have dark mode support',\n * });\n *\n * // Rate an article\n * await census.submitFeedback({\n * type: 'article_rating',\n * articleId: 'article_123',\n * helpful: true,\n * rating: 5,\n * });\n * ```\n */\n async submitFeedback(options: FeedbackOptions): Promise<{ feedbackId: string }> {\n const validTypes = ['feedback', 'bug_report', 'feature_request', 'article_rating'];\n if (!options.type || !validTypes.includes(options.type)) {\n throw new Error(`Census: type must be one of: ${validTypes.join(', ')}`);\n }\n\n if (options.type === 'article_rating') {\n if (options.rating === undefined && options.helpful === undefined) {\n throw new Error('Census: article_rating requires rating or helpful field');\n }\n } else if (!options.message) {\n throw new Error('Census: message is required for this feedback type');\n }\n\n const response = await this.request<{ success: boolean; feedbackId: string }>(\n '/api/sdk/feedback',\n 'POST',\n {\n type: options.type,\n message: options.message,\n rating: options.rating,\n helpful: options.helpful,\n userId: this.currentUserId,\n articleId: options.articleId,\n pageUrl: typeof window !== 'undefined' ? window.location.href : undefined,\n metadata: options.metadata,\n }\n );\n\n this.log('Feedback submitted:', response.feedbackId);\n return { feedbackId: response.feedbackId };\n }\n\n /**\n * Fetch published articles from the knowledge base.\n *\n * @param options - Query options\n * @returns Articles and pagination info\n *\n * @example\n * ```typescript\n * // Get all articles\n * const { articles } = await census.getArticles();\n *\n * // Search articles\n * const { articles } = await census.getArticles({ search: 'getting started' });\n *\n * // Filter by category\n * const { articles } = await census.getArticles({ category: 'guides' });\n * ```\n */\n async getArticles(options?: ArticlesOptions): Promise<ArticlesResponse> {\n const params = new URLSearchParams();\n if (options?.category) params.set('category', options.category);\n if (options?.search) params.set('search', options.search);\n if (options?.limit) params.set('limit', String(options.limit));\n if (options?.offset) params.set('offset', String(options.offset));\n\n const queryString = params.toString();\n const url = `/api/sdk/articles${queryString ? `?${queryString}` : ''}`;\n\n const response = await this.request<ArticlesResponse>(url, 'GET');\n this.log('Fetched articles:', response.articles.length);\n return response;\n }\n\n /**\n * Fetch a single article by slug or ID.\n *\n * @param slugOrId - Article slug or ID\n * @returns Article or null if not found\n *\n * @example\n * ```typescript\n * const article = await census.getArticle('getting-started');\n * if (article) {\n * console.log(article.title, article.content_html);\n * }\n * ```\n */\n async getArticle(slugOrId: string): Promise<Article | null> {\n try {\n const response = await this.request<{ article: Article }>(\n `/api/sdk/articles/${encodeURIComponent(slugOrId)}`,\n 'GET'\n );\n this.log('Fetched article:', slugOrId);\n return response.article;\n } catch (error) {\n if ((error as CensusError).status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch the current user's submitted requests (feedback, bugs, feature requests).\n * Requires a user to be identified first.\n *\n * @param options - Query options\n * @returns Requests and pagination info\n *\n * @example\n * ```typescript\n * // Get all requests for the current user\n * const { requests } = await census.getRequests();\n *\n * // Filter by status\n * const { requests } = await census.getRequests({ status: 'in_progress' });\n *\n * // Filter by type\n * const { requests } = await census.getRequests({ type: 'bug_report' });\n * ```\n */\n async getRequests(options?: RequestsOptions): Promise<RequestsResponse> {\n if (!this.currentUserId) {\n throw new Error('Census: User must be identified before fetching requests. Call identify() first.');\n }\n\n const params = new URLSearchParams();\n params.set('userId', this.currentUserId);\n if (options?.status) params.set('status', options.status);\n if (options?.type) params.set('type', options.type);\n if (options?.limit) params.set('limit', String(options.limit));\n if (options?.offset) params.set('offset', String(options.offset));\n\n const response = await this.request<RequestsResponse>(\n `/api/sdk/requests?${params.toString()}`,\n 'GET'\n );\n this.log('Fetched requests:', response.requests.length);\n return response;\n }\n\n /**\n * Track a custom analytics event.\n *\n * @param eventType - Name of the event\n * @param properties - Additional event properties\n *\n * @example\n * ```typescript\n * // Track a button click\n * await census.track('button_clicked', { buttonId: 'submit-form' });\n *\n * // Track a page view\n * await census.track('page_viewed', { page: '/pricing' });\n * ```\n */\n async track(eventType: string, properties?: Record<string, unknown>): Promise<void> {\n if (!eventType) {\n throw new Error('Census: eventType is required for track()');\n }\n\n await this.request('/api/sdk/events', 'POST', {\n eventType,\n userId: this.currentUserId,\n properties,\n });\n\n this.log('Event tracked:', eventType);\n }\n\n /**\n * Track multiple events in a single request.\n * More efficient than calling track() multiple times.\n *\n * @param events - Array of events to track\n *\n * @example\n * ```typescript\n * await census.trackBatch({\n * events: [\n * { eventType: 'page_viewed', properties: { page: '/home' } },\n * { eventType: 'button_clicked', properties: { button: 'cta' } },\n * ],\n * });\n * ```\n */\n async trackBatch(options: BatchEventsOptions): Promise<void> {\n if (!options.events || options.events.length === 0) {\n throw new Error('Census: at least one event is required');\n }\n\n if (options.events.length > 100) {\n throw new Error('Census: maximum 100 events per batch');\n }\n\n const events = options.events.map((event) => ({\n eventType: event.eventType,\n userId: this.currentUserId,\n articleId: event.articleId,\n featureId: event.featureId,\n properties: event.properties,\n }));\n\n await this.request('/api/sdk/events', 'POST', { events });\n\n this.log('Batch events tracked:', options.events.length);\n }\n\n /**\n * Fetch available guides for the current user.\n * Returns guides that match the user's context and haven't been completed.\n *\n * @returns Guides and list of completed guide IDs\n *\n * @example\n * ```typescript\n * const { guides, completedGuides } = await census.getGuides();\n * guides.forEach(guide => console.log(guide.name));\n * ```\n */\n async getGuides(): Promise<GuidesResponse> {\n const params = new URLSearchParams();\n if (this.currentUserId) {\n params.set('userId', this.currentUserId);\n }\n\n const queryString = params.toString();\n const url = `/api/sdk/guides${queryString ? `?${queryString}` : ''}`;\n\n const response = await this.request<GuidesResponse>(url, 'GET');\n this.log('Fetched guides:', response.guides.length);\n return response;\n }\n\n /**\n * Fetch a single guide by slug or ID.\n *\n * @param slugOrId - Guide slug or ID\n * @returns Guide or null if not found\n *\n * @example\n * ```typescript\n * const guide = await census.getGuide('onboarding-tour');\n * if (guide) {\n * console.log(guide.name, guide.guide_steps.length);\n * }\n * ```\n */\n async getGuide(slugOrId: string): Promise<Guide | null> {\n try {\n const params = new URLSearchParams();\n if (this.currentUserId) {\n params.set('userId', this.currentUserId);\n }\n\n const queryString = params.toString();\n const url = `/api/sdk/guides/${encodeURIComponent(slugOrId)}${queryString ? `?${queryString}` : ''}`;\n\n const response = await this.request<{ guide: Guide }>(url, 'GET');\n this.log('Fetched guide:', slugOrId);\n return response.guide;\n } catch (error) {\n if ((error as CensusError).status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Track a guide analytics event.\n * Used to track user progress through guides.\n *\n * @param event - Guide analytics event\n *\n * @example\n * ```typescript\n * await census.trackGuideEvent({\n * guideId: 'guide_123',\n * eventType: 'step_completed',\n * stepId: 'step_456',\n * stepIndex: 2,\n * sessionId: 'session_789',\n * });\n * ```\n */\n async trackGuideEvent(event: GuideAnalyticsEvent): Promise<void> {\n if (!event.guideId || !event.eventType || !event.sessionId) {\n throw new Error('Census: guideId, eventType, and sessionId are required for trackGuideEvent()');\n }\n\n await this.request('/api/sdk/guides/events', 'POST', {\n guideId: event.guideId,\n eventType: event.eventType,\n stepId: event.stepId,\n stepIndex: event.stepIndex,\n pageUrl: event.pageUrl || (typeof window !== 'undefined' ? window.location.href : undefined),\n sessionId: event.sessionId,\n userId: event.userId || this.currentUserId,\n metadata: event.metadata,\n });\n\n this.log('Guide event tracked:', event.eventType, event.guideId);\n }\n\n /**\n * Mark a guide as completed for the current user.\n * Prevents the guide from showing again.\n *\n * @param guideId - ID of the guide to mark as completed\n *\n * @example\n * ```typescript\n * await census.markGuideCompleted('guide_123');\n * ```\n */\n async markGuideCompleted(guideId: string): Promise<void> {\n if (!guideId) {\n throw new Error('Census: guideId is required for markGuideCompleted()');\n }\n\n if (!this.currentUserId) {\n throw new Error('Census: User must be identified before marking guides complete. Call identify() first.');\n }\n\n await this.request('/api/sdk/guides/complete', 'POST', {\n guideId,\n userId: this.currentUserId,\n });\n\n this.log('Guide marked completed:', guideId);\n }\n\n /**\n * Get the current identified user ID\n */\n getCurrentUserId(): string | null {\n return this.currentUserId;\n }\n\n /**\n * Check if a user is currently identified\n */\n isIdentified(): boolean {\n return this.currentUserId !== null;\n }\n\n /**\n * Make an API request\n */\n private async request<T>(path: string, method: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n const headers: Record<string, string> = {\n 'X-Census-Key': this.apiKey,\n };\n\n if (body) {\n headers['Content-Type'] = 'application/json';\n }\n\n this.log(`${method} ${path}`, body);\n\n const response = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n let errorMessage = `Request failed with status ${response.status}`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.error || errorMessage;\n } catch {\n // Use default error message\n }\n\n const error: CensusError = {\n error: errorMessage,\n status: response.status,\n };\n throw error;\n }\n\n return response.json();\n }\n\n /**\n * Log debug messages\n */\n private log(...args: unknown[]): void {\n if (this.debug) {\n console.log('[Census]', ...args);\n }\n }\n}\n\n/**\n * Create a new Census SDK client.\n *\n * @param config - Configuration options\n * @returns Census client instance\n *\n * @example\n * ```typescript\n * import { createCensus } from '@census-ai/census-sdk';\n *\n * const census = createCensus({\n * apiKey: 'cs_live_your_key_here',\n * debug: true, // Enable debug logging\n * });\n * ```\n */\nexport function createCensus(config: CensusConfig): CensusClient {\n return new CensusClient(config);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["DEFAULT_BASE_URL","CensusClient","config","prefix","user","options","validTypes","response","params","queryString","url","slugOrId","error","eventType","properties","events","event","guideId","body","stepId","stepOrder","path","method","headers","errorMessage","args","createCensus"],"mappings":"AA0BA,IAAMA,EAAmB,uBAAA,CAkBZC,CAAAA,CAAN,KAAmB,CAMxB,YAAYC,CAAAA,CAAsB,CAFlC,IAAA,CAAQ,aAAA,CAA+B,KAGrC,GAAI,CAACA,EAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,4BAA4B,CAAA,CAIxB,CAAC,WAAY,UAAA,CAAY,UAAA,CAAY,UAAU,CAAA,CAClD,KAAKC,CAAAA,EAAUD,CAAAA,CAAO,MAAA,CAAO,U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":"index.js","sourcesContent":["import type {\n CensusConfig,\n UserIdentity,\n FeedbackOptions,\n ArticlesOptions,\n ArticlesResponse,\n Article,\n FeatureGroupsResponse,\n RequestsOptions,\n RequestsResponse,\n BatchEventsOptions,\n CensusError,\n Guide,\n GuideStep,\n GuidesOptions,\n GuidesResponse,\n GuideAnalyticsEvent,\n CreateGuideOptions,\n UpdateGuideOptions,\n CreateGuideStepOptions,\n UpdateGuideStepOptions,\n} from './types';\n\n/**\n * Default API base URL\n */\nconst DEFAULT_BASE_URL = 'https://api.census.ai';\n\n/**\n * Census SDK Client\n *\n * The main client for interacting with the Census API.\n * Use `createCensus()` to create an instance.\n *\n * @example\n * ```typescript\n * import { createCensus } from '@census-ai/census-sdk';\n *\n * const census = createCensus({ apiKey: 'cs_live_xxx' });\n *\n * await census.identify({ userId: 'user_123', email: 'user@example.com' });\n * await census.submitFeedback({ type: 'bug_report', message: 'Button is broken' });\n * ```\n */\nexport class CensusClient {\n private apiKey: string;\n private baseUrl: string;\n private debug: boolean;\n private currentUserId: string | null = null;\n\n constructor(config: CensusConfig) {\n if (!config.apiKey) {\n throw new Error('Census: apiKey is required');\n }\n\n // Support both new (cs_) and legacy (op_) key prefixes\n const validPrefixes = ['cs_live_', 'cs_test_', 'op_live_', 'op_test_'];\n if (!validPrefixes.some(prefix => config.apiKey.startsWith(prefix))) {\n console.warn('Census: API key should start with \"cs_live_\" or \"cs_test_\"');\n }\n\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;\n this.debug = config.debug || false;\n\n this.log('Initialized with base URL:', this.baseUrl);\n }\n\n /**\n * Identify a user for tracking purposes.\n * Call this when a user logs in or when you have user information.\n *\n * @param user - User identity information\n *\n * @example\n * ```typescript\n * await census.identify({\n * userId: 'user_123',\n * email: 'john@example.com',\n * name: 'John Doe',\n * organizationId: 'org_456',\n * organizationName: 'Acme Inc',\n * });\n * ```\n */\n async identify(user: UserIdentity): Promise<void> {\n if (!user.userId) {\n throw new Error('Census: userId is required for identify()');\n }\n\n this.currentUserId = user.userId;\n\n await this.request('/api/sdk/identify', 'POST', {\n userId: user.userId,\n email: user.email,\n name: user.name,\n avatarUrl: user.avatarUrl,\n metadata: user.metadata,\n organizationId: user.organizationId,\n organizationName: user.organizationName,\n organizationDomain: user.organizationDomain,\n organizationPlan: user.organizationPlan,\n });\n\n this.log('User identified:', user.userId);\n }\n\n /**\n * Clear the current user identity.\n * Call this when a user logs out.\n */\n reset(): void {\n this.currentUserId = null;\n this.log('User identity reset');\n }\n\n /**\n * Submit feedback, bug report, or feature request.\n *\n * @param options - Feedback options\n *\n * @example\n * ```typescript\n * // Submit a bug report\n * await census.submitFeedback({\n * type: 'bug_report',\n * message: 'The submit button is not working on Firefox',\n * });\n *\n * // Submit a feature request\n * await census.submitFeedback({\n * type: 'feature_request',\n * message: 'It would be great to have dark mode support',\n * });\n *\n * // Rate an article\n * await census.submitFeedback({\n * type: 'article_rating',\n * articleId: 'article_123',\n * helpful: true,\n * rating: 5,\n * });\n * ```\n */\n async submitFeedback(options: FeedbackOptions): Promise<{ feedbackId: string }> {\n const validTypes = ['feedback', 'bug_report', 'feature_request', 'article_rating'];\n if (!options.type || !validTypes.includes(options.type)) {\n throw new Error(`Census: type must be one of: ${validTypes.join(', ')}`);\n }\n\n if (options.type === 'article_rating') {\n if (options.rating === undefined && options.helpful === undefined) {\n throw new Error('Census: article_rating requires rating or helpful field');\n }\n } else if (!options.message) {\n throw new Error('Census: message is required for this feedback type');\n }\n\n const response = await this.request<{ success: boolean; feedbackId: string }>(\n '/api/sdk/feedback',\n 'POST',\n {\n type: options.type,\n message: options.message,\n rating: options.rating,\n helpful: options.helpful,\n userId: this.currentUserId,\n articleId: options.articleId,\n pageUrl: typeof window !== 'undefined' ? window.location.href : undefined,\n metadata: options.metadata,\n }\n );\n\n this.log('Feedback submitted:', response.feedbackId);\n return { feedbackId: response.feedbackId };\n }\n\n /**\n * Fetch published articles from the knowledge base.\n *\n * @param options - Query options\n * @returns Articles and pagination info\n *\n * @example\n * ```typescript\n * // Get all articles\n * const { articles } = await census.getArticles();\n *\n * // Search articles\n * const { articles } = await census.getArticles({ search: 'getting started' });\n *\n * // Filter by category\n * const { articles } = await census.getArticles({ category: 'guides' });\n * ```\n */\n async getArticles(options?: ArticlesOptions): Promise<ArticlesResponse> {\n const params = new URLSearchParams();\n if (options?.category) params.set('category', options.category);\n if (options?.search) params.set('search', options.search);\n if (options?.limit) params.set('limit', String(options.limit));\n if (options?.offset) params.set('offset', String(options.offset));\n\n const queryString = params.toString();\n const url = `/api/sdk/articles${queryString ? `?${queryString}` : ''}`;\n\n const response = await this.request<ArticlesResponse>(url, 'GET');\n this.log('Fetched articles:', response.articles.length);\n return response;\n }\n\n /**\n * Fetch a single article by slug or ID.\n *\n * @param slugOrId - Article slug or ID\n * @returns Article or null if not found\n *\n * @example\n * ```typescript\n * const article = await census.getArticle('getting-started');\n * if (article) {\n * console.log(article.title, article.content_html);\n * }\n * ```\n */\n async getArticle(slugOrId: string): Promise<Article | null> {\n try {\n const response = await this.request<{ article: Article }>(\n `/api/sdk/articles/${encodeURIComponent(slugOrId)}`,\n 'GET'\n );\n this.log('Fetched article:', slugOrId);\n return response.article;\n } catch (error) {\n if ((error as CensusError).status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch feature groups with their features.\n * Used by the HelpCenter component for navigation.\n *\n * @returns Feature groups with features and article counts\n *\n * @example\n * ```typescript\n * const { feature_groups } = await census.getFeatureGroups();\n * feature_groups.forEach(group => {\n * console.log(group.name, group.features.length);\n * });\n * ```\n */\n async getFeatureGroups(): Promise<FeatureGroupsResponse> {\n const response = await this.request<FeatureGroupsResponse>(\n '/api/sdk/feature-groups',\n 'GET'\n );\n this.log('Fetched feature groups:', response.feature_groups.length);\n return response;\n }\n\n /**\n * Fetch the current user's submitted requests (feedback, bugs, feature requests).\n * Requires a user to be identified first.\n *\n * @param options - Query options\n * @returns Requests and pagination info\n *\n * @example\n * ```typescript\n * // Get all requests for the current user\n * const { requests } = await census.getRequests();\n *\n * // Filter by status\n * const { requests } = await census.getRequests({ status: 'in_progress' });\n *\n * // Filter by type\n * const { requests } = await census.getRequests({ type: 'bug_report' });\n * ```\n */\n async getRequests(options?: RequestsOptions): Promise<RequestsResponse> {\n if (!this.currentUserId) {\n throw new Error('Census: User must be identified before fetching requests. Call identify() first.');\n }\n\n const params = new URLSearchParams();\n params.set('userId', this.currentUserId);\n if (options?.status) params.set('status', options.status);\n if (options?.type) params.set('type', options.type);\n if (options?.limit) params.set('limit', String(options.limit));\n if (options?.offset) params.set('offset', String(options.offset));\n\n const response = await this.request<RequestsResponse>(\n `/api/sdk/requests?${params.toString()}`,\n 'GET'\n );\n this.log('Fetched requests:', response.requests.length);\n return response;\n }\n\n /**\n * Track a custom analytics event.\n *\n * @param eventType - Name of the event\n * @param properties - Additional event properties\n *\n * @example\n * ```typescript\n * // Track a button click\n * await census.track('button_clicked', { buttonId: 'submit-form' });\n *\n * // Track a page view\n * await census.track('page_viewed', { page: '/pricing' });\n * ```\n */\n async track(eventType: string, properties?: Record<string, unknown>): Promise<void> {\n if (!eventType) {\n throw new Error('Census: eventType is required for track()');\n }\n\n await this.request('/api/sdk/events', 'POST', {\n eventType,\n userId: this.currentUserId,\n properties,\n });\n\n this.log('Event tracked:', eventType);\n }\n\n /**\n * Track multiple events in a single request.\n * More efficient than calling track() multiple times.\n *\n * @param events - Array of events to track\n *\n * @example\n * ```typescript\n * await census.trackBatch({\n * events: [\n * { eventType: 'page_viewed', properties: { page: '/home' } },\n * { eventType: 'button_clicked', properties: { button: 'cta' } },\n * ],\n * });\n * ```\n */\n async trackBatch(options: BatchEventsOptions): Promise<void> {\n if (!options.events || options.events.length === 0) {\n throw new Error('Census: at least one event is required');\n }\n\n if (options.events.length > 100) {\n throw new Error('Census: maximum 100 events per batch');\n }\n\n const events = options.events.map((event) => ({\n eventType: event.eventType,\n userId: this.currentUserId,\n articleId: event.articleId,\n featureId: event.featureId,\n properties: event.properties,\n }));\n\n await this.request('/api/sdk/events', 'POST', { events });\n\n this.log('Batch events tracked:', options.events.length);\n }\n\n // ============================================================================\n // Guide Builder Methods\n // ============================================================================\n\n /**\n * Get published guides.\n *\n * @param options - Query options\n * @returns Guides and completion status\n *\n * @example\n * ```typescript\n * const { guides, completedGuides } = await census.getGuides({\n * url: window.location.href,\n * userId: 'user_123',\n * });\n * ```\n */\n async getGuides(options?: GuidesOptions): Promise<GuidesResponse> {\n const params = new URLSearchParams();\n if (options?.projectId) params.set('project_id', options.projectId);\n if (options?.url) params.set('url', options.url);\n if (options?.userId) params.set('user_id', options.userId);\n\n const queryString = params.toString();\n const url = `/api/sdk/guides${queryString ? `?${queryString}` : ''}`;\n\n const response = await this.request<GuidesResponse>(url, 'GET');\n this.log('Fetched guides:', response.guides.length);\n return response;\n }\n\n /**\n * Get a single guide by ID.\n *\n * @param guideId - Guide ID\n * @returns Guide with steps or null if not found\n *\n * @example\n * ```typescript\n * const guide = await census.getGuide('guide_123');\n * if (guide) {\n * console.log(guide.name, guide.guide_steps.length);\n * }\n * ```\n */\n async getGuide(guideId: string): Promise<Guide | null> {\n try {\n const response = await this.request<{ guide: Guide }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}`,\n 'GET'\n );\n this.log('Fetched guide:', guideId);\n return response.guide;\n } catch (error) {\n if ((error as CensusError).status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Create a new guide.\n * Requires guides:create or guides:admin scope.\n *\n * @param options - Guide creation options\n * @returns Created guide\n *\n * @example\n * ```typescript\n * const guide = await census.createGuide({\n * name: 'Welcome Tour',\n * slug: 'welcome-tour',\n * description: 'Introduction to the app',\n * triggerType: 'first_visit',\n * });\n * ```\n */\n async createGuide(options: CreateGuideOptions): Promise<Guide> {\n if (!options.name || !options.slug) {\n throw new Error('Census: name and slug are required for createGuide()');\n }\n\n const response = await this.request<{ guide: Guide }>(\n '/api/sdk/guides',\n 'POST',\n {\n name: options.name,\n slug: options.slug,\n description: options.description,\n project_id: options.projectId,\n trigger_type: options.triggerType || 'manual',\n trigger_config: options.triggerConfig || {},\n theme: options.theme || {},\n allow_skip: options.allowSkip ?? true,\n show_progress: options.showProgress ?? true,\n }\n );\n\n this.log('Guide created:', response.guide.id);\n return response.guide;\n }\n\n /**\n * Update an existing guide.\n * Requires guides:create or guides:admin scope.\n *\n * @param guideId - Guide ID to update\n * @param options - Update options\n * @returns Updated guide\n *\n * @example\n * ```typescript\n * const guide = await census.updateGuide('guide_123', {\n * name: 'Updated Tour Name',\n * status: 'published',\n * });\n * ```\n */\n async updateGuide(guideId: string, options: UpdateGuideOptions): Promise<Guide> {\n if (!guideId) {\n throw new Error('Census: guideId is required for updateGuide()');\n }\n\n const body: Record<string, unknown> = {};\n if (options.name !== undefined) body.name = options.name;\n if (options.slug !== undefined) body.slug = options.slug;\n if (options.description !== undefined) body.description = options.description;\n if (options.triggerType !== undefined) body.trigger_type = options.triggerType;\n if (options.triggerConfig !== undefined) body.trigger_config = options.triggerConfig;\n if (options.theme !== undefined) body.theme = options.theme;\n if (options.allowSkip !== undefined) body.allow_skip = options.allowSkip;\n if (options.showProgress !== undefined) body.show_progress = options.showProgress;\n if (options.status !== undefined) body.status = options.status;\n\n const response = await this.request<{ guide: Guide }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}`,\n 'PUT',\n body\n );\n\n this.log('Guide updated:', guideId);\n return response.guide;\n }\n\n /**\n * Delete a guide.\n * Requires guides:admin scope.\n *\n * @param guideId - Guide ID to delete\n *\n * @example\n * ```typescript\n * await census.deleteGuide('guide_123');\n * ```\n */\n async deleteGuide(guideId: string): Promise<void> {\n if (!guideId) {\n throw new Error('Census: guideId is required for deleteGuide()');\n }\n\n await this.request(\n `/api/sdk/guides/${encodeURIComponent(guideId)}`,\n 'DELETE'\n );\n\n this.log('Guide deleted:', guideId);\n }\n\n /**\n * Get steps for a guide.\n *\n * @param guideId - Guide ID\n * @returns Array of steps\n *\n * @example\n * ```typescript\n * const steps = await census.getGuideSteps('guide_123');\n * ```\n */\n async getGuideSteps(guideId: string): Promise<GuideStep[]> {\n const response = await this.request<{ steps: GuideStep[] }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}/steps`,\n 'GET'\n );\n this.log('Fetched steps for guide:', guideId);\n return response.steps;\n }\n\n /**\n * Add a step to a guide.\n * Requires guides:create or guides:admin scope.\n *\n * @param guideId - Guide ID\n * @param options - Step creation options\n * @returns Created step\n *\n * @example\n * ```typescript\n * const step = await census.addGuideStep('guide_123', {\n * stepType: 'tooltip',\n * selectorStrategy: { css: '.welcome-button' },\n * richContent: {\n * title: 'Welcome!',\n * body: 'Click here to get started',\n * },\n * });\n * ```\n */\n async addGuideStep(guideId: string, options: CreateGuideStepOptions): Promise<GuideStep> {\n if (!guideId) {\n throw new Error('Census: guideId is required for addGuideStep()');\n }\n\n const response = await this.request<{ step: GuideStep }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}/steps`,\n 'POST',\n {\n step_type: options.stepType || 'tooltip',\n sort_order: options.sortOrder,\n selector_strategy: options.selectorStrategy || {},\n title: options.title,\n content: options.content,\n tooltip_position: options.tooltipPosition || 'auto',\n rich_content: options.richContent || {},\n display_config: options.displayConfig || {},\n advance_config: options.advanceConfig || { trigger: 'button' },\n style_config: options.styleConfig || {},\n }\n );\n\n this.log('Step added to guide:', guideId);\n return response.step;\n }\n\n /**\n * Update a guide step.\n * Requires guides:create or guides:admin scope.\n *\n * @param guideId - Guide ID\n * @param stepId - Step ID\n * @param options - Update options\n * @returns Updated step\n *\n * @example\n * ```typescript\n * const step = await census.updateGuideStep('guide_123', 'step_456', {\n * richContent: { title: 'Updated title' },\n * });\n * ```\n */\n async updateGuideStep(\n guideId: string,\n stepId: string,\n options: UpdateGuideStepOptions\n ): Promise<GuideStep> {\n if (!guideId || !stepId) {\n throw new Error('Census: guideId and stepId are required for updateGuideStep()');\n }\n\n const body: Record<string, unknown> = {};\n if (options.stepType !== undefined) body.step_type = options.stepType;\n if (options.sortOrder !== undefined) body.sort_order = options.sortOrder;\n if (options.selectorStrategy !== undefined) body.selector_strategy = options.selectorStrategy;\n if (options.title !== undefined) body.title = options.title;\n if (options.content !== undefined) body.content = options.content;\n if (options.tooltipPosition !== undefined) body.tooltip_position = options.tooltipPosition;\n if (options.richContent !== undefined) body.rich_content = options.richContent;\n if (options.displayConfig !== undefined) body.display_config = options.displayConfig;\n if (options.advanceConfig !== undefined) body.advance_config = options.advanceConfig;\n if (options.styleConfig !== undefined) body.style_config = options.styleConfig;\n\n const response = await this.request<{ step: GuideStep }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}/steps/${encodeURIComponent(stepId)}`,\n 'PUT',\n body\n );\n\n this.log('Step updated:', stepId);\n return response.step;\n }\n\n /**\n * Delete a guide step.\n * Requires guides:create or guides:admin scope.\n *\n * @param guideId - Guide ID\n * @param stepId - Step ID\n *\n * @example\n * ```typescript\n * await census.deleteGuideStep('guide_123', 'step_456');\n * ```\n */\n async deleteGuideStep(guideId: string, stepId: string): Promise<void> {\n if (!guideId || !stepId) {\n throw new Error('Census: guideId and stepId are required for deleteGuideStep()');\n }\n\n await this.request(\n `/api/sdk/guides/${encodeURIComponent(guideId)}/steps/${encodeURIComponent(stepId)}`,\n 'DELETE'\n );\n\n this.log('Step deleted:', stepId);\n }\n\n /**\n * Reorder steps in a guide.\n * Requires guides:create or guides:admin scope.\n *\n * @param guideId - Guide ID\n * @param stepOrder - Array of { id, sort_order } to define new order\n * @returns Updated steps\n *\n * @example\n * ```typescript\n * const steps = await census.reorderGuideSteps('guide_123', [\n * { id: 'step_a', sort_order: 0 },\n * { id: 'step_b', sort_order: 1 },\n * { id: 'step_c', sort_order: 2 },\n * ]);\n * ```\n */\n async reorderGuideSteps(\n guideId: string,\n stepOrder: Array<{ id: string; sort_order: number }>\n ): Promise<GuideStep[]> {\n if (!guideId) {\n throw new Error('Census: guideId is required for reorderGuideSteps()');\n }\n\n const response = await this.request<{ steps: GuideStep[] }>(\n `/api/sdk/guides/${encodeURIComponent(guideId)}/steps`,\n 'PUT',\n { steps: stepOrder }\n );\n\n this.log('Steps reordered for guide:', guideId);\n return response.steps;\n }\n\n /**\n * Track a guide analytics event.\n * Used to track user progress through guides.\n *\n * @param event - Guide analytics event\n *\n * @example\n * ```typescript\n * await census.trackGuideEvent({\n * guideId: 'guide_123',\n * eventType: 'step_completed',\n * stepId: 'step_456',\n * stepIndex: 2,\n * sessionId: 'session_789',\n * });\n * ```\n */\n async trackGuideEvent(event: GuideAnalyticsEvent): Promise<void> {\n if (!event.guideId || !event.eventType || !event.sessionId) {\n throw new Error('Census: guideId, eventType, and sessionId are required for trackGuideEvent()');\n }\n\n await this.request('/api/sdk/guides/events', 'POST', {\n guideId: event.guideId,\n eventType: event.eventType,\n stepId: event.stepId,\n stepIndex: event.stepIndex,\n pageUrl: event.pageUrl || (typeof window !== 'undefined' ? window.location.href : undefined),\n sessionId: event.sessionId,\n userId: event.userId || this.currentUserId,\n metadata: event.metadata,\n });\n\n this.log('Guide event tracked:', event.eventType, event.guideId);\n }\n\n /**\n * Mark a guide as completed for the current user.\n * Prevents the guide from showing again.\n *\n * @param guideId - ID of the guide to mark as completed\n *\n * @example\n * ```typescript\n * await census.markGuideCompleted('guide_123');\n * ```\n */\n async markGuideCompleted(guideId: string): Promise<void> {\n if (!guideId) {\n throw new Error('Census: guideId is required for markGuideCompleted()');\n }\n\n if (!this.currentUserId) {\n throw new Error('Census: User must be identified before marking guides complete. Call identify() first.');\n }\n\n await this.request('/api/sdk/guides/complete', 'POST', {\n guideId,\n userId: this.currentUserId,\n });\n\n this.log('Guide marked completed:', guideId);\n }\n\n /**\n * Get the current identified user ID\n */\n getCurrentUserId(): string | null {\n return this.currentUserId;\n }\n\n /**\n * Check if a user is currently identified\n */\n isIdentified(): boolean {\n return this.currentUserId !== null;\n }\n\n /**\n * Make an API request\n */\n private async request<T>(path: string, method: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n const headers: Record<string, string> = {\n 'X-Census-Key': this.apiKey,\n };\n\n if (body) {\n headers['Content-Type'] = 'application/json';\n }\n\n this.log(`${method} ${path}`, body);\n\n const response = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n let errorMessage = `Request failed with status ${response.status}`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.error || errorMessage;\n } catch {\n // Use default error message\n }\n\n const error: CensusError = {\n error: errorMessage,\n status: response.status,\n };\n throw error;\n }\n\n return response.json();\n }\n\n /**\n * Log debug messages\n */\n private log(...args: unknown[]): void {\n if (this.debug) {\n console.log('[Census]', ...args);\n }\n }\n}\n\n/**\n * Create a new Census SDK client.\n *\n * @param config - Configuration options\n * @returns Census client instance\n *\n * @example\n * ```typescript\n * import { createCensus } from '@census-ai/census-sdk';\n *\n * const census = createCensus({\n * apiKey: 'cs_live_your_key_here',\n * debug: true, // Enable debug logging\n * });\n * ```\n */\nexport function createCensus(config: CensusConfig): CensusClient {\n return new CensusClient(config);\n}\n"]}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var re="https://api.census.ai",G=class{constructor(e){this.currentUserId=null;if(!e.apiKey)throw new Error("Census: apiKey is required");["cs_live_","cs_test_","op_live_","op_test_"].some(s=>e.apiKey.startsWith(s))||console.warn('Census: API key should start with "cs_live_" or "cs_test_"'),this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||re,this.debug=e.debug||false,this.log("Initialized with base URL:",this.baseUrl);}async identify(e){if(!e.userId)throw new Error("Census: userId is required for identify()");this.currentUserId=e.userId,await this.request("/api/sdk/identify","POST",{userId:e.userId,email:e.email,name:e.name,avatarUrl:e.avatarUrl,metadata:e.metadata,organizationId:e.organizationId,organizationName:e.organizationName,organizationDomain:e.organizationDomain,organizationPlan:e.organizationPlan}),this.log("User identified:",e.userId);}reset(){this.currentUserId=null,this.log("User identity reset");}async submitFeedback(e){let t=["feedback","bug_report","feature_request","article_rating"];if(!e.type||!t.includes(e.type))throw new Error(`Census: type must be one of: ${t.join(", ")}`);if(e.type==="article_rating"){if(e.rating===void 0&&e.helpful===void 0)throw new Error("Census: article_rating requires rating or helpful field")}else if(!e.message)throw new Error("Census: message is required for this feedback type");let s=await this.request("/api/sdk/feedback","POST",{type:e.type,message:e.message,rating:e.rating,helpful:e.helpful,userId:this.currentUserId,articleId:e.articleId,pageUrl:typeof window<"u"?window.location.href:void 0,metadata:e.metadata});return this.log("Feedback submitted:",s.feedbackId),{feedbackId:s.feedbackId}}async getArticles(e){let t=new URLSearchParams;e?.category&&t.set("category",e.category),e?.search&&t.set("search",e.search),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let s=t.toString(),o=`/api/sdk/articles${s?`?${s}`:""}`,a=await this.request(o,"GET");return this.log("Fetched articles:",a.articles.length),a}async getArticle(e){try{let t=await this.request(`/api/sdk/articles/${encodeURIComponent(e)}`,"GET");return this.log("Fetched article:",e),t.article}catch(t){if(t.status===404)return null;throw t}}async getRequests(e){if(!this.currentUserId)throw new Error("Census: User must be identified before fetching requests. Call identify() first.");let t=new URLSearchParams;t.set("userId",this.currentUserId),e?.status&&t.set("status",e.status),e?.type&&t.set("type",e.type),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let s=await this.request(`/api/sdk/requests?${t.toString()}`,"GET");return this.log("Fetched requests:",s.requests.length),s}async track(e,t){if(!e)throw new Error("Census: eventType is required for track()");await this.request("/api/sdk/events","POST",{eventType:e,userId:this.currentUserId,properties:t}),this.log("Event tracked:",e);}async trackBatch(e){if(!e.events||e.events.length===0)throw new Error("Census: at least one event is required");if(e.events.length>100)throw new Error("Census: maximum 100 events per batch");let t=e.events.map(s=>({eventType:s.eventType,userId:this.currentUserId,articleId:s.articleId,featureId:s.featureId,properties:s.properties}));await this.request("/api/sdk/events","POST",{events:t}),this.log("Batch events tracked:",e.events.length);}async getGuides(){let e=new URLSearchParams;this.currentUserId&&e.set("userId",this.currentUserId);let t=e.toString(),s=`/api/sdk/guides${t?`?${t}`:""}`,o=await this.request(s,"GET");return this.log("Fetched guides:",o.guides.length),o}async getGuide(e){try{let t=new URLSearchParams;this.currentUserId&&t.set("userId",this.currentUserId);let s=t.toString(),o=`/api/sdk/guides/${encodeURIComponent(e)}${s?`?${s}`:""}`,a=await this.request(o,"GET");return this.log("Fetched guide:",e),a.guide}catch(t){if(t.status===404)return null;throw t}}async trackGuideEvent(e){if(!e.guideId||!e.eventType||!e.sessionId)throw new Error("Census: guideId, eventType, and sessionId are required for trackGuideEvent()");await this.request("/api/sdk/guides/events","POST",{guideId:e.guideId,eventType:e.eventType,stepId:e.stepId,stepIndex:e.stepIndex,pageUrl:e.pageUrl||(typeof window<"u"?window.location.href:void 0),sessionId:e.sessionId,userId:e.userId||this.currentUserId,metadata:e.metadata}),this.log("Guide event tracked:",e.eventType,e.guideId);}async markGuideCompleted(e){if(!e)throw new Error("Census: guideId is required for markGuideCompleted()");if(!this.currentUserId)throw new Error("Census: User must be identified before marking guides complete. Call identify() first.");await this.request("/api/sdk/guides/complete","POST",{guideId:e,userId:this.currentUserId}),this.log("Guide marked completed:",e);}getCurrentUserId(){return this.currentUserId}isIdentified(){return this.currentUserId!==null}async request(e,t,s){let o=`${this.baseUrl}${e}`,a={"X-Census-Key":this.apiKey};s&&(a["Content-Type"]="application/json"),this.log(`${t} ${e}`,s);let d=await fetch(o,{method:t,headers:a,body:s?JSON.stringify(s):void 0});if(!d.ok){let u=`Request failed with status ${d.status}`;try{u=(await d.json()).error||u;}catch{}throw {error:u,status:d.status}}return d.json()}log(...e){this.debug&&console.log("[Census]",...e);}};function Q(r){return new G(r)}var D=react.createContext(null);function ne({apiKey:r,baseUrl:e,debug:t,user:s,theme:o={},children:a}){let[d,u]=react.useState(false),[l,c]=react.useState(false),n=react.useMemo(()=>Q({apiKey:r,baseUrl:e,debug:t}),[r,e,t]);react.useEffect(()=>{s?n.identify(s).then(()=>{c(true),u(true);}).catch(m=>{console.error("[Census] Failed to identify user:",m),u(true);}):u(true);},[n,s]);let p=react.useMemo(()=>({client:n,theme:o,isReady:d,isIdentified:l}),[n,o,d,l]);return jsxRuntime.jsx(D.Provider,{value:p,children:a})}function ie(){let r=react.useContext(D);if(!r)throw new Error("useCensus must be used within a CensusProvider");return r.client}function C(){let r=react.useContext(D);if(!r)throw new Error("useCensusContext must be used within a CensusProvider");return r}function ae(){let{client:r}=C(),[e,t]=react.useState(false),[s,o]=react.useState(null);return {identify:async u=>{t(true),o(null);try{await r.identify(u);}catch(l){throw o(l instanceof Error?l:new Error("Failed to identify user")),l}finally{t(false);}},reset:()=>{r.reset();},isIdentifying:e,isIdentified:r.isIdentified(),error:s}}function W(){let{client:r}=C(),[e,t]=react.useState(false),[s,o]=react.useState(false),[a,d]=react.useState(null),[u,l]=react.useState(null),c=react.useCallback(async p=>{t(true),o(false),d(null),l(null);try{let m=await r.submitFeedback(p);return l(m.feedbackId),o(!0),m}catch(m){let R=m instanceof Error?m:new Error("Failed to submit feedback");throw d(R),R}finally{t(false);}},[r]),n=react.useCallback(()=>{o(false),d(null),l(null);},[]);return {submitFeedback:c,reset:n,isSubmitting:e,isSuccess:s,error:a,feedbackId:u}}function $(r){let{client:e,isReady:t}=C(),[s,o]=react.useState(null),[a,d]=react.useState(true),[u,l]=react.useState(null),c=react.useCallback(async()=>{d(true),l(null);try{let n=await e.getArticles(r);o(n);}catch(n){l(n instanceof Error?n:new Error("Failed to fetch articles"));}finally{d(false);}},[e,r?.category,r?.search,r?.limit,r?.offset]);return react.useEffect(()=>{t&&c();},[t,c]),{articles:s?.articles||[],pagination:s?.pagination,isLoading:a,error:u,refetch:c}}function K(r){let{client:e,isReady:t}=C(),[s,o]=react.useState(null),[a,d]=react.useState(true),[u,l]=react.useState(null),c=react.useCallback(async()=>{if(!r){o(null),d(false);return}d(true),l(null);try{let n=await e.getArticle(r);o(n);}catch(n){l(n instanceof Error?n:new Error("Failed to fetch article"));}finally{d(false);}},[e,r]);return react.useEffect(()=>{t&&c();},[t,c]),{article:s,isLoading:a,error:u,refetch:c}}function H(r){let{client:e,isReady:t,isIdentified:s}=C(),[o,a]=react.useState(null),[d,u]=react.useState(true),[l,c]=react.useState(null),n=react.useCallback(async()=>{if(!s){a(null),u(false);return}u(true),c(null);try{let p=await e.getRequests(r);a(p);}catch(p){c(p instanceof Error?p:new Error("Failed to fetch requests"));}finally{u(false);}},[e,s,r?.status,r?.type,r?.limit,r?.offset]);return react.useEffect(()=>{t&&s&&n();},[t,s,n]),{requests:o?.requests||[],pagination:o?.pagination,isLoading:d,error:l,refetch:n}}function de(){let{client:r}=C(),e=react.useCallback(async(s,o)=>{await r.track(s,o);},[r]),t=react.useCallback(async s=>{await r.trackBatch({events:s});},[r]);return {track:e,trackBatch:t}}var q={button:{position:"fixed",padding:"12px 20px",border:"none",borderRadius:"8px",cursor:"pointer",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",fontWeight:"500",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",transition:"transform 0.2s, box-shadow 0.2s",zIndex:9999},modal:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:1e4},modalContent:{backgroundColor:"white",borderRadius:"12px",padding:"24px",width:"100%",maxWidth:"400px",margin:"16px",boxShadow:"0 20px 50px rgba(0, 0, 0, 0.2)",fontFamily:"system-ui, -apple-system, sans-serif"},textarea:{width:"100%",padding:"10px 12px",border:"1px solid #e0e0e0",borderRadius:"6px",fontSize:"14px",marginBottom:"16px",minHeight:"100px",resize:"vertical",boxSizing:"border-box",fontFamily:"inherit"},submitButton:{width:"100%",padding:"12px",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"500",transition:"opacity 0.2s"},typeButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"6px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"}},ce={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},ue={feedback:"General Feedback",bug_report:"Bug Report",feature_request:"Feature Request",article_rating:"Article Rating"},pe={feedback:"\u{1F4AC}",bug_report:"\u{1F41B}",feature_request:"\u{1F4A1}",article_rating:"\u2B50"};function fe(r){return {primaryColor:r.primaryColor||"#000000",textColor:r.textColor||"#333333",backgroundColor:r.backgroundColor||"#ffffff",borderRadius:r.borderRadius||"8px",fontFamily:r.fontFamily||"system-ui, -apple-system, sans-serif"}}function ge({position:r="bottom-right",text:e="Feedback",allowedTypes:t=["feedback","bug_report","feature_request"],theme:s,onSubmit:o,onError:a,children:d}){let{theme:u}=C(),{submitFeedback:l,isSubmitting:c,isSuccess:n,reset:p}=W(),[m,R]=react.useState(false),[i,k]=react.useState(t[0]),[I,F]=react.useState(""),v={...u,...s},P=fe(v),O=react.useCallback(()=>{R(true),p();},[p]),A=react.useCallback(()=>{R(false),F(""),k(t[0]);},[t]),U=react.useCallback(async z=>{z.preventDefault();let f={type:i,message:I};try{await l(f),o?.(f),setTimeout(A,1500);}catch(T){a?.(T instanceof Error?T:new Error("Failed to submit feedback"));}},[i,I,l,o,a,A]);return d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{onClick:O,style:{cursor:"pointer"},children:d}),m&&jsxRuntime.jsx(Y,{isOpen:m,onClose:A,selectedType:i,onTypeChange:k,allowedTypes:t,message:I,onMessageChange:F,onSubmit:U,isSubmitting:c,isSuccess:n,themeStyles:P})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:O,style:{...q.button,...ce[r],backgroundColor:P.primaryColor,color:"white",borderRadius:P.borderRadius,fontFamily:P.fontFamily},"aria-label":"Open feedback form",children:e}),m&&jsxRuntime.jsx(Y,{isOpen:m,onClose:A,selectedType:i,onTypeChange:k,allowedTypes:t,message:I,onMessageChange:F,onSubmit:U,isSubmitting:c,isSuccess:n,themeStyles:P})]})}function Y({isOpen:r,onClose:e,selectedType:t,onTypeChange:s,allowedTypes:o,message:a,onMessageChange:d,onSubmit:u,isSubmitting:l,isSuccess:c,themeStyles:n}){return r?c?jsxRuntime.jsx("div",{style:q.modal,onClick:e,children:jsxRuntime.jsxs("div",{style:{...q.modalContent,textAlign:"center",fontFamily:n.fontFamily},onClick:p=>p.stopPropagation(),children:[jsxRuntime.jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsxRuntime.jsx("h3",{style:{margin:"0 0 8px 0",color:n.textColor},children:"Thanks for your feedback!"}),jsxRuntime.jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsxRuntime.jsx("div",{style:q.modal,onClick:e,children:jsxRuntime.jsxs("div",{style:{...q.modalContent,fontFamily:n.fontFamily},onClick:p=>p.stopPropagation(),children:[jsxRuntime.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsxRuntime.jsx("h3",{style:{margin:0,color:n.textColor},children:"Send Feedback"}),jsxRuntime.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsxs("form",{onSubmit:u,children:[jsxRuntime.jsxs("div",{style:{marginBottom:"16px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:o.map(p=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(p),style:{...q.typeButton,backgroundColor:t===p?n.primaryColor:"white",color:t===p?"white":n.textColor,borderColor:t===p?n.primaryColor:"#e0e0e0"},children:[pe[p]," ",ue[p]]},p))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),jsxRuntime.jsx("textarea",{value:a,onChange:p=>d(p.target.value),placeholder:t==="bug_report"?"Describe the bug and steps to reproduce...":t==="feature_request"?"Describe the feature you would like...":"Share your thoughts...",style:q.textarea,required:true})]}),jsxRuntime.jsx("button",{type:"submit",disabled:l||!a.trim(),style:{...q.submitButton,backgroundColor:n.primaryColor,color:"white",opacity:l||!a.trim()?.6:1,cursor:l||!a.trim()?"not-allowed":"pointer"},children:l?"Sending...":"Send Feedback"})]})]})}):null}var g={container:{fontFamily:"system-ui, -apple-system, sans-serif",maxWidth:"800px"},searchInput:{width:"100%",padding:"12px 16px",border:"1px solid #e0e0e0",borderRadius:"8px",fontSize:"15px",marginBottom:"24px",boxSizing:"border-box"},categoryButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"20px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"},articleCard:{padding:"20px",border:"1px solid #e0e0e0",borderRadius:"8px",marginBottom:"12px",cursor:"pointer",transition:"box-shadow 0.2s, border-color 0.2s",backgroundColor:"white"},articleTitle:{margin:"0 0 8px 0",fontSize:"16px",fontWeight:"600"},articleDescription:{margin:0,fontSize:"14px",color:"#666",lineHeight:1.5},articleMeta:{display:"flex",gap:"16px",marginTop:"12px",fontSize:"12px",color:"#999"},backButton:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"8px 0",border:"none",background:"none",cursor:"pointer",fontSize:"14px",color:"#666",marginBottom:"16px"},articleContent:{lineHeight:1.7,fontSize:"15px"},loading:{textAlign:"center",padding:"40px",color:"#666"},error:{padding:"20px",backgroundColor:"#fef2f2",borderRadius:"8px",color:"#b91c1c",textAlign:"center"},empty:{textAlign:"center",padding:"40px",color:"#666"}};function me(r){return {primaryColor:r.primaryColor||"#000000",textColor:r.textColor||"#333333",backgroundColor:r.backgroundColor||"#ffffff",borderRadius:r.borderRadius||"8px",fontFamily:r.fontFamily||"system-ui, -apple-system, sans-serif"}}function be({showSearch:r=true,showCategories:e=true,defaultCategory:t,theme:s,className:o,onArticleView:a}){let{theme:d}=C(),[u,l]=react.useState(""),[c,n]=react.useState(t),[p,m]=react.useState(null),R={...d,...s},i=me(R),{articles:k,isLoading:I,error:F}=$({category:c,search:u||void 0}),{article:v,isLoading:P,error:O}=K(p||""),A=react.useMemo(()=>{let f=new Set;return k.forEach(T=>{T.category&&f.add(T.category);}),Array.from(f).sort()},[k]),U=f=>{m(f.slug),a?.(f);},z=()=>{m(null);};return p?P?jsxRuntime.jsx("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:jsxRuntime.jsx("div",{style:g.loading,children:"Loading article..."})}):O?jsxRuntime.jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsxRuntime.jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:g.error,children:"Failed to load article. Please try again."})]}):v?jsxRuntime.jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsxRuntime.jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsxs("article",{children:[jsxRuntime.jsx("h1",{style:{margin:"0 0 16px 0",color:i.textColor},children:v.title}),v.read_time_minutes&&jsxRuntime.jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[v.read_time_minutes," min read"]}),v.content_html?jsxRuntime.jsx("div",{style:{...g.articleContent,color:i.textColor},dangerouslySetInnerHTML:{__html:v.content_html}}):jsxRuntime.jsx("div",{style:{...g.articleContent,color:i.textColor},children:typeof v.content=="string"?v.content:"No content available."})]})]}):jsxRuntime.jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsxRuntime.jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:g.empty,children:"Article not found."})]}):jsxRuntime.jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[r&&jsxRuntime.jsx("input",{type:"text",placeholder:"Search articles...",value:u,onChange:f=>l(f.target.value),style:g.searchInput}),e&&A.length>0&&jsxRuntime.jsxs("div",{style:{marginBottom:"24px"},children:[jsxRuntime.jsx("button",{onClick:()=>n(void 0),style:{...g.categoryButton,backgroundColor:c?"white":i.primaryColor,color:c?i.textColor:"white",borderColor:c?"#e0e0e0":i.primaryColor},children:"All"}),A.map(f=>jsxRuntime.jsx("button",{onClick:()=>n(f),style:{...g.categoryButton,backgroundColor:c===f?i.primaryColor:"white",color:c===f?"white":i.textColor,borderColor:c===f?i.primaryColor:"#e0e0e0"},children:f},f))]}),I&&jsxRuntime.jsx("div",{style:g.loading,children:"Loading articles..."}),F&&jsxRuntime.jsx("div",{style:g.error,children:"Failed to load articles. Please try again."}),!I&&!F&&k.length===0&&jsxRuntime.jsx("div",{style:g.empty,children:u?`No articles found for "${u}"`:"No articles available yet."}),!I&&!F&&k.length>0&&jsxRuntime.jsx("div",{children:k.map(f=>jsxRuntime.jsxs("div",{onClick:()=>U(f),style:g.articleCard,role:"button",tabIndex:0,onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&U(f);},children:[jsxRuntime.jsx("h3",{style:{...g.articleTitle,color:i.textColor},children:f.title}),f.seo_description&&jsxRuntime.jsx("p",{style:g.articleDescription,children:f.seo_description}),jsxRuntime.jsxs("div",{style:g.articleMeta,children:[f.category&&jsxRuntime.jsx("span",{children:f.category}),f.read_time_minutes&&jsxRuntime.jsxs("span",{children:[f.read_time_minutes," min read"]})]})]},f.id))})]})}var x={container:{fontFamily:"system-ui, -apple-system, sans-serif"},list:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"12px"},card:{border:"1px solid #e5e7eb",borderRadius:"8px",padding:"16px",backgroundColor:"#ffffff",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s"},cardHover:{borderColor:"#d1d5db",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",marginBottom:"8px"},badges:{display:"flex",alignItems:"center",gap:"6px"},badge:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},message:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},meta:{display:"flex",gap:"12px",marginTop:"8px",fontSize:"12px",color:"#6b7280"},empty:{textAlign:"center",padding:"32px 16px",color:"#6b7280"},emptyIcon:{width:"48px",height:"48px",margin:"0 auto 12px",color:"#d1d5db"},loading:{textAlign:"center",padding:"24px",color:"#6b7280"},error:{textAlign:"center",padding:"24px",color:"#dc2626"}},ee={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug Report",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature Request",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Article Rating",color:"#7c3aed",bg:"#ede9fe"}},te={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function Ce(r){return new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function ke({status:r,type:e,limit:t=50,className:s,showEmptyState:o=true,onRequestClick:a}){let{isIdentified:d}=C(),[u,l]=react.useState(null),{requests:c,isLoading:n,error:p,refetch:m}=H({status:r,type:e,limit:t}),R=react.useCallback(i=>{a?.(i);},[a]);return d?n?jsxRuntime.jsx("div",{style:x.loading,children:jsxRuntime.jsx("p",{children:"Loading requests..."})}):p?jsxRuntime.jsx("div",{style:x.error,children:jsxRuntime.jsxs("p",{children:["Failed to load requests. ",jsxRuntime.jsx("button",{onClick:m,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})}):c.length===0&&o?jsxRuntime.jsxs("div",{style:x.empty,children:[jsxRuntime.jsx("svg",{style:x.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),jsxRuntime.jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsxRuntime.jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"When you submit feedback, bug reports, or feature requests, they'll appear here."})]}):jsxRuntime.jsx("div",{style:x.container,className:s,children:jsxRuntime.jsx("ul",{style:x.list,children:c.map(i=>{let k=ee[i.feedback_type]||ee.feedback,I=te[i.status]||te.new,F=u===i.id;return jsxRuntime.jsxs("li",{style:{...x.card,...F?x.cardHover:{}},onMouseEnter:()=>l(i.id),onMouseLeave:()=>l(null),onClick:()=>R(i),role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&R(i);},children:[jsxRuntime.jsx("div",{style:x.header,children:jsxRuntime.jsxs("div",{style:x.badges,children:[jsxRuntime.jsx("span",{style:{...x.badge,color:k.color,backgroundColor:k.bg},children:k.label}),jsxRuntime.jsx("span",{style:{...x.badge,color:I.color,backgroundColor:I.bg},children:I.label})]})}),jsxRuntime.jsx("p",{style:x.message,children:i.message||"No message provided"}),jsxRuntime.jsxs("div",{style:x.meta,children:[jsxRuntime.jsx("span",{children:Ce(i.created_at)}),i.page_url&&jsxRuntime.jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",i.page_url]})]})]},i.id)})})}):o?jsxRuntime.jsx("div",{style:x.empty,children:jsxRuntime.jsx("p",{children:"Please sign in to view your requests."})}):null}
|
|
2
|
-
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var kt="https://api.census.ai",ze=class{constructor(e){this.currentUserId=null;if(!e.apiKey)throw new Error("Census: apiKey is required");["cs_live_","cs_test_","op_live_","op_test_"].some(r=>e.apiKey.startsWith(r))||console.warn('Census: API key should start with "cs_live_" or "cs_test_"'),this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||kt,this.debug=e.debug||false,this.log("Initialized with base URL:",this.baseUrl);}async identify(e){if(!e.userId)throw new Error("Census: userId is required for identify()");this.currentUserId=e.userId,await this.request("/api/sdk/identify","POST",{userId:e.userId,email:e.email,name:e.name,avatarUrl:e.avatarUrl,metadata:e.metadata,organizationId:e.organizationId,organizationName:e.organizationName,organizationDomain:e.organizationDomain,organizationPlan:e.organizationPlan}),this.log("User identified:",e.userId);}reset(){this.currentUserId=null,this.log("User identity reset");}async submitFeedback(e){let t=["feedback","bug_report","feature_request","article_rating"];if(!e.type||!t.includes(e.type))throw new Error(`Census: type must be one of: ${t.join(", ")}`);if(e.type==="article_rating"){if(e.rating===void 0&&e.helpful===void 0)throw new Error("Census: article_rating requires rating or helpful field")}else if(!e.message)throw new Error("Census: message is required for this feedback type");let r=await this.request("/api/sdk/feedback","POST",{type:e.type,message:e.message,rating:e.rating,helpful:e.helpful,userId:this.currentUserId,articleId:e.articleId,pageUrl:typeof window<"u"?window.location.href:void 0,metadata:e.metadata});return this.log("Feedback submitted:",r.feedbackId),{feedbackId:r.feedbackId}}async getArticles(e){let t=new URLSearchParams;e?.category&&t.set("category",e.category),e?.search&&t.set("search",e.search),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let r=t.toString(),i=`/api/sdk/articles${r?`?${r}`:""}`,n=await this.request(i,"GET");return this.log("Fetched articles:",n.articles.length),n}async getArticle(e){try{let t=await this.request(`/api/sdk/articles/${encodeURIComponent(e)}`,"GET");return this.log("Fetched article:",e),t.article}catch(t){if(t.status===404)return null;throw t}}async getFeatureGroups(){let e=await this.request("/api/sdk/feature-groups","GET");return this.log("Fetched feature groups:",e.feature_groups.length),e}async getRequests(e){if(!this.currentUserId)throw new Error("Census: User must be identified before fetching requests. Call identify() first.");let t=new URLSearchParams;t.set("userId",this.currentUserId),e?.status&&t.set("status",e.status),e?.type&&t.set("type",e.type),e?.limit&&t.set("limit",String(e.limit)),e?.offset&&t.set("offset",String(e.offset));let r=await this.request(`/api/sdk/requests?${t.toString()}`,"GET");return this.log("Fetched requests:",r.requests.length),r}async track(e,t){if(!e)throw new Error("Census: eventType is required for track()");await this.request("/api/sdk/events","POST",{eventType:e,userId:this.currentUserId,properties:t}),this.log("Event tracked:",e);}async trackBatch(e){if(!e.events||e.events.length===0)throw new Error("Census: at least one event is required");if(e.events.length>100)throw new Error("Census: maximum 100 events per batch");let t=e.events.map(r=>({eventType:r.eventType,userId:this.currentUserId,articleId:r.articleId,featureId:r.featureId,properties:r.properties}));await this.request("/api/sdk/events","POST",{events:t}),this.log("Batch events tracked:",e.events.length);}async getGuides(e){let t=new URLSearchParams;e?.projectId&&t.set("project_id",e.projectId),e?.url&&t.set("url",e.url),e?.userId&&t.set("user_id",e.userId);let r=t.toString(),i=`/api/sdk/guides${r?`?${r}`:""}`,n=await this.request(i,"GET");return this.log("Fetched guides:",n.guides.length),n}async getGuide(e){try{let t=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}`,"GET");return this.log("Fetched guide:",e),t.guide}catch(t){if(t.status===404)return null;throw t}}async createGuide(e){if(!e.name||!e.slug)throw new Error("Census: name and slug are required for createGuide()");let t=await this.request("/api/sdk/guides","POST",{name:e.name,slug:e.slug,description:e.description,project_id:e.projectId,trigger_type:e.triggerType||"manual",trigger_config:e.triggerConfig||{},theme:e.theme||{},allow_skip:e.allowSkip??true,show_progress:e.showProgress??true});return this.log("Guide created:",t.guide.id),t.guide}async updateGuide(e,t){if(!e)throw new Error("Census: guideId is required for updateGuide()");let r={};t.name!==void 0&&(r.name=t.name),t.slug!==void 0&&(r.slug=t.slug),t.description!==void 0&&(r.description=t.description),t.triggerType!==void 0&&(r.trigger_type=t.triggerType),t.triggerConfig!==void 0&&(r.trigger_config=t.triggerConfig),t.theme!==void 0&&(r.theme=t.theme),t.allowSkip!==void 0&&(r.allow_skip=t.allowSkip),t.showProgress!==void 0&&(r.show_progress=t.showProgress),t.status!==void 0&&(r.status=t.status);let i=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}`,"PUT",r);return this.log("Guide updated:",e),i.guide}async deleteGuide(e){if(!e)throw new Error("Census: guideId is required for deleteGuide()");await this.request(`/api/sdk/guides/${encodeURIComponent(e)}`,"DELETE"),this.log("Guide deleted:",e);}async getGuideSteps(e){let t=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}/steps`,"GET");return this.log("Fetched steps for guide:",e),t.steps}async addGuideStep(e,t){if(!e)throw new Error("Census: guideId is required for addGuideStep()");let r=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}/steps`,"POST",{step_type:t.stepType||"tooltip",sort_order:t.sortOrder,selector_strategy:t.selectorStrategy||{},title:t.title,content:t.content,tooltip_position:t.tooltipPosition||"auto",rich_content:t.richContent||{},display_config:t.displayConfig||{},advance_config:t.advanceConfig||{trigger:"button"},style_config:t.styleConfig||{}});return this.log("Step added to guide:",e),r.step}async updateGuideStep(e,t,r){if(!e||!t)throw new Error("Census: guideId and stepId are required for updateGuideStep()");let i={};r.stepType!==void 0&&(i.step_type=r.stepType),r.sortOrder!==void 0&&(i.sort_order=r.sortOrder),r.selectorStrategy!==void 0&&(i.selector_strategy=r.selectorStrategy),r.title!==void 0&&(i.title=r.title),r.content!==void 0&&(i.content=r.content),r.tooltipPosition!==void 0&&(i.tooltip_position=r.tooltipPosition),r.richContent!==void 0&&(i.rich_content=r.richContent),r.displayConfig!==void 0&&(i.display_config=r.displayConfig),r.advanceConfig!==void 0&&(i.advance_config=r.advanceConfig),r.styleConfig!==void 0&&(i.style_config=r.styleConfig);let n=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}`,"PUT",i);return this.log("Step updated:",t),n.step}async deleteGuideStep(e,t){if(!e||!t)throw new Error("Census: guideId and stepId are required for deleteGuideStep()");await this.request(`/api/sdk/guides/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}`,"DELETE"),this.log("Step deleted:",t);}async reorderGuideSteps(e,t){if(!e)throw new Error("Census: guideId is required for reorderGuideSteps()");let r=await this.request(`/api/sdk/guides/${encodeURIComponent(e)}/steps`,"PUT",{steps:t});return this.log("Steps reordered for guide:",e),r.steps}async trackGuideEvent(e){if(!e.guideId||!e.eventType||!e.sessionId)throw new Error("Census: guideId, eventType, and sessionId are required for trackGuideEvent()");await this.request("/api/sdk/guides/events","POST",{guideId:e.guideId,eventType:e.eventType,stepId:e.stepId,stepIndex:e.stepIndex,pageUrl:e.pageUrl||(typeof window<"u"?window.location.href:void 0),sessionId:e.sessionId,userId:e.userId||this.currentUserId,metadata:e.metadata}),this.log("Guide event tracked:",e.eventType,e.guideId);}async markGuideCompleted(e){if(!e)throw new Error("Census: guideId is required for markGuideCompleted()");if(!this.currentUserId)throw new Error("Census: User must be identified before marking guides complete. Call identify() first.");await this.request("/api/sdk/guides/complete","POST",{guideId:e,userId:this.currentUserId}),this.log("Guide marked completed:",e);}getCurrentUserId(){return this.currentUserId}isIdentified(){return this.currentUserId!==null}async request(e,t,r){let i=`${this.baseUrl}${e}`,n={"X-Census-Key":this.apiKey};r&&(n["Content-Type"]="application/json"),this.log(`${t} ${e}`,r);let p=await fetch(i,{method:t,headers:n,body:r?JSON.stringify(r):void 0});if(!p.ok){let d=`Request failed with status ${p.status}`;try{d=(await p.json()).error||d;}catch{}throw {error:d,status:p.status}}return p.json()}log(...e){this.debug&&console.log("[Census]",...e);}};function Ye(o){return new ze(o)}var Ae=react.createContext(null);function Pt({apiKey:o,baseUrl:e,debug:t,user:r,theme:i={},children:n}){let[p,d]=react.useState(false),[s,a]=react.useState(false),l=react.useMemo(()=>Ye({apiKey:o,baseUrl:e,debug:t}),[o,e,t]);react.useEffect(()=>{r?l.identify(r).then(()=>{a(true),d(true);}).catch(f=>{console.error("[Census] Failed to identify user:",f),d(true);}):d(true);},[l,r]);let c=react.useMemo(()=>({client:l,theme:i,isReady:p,isIdentified:s}),[l,i,p,s]);return jsxRuntime.jsx(Ae.Provider,{value:c,children:n})}function Et(){let o=react.useContext(Ae);if(!o)throw new Error("useCensus must be used within a CensusProvider");return o.client}function O(){let o=react.useContext(Ae);if(!o)throw new Error("useCensusContext must be used within a CensusProvider");return o}function Tt(){let{client:o}=O(),[e,t]=react.useState(false),[r,i]=react.useState(null);return {identify:async d=>{t(true),i(null);try{await o.identify(d);}catch(s){throw i(s instanceof Error?s:new Error("Failed to identify user")),s}finally{t(false);}},reset:()=>{o.reset();},isIdentifying:e,isIdentified:o.isIdentified(),error:r}}function Le(){let{client:o}=O(),[e,t]=react.useState(false),[r,i]=react.useState(false),[n,p]=react.useState(null),[d,s]=react.useState(null),a=react.useCallback(async c=>{t(true),i(false),p(null),s(null);try{let f=await o.submitFeedback(c);return s(f.feedbackId),i(!0),f}catch(f){let g=f instanceof Error?f:new Error("Failed to submit feedback");throw p(g),g}finally{t(false);}},[o]),l=react.useCallback(()=>{i(false),p(null),s(null);},[]);return {submitFeedback:a,reset:l,isSubmitting:e,isSuccess:r,error:n,feedbackId:d}}function ue(o){let{client:e,isReady:t}=O(),[r,i]=react.useState(null),[n,p]=react.useState(true),[d,s]=react.useState(null),a=react.useCallback(async()=>{p(true),s(null);try{let l=await e.getArticles(o);i(l);}catch(l){s(l instanceof Error?l:new Error("Failed to fetch articles"));}finally{p(false);}},[e,o?.category,o?.search,o?.limit,o?.offset]);return react.useEffect(()=>{t&&a();},[t,a]),{articles:r?.articles||[],pagination:r?.pagination,isLoading:n,error:d,refetch:a}}function fe(o){let{client:e,isReady:t}=O(),[r,i]=react.useState(null),[n,p]=react.useState(true),[d,s]=react.useState(null),a=react.useCallback(async()=>{if(!o){i(null),p(false);return}p(true),s(null);try{let l=await e.getArticle(o);i(l);}catch(l){s(l instanceof Error?l:new Error("Failed to fetch article"));}finally{p(false);}},[e,o]);return react.useEffect(()=>{t&&a();},[t,a]),{article:r,isLoading:n,error:d,refetch:a}}function qe(){let{client:o,isReady:e}=O(),[t,r]=react.useState([]),[i,n]=react.useState(true),[p,d]=react.useState(null),s=react.useCallback(async()=>{n(true),d(null);try{let a=await o.getFeatureGroups();r(a.feature_groups);}catch(a){d(a instanceof Error?a:new Error("Failed to fetch feature groups"));}finally{n(false);}},[o]);return react.useEffect(()=>{e&&s();},[e,s]),{featureGroups:t,isLoading:i,error:p,refetch:s}}function ne(o){let{client:e,isReady:t,isIdentified:r}=O(),[i,n]=react.useState(null),[p,d]=react.useState(true),[s,a]=react.useState(null),l=react.useCallback(async()=>{if(!r){n(null),d(false);return}d(true),a(null);try{let c=await e.getRequests(o);n(c);}catch(c){a(c instanceof Error?c:new Error("Failed to fetch requests"));}finally{d(false);}},[e,r,o?.status,o?.type,o?.limit,o?.offset]);return react.useEffect(()=>{t&&r&&l();},[t,r,l]),{requests:i?.requests||[],pagination:i?.pagination,isLoading:p,error:s,refetch:l}}function Bt(){let{client:o}=O(),e=react.useCallback(async(r,i)=>{await o.track(r,i);},[o]),t=react.useCallback(async r=>{await o.trackBatch({events:r});},[o]);return {track:e,trackBatch:t}}function Ft(o){let{client:e,isReady:t}=O(),[r,i]=react.useState(null),[n,p]=react.useState(true),[d,s]=react.useState(null),a=react.useCallback(async()=>{p(true),s(null);try{let l=await e.getGuides(o);i(l);}catch(l){s(l instanceof Error?l:new Error("Failed to fetch guides"));}finally{p(false);}},[e,o?.projectId,o?.url,o?.userId]);return react.useEffect(()=>{t&&a();},[t,a]),{guides:r?.guides||[],completedGuides:r?.completedGuides||[],isLoading:n,error:d,refetch:a}}function Oe(){let{client:o,isReady:e}=O(),[t,r]=react.useState(null),[i,n]=react.useState([]),[p,d]=react.useState(false),[s,a]=react.useState(false),[l,c]=react.useState(null),[f,g]=react.useState(null),u=react.useRef(false),R=react.useCallback(async G=>{d(true),c(null);try{let y=await o.getGuide(G);return y&&(r(y),n(y.guide_steps||[]),g(y.guide_steps?.[0]?.id||null)),y}catch(y){return c(y instanceof Error?y:new Error("Failed to load guide")),null}finally{d(false);}},[o]),S=react.useCallback(async G=>{a(true),c(null);try{let y=await o.createGuide(G);return r(y),n([]),g(null),y}catch(y){throw c(y instanceof Error?y:new Error("Failed to create guide")),y}finally{a(false);}},[o]),x=react.useCallback(async G=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{let y=await o.updateGuide(t.id,G);return r(y),u.current=!1,y}catch(y){throw c(y instanceof Error?y:new Error("Failed to update guide")),y}finally{a(false);}},[o,t]),w=react.useCallback(async()=>x({status:"published"}),[x]),b=react.useCallback(async()=>x({status:"draft"}),[x]),v=react.useCallback(async()=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{await o.deleteGuide(t.id),r(null),n([]),g(null);}catch(G){throw c(G instanceof Error?G:new Error("Failed to delete guide")),G}finally{a(false);}},[o,t]),E=react.useCallback(async G=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{let y=await o.addGuideStep(t.id,G);return n(N=>[...N,y]),g(y.id),u.current=!0,y}catch(y){throw c(y instanceof Error?y:new Error("Failed to add step")),y}finally{a(false);}},[o,t]),k=react.useCallback(async(G,y)=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{let N=await o.updateGuideStep(t.id,G,y);return n(P=>P.map(D=>D.id===G?N:D)),u.current=!0,N}catch(N){throw c(N instanceof Error?N:new Error("Failed to update step")),N}finally{a(false);}},[o,t]),T=react.useCallback(async G=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{await o.deleteGuideStep(t.id,G),n(y=>y.filter(N=>N.id!==G)),f===G&&g(i[0]?.id||null),u.current=!0;}catch(y){throw c(y instanceof Error?y:new Error("Failed to delete step")),y}finally{a(false);}},[o,t,f,i]),m=react.useCallback(async G=>{if(!t)throw new Error("No guide loaded");a(true),c(null);try{let y=await o.reorderGuideSteps(t.id,G);return n(y),u.current=!0,y}catch(y){throw c(y instanceof Error?y:new Error("Failed to reorder steps")),y}finally{a(false);}},[o,t]),L=react.useCallback(async G=>{let y=i.findIndex(P=>P.id===G);if(y<=0)return;let N=i.map((P,D)=>D===y?{id:P.id,sort_order:y-1}:D===y-1?{id:P.id,sort_order:y}:{id:P.id,sort_order:D});return m(N)},[i,m]),U=react.useCallback(async G=>{let y=i.findIndex(P=>P.id===G);if(y<0||y>=i.length-1)return;let N=i.map((P,D)=>D===y?{id:P.id,sort_order:y+1}:D===y+1?{id:P.id,sort_order:y}:{id:P.id,sort_order:D});return m(N)},[i,m]),j=f&&i.find(G=>G.id===f)||null,_=react.useCallback(()=>{r(null),n([]),g(null),c(null),u.current=false;},[]);return {guide:t,steps:i,selectedStep:j,selectedStepId:f,isLoading:p,isSaving:s,error:l,isReady:e,hasUnsavedChanges:u.current,loadGuide:R,createGuide:S,updateGuide:x,publishGuide:w,unpublishGuide:b,deleteGuide:v,addStep:E,updateStep:k,deleteStep:T,reorderSteps:m,moveStepUp:L,moveStepDown:U,setSelectedStepId:g,reset:_}}function zt(){let{client:o,isReady:e}=O(),[t,r]=react.useState(null),[i,n]=react.useState(0),[p,d]=react.useState(false),[s,a]=react.useState([]),[l,c]=react.useState([]),f=react.useCallback((_,G=0)=>{r(_),n(G),d(true);},[]),g=react.useCallback(()=>{if(!t)return;let _=t.guide_steps||[];i<_.length-1?n(G=>G+1):(a(G=>[...G,t.id]),d(false),r(null));},[t,i]),u=react.useCallback(()=>{i>0&&n(_=>_-1);},[i]),R=react.useCallback(_=>{if(!t)return;let G=t.guide_steps||[];_>=0&&_<G.length&&n(_);},[t]),S=react.useCallback(()=>{t&&c(_=>[..._,t.id]),d(false),r(null),n(0);},[t]),x=react.useCallback(()=>{d(false);},[]),w=react.useCallback(()=>{t&&d(true);},[t]),b=react.useCallback(async(_,G)=>{let y=_.guide_steps?.[G];if(y)try{await o.track("guide_step_viewed",{guide_id:_.id,guide_name:_.name,step_id:y.id,step_index:G,step_type:y.step_type});}catch{}},[o]),v=react.useCallback(async _=>{try{await o.track("guide_completed",{guide_id:_.id,guide_name:_.name,total_steps:_.guide_steps?.length||0});}catch{}},[o]),E=react.useCallback(async(_,G)=>{try{await o.track("guide_dismissed",{guide_id:_.id,guide_name:_.name,dismissed_at_step:G,total_steps:_.guide_steps?.length||0});}catch{}},[o]),k=t?.guide_steps?.[i]||null,T=t?.guide_steps?.length||0,m=i===T-1,L=i===0,U=react.useCallback(_=>s.includes(_),[s]),j=react.useCallback(_=>l.includes(_),[l]);return {activeGuide:t,currentStep:k,currentStepIndex:i,totalSteps:T,isPlaying:p,isFirstStep:L,isLastStep:m,isReady:e,startGuide:f,nextStep:g,prevStep:u,goToStep:R,dismiss:S,pause:x,resume:w,trackStepView:b,trackGuideComplete:v,trackGuideDismiss:E,completedGuideIds:s,dismissedGuideIds:l,isGuideCompleted:U,isGuideDismissed:j}}var oe={button:{position:"fixed",padding:"12px 20px",border:"none",borderRadius:"8px",cursor:"pointer",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px",fontWeight:"500",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",transition:"transform 0.2s, box-shadow 0.2s",zIndex:9999},modal:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",zIndex:1e4},modalContent:{backgroundColor:"white",borderRadius:"12px",padding:"24px",width:"100%",maxWidth:"400px",margin:"16px",boxShadow:"0 20px 50px rgba(0, 0, 0, 0.2)",fontFamily:"system-ui, -apple-system, sans-serif"},textarea:{width:"100%",padding:"10px 12px",border:"1px solid #e0e0e0",borderRadius:"6px",fontSize:"14px",marginBottom:"16px",minHeight:"100px",resize:"vertical",boxSizing:"border-box",fontFamily:"inherit"},submitButton:{width:"100%",padding:"12px",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"14px",fontWeight:"500",transition:"opacity 0.2s"},typeButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"6px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"}},At={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},Lt={feedback:"General Feedback",bug_report:"Bug Report",feature_request:"Feature Request",article_rating:"Article Rating"},qt={feedback:"\u{1F4AC}",bug_report:"\u{1F41B}",feature_request:"\u{1F4A1}",article_rating:"\u2B50"};function Ot(o){return {primaryColor:o.primaryColor||"#000000",textColor:o.textColor||"#333333",backgroundColor:o.backgroundColor||"#ffffff",borderRadius:o.borderRadius||"8px",fontFamily:o.fontFamily||"system-ui, -apple-system, sans-serif"}}function Dt({position:o="bottom-right",text:e="Feedback",allowedTypes:t=["feedback","bug_report","feature_request"],theme:r,onSubmit:i,onError:n,children:p}){let{theme:d}=O(),{submitFeedback:s,isSubmitting:a,isSuccess:l,reset:c}=Le(),[f,g]=react.useState(false),[u,R]=react.useState(t[0]),[S,x]=react.useState(""),w={...d,...r},b=Ot(w),v=react.useCallback(()=>{g(true),c();},[c]),E=react.useCallback(()=>{g(false),x(""),R(t[0]);},[t]),k=react.useCallback(async T=>{T.preventDefault();let m={type:u,message:S};try{await s(m),i?.(m),setTimeout(E,1500);}catch(L){n?.(L instanceof Error?L:new Error("Failed to submit feedback"));}},[u,S,s,i,n,E]);return p?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{onClick:v,style:{cursor:"pointer"},children:p}),f&&jsxRuntime.jsx(Ze,{isOpen:f,onClose:E,selectedType:u,onTypeChange:R,allowedTypes:t,message:S,onMessageChange:x,onSubmit:k,isSubmitting:a,isSuccess:l,themeStyles:b})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{onClick:v,style:{...oe.button,...At[o],backgroundColor:b.primaryColor,color:"white",borderRadius:b.borderRadius,fontFamily:b.fontFamily},"aria-label":"Open feedback form",children:e}),f&&jsxRuntime.jsx(Ze,{isOpen:f,onClose:E,selectedType:u,onTypeChange:R,allowedTypes:t,message:S,onMessageChange:x,onSubmit:k,isSubmitting:a,isSuccess:l,themeStyles:b})]})}function Ze({isOpen:o,onClose:e,selectedType:t,onTypeChange:r,allowedTypes:i,message:n,onMessageChange:p,onSubmit:d,isSubmitting:s,isSuccess:a,themeStyles:l}){return o?a?jsxRuntime.jsx("div",{style:oe.modal,onClick:e,children:jsxRuntime.jsxs("div",{style:{...oe.modalContent,textAlign:"center",fontFamily:l.fontFamily},onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsxRuntime.jsx("h3",{style:{margin:"0 0 8px 0",color:l.textColor},children:"Thanks for your feedback!"}),jsxRuntime.jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsxRuntime.jsx("div",{style:oe.modal,onClick:e,children:jsxRuntime.jsxs("div",{style:{...oe.modalContent,fontFamily:l.fontFamily},onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsxRuntime.jsx("h3",{style:{margin:0,color:l.textColor},children:"Send Feedback"}),jsxRuntime.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsxs("form",{onSubmit:d,children:[jsxRuntime.jsxs("div",{style:{marginBottom:"16px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:i.map(c=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>r(c),style:{...oe.typeButton,backgroundColor:t===c?l.primaryColor:"white",color:t===c?"white":l.textColor,borderColor:t===c?l.primaryColor:"#e0e0e0"},children:[qt[c]," ",Lt[c]]},c))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),jsxRuntime.jsx("textarea",{value:n,onChange:c=>p(c.target.value),placeholder:t==="bug_report"?"Describe the bug and steps to reproduce...":t==="feature_request"?"Describe the feature you would like...":"Share your thoughts...",style:oe.textarea,required:true})]}),jsxRuntime.jsx("button",{type:"submit",disabled:s||!n.trim(),style:{...oe.submitButton,backgroundColor:l.primaryColor,color:"white",opacity:s||!n.trim()?.6:1,cursor:s||!n.trim()?"not-allowed":"pointer"},children:s?"Sending...":"Send Feedback"})]})]})}):null}var q={container:{fontFamily:"system-ui, -apple-system, sans-serif",maxWidth:"800px"},searchInput:{width:"100%",padding:"12px 16px",border:"1px solid #e0e0e0",borderRadius:"8px",fontSize:"15px",marginBottom:"24px",boxSizing:"border-box"},categoryButton:{padding:"8px 16px",border:"1px solid #e0e0e0",borderRadius:"20px",cursor:"pointer",fontSize:"13px",backgroundColor:"white",transition:"all 0.2s",marginRight:"8px",marginBottom:"8px"},articleCard:{padding:"20px",border:"1px solid #e0e0e0",borderRadius:"8px",marginBottom:"12px",cursor:"pointer",transition:"box-shadow 0.2s, border-color 0.2s",backgroundColor:"white"},articleTitle:{margin:"0 0 8px 0",fontSize:"16px",fontWeight:"600"},articleDescription:{margin:0,fontSize:"14px",color:"#666",lineHeight:1.5},articleMeta:{display:"flex",gap:"16px",marginTop:"12px",fontSize:"12px",color:"#999"},backButton:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"8px 0",border:"none",background:"none",cursor:"pointer",fontSize:"14px",color:"#666",marginBottom:"16px"},articleContent:{lineHeight:1.7,fontSize:"15px"},loading:{textAlign:"center",padding:"40px",color:"#666"},error:{padding:"20px",backgroundColor:"#fef2f2",borderRadius:"8px",color:"#b91c1c",textAlign:"center"},empty:{textAlign:"center",padding:"40px",color:"#666"}};function Ut(o){return {primaryColor:o.primaryColor||"#000000",textColor:o.textColor||"#333333",backgroundColor:o.backgroundColor||"#ffffff",borderRadius:o.borderRadius||"8px",fontFamily:o.fontFamily||"system-ui, -apple-system, sans-serif"}}function Nt({showSearch:o=true,showCategories:e=true,defaultCategory:t,theme:r,className:i,onArticleView:n}){let{theme:p}=O(),[d,s]=react.useState(""),[a,l]=react.useState(t),[c,f]=react.useState(null),g={...p,...r},u=Ut(g),{articles:R,isLoading:S,error:x}=ue({category:a,search:d||void 0}),{article:w,isLoading:b,error:v}=fe(c||""),E=react.useMemo(()=>{let m=new Set;return R.forEach(L=>{L.category&&m.add(L.category);}),Array.from(m).sort()},[R]),k=m=>{f(m.slug),n?.(m);},T=()=>{f(null);};return c?b?jsxRuntime.jsx("div",{style:{...q.container,fontFamily:u.fontFamily},className:i,children:jsxRuntime.jsx("div",{style:q.loading,children:"Loading article..."})}):v?jsxRuntime.jsxs("div",{style:{...q.container,fontFamily:u.fontFamily},className:i,children:[jsxRuntime.jsx("button",{onClick:T,style:q.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:q.error,children:"Failed to load article. Please try again."})]}):w?jsxRuntime.jsxs("div",{style:{...q.container,fontFamily:u.fontFamily},className:i,children:[jsxRuntime.jsx("button",{onClick:T,style:q.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsxs("article",{children:[jsxRuntime.jsx("h1",{style:{margin:"0 0 16px 0",color:u.textColor},children:w.title}),w.read_time_minutes&&jsxRuntime.jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[w.read_time_minutes," min read"]}),w.content_html?jsxRuntime.jsx("div",{style:{...q.articleContent,color:u.textColor},dangerouslySetInnerHTML:{__html:w.content_html}}):jsxRuntime.jsx("div",{style:{...q.articleContent,color:u.textColor},children:typeof w.content=="string"?w.content:"No content available."})]})]}):jsxRuntime.jsxs("div",{style:{...q.container,fontFamily:u.fontFamily},className:i,children:[jsxRuntime.jsx("button",{onClick:T,style:q.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:q.empty,children:"Article not found."})]}):jsxRuntime.jsxs("div",{style:{...q.container,fontFamily:u.fontFamily},className:i,children:[o&&jsxRuntime.jsx("input",{type:"text",placeholder:"Search articles...",value:d,onChange:m=>s(m.target.value),style:q.searchInput}),e&&E.length>0&&jsxRuntime.jsxs("div",{style:{marginBottom:"24px"},children:[jsxRuntime.jsx("button",{onClick:()=>l(void 0),style:{...q.categoryButton,backgroundColor:a?"white":u.primaryColor,color:a?u.textColor:"white",borderColor:a?"#e0e0e0":u.primaryColor},children:"All"}),E.map(m=>jsxRuntime.jsx("button",{onClick:()=>l(m),style:{...q.categoryButton,backgroundColor:a===m?u.primaryColor:"white",color:a===m?"white":u.textColor,borderColor:a===m?u.primaryColor:"#e0e0e0"},children:m},m))]}),S&&jsxRuntime.jsx("div",{style:q.loading,children:"Loading articles..."}),x&&jsxRuntime.jsx("div",{style:q.error,children:"Failed to load articles. Please try again."}),!S&&!x&&R.length===0&&jsxRuntime.jsx("div",{style:q.empty,children:d?`No articles found for "${d}"`:"No articles available yet."}),!S&&!x&&R.length>0&&jsxRuntime.jsx("div",{children:R.map(m=>jsxRuntime.jsxs("div",{onClick:()=>k(m),style:q.articleCard,role:"button",tabIndex:0,onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&k(m);},children:[jsxRuntime.jsx("h3",{style:{...q.articleTitle,color:u.textColor},children:m.title}),m.seo_description&&jsxRuntime.jsx("p",{style:q.articleDescription,children:m.seo_description}),jsxRuntime.jsxs("div",{style:q.articleMeta,children:[m.category&&jsxRuntime.jsx("span",{children:m.category}),m.read_time_minutes&&jsxRuntime.jsxs("span",{children:[m.read_time_minutes," min read"]})]})]},m.id))})]})}var K={container:{fontFamily:"system-ui, -apple-system, sans-serif"},list:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"12px"},card:{border:"1px solid #e5e7eb",borderRadius:"8px",padding:"16px",backgroundColor:"#ffffff",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s"},cardHover:{borderColor:"#d1d5db",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",marginBottom:"8px"},badges:{display:"flex",alignItems:"center",gap:"6px"},badge:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},message:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},meta:{display:"flex",gap:"12px",marginTop:"8px",fontSize:"12px",color:"#6b7280"},empty:{textAlign:"center",padding:"32px 16px",color:"#6b7280"},emptyIcon:{width:"48px",height:"48px",margin:"0 auto 12px",color:"#d1d5db"},loading:{textAlign:"center",padding:"24px",color:"#6b7280"},error:{textAlign:"center",padding:"24px",color:"#dc2626"}},tt={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug Report",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature Request",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Article Rating",color:"#7c3aed",bg:"#ede9fe"}},ot={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function $t(o){return new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Vt({status:o,type:e,limit:t=50,className:r,showEmptyState:i=true,onRequestClick:n}){let{isIdentified:p}=O(),[d,s]=react.useState(null),{requests:a,isLoading:l,error:c,refetch:f}=ne({status:o,type:e,limit:t}),g=react.useCallback(u=>{n?.(u);},[n]);return p?l?jsxRuntime.jsx("div",{style:K.loading,children:jsxRuntime.jsx("p",{children:"Loading requests..."})}):c?jsxRuntime.jsx("div",{style:K.error,children:jsxRuntime.jsxs("p",{children:["Failed to load requests. ",jsxRuntime.jsx("button",{onClick:f,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})}):a.length===0&&i?jsxRuntime.jsxs("div",{style:K.empty,children:[jsxRuntime.jsx("svg",{style:K.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),jsxRuntime.jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsxRuntime.jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"When you submit feedback, bug reports, or feature requests, they'll appear here."})]}):jsxRuntime.jsx("div",{style:K.container,className:r,children:jsxRuntime.jsx("ul",{style:K.list,children:a.map(u=>{let R=tt[u.feedback_type]||tt.feedback,S=ot[u.status]||ot.new,x=d===u.id;return jsxRuntime.jsxs("li",{style:{...K.card,...x?K.cardHover:{}},onMouseEnter:()=>s(u.id),onMouseLeave:()=>s(null),onClick:()=>g(u),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&g(u);},children:[jsxRuntime.jsx("div",{style:K.header,children:jsxRuntime.jsxs("div",{style:K.badges,children:[jsxRuntime.jsx("span",{style:{...K.badge,color:R.color,backgroundColor:R.bg},children:R.label}),jsxRuntime.jsx("span",{style:{...K.badge,color:S.color,backgroundColor:S.bg},children:S.label})]})}),jsxRuntime.jsx("p",{style:K.message,children:u.message||"No message provided"}),jsxRuntime.jsxs("div",{style:K.meta,children:[jsxRuntime.jsx("span",{children:$t(u.created_at)}),u.page_url&&jsxRuntime.jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",u.page_url]})]})]},u.id)})})}):i?jsxRuntime.jsx("div",{style:K.empty,children:jsxRuntime.jsx("p",{children:"Please sign in to view your requests."})}):null}var h={container:{fontFamily:"system-ui, -apple-system, sans-serif",display:"flex",minHeight:"400px"},sidebar:{width:"240px",flexShrink:0,borderRight:"1px solid #e5e7eb",paddingRight:"16px",marginRight:"24px"},sidebarSection:{marginBottom:"24px"},sidebarLabel:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#6b7280",marginBottom:"8px",paddingLeft:"8px"},sidebarItem:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"6px",cursor:"pointer",fontSize:"14px",color:"#374151",transition:"background-color 0.15s, color 0.15s",border:"none",background:"none",width:"100%",textAlign:"left"},sidebarItemActive:{backgroundColor:"#f3f4f6",color:"#111827",fontWeight:500},sidebarFeature:{padding:"6px 12px 6px 32px",fontSize:"13px"},sidebarBadge:{marginLeft:"auto",padding:"2px 6px",borderRadius:"9999px",fontSize:"11px",fontWeight:500,backgroundColor:"#e5e7eb",color:"#374151"},main:{flex:1,minWidth:0},tabs:{display:"flex",gap:"4px",marginBottom:"24px",borderBottom:"1px solid #e5e7eb"},tab:{padding:"12px 20px",border:"none",background:"none",cursor:"pointer",fontSize:"14px",fontWeight:500,color:"#6b7280",borderBottom:"2px solid transparent",marginBottom:"-1px",transition:"color 0.15s, border-color 0.15s"},tabActive:{color:"#111827",borderBottomColor:"#111827"},tabBadge:{marginLeft:"6px",padding:"2px 6px",borderRadius:"9999px",fontSize:"11px",fontWeight:600,backgroundColor:"#e5e7eb",color:"#374151"},groupCardsGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:"16px",marginBottom:"24px"},groupCard:{padding:"20px",border:"1px solid #e5e7eb",borderRadius:"12px",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s",backgroundColor:"white"},groupCardName:{fontSize:"16px",fontWeight:600,color:"#111827",margin:0},groupCardMeta:{fontSize:"13px",color:"#6b7280",marginTop:"4px"},searchInput:{width:"100%",padding:"10px 14px",border:"1px solid #e5e7eb",borderRadius:"8px",fontSize:"14px",marginBottom:"20px",boxSizing:"border-box"},articleCard:{padding:"16px",border:"1px solid #e5e7eb",borderRadius:"10px",marginBottom:"12px",cursor:"pointer",transition:"border-color 0.15s, box-shadow 0.15s",backgroundColor:"white"},articleTitle:{margin:"0 0 6px 0",fontSize:"15px",fontWeight:600},articleDescription:{margin:0,fontSize:"14px",color:"#6b7280",lineHeight:1.5},articleMeta:{display:"flex",gap:"12px",marginTop:"10px",fontSize:"12px",color:"#9ca3af"},backButton:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 0",border:"none",background:"none",cursor:"pointer",fontSize:"14px",color:"#6b7280",marginBottom:"16px"},articleContent:{lineHeight:1.7,fontSize:"15px"},requestCard:{border:"1px solid #e5e7eb",borderRadius:"10px",padding:"16px",backgroundColor:"#ffffff",marginBottom:"12px",transition:"border-color 0.15s"},requestHeader:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},badge:{display:"inline-flex",alignItems:"center",padding:"3px 10px",borderRadius:"9999px",fontSize:"12px",fontWeight:500},requestMessage:{fontSize:"14px",color:"#111827",margin:0,lineHeight:1.5},requestMeta:{display:"flex",gap:"12px",marginTop:"10px",fontSize:"12px",color:"#9ca3af"},sectionHeader:{marginBottom:"16px"},sectionTitle:{fontSize:"18px",fontWeight:600,color:"#111827",margin:"0 0 4px 0"},sectionDescription:{fontSize:"14px",color:"#6b7280",margin:0},loading:{textAlign:"center",padding:"40px",color:"#6b7280"},error:{padding:"20px",backgroundColor:"#fef2f2",borderRadius:"10px",color:"#b91c1c",textAlign:"center"},empty:{textAlign:"center",padding:"48px 24px",color:"#6b7280"},emptyIcon:{width:"48px",height:"48px",margin:"0 auto 16px",color:"#d1d5db"}},rt={feedback:{label:"Feedback",color:"#2563eb",bg:"#dbeafe"},bug_report:{label:"Bug",color:"#dc2626",bg:"#fee2e2"},feature_request:{label:"Feature",color:"#d97706",bg:"#fef3c7"},article_rating:{label:"Rating",color:"#7c3aed",bg:"#ede9fe"}},nt={new:{label:"New",color:"#6b7280",bg:"#f3f4f6"},reviewed:{label:"Reviewed",color:"#2563eb",bg:"#dbeafe"},in_progress:{label:"In Progress",color:"#d97706",bg:"#fef3c7"},resolved:{label:"Resolved",color:"#059669",bg:"#d1fae5"},closed:{label:"Closed",color:"#6b7280",bg:"#f3f4f6"}};function Kt(o){return new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function jt(o){return {primaryColor:o.primaryColor||"#111827",textColor:o.textColor||"#111827",backgroundColor:o.backgroundColor||"#ffffff",borderRadius:o.borderRadius||"10px",fontFamily:o.fontFamily||"system-ui, -apple-system, sans-serif"}}var Xt={articles:"Articles",requests:"My Requests"};function Yt({group:o,onClick:e}){return jsxRuntime.jsxs("div",{style:h.groupCard,onClick:e,role:"button",tabIndex:0,onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&e();},children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{style:h.groupCardName,children:o.name}),jsxRuntime.jsxs("p",{style:h.groupCardMeta,children:[o.feature_count," feature",o.feature_count!==1?"s":""," \xB7 ",o.article_count," article",o.article_count!==1?"s":""]})]}),o.description&&jsxRuntime.jsx("p",{style:{...h.articleDescription,marginTop:"8px"},children:o.description})]})}function it({featureId:o,featureName:e,showSearch:t,themeStyles:r,onArticleView:i,onBack:n}){let[p,d]=react.useState(""),[s,a]=react.useState(null),{articles:l,isLoading:c,error:f}=ue({search:p||void 0}),{article:g,isLoading:u,error:R}=fe(s||""),S=react.useMemo(()=>o?l.filter(b=>b.features?.id===o):l,[l,o]),x=b=>{a(b.slug),i?.(b);},w=()=>{a(null);};return s?u?jsxRuntime.jsx("div",{style:h.loading,children:"Loading article..."}):R?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:w,style:h.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:h.error,children:"Failed to load article."})]}):g?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:w,style:h.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsxs("article",{children:[jsxRuntime.jsx("h1",{style:{margin:"0 0 12px 0",fontSize:"24px",color:r.textColor},children:g.title}),g.read_time_minutes&&jsxRuntime.jsxs("div",{style:{fontSize:"14px",color:"#6b7280",marginBottom:"24px"},children:[g.read_time_minutes," min read"]}),g.content_html?jsxRuntime.jsx("div",{style:{...h.articleContent,color:r.textColor},dangerouslySetInnerHTML:{__html:g.content_html}}):jsxRuntime.jsx("div",{style:{...h.articleContent,color:r.textColor},children:typeof g.content=="string"?g.content:"No content available."})]})]}):jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("button",{onClick:w,style:h.backButton,children:"\u2190 Back to articles"}),jsxRuntime.jsx("div",{style:h.empty,children:"Article not found."})]}):jsxRuntime.jsxs("div",{children:[e&&n&&jsxRuntime.jsxs("div",{style:h.sectionHeader,children:[jsxRuntime.jsx("button",{onClick:n,style:h.backButton,children:"\u2190 Back to features"}),jsxRuntime.jsx("h2",{style:h.sectionTitle,children:e}),jsxRuntime.jsx("p",{style:h.sectionDescription,children:"Documentation and guides for this feature"})]}),t&&jsxRuntime.jsx("input",{type:"text",placeholder:"Search articles...",value:p,onChange:b=>d(b.target.value),style:h.searchInput}),c&&jsxRuntime.jsx("div",{style:h.loading,children:"Loading articles..."}),f&&jsxRuntime.jsx("div",{style:h.error,children:"Failed to load articles. Please try again."}),!c&&!f&&S.length===0&&jsxRuntime.jsxs("div",{style:h.empty,children:[jsxRuntime.jsx("svg",{style:h.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),jsxRuntime.jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:p?`No articles found for "${p}"`:"No articles yet"}),jsxRuntime.jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"Check back soon for helpful content."})]}),!c&&!f&&S.length>0&&jsxRuntime.jsx("div",{children:S.map(b=>jsxRuntime.jsxs("div",{onClick:()=>x(b),style:h.articleCard,role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&x(b);},children:[jsxRuntime.jsx("h3",{style:{...h.articleTitle,color:r.textColor},children:b.title}),b.seo_description&&jsxRuntime.jsx("p",{style:h.articleDescription,children:b.seo_description}),jsxRuntime.jsxs("div",{style:h.articleMeta,children:[b.category&&jsxRuntime.jsx("span",{children:b.category}),b.read_time_minutes&&jsxRuntime.jsxs("span",{children:[b.read_time_minutes," min read"]})]})]},b.id))})]})}function Qt({onRequestClick:o}){let{isIdentified:e}=O(),{requests:t,isLoading:r,error:i,refetch:n}=ne({limit:50});return e?r?jsxRuntime.jsx("div",{style:h.loading,children:"Loading requests..."}):i?jsxRuntime.jsx("div",{style:h.error,children:jsxRuntime.jsxs("p",{children:["Failed to load requests."," ",jsxRuntime.jsx("button",{onClick:n,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})}):t.length===0?jsxRuntime.jsxs("div",{style:h.empty,children:[jsxRuntime.jsx("svg",{style:h.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),jsxRuntime.jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsxRuntime.jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"When you submit feedback, bug reports, or feature requests, they'll appear here."})]}):jsxRuntime.jsx("div",{children:t.map(p=>{let d=rt[p.feedback_type]||rt.feedback,s=nt[p.status]||nt.new;return jsxRuntime.jsxs("div",{style:h.requestCard,onClick:()=>o?.(p),role:o?"button":void 0,tabIndex:o?0:void 0,onKeyDown:o?a=>{(a.key==="Enter"||a.key===" ")&&o(p);}:void 0,children:[jsxRuntime.jsxs("div",{style:h.requestHeader,children:[jsxRuntime.jsx("span",{style:{...h.badge,color:d.color,backgroundColor:d.bg},children:d.label}),jsxRuntime.jsx("span",{style:{...h.badge,color:s.color,backgroundColor:s.bg},children:s.label})]}),jsxRuntime.jsx("p",{style:h.requestMessage,children:p.message||"No message provided"}),jsxRuntime.jsxs("div",{style:h.requestMeta,children:[jsxRuntime.jsx("span",{children:Kt(p.created_at)}),p.page_url&&jsxRuntime.jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",p.page_url]})]})]},p.id)})}):jsxRuntime.jsxs("div",{style:h.empty,children:[jsxRuntime.jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"Sign in required"}),jsxRuntime.jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"Please sign in to view your requests."})]})}function Jt({tabs:o=["articles","requests"],defaultTab:e,tabLabels:t,showSearch:r=true,showCategories:i=true,theme:n,className:p,onArticleView:d,onRequestClick:s,onTabChange:a}){let{theme:l}=O(),c={...l,...n},f=jt(c),g=e&&o.includes(e)?e:o[0],[u,R]=react.useState(g),[S,x]=react.useState(null),[w,b]=react.useState(null),{featureGroups:v,isLoading:E}=qe(),{requests:k}=ne({limit:100}),T=k.filter(P=>["new","reviewed","in_progress"].includes(P.status)).length,m={...Xt,...t},L=react.useMemo(()=>v.find(P=>P.id===S)||null,[v,S]),U=P=>{R(P),x(null),b(null),a?.(P);},j=P=>{x(P.id),b(null);},_=P=>{b(P);},G=()=>{x(null),b(null);},y=()=>{b(null);},N=o.length>1;return jsxRuntime.jsxs("div",{style:{...h.container,fontFamily:f.fontFamily},className:p,children:[u==="articles"&&v.length>0&&jsxRuntime.jsxs("div",{style:h.sidebar,children:[jsxRuntime.jsxs("div",{style:h.sidebarSection,children:[jsxRuntime.jsx("div",{style:h.sidebarLabel,children:"Resources"}),jsxRuntime.jsxs("button",{style:{...h.sidebarItem,...S?{}:h.sidebarItemActive},onClick:G,children:[jsxRuntime.jsx("span",{children:"\u{1F3E0}"}),jsxRuntime.jsx("span",{children:"All Features"})]})]}),jsxRuntime.jsxs("div",{style:h.sidebarSection,children:[jsxRuntime.jsx("div",{style:h.sidebarLabel,children:"Features"}),E?jsxRuntime.jsx("div",{style:{padding:"8px 12px",fontSize:"13px",color:"#6b7280"},children:"Loading..."}):v.map(P=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{style:{...h.sidebarItem,...S===P.id?h.sidebarItemActive:{}},onClick:()=>j(P),children:[jsxRuntime.jsx("span",{style:{flex:1},children:P.name}),jsxRuntime.jsx("span",{style:h.sidebarBadge,children:P.feature_count})]}),S===P.id&&jsxRuntime.jsx("div",{children:P.features.map(D=>jsxRuntime.jsxs("button",{style:{...h.sidebarItem,...h.sidebarFeature,...w?.id===D.id?h.sidebarItemActive:{}},onClick:()=>_(D),children:[D.name,D.article_count>0&&jsxRuntime.jsx("span",{style:h.sidebarBadge,children:D.article_count})]},D.id))})]},P.id))]})]}),jsxRuntime.jsxs("div",{style:h.main,children:[N&&jsxRuntime.jsx("div",{style:h.tabs,children:o.map(P=>jsxRuntime.jsxs("button",{onClick:()=>U(P),style:{...h.tab,...u===P?h.tabActive:{},...u===P?{borderBottomColor:f.primaryColor,color:f.primaryColor}:{}},children:[m[P],P==="requests"&&T>0&&jsxRuntime.jsx("span",{style:h.tabBadge,children:T})]},P))}),u==="articles"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!S&&!w&&v.length>0&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:h.sectionHeader,children:[jsxRuntime.jsx("h2",{style:h.sectionTitle,children:"Browse by Feature"}),jsxRuntime.jsx("p",{style:h.sectionDescription,children:"Select a feature group to find relevant documentation"})]}),jsxRuntime.jsx("div",{style:h.groupCardsGrid,children:v.map(P=>jsxRuntime.jsx(Yt,{group:P,onClick:()=>j(P)},P.id))})]}),L&&!w&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:h.sectionHeader,children:[jsxRuntime.jsx("button",{onClick:G,style:h.backButton,children:"\u2190 Back to all features"}),jsxRuntime.jsx("h2",{style:h.sectionTitle,children:L.name}),L.description&&jsxRuntime.jsx("p",{style:h.sectionDescription,children:L.description})]}),jsxRuntime.jsx("div",{style:h.groupCardsGrid,children:L.features.map(P=>jsxRuntime.jsxs("div",{style:h.groupCard,onClick:()=>_(P),role:"button",tabIndex:0,onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&_(P);},children:[jsxRuntime.jsx("h3",{style:h.groupCardName,children:P.name}),jsxRuntime.jsxs("p",{style:h.groupCardMeta,children:[P.article_count," article",P.article_count!==1?"s":""]}),P.description&&jsxRuntime.jsx("p",{style:{...h.articleDescription,marginTop:"8px"},children:P.description})]},P.id))})]}),w&&jsxRuntime.jsx(it,{featureId:w.id,featureName:w.name,showSearch:r,themeStyles:f,onArticleView:d,onBack:y}),v.length===0&&jsxRuntime.jsx(it,{showSearch:r,themeStyles:f,onArticleView:d})]}),u==="requests"&&jsxRuntime.jsx(Qt,{onRequestClick:s})]})]})}var at={tooltip:"Tooltip",modal:"Modal",slideout:"Slideout",hotspot:"Hotspot",banner:"Banner"},to={tooltip:"Points to a specific element with an arrow",modal:"Centered overlay that grabs attention",slideout:"Slides in from the side of the screen",hotspot:"Pulsing beacon that expands on click",banner:"Top or bottom bar announcement"},oo=[{value:"auto",label:"Auto"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],ro=[{value:"button",label:"Button click"},{value:"click",label:"Click anywhere"},{value:"delay",label:"After delay"},{value:"form-submit",label:"Form submit"}];function lt({step:o,onUpdate:e,onSelectElement:t,isSelectingElement:r}){let[i,n]=react.useState(false),[p,d]=react.useState(o.step_type),[s,a]=react.useState(o.rich_content?.title||o.title||""),[l,c]=react.useState(o.rich_content?.body||o.content||""),[f,g]=react.useState(o.tooltip_position||o.display_config?.position||"auto"),[u,R]=react.useState(o.selector_strategy?.css||""),[S,x]=react.useState(o.display_config?.backdrop!==false),[w,b]=react.useState(o.advance_config?.trigger||"button"),[v,E]=react.useState(o.advance_config?.delay||3e3),k=react.useCallback(async()=>{n(true);try{let m=u?{css:u}:void 0,L={title:s||void 0,body:l||void 0},U={position:f!=="auto"?f:void 0,backdrop:S},j={trigger:w,delay:w==="delay"?v:void 0};await e(o.id,{stepType:p,selectorStrategy:m,richContent:L,displayConfig:U,advanceConfig:j,tooltipPosition:f});}finally{n(false);}},[o.id,p,s,l,f,u,S,w,v,e]),T=p==="tooltip"||p==="hotspot";return jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[jsxRuntime.jsxs("div",{style:{padding:"16px",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsx("span",{style:{fontWeight:500},children:"Edit Step"}),jsxRuntime.jsx("button",{onClick:k,disabled:i,style:{padding:"6px 12px",fontSize:"13px",border:"none",borderRadius:"4px",backgroundColor:"#2563eb",color:"white",cursor:i?"wait":"pointer",opacity:i?.7:1},children:i?"Saving...":"Save Changes"})]}),jsxRuntime.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px"},children:[jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Step Type"}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"8px"},children:Object.keys(at).map(m=>jsxRuntime.jsxs("button",{onClick:()=>d(m),style:{padding:"10px",border:`2px solid ${p===m?"#2563eb":"#e5e7eb"}`,borderRadius:"6px",backgroundColor:p===m?"#eff6ff":"white",cursor:"pointer",textAlign:"left"},children:[jsxRuntime.jsx("div",{style:{fontWeight:500,fontSize:"13px"},children:at[m]}),jsxRuntime.jsx("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:to[m]})]},m))})]}),T&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Target Element"}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"8px"},children:[jsxRuntime.jsx("input",{type:"text",value:u,onChange:m=>R(m.target.value),placeholder:"CSS selector (e.g., #my-button)",style:{flex:1,padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",fontFamily:"monospace"}}),jsxRuntime.jsx("button",{onClick:t,disabled:r,style:{padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:r?"#f3f4f6":"white",cursor:r?"wait":"pointer"},children:r?"Selecting...":"Select"})]}),jsxRuntime.jsx("p",{style:{fontSize:"11px",color:"#6b7280",marginTop:"4px"},children:'Click "Select" to pick an element on the page, or enter a CSS selector manually'})]}),jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Title"}),jsxRuntime.jsx("input",{type:"text",value:s,onChange:m=>a(m.target.value),placeholder:"Enter step title",style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Content"}),jsxRuntime.jsx("textarea",{value:l,onChange:m=>c(m.target.value),placeholder:"Enter step content (HTML supported)",rows:4,style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",resize:"vertical",fontFamily:"inherit"}})]}),(p==="tooltip"||p==="hotspot")&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Position"}),jsxRuntime.jsx("select",{value:f,onChange:m=>g(m.target.value),style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white"},children:oo.map(m=>jsxRuntime.jsx("option",{value:m.value,children:m.label},m.value))})]}),p==="banner"&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Banner Position"}),jsxRuntime.jsxs("select",{value:f==="bottom"?"bottom":"top",onChange:m=>g(m.target.value),style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white"},children:[jsxRuntime.jsx("option",{value:"top",children:"Top"}),jsxRuntime.jsx("option",{value:"bottom",children:"Bottom"})]})]}),p==="slideout"&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Slideout Side"}),jsxRuntime.jsxs("select",{value:f==="left"?"left":"right",onChange:m=>g(m.target.value),style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white"},children:[jsxRuntime.jsx("option",{value:"right",children:"Right"}),jsxRuntime.jsx("option",{value:"left",children:"Left"})]})]}),(p==="tooltip"||p==="modal")&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[jsxRuntime.jsx("input",{type:"checkbox",checked:S,onChange:m=>x(m.target.checked),style:{width:"16px",height:"16px"}}),jsxRuntime.jsx("span",{style:{fontSize:"13px",fontWeight:500},children:"Show backdrop overlay"})]}),jsxRuntime.jsx("p",{style:{fontSize:"11px",color:"#6b7280",marginTop:"4px",marginLeft:"24px"},children:"Dims the background to focus attention on the step"})]}),jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Advance When"}),jsxRuntime.jsx("select",{value:w,onChange:m=>b(m.target.value),style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white"},children:ro.map(m=>jsxRuntime.jsx("option",{value:m.value,children:m.label},m.value))})]}),w==="delay"&&jsxRuntime.jsxs("div",{style:{marginBottom:"20px"},children:[jsxRuntime.jsx("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:"Delay (seconds)"}),jsxRuntime.jsx("input",{type:"number",value:v/1e3,onChange:m=>E(Number(m.target.value)*1e3),min:1,max:60,style:{width:"100%",padding:"8px 12px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px"}})]})]})]})}function io(o){let e={},t=o.getAttribute("data-testid");if(t)return e.testId=t,e.css=`[data-testid="${t}"]`,e;if(o.id)return e.css=`#${CSS.escape(o.id)}`,e;let r=[],i=o,n=0,p=5;for(;i&&i!==document.body&&n<p;){let s=i.tagName.toLowerCase(),a=Array.from(i.classList).filter(f=>!f.startsWith("hover")&&!f.startsWith("focus")&&!f.startsWith("active")).slice(0,2);a.length>0&&(s+="."+a.map(f=>CSS.escape(f)).join("."));let l=i.parentElement;if(l){let f=Array.from(l.children).filter(g=>g.tagName===i.tagName);if(f.length>1){let g=f.indexOf(i)+1;s+=`:nth-of-type(${g})`;}}r.unshift(s);let c=r.join(" > ");try{if(document.querySelectorAll(c).length===1){e.css=c;break}}catch{}i=i.parentElement,n++;}!e.css&&r.length>0&&(e.css=r.join(" > "));let d=o.textContent?.trim();return d&&d.length<100&&d.length>2&&(e.text=d.slice(0,50)),e}function so(o){let e=0;if(o.css)try{e=document.querySelectorAll(o.css).length;}catch{}return o.testId&&(e=document.querySelectorAll(`[data-testid="${o.testId}"]`).length),{isUnique:e===1,count:e}}function pt({isActive:o,onSelect:e,onCancel:t,ignoreSelector:r="[data-census-builder]",zIndex:i=99999}){let[n,p]=react.useState(null),[d,s]=react.useState(null),[a,l]=react.useState(null),c=react.useRef(null),f=react.useCallback(()=>{if(!n){s(null);return}s(n.getBoundingClientRect());},[n]);react.useEffect(()=>{if(!o)return;let R=x=>{let b=document.elementsFromPoint(x.clientX,x.clientY).find(v=>!(c.current?.contains(v)||r&&v.closest(r)||v===document.body||v===document.documentElement));b!==n&&(p(b||null),l(b?io(b):null));},S=()=>{f();};return document.addEventListener("mousemove",R,true),window.addEventListener("scroll",S,true),window.addEventListener("resize",S),()=>{document.removeEventListener("mousemove",R,true),window.removeEventListener("scroll",S,true),window.removeEventListener("resize",S);}},[o,n,r,f]),react.useEffect(()=>{f();},[n,f]);let g=react.useCallback(R=>{R.preventDefault(),R.stopPropagation(),n&&a&&e(a,n);},[n,a,e]);if(react.useEffect(()=>{if(!o)return;let R=S=>{S.key==="Escape"&&t();};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[o,t]),!o)return null;let u=a?so(a):null;return jsxRuntime.jsxs("div",{ref:c,"data-census-builder":true,style:{position:"fixed",inset:0,zIndex:i,cursor:"crosshair"},onClick:g,children:[d&&jsxRuntime.jsx("div",{style:{position:"fixed",top:d.top,left:d.left,width:d.width,height:d.height,border:"2px solid #2563eb",borderRadius:"4px",backgroundColor:"rgba(37, 99, 235, 0.1)",pointerEvents:"none",transition:"all 0.1s ease-out"}}),d&&a&&jsxRuntime.jsxs("div",{style:{position:"fixed",top:Math.max(8,d.top-40),left:d.left,padding:"6px 10px",backgroundColor:"#1f2937",color:"white",fontSize:"12px",fontFamily:"monospace",borderRadius:"4px",maxWidth:"300px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",pointerEvents:"none",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},children:[jsxRuntime.jsx("span",{style:{color:"#9ca3af"},children:a.testId?"data-testid: ":""}),a.testId||a.css,u&&jsxRuntime.jsxs("span",{style:{marginLeft:"8px",color:u.isUnique?"#4ade80":"#fbbf24"},children:["(",u.count," match",u.count!==1?"es":"",")"]})]}),jsxRuntime.jsxs("div",{style:{position:"fixed",bottom:0,left:0,right:0,padding:"12px 20px",backgroundColor:"#1f2937",color:"white",display:"flex",alignItems:"center",justifyContent:"space-between",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"14px"},children:[jsxRuntime.jsxs("span",{children:["Click on any element to select it, or press ",jsxRuntime.jsx("kbd",{style:{padding:"2px 6px",backgroundColor:"#374151",borderRadius:"4px",marginLeft:"4px",marginRight:"4px"},children:"Esc"})," to cancel"]}),jsxRuntime.jsx("button",{onClick:R=>{R.stopPropagation(),t();},style:{padding:"6px 12px",border:"1px solid #4b5563",borderRadius:"4px",backgroundColor:"transparent",color:"white",cursor:"pointer"},children:"Cancel"})]})]})}function ao({isOpen:o,onClose:e,guideId:t,onSave:r,onPublish:i,trigger:n,className:p}){let[d,s]=react.useState(false),a=o??d,{guide:l,steps:c,selectedStep:f,selectedStepId:g,isLoading:u,isSaving:R,error:S,loadGuide:x,updateGuide:w,publishGuide:b,addStep:v,updateStep:E,deleteStep:k,moveStepUp:T,moveStepDown:m,setSelectedStepId:L,reset:U}=Oe(),j=react.useCallback(async()=>{s(true),t&&await x(t);},[t,x]),_=react.useCallback(()=>{s(false),U(),e?.();},[U,e]),G=react.useCallback(async()=>{if(l)try{await w({}),r?.(l);}catch{}},[l,w,r]),y=react.useCallback(async()=>{if(l)try{let P=await b();i?.(P);}catch{}},[l,b,i]),N=react.useCallback(async(P="tooltip")=>{try{await v({stepType:P,richContent:{title:"New Step",body:"Click to edit..."}});}catch{}},[v]);return n&&o===void 0?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{onClick:j,children:n}),a&&jsxRuntime.jsx(ct,{guide:l,steps:c,selectedStep:f,selectedStepId:g,isLoading:u,isSaving:R,error:S,onClose:_,onSave:G,onPublish:y,onAddStep:N,onSelectStep:L,onUpdateStep:E,onDeleteStep:k,onMoveStepUp:T,onMoveStepDown:m,className:p})]}):a?jsxRuntime.jsx(ct,{guide:l,steps:c,selectedStep:f,selectedStepId:g,isLoading:u,isSaving:R,error:S,onClose:_,onSave:G,onPublish:y,onAddStep:N,onSelectStep:L,onUpdateStep:E,onDeleteStep:k,onMoveStepUp:T,onMoveStepDown:m,className:p}):null}function ct({guide:o,steps:e,selectedStep:t,selectedStepId:r,isLoading:i,isSaving:n,error:p,onClose:d,onSave:s,onPublish:a,onAddStep:l,onSelectStep:c,onUpdateStep:f,onDeleteStep:g,onMoveStepUp:u,onMoveStepDown:R,className:S}){let[x,w]=react.useState(false),b={tooltip:"Tooltip",modal:"Modal",slideout:"Slideout",hotspot:"Hotspot",banner:"Banner"},v=react.useCallback((E,k)=>{t&&f(t.id,{selectorStrategy:E}),w(false);},[t,f]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(pt,{isActive:x,onSelect:v,onCancel:()=>w(false),ignoreSelector:"[data-census-builder]"}),jsxRuntime.jsxs("div",{className:S,"data-census-builder":true,style:{position:"fixed",inset:0,zIndex:9999,display:"flex",flexDirection:"column",backgroundColor:"#f8f9fa",fontFamily:"system-ui, -apple-system, sans-serif"},children:[jsxRuntime.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:"white",borderBottom:"1px solid #e5e7eb"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[jsxRuntime.jsx("button",{onClick:d,style:{padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white",cursor:"pointer"},children:"Close"}),jsxRuntime.jsx("h1",{style:{margin:0,fontSize:"18px",fontWeight:600},children:o?o.name:"Guide Builder"}),o?.status&&jsxRuntime.jsx("span",{style:{padding:"2px 8px",fontSize:"12px",borderRadius:"4px",backgroundColor:o.status==="published"?"#dcfce7":"#fef3c7",color:o.status==="published"?"#166534":"#92400e"},children:o.status})]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"8px"},children:[p&&jsxRuntime.jsx("span",{style:{color:"#dc2626",fontSize:"14px"},children:p.message}),jsxRuntime.jsx("button",{onClick:s,disabled:n||!o,style:{padding:"8px 16px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white",cursor:n?"wait":"pointer",opacity:n?.5:1},children:n?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:a,disabled:n||!o||o.status==="published",style:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#2563eb",color:"white",cursor:n?"wait":"pointer",opacity:n||o?.status==="published"?.5:1},children:"Publish"})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[jsxRuntime.jsxs("aside",{style:{width:"280px",backgroundColor:"white",borderRight:"1px solid #e5e7eb",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{padding:"16px",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:500},children:["Steps (",e.length,")"]}),jsxRuntime.jsx("button",{onClick:()=>l("tooltip"),disabled:!o,style:{padding:"6px 12px",fontSize:"13px",border:"none",borderRadius:"4px",backgroundColor:"#2563eb",color:"white",cursor:o?"pointer":"not-allowed",opacity:o?1:.5},children:"+ Add Step"})]}),jsxRuntime.jsx("div",{style:{flex:1,overflow:"auto",padding:"8px"},children:i?jsxRuntime.jsx("div",{style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:"Loading..."}):e.length===0?jsxRuntime.jsx("div",{style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:'No steps yet. Click "Add Step" to get started.'}):e.map((E,k)=>jsxRuntime.jsxs("div",{onClick:()=>c(E.id),style:{padding:"12px",marginBottom:"4px",borderRadius:"6px",backgroundColor:r===E.id?"#eff6ff":"white",border:`1px solid ${r===E.id?"#3b82f6":"#e5e7eb"}`,cursor:"pointer"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:500,fontSize:"14px"},children:[k+1,". ",b[E.step_type]]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px"},children:[jsxRuntime.jsx("button",{onClick:T=>{T.stopPropagation(),u(E.id);},disabled:k===0,style:{padding:"2px 6px",fontSize:"12px",border:"1px solid #d1d5db",borderRadius:"3px",backgroundColor:"white",cursor:k===0?"not-allowed":"pointer",opacity:k===0?.3:1},children:"Up"}),jsxRuntime.jsx("button",{onClick:T=>{T.stopPropagation(),R(E.id);},disabled:k===e.length-1,style:{padding:"2px 6px",fontSize:"12px",border:"1px solid #d1d5db",borderRadius:"3px",backgroundColor:"white",cursor:k===e.length-1?"not-allowed":"pointer",opacity:k===e.length-1?.3:1},children:"Down"}),jsxRuntime.jsx("button",{onClick:T=>{T.stopPropagation(),confirm("Delete this step?")&&g(E.id);},style:{padding:"2px 6px",fontSize:"12px",border:"1px solid #fecaca",borderRadius:"3px",backgroundColor:"#fef2f2",color:"#dc2626",cursor:"pointer"},children:"Delete"})]})]}),jsxRuntime.jsx("p",{style:{margin:"4px 0 0",fontSize:"13px",color:"#6b7280"},children:E.rich_content?.title||E.title||"Untitled"})]},E.id))})]}),jsxRuntime.jsxs("main",{style:{flex:1,display:"flex",flexDirection:"column",backgroundColor:"#f3f4f6"},children:[jsxRuntime.jsx("div",{style:{padding:"16px",borderBottom:"1px solid #e5e7eb",backgroundColor:"white"},children:jsxRuntime.jsx("span",{style:{fontWeight:500},children:"Preview"})}),jsxRuntime.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280"},children:t?jsxRuntime.jsxs("div",{style:{padding:"24px",backgroundColor:"white",borderRadius:"8px",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)",maxWidth:"400px",width:"100%"},children:[jsxRuntime.jsx("div",{style:{marginBottom:"12px"},children:jsxRuntime.jsx("span",{style:{padding:"4px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",backgroundColor:"#f3f4f6",color:"#6b7280",textTransform:"uppercase"},children:b[t.step_type]})}),jsxRuntime.jsx("h3",{style:{margin:"0 0 8px",fontSize:"16px"},children:t.rich_content?.title||t.title||"Step Preview"}),jsxRuntime.jsx("p",{style:{margin:0,color:"#4b5563"},children:t.rich_content?.body||t.content||"No content"}),t.rich_content?.media&&jsxRuntime.jsx("div",{style:{marginTop:"12px"},children:t.rich_content.media.type==="image"&&jsxRuntime.jsx("img",{src:t.rich_content.media.url,alt:t.rich_content.media.alt||"",style:{maxWidth:"100%",borderRadius:"4px"}})}),t.rich_content?.buttons&&t.rich_content.buttons.length>0&&jsxRuntime.jsx("div",{style:{marginTop:"16px",display:"flex",gap:"8px"},children:t.rich_content.buttons.map((E,k)=>jsxRuntime.jsx("span",{style:{padding:"6px 12px",fontSize:"13px",borderRadius:"4px",backgroundColor:E.style==="primary"?"#2563eb":"#f3f4f6",color:E.style==="primary"?"white":"#374151"},children:E.label},k))}),t.selector_strategy?.css&&jsxRuntime.jsxs("div",{style:{marginTop:"16px",padding:"8px",backgroundColor:"#f9fafb",borderRadius:"4px",fontSize:"11px",fontFamily:"monospace",color:"#6b7280"},children:["Target: ",t.selector_strategy.css]})]}):jsxRuntime.jsx("p",{children:"Select a step to preview"})})]}),jsxRuntime.jsx("aside",{style:{width:"360px",backgroundColor:"white",borderLeft:"1px solid #e5e7eb",display:"flex",flexDirection:"column",overflow:"hidden"},children:t?jsxRuntime.jsx(lt,{step:t,onUpdate:f,onSelectElement:()=>w(true),isSelectingElement:x}):jsxRuntime.jsx("div",{style:{padding:"16px"},children:jsxRuntime.jsx("p",{style:{color:"#6b7280"},children:"Select a step to edit its settings"})})})]})]})]})}function $e(o){let e=o.getBoundingClientRect();return {top:e.top+window.scrollY,left:e.left+window.scrollX,right:e.right+window.scrollX,bottom:e.bottom+window.scrollY,width:e.width,height:e.height}}function Ve(){return {width:window.innerWidth,height:window.innerHeight,scrollX:window.scrollX,scrollY:window.scrollY}}function He(o,e,t,r,i){let n=Ve(),{scrollX:p,scrollY:d,width:s,height:a}=n;switch(r){case "top":return o.top-d-t-i>0&&o.left-p+o.width/2-e/2>0&&o.left-p+o.width/2+e/2<s;case "bottom":return o.bottom-d+t+i<a&&o.left-p+o.width/2-e/2>0&&o.left-p+o.width/2+e/2<s;case "left":return o.left-p-e-i>0&&o.top-d+o.height/2-t/2>0&&o.top-d+o.height/2+t/2<a;case "right":return o.right-p+e+i<s&&o.top-d+o.height/2-t/2>0&&o.top-d+o.height/2+t/2<a;default:return true}}function lo(o,e,t,r){let i=["bottom","top","right","left"];for(let n of i)if(He(o,e,t,n,r))return n;return "bottom"}function we(o,e,t,r){let{preferredPosition:i,offset:n={x:0,y:0},containerPadding:p=10,arrowSize:d=8}=r,s=$e(o),a=Ve(),l=i;if(i==="auto")l=lo(s,e,t,p);else if(!He(s,e,t,i,p)){let k={top:"bottom",bottom:"top",left:"right",right:"left"}[i];k&&He(s,e,t,k,p)&&(l=k);}let c=0,f=0,g={},u=d+4;switch(l){case "top":c=s.top-t-u+n.y,f=s.left+s.width/2-e/2+n.x,g={left:e/2-d/2,top:t,transform:"rotate(180deg)"};break;case "bottom":c=s.bottom+u+n.y,f=s.left+s.width/2-e/2+n.x,g={left:e/2-d/2,top:-d};break;case "left":c=s.top+s.height/2-t/2+n.y,f=s.left-e-u+n.x,g={top:t/2-d/2,left:e,transform:"rotate(-90deg)"};break;case "right":c=s.top+s.height/2-t/2+n.y,f=s.right+u+n.x,g={top:t/2-d/2,left:-d,transform:"rotate(90deg)"};break}let R=a.scrollX+p,S=a.scrollX+a.width-e-p,x=a.scrollY+p,w=a.scrollY+a.height-t-p,b=f;f=Math.max(R,Math.min(S,f)),(l==="top"||l==="bottom")&&(g.left=(g.left||0)+(b-f));let v=c;return c=Math.max(x,Math.min(w,c)),(l==="left"||l==="right")&&(g.top=(g.top||0)+(v-c)),{top:c,left:f,placement:l,arrowPosition:g}}function ke(o,e=100){let t=o.getBoundingClientRect(),r=Ve(),i=t.top<e,n=t.bottom>r.height-e,p=t.left<e,d=t.right>r.width-e;(i||n||p||d)&&o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"});}function Ge(o){if(!o)return null;if(o.css)try{let e=document.querySelector(o.css);if(e)return e}catch{}if(o.testId){let e=document.querySelector(`[data-testid="${o.testId}"]`);if(e)return e}if(o.xpath)try{let e=document.evaluate(o.xpath,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null);if(e.singleNodeValue)return e.singleNodeValue}catch{}if(o.text){let e=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT),t;for(;t=e.nextNode();)if(t.textContent?.includes(o.text))return t.parentElement}return null}function gt(o,e=8){let t=o.getBoundingClientRect(),r={top:t.top-e,left:t.left-e,right:t.right+e,bottom:t.bottom+e,width:t.width+e*2,height:t.height+e*2};return `polygon(
|
|
2
|
+
0 0,
|
|
3
|
+
100% 0,
|
|
4
|
+
100% 100%,
|
|
5
|
+
0 100%,
|
|
6
|
+
0 0,
|
|
7
|
+
${r.left}px ${r.top}px,
|
|
8
|
+
${r.left}px ${r.bottom}px,
|
|
9
|
+
${r.right}px ${r.bottom}px,
|
|
10
|
+
${r.right}px ${r.top}px,
|
|
11
|
+
${r.left}px ${r.top}px
|
|
12
|
+
)`}function ee({visible:o,spotlightElement:e,spotlightPadding:t=8,onClick:r,dismissOnClick:i=false,zIndex:n=9998,opacity:p=.5}){let[d,s]=react.useState(),a=react.useCallback(()=>{s(e?gt(e,t):void 0);},[e,t]);return react.useEffect(()=>{if(o)return a(),window.addEventListener("scroll",a,true),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,true),window.removeEventListener("resize",a);}},[o,a]),o?jsxRuntime.jsx("div",{onClick:c=>{i&&r&&r(),c.stopPropagation();},style:{position:"fixed",inset:0,zIndex:n,backgroundColor:`rgba(0, 0, 0, ${p})`,clipPath:d,transition:"clip-path 0.2s ease-out",cursor:i?"pointer":"default",pointerEvents:"auto"},"aria-hidden":"true"}):null}function X({buttons:o,currentStep:e,isLastStep:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,accentColor:d="#2563eb"}){if(!o||o.length===0)return jsxRuntime.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"16px"},children:[jsxRuntime.jsx("div",{children:e>0&&jsxRuntime.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white",color:"#374151",cursor:"pointer"},children:"Back"})}),jsxRuntime.jsx("button",{onClick:t?n:r,style:{padding:"8px 16px",fontSize:"14px",border:"none",borderRadius:"6px",backgroundColor:d,color:"white",cursor:"pointer"},children:t?"Done":"Next"})]});let s=l=>{switch(l.action){case "next":r();break;case "prev":i();break;case "dismiss":n();break;case "url":l.url&&window.open(l.url,"_blank","noopener,noreferrer");break;case "custom":l.customAction&&p&&p(l.customAction);break}},a=l=>{switch(l){case "primary":return {padding:"8px 16px",fontSize:"14px",border:"none",borderRadius:"6px",backgroundColor:d,color:"white",cursor:"pointer"};case "text":return {padding:"8px 16px",fontSize:"14px",border:"none",borderRadius:"6px",backgroundColor:"transparent",color:d,cursor:"pointer"};default:return {padding:"8px 16px",fontSize:"14px",border:"1px solid #d1d5db",borderRadius:"6px",backgroundColor:"white",color:"#374151",cursor:"pointer"}}};return jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px"},children:o.map((l,c)=>jsxRuntime.jsx("button",{onClick:()=>s(l),style:a(l.style),children:l.label},c))})}function Y({step:o,textColor:e="#1f2937",showTitle:t=true}){let r=o.rich_content,i=r?.title||o.title,n=r?.body||o.content;return jsxRuntime.jsxs("div",{children:[t&&i&&jsxRuntime.jsx("h3",{style:{margin:"0 0 8px 0",fontSize:"16px",fontWeight:600,color:e,lineHeight:1.4},children:i}),n&&jsxRuntime.jsx("div",{style:{fontSize:"14px",color:e,opacity:.9,lineHeight:1.5},dangerouslySetInnerHTML:n.includes("<")?{__html:mo(n)}:void 0,children:n.includes("<")?null:n}),r?.media&&jsxRuntime.jsxs("div",{style:{marginTop:"12px"},children:[r.media.type==="image"&&jsxRuntime.jsx("img",{src:r.media.url,alt:r.media.alt||"",style:{maxWidth:"100%",height:"auto",borderRadius:"4px"}}),r.media.type==="video"&&jsxRuntime.jsx("video",{src:r.media.url,controls:true,style:{maxWidth:"100%",height:"auto",borderRadius:"4px"},children:"Your browser does not support the video tag."})]})]})}function mo(o){let e=["p","br","b","i","strong","em","u","s","h1","h2","h3","h4","h5","h6","ul","ol","li","a","code","pre","blockquote","span","div"];if(typeof document>"u")return o.replace(/<[^>]*>/g,"");let t=document.createElement("div");return t.innerHTML=o,t.querySelectorAll("script").forEach(n=>n.remove()),t.querySelectorAll("*").forEach(n=>{if(!e.includes(n.tagName.toLowerCase())){let d=document.createTextNode(n.textContent||"");n.parentNode?.replaceChild(d,n);return}Array.from(n.attributes).forEach(d=>{let s=d.name.toLowerCase();if(s.startsWith("on")&&n.removeAttribute(d.name),s==="href"||s==="src"){let l=d.value.toLowerCase().trim();(l.startsWith("javascript:")||l.startsWith("data:"))&&n.removeAttribute(d.name);}["href","target","rel","class","style"].includes(s)||n.removeAttribute(d.name);}),n.tagName.toLowerCase()==="a"&&(n.setAttribute("rel","noopener noreferrer"),n.setAttribute("target","_blank"));}),t.innerHTML}function ye({step:o,currentStep:e,totalSteps:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,showProgress:d=true,globalStyle:s,zIndex:a=9999}){let l=react.useRef(null),[c,f]=react.useState(null),[g,u]=react.useState(null),[R,S]=react.useState(false),x={...s,...o.style_config},w=x.backgroundColor||"white",b=x.textColor||"#1f2937",v=x.accentColor||"#2563eb",E=x.borderRadius||8;react.useEffect(()=>{let T=Ge(o.selector_strategy);f(T),T&&ke(T,120);},[o.selector_strategy]);let k=react.useCallback(()=>{if(!c||!l.current)return;let T=l.current.getBoundingClientRect(),m=we(c,T.width,T.height,{preferredPosition:o.tooltip_position||o.display_config?.position||"auto",offset:o.display_config?.offset,arrowSize:8});u(m),S(true);},[c,o.tooltip_position,o.display_config]);return react.useEffect(()=>{let T=setTimeout(k,10);return window.addEventListener("scroll",k,true),window.addEventListener("resize",k),()=>{clearTimeout(T),window.removeEventListener("scroll",k,true),window.removeEventListener("resize",k);}},[k]),c?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ee,{visible:o.display_config?.backdrop!==false,spotlightElement:c,spotlightPadding:o.display_config?.spotlightPadding||8,dismissOnClick:false}),jsxRuntime.jsxs("div",{ref:l,style:{position:"absolute",top:g?.top||0,left:g?.left||0,zIndex:a,padding:"16px 20px",backgroundColor:w,color:b,borderRadius:E,boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",maxWidth:o.display_config?.width||320,fontFamily:"system-ui, -apple-system, sans-serif",opacity:R?1:0,transition:"opacity 0.15s ease-out"},children:[g&&jsxRuntime.jsx("div",{style:{position:"absolute",width:0,height:0,borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderBottom:`8px solid ${w}`,top:g.arrowPosition.top,left:g.arrowPosition.left,transform:g.arrowPosition.transform}}),jsxRuntime.jsx(Y,{step:o,textColor:b}),d&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6b7280",marginTop:"8px"},children:["Step ",e+1," of ",t]}),jsxRuntime.jsx(X,{buttons:o.rich_content?.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,accentColor:v})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ee,{visible:true}),jsxRuntime.jsxs("div",{style:{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",zIndex:a,padding:"24px",backgroundColor:w,color:b,borderRadius:E,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",maxWidth:"400px",width:"90%",fontFamily:"system-ui, -apple-system, sans-serif"},children:[jsxRuntime.jsx(Y,{step:o,textColor:b}),d&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6b7280",marginTop:"8px"},children:["Step ",e+1," of ",t]}),jsxRuntime.jsx(X,{buttons:o.rich_content?.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,accentColor:v})]})]})}function Pe({step:o,currentStep:e,totalSteps:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,showProgress:d=true,globalStyle:s,zIndex:a=9999}){let l={...s,...o.style_config},c=l.backgroundColor||"white",f=l.textColor||"#1f2937",g=l.accentColor||"#2563eb",u=l.borderRadius||12,R=o.display_config||{},S=R.width||480,x=R.position||"center",w=R.backdrop!==false;return react.useEffect(()=>{let v=E=>{E.key==="Escape"&&n();};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[n]),react.useEffect(()=>{let v=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=v;}},[]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ee,{visible:true,onClick:w?n:void 0,dismissOnClick:w,opacity:.6}),jsxRuntime.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"guide-modal-title",style:{position:"fixed",...(()=>{switch(x){case "top":return {top:"10%",left:"50%",transform:"translateX(-50%)"};case "bottom":return {bottom:"10%",left:"50%",transform:"translateX(-50%)"};default:return {top:"50%",left:"50%",transform:"translate(-50%, -50%)"}}})(),zIndex:a,width:"90%",maxWidth:S,maxHeight:"85vh",overflow:"auto",padding:"24px",backgroundColor:c,color:f,borderRadius:u,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",fontFamily:"system-ui, -apple-system, sans-serif"},children:[jsxRuntime.jsx("button",{onClick:n,"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",border:"none",borderRadius:"50%",backgroundColor:"transparent",color:"#9ca3af",fontSize:"20px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s"},onMouseEnter:v=>v.currentTarget.style.color="#6b7280",onMouseLeave:v=>v.currentTarget.style.color="#9ca3af",children:"\xD7"}),jsxRuntime.jsx(Y,{step:o,textColor:f}),d&&t>1&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"16px"},children:Array.from({length:t}).map((v,E)=>jsxRuntime.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:E===e?g:"#e5e7eb",transition:"background-color 0.15s"}},E))}),jsxRuntime.jsx(X,{buttons:o.rich_content?.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,accentColor:g})]})]})}function Ee({step:o,currentStep:e,totalSteps:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,showProgress:d=true,globalStyle:s,zIndex:a=9999}){let[l,c]=react.useState(true),f={...s,...o.style_config},g=f.backgroundColor||"white",u=f.textColor||"#1f2937",R=f.accentColor||"#2563eb",S=f.borderRadius||0,x=o.display_config||{},w=x.width||400,b=x.position==="left"?"left":"right",v=x.backdrop!==false;return react.useEffect(()=>{let k=setTimeout(()=>c(false),50);return ()=>clearTimeout(k)},[]),react.useEffect(()=>{let k=T=>{T.key==="Escape"&&n();};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[n]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[v&&jsxRuntime.jsx(ee,{visible:true,onClick:n,dismissOnClick:true,opacity:.4}),jsxRuntime.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"guide-slideout-title",style:(()=>{let k={position:"fixed",top:0,bottom:0,width:"90%",maxWidth:w,zIndex:a,backgroundColor:g,color:u,boxShadow:b==="right"?"-10px 0 30px -5px rgba(0, 0, 0, 0.1)":"10px 0 30px -5px rgba(0, 0, 0, 0.1)",fontFamily:"system-ui, -apple-system, sans-serif",overflow:"auto",transition:"transform 0.3s ease-out"};return b==="right"?{...k,right:0,borderTopLeftRadius:S,borderBottomLeftRadius:S,transform:l?"translateX(100%)":"translateX(0)"}:{...k,left:0,borderTopRightRadius:S,borderBottomRightRadius:S,transform:l?"translateX(-100%)":"translateX(0)"}})(),children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:"1px solid #e5e7eb",position:"sticky",top:0,backgroundColor:g,zIndex:1},children:[jsxRuntime.jsx("h2",{id:"guide-slideout-title",style:{margin:0,fontSize:"18px",fontWeight:600,color:u},children:o.rich_content?.title||o.title||"Guide"}),jsxRuntime.jsx("button",{onClick:n,"aria-label":"Close",style:{width:"28px",height:"28px",border:"none",borderRadius:"50%",backgroundColor:"transparent",color:"#9ca3af",fontSize:"20px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),jsxRuntime.jsxs("div",{style:{padding:"20px"},children:[jsxRuntime.jsx(Y,{step:o,textColor:u,showTitle:false}),d&&t>1&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6b7280",marginTop:"16px"},children:["Step ",e+1," of ",t]})]}),jsxRuntime.jsx("div",{style:{padding:"16px 20px",borderTop:"1px solid #e5e7eb",position:"sticky",bottom:0,backgroundColor:g},children:jsxRuntime.jsx(X,{buttons:o.rich_content?.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,accentColor:R})})]})]})}function _e({step:o,currentStep:e,totalSteps:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,showProgress:d=true,globalStyle:s,zIndex:a=9999}){let l=react.useRef(null),[c,f]=react.useState(null),[g,u]=react.useState(false),[R,S]=react.useState({top:0,left:0}),[x,w]=react.useState(null),b={...s,...o.style_config},v=b.backgroundColor||"white",E=b.textColor||"#1f2937",k=b.accentColor||"#2563eb",T=b.borderRadius||8,m=o.display_config||{};react.useEffect(()=>{let G=Ge(o.selector_strategy);f(G),G&&ke(G,120);},[o.selector_strategy]);let U=react.useCallback(()=>{if(!c)return;let G=$e(c);S({top:G.top-8,left:G.right-8});},[c]),j=react.useCallback(()=>{if(!c||!l.current||!g)return;let G=l.current.getBoundingClientRect(),y=we(c,G.width,G.height,{preferredPosition:o.tooltip_position||"auto",offset:o.display_config?.offset,arrowSize:8});w(y);},[c,g,o.tooltip_position,o.display_config?.offset]);if(react.useEffect(()=>(U(),g&&setTimeout(j,10),window.addEventListener("scroll",U,true),window.addEventListener("resize",U),()=>{window.removeEventListener("scroll",U,true),window.removeEventListener("resize",U);}),[U,j,g]),react.useEffect(()=>{if(!g)return;let G=y=>{l.current&&!l.current.contains(y.target)&&u(false);};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[g]),!c)return null;let _=`
|
|
13
|
+
@keyframes census-hotspot-pulse {
|
|
14
|
+
0% {
|
|
15
|
+
transform: scale(1);
|
|
16
|
+
box-shadow: 0 0 0 0 ${k}66;
|
|
17
|
+
}
|
|
18
|
+
70% {
|
|
19
|
+
transform: scale(1.1);
|
|
20
|
+
box-shadow: 0 0 0 10px ${k}00;
|
|
21
|
+
}
|
|
22
|
+
100% {
|
|
23
|
+
transform: scale(1);
|
|
24
|
+
box-shadow: 0 0 0 0 ${k}00;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{dangerouslySetInnerHTML:{__html:_}}),jsxRuntime.jsx("button",{onClick:()=>u(!g),"aria-label":"Show more information","aria-expanded":g,style:{position:"absolute",top:R.top,left:R.left,width:"24px",height:"24px",borderRadius:"50%",border:"none",backgroundColor:k,color:"white",cursor:"pointer",zIndex:a,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,animation:!g?"census-hotspot-pulse 2s infinite":"none",transition:"transform 0.15s"},children:"?"}),g&&jsxRuntime.jsxs("div",{ref:l,style:{position:"absolute",top:x?.top||R.top+30,left:x?.left||R.left-140,zIndex:a+1,padding:"16px 20px",backgroundColor:v,color:E,borderRadius:T,boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",maxWidth:m.width||300,fontFamily:"system-ui, -apple-system, sans-serif"},children:[x&&jsxRuntime.jsx("div",{style:{position:"absolute",width:0,height:0,borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderBottom:`8px solid ${v}`,top:x.arrowPosition.top,left:x.arrowPosition.left,transform:x.arrowPosition.transform}}),jsxRuntime.jsx(Y,{step:o,textColor:E}),d&&t>1&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6b7280",marginTop:"8px"},children:["Step ",e+1," of ",t]}),jsxRuntime.jsx(X,{buttons:o.rich_content?.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:()=>{u(false),r();},onPrev:()=>{u(false),i();},onDismiss:()=>{u(false),n();},onCustomAction:p,accentColor:k})]})]})}var Ie={info:{bg:"#eff6ff",text:"#1e40af",icon:"i"},warning:{bg:"#fef3c7",text:"#92400e",icon:"!"},success:{bg:"#dcfce7",text:"#166534",icon:"\u2713"},custom:{bg:"#2563eb",text:"white",icon:""}};function Be({step:o,currentStep:e,totalSteps:t,onNext:r,onPrev:i,onDismiss:n,onCustomAction:p,showProgress:d=true,globalStyle:s,zIndex:a=9999}){let [l,c]=react.useState(true),[f,g]=react.useState(true),u={...s,...o.style_config},S=(o.display_config||{}).bannerPosition||"top",x="custom",w=u.backgroundColor||Ie[x].bg,b=u.textColor||Ie[x].text;react.useEffect(()=>{let U=setTimeout(()=>c(false),50);return ()=>clearTimeout(U)},[]);let E=()=>{c(true),setTimeout(()=>{g(false),n();},200);};if(!f)return null;let k=o.rich_content,T=k?.title||o.title,m=k?.body||o.content,L=k?.buttons&&k.buttons.length>0;return jsxRuntime.jsx("div",{role:"alert",style:{position:"fixed",left:0,right:0,[S]:0,zIndex:a,padding:"12px 20px",backgroundColor:w,color:b,boxShadow:S==="top"?"0 4px 6px -1px rgba(0, 0, 0, 0.1)":"0 -4px 6px -1px rgba(0, 0, 0, 0.1)",fontFamily:"system-ui, -apple-system, sans-serif",transform:l?S==="top"?"translateY(-100%)":"translateY(100%)":"translateY(0)",transition:"transform 0.2s ease-out"},children:jsxRuntime.jsxs("div",{style:{maxWidth:"1200px",margin:"0 auto",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"16px"},children:[jsxRuntime.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",gap:"12px"},children:[Ie[x].icon,jsxRuntime.jsxs("div",{style:{flex:1},children:[T&&jsxRuntime.jsx("strong",{style:{display:"block",marginBottom:m?"2px":0},children:T}),m&&jsxRuntime.jsx("span",{style:{opacity:.9,fontSize:"14px"},children:m})]}),d&&t>1&&jsxRuntime.jsxs("span",{style:{fontSize:"12px",opacity:.7,flexShrink:0},children:[e+1,"/",t]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0},children:[L?jsxRuntime.jsx(X,{buttons:k.buttons,currentStep:e,totalSteps:t,isLastStep:e===t-1,onNext:r,onPrev:i,onDismiss:E,onCustomAction:p,accentColor:"white"}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:e<t-1?jsxRuntime.jsx("button",{onClick:r,style:{padding:"6px 12px",fontSize:"14px",border:"none",borderRadius:"4px",backgroundColor:"rgba(255,255,255,0.2)",color:b,cursor:"pointer"},children:"Next"}):jsxRuntime.jsx("button",{onClick:E,style:{padding:"6px 12px",fontSize:"14px",border:"none",borderRadius:"4px",backgroundColor:"rgba(255,255,255,0.2)",color:b,cursor:"pointer"},children:"Got it"})}),jsxRuntime.jsx("button",{onClick:E,"aria-label":"Dismiss",style:{width:"28px",height:"28px",border:"none",borderRadius:"4px",backgroundColor:"transparent",color:b,opacity:.7,fontSize:"18px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]})]})})}function Ro({guide:o,onComplete:e,onDismiss:t,onStepChange:r,onCustomAction:i,globalStyle:n,startStep:p=0,zIndex:d=9999}){let[s,a]=react.useState(p),[l,c]=react.useState(true),f=o.guide_steps||[],g=f.length,u=f[s];react.useEffect(()=>{r?.(s,g);},[s,g,r]);let R=react.useCallback(()=>{s<g-1?a(v=>v+1):(c(false),e?.(o));},[s,g,o,e]),S=react.useCallback(()=>{s>0&&a(v=>v-1);},[s]),x=react.useCallback(()=>{c(false),t?.(o,s);},[o,s,t]),w=react.useCallback(v=>{u&&i?.(v,u);},[u,i]);if(!l||!u||f.length===0)return null;let b={step:u,currentStep:s,totalSteps:g,onNext:R,onPrev:S,onDismiss:x,onCustomAction:w,showProgress:o.show_progress!==false,globalStyle:{...o.theme,...n},zIndex:d};switch(u.step_type){case "tooltip":return jsxRuntime.jsx(ye,{...b});case "modal":return jsxRuntime.jsx(Pe,{...b});case "slideout":return jsxRuntime.jsx(Ee,{...b});case "hotspot":return jsxRuntime.jsx(_e,{...b});case "banner":return jsxRuntime.jsx(Be,{...b});default:return jsxRuntime.jsx(ye,{...b})}}exports.Backdrop=ee;exports.BannerStep=Be;exports.CensusProvider=Pt;exports.FeedbackButton=Dt;exports.GuideBuilder=ao;exports.GuideRenderer=Ro;exports.HelpCenter=Jt;exports.HotspotStep=_e;exports.KnowledgeBase=Nt;exports.ModalStep=Pe;exports.Requests=Vt;exports.SlideoutStep=Ee;exports.StepButtons=X;exports.StepContent=Y;exports.TooltipStep=ye;exports.useArticle=fe;exports.useArticles=ue;exports.useCensus=Et;exports.useCensusContext=O;exports.useFeatureGroups=qe;exports.useFeedback=Le;exports.useGuideBuilder=Oe;exports.useGuideRenderer=zt;exports.useGuides=Ft;exports.useIdentify=Tt;exports.useRequests=ne;exports.useTrack=Bt;//# sourceMappingURL=index.cjs.map
|
|
3
28
|
//# sourceMappingURL=index.cjs.map
|