@census-ai/census-sdk 0.2.0 → 0.2.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.
@@ -188,6 +188,21 @@ interface Request {
188
188
  rating: number | null;
189
189
  helpful: boolean | null;
190
190
  metadata: Record<string, unknown>;
191
+ vote_count: number;
192
+ user_has_voted: boolean;
193
+ is_own: boolean;
194
+ }
195
+ /**
196
+ * Feedback visibility setting
197
+ */
198
+ type FeedbackVisibility = 'own' | 'organization' | 'all';
199
+ /**
200
+ * Project settings for requests
201
+ */
202
+ interface RequestsSettings {
203
+ feedbackVisibility: FeedbackVisibility;
204
+ allowVoting: boolean;
205
+ allowRequestCreation: boolean;
191
206
  }
192
207
  /**
193
208
  * Options for fetching requests
@@ -223,6 +238,7 @@ interface RequestsResponse {
223
238
  offset: number;
224
239
  hasMore: boolean;
225
240
  };
241
+ settings: RequestsSettings;
226
242
  }
227
243
  /**
228
244
  * Position for floating UI elements
@@ -442,6 +458,36 @@ interface GuidesResponse {
442
458
  completedGuides: string[];
443
459
  }
444
460
  type GuideEventType = 'started' | 'step_viewed' | 'step_completed' | 'completed' | 'skipped' | 'dismissed';
461
+ /**
462
+ * A feature within a feature group
463
+ */
464
+ interface Feature {
465
+ id: string;
466
+ name: string;
467
+ slug: string;
468
+ description: string | null;
469
+ status: string;
470
+ article_count: number;
471
+ }
472
+ /**
473
+ * A group of related features
474
+ */
475
+ interface FeatureGroup {
476
+ id: string;
477
+ name: string;
478
+ slug: string;
479
+ description: string | null;
480
+ color: string | null;
481
+ features: Feature[];
482
+ feature_count: number;
483
+ article_count: number;
484
+ }
485
+ /**
486
+ * Response from feature groups endpoint
487
+ */
488
+ interface FeatureGroupsResponse {
489
+ feature_groups: FeatureGroup[];
490
+ }
445
491
  interface GuideAnalyticsEvent {
446
492
  guideId: string;
447
493
  eventType: GuideEventType;
@@ -563,6 +609,21 @@ declare class CensusClient {
563
609
  * ```
564
610
  */
565
611
  getArticle(slugOrId: string): Promise<Article | null>;
612
+ /**
613
+ * Fetch feature groups with their features and article counts.
614
+ * Used for navigation in the knowledge base.
615
+ *
616
+ * @returns Feature groups with nested features
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * const { feature_groups } = await census.getFeatureGroups();
621
+ * feature_groups.forEach(group => {
622
+ * console.log(group.name, group.features.length);
623
+ * });
624
+ * ```
625
+ */
626
+ getFeatureGroups(): Promise<FeatureGroupsResponse>;
566
627
  /**
567
628
  * Fetch the current user's submitted requests (feedback, bugs, feature requests).
568
629
  * Requires a user to be identified first.
@@ -583,6 +644,29 @@ declare class CensusClient {
583
644
  * ```
584
645
  */
585
646
  getRequests(options?: RequestsOptions): Promise<RequestsResponse>;
647
+ /**
648
+ * Vote on a feedback request (toggle).
649
+ * If the user has already voted, removes the vote.
650
+ * If the user hasn't voted, adds a vote.
651
+ *
652
+ * @param feedbackId - ID of the feedback to vote on
653
+ * @returns Vote result with action taken and new vote count
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * // Vote on a feedback request
658
+ * const result = await census.vote('feedback-id-123');
659
+ * console.log(result.action); // 'added' or 'removed'
660
+ * console.log(result.vote_count); // 5
661
+ * console.log(result.user_has_voted); // true
662
+ * ```
663
+ */
664
+ vote(feedbackId: string): Promise<{
665
+ success: boolean;
666
+ action: 'added' | 'removed';
667
+ vote_count: number;
668
+ user_has_voted: boolean;
669
+ }>;
586
670
  /**
587
671
  * Track a custom analytics event.
588
672
  *
@@ -889,7 +973,7 @@ declare function useArticle(slugOrId: string): {
889
973
  * @example
890
974
  * ```tsx
891
975
  * function MyRequests() {
892
- * const { requests, isLoading, error, refetch } = useRequests();
976
+ * const { requests, isLoading, error, refetch, settings } = useRequests();
893
977
  *
894
978
  * if (isLoading) return <p>Loading...</p>;
895
979
  * if (error) return <p>Error: {error.message}</p>;
@@ -912,10 +996,44 @@ declare function useRequests(options?: RequestsOptions): {
912
996
  offset: number;
913
997
  hasMore: boolean;
914
998
  } | undefined;
999
+ settings: RequestsSettings;
915
1000
  isLoading: boolean;
916
1001
  error: Error | null;
917
1002
  refetch: () => Promise<void>;
918
1003
  };
1004
+ /**
1005
+ * Hook for voting on requests.
1006
+ *
1007
+ * @returns Object with vote function and loading state
1008
+ *
1009
+ * @example
1010
+ * ```tsx
1011
+ * function VoteButton({ feedbackId }: { feedbackId: string }) {
1012
+ * const { vote, isVoting } = useVote();
1013
+ *
1014
+ * const handleVote = async () => {
1015
+ * const result = await vote(feedbackId);
1016
+ * console.log('Voted:', result.action); // 'added' or 'removed'
1017
+ * };
1018
+ *
1019
+ * return (
1020
+ * <button onClick={handleVote} disabled={isVoting}>
1021
+ * Vote
1022
+ * </button>
1023
+ * );
1024
+ * }
1025
+ * ```
1026
+ */
1027
+ declare function useVote(): {
1028
+ vote: (feedbackId: string) => Promise<{
1029
+ success: boolean;
1030
+ action: "added" | "removed";
1031
+ vote_count: number;
1032
+ user_has_voted: boolean;
1033
+ }>;
1034
+ isVoting: boolean;
1035
+ error: Error | null;
1036
+ };
919
1037
  /**
920
1038
  * Hook for tracking events.
921
1039
  *
@@ -943,6 +1061,37 @@ declare function useTrack(): {
943
1061
  properties?: Record<string, unknown>;
944
1062
  }>) => Promise<void>;
945
1063
  };
1064
+ /**
1065
+ * Hook for fetching feature groups with their features.
1066
+ *
1067
+ * @returns Object with feature groups data and loading state
1068
+ *
1069
+ * @example
1070
+ * ```tsx
1071
+ * function FeatureNav() {
1072
+ * const { featureGroups, isLoading, error } = useFeatureGroups();
1073
+ *
1074
+ * if (isLoading) return <p>Loading...</p>;
1075
+ * if (error) return <p>Error: {error.message}</p>;
1076
+ *
1077
+ * return (
1078
+ * <ul>
1079
+ * {featureGroups.map(group => (
1080
+ * <li key={group.id}>
1081
+ * {group.name} ({group.feature_count} features)
1082
+ * </li>
1083
+ * ))}
1084
+ * </ul>
1085
+ * );
1086
+ * }
1087
+ * ```
1088
+ */
1089
+ declare function useFeatureGroups(): {
1090
+ featureGroups: FeatureGroup[];
1091
+ isLoading: boolean;
1092
+ error: Error | null;
1093
+ refetch: () => Promise<void>;
1094
+ };
946
1095
 
947
1096
  /**
948
1097
  * Floating feedback button component.
@@ -1010,4 +1159,4 @@ declare function KnowledgeBase({ showSearch, showCategories, defaultCategory, th
1010
1159
  */
1011
1160
  declare function Requests({ status, type, limit, className, showEmptyState, onRequestClick, }: RequestsProps): react_jsx_runtime.JSX.Element | null;
1012
1161
 
1013
- export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeedback, useIdentify, useRequests, useTrack };
1162
+ export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, type Feature, type FeatureGroup, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type FeedbackVisibility, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type RequestsSettings, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeatureGroups, useFeedback, useIdentify, useRequests, useTrack, useVote };
@@ -188,6 +188,21 @@ interface Request {
188
188
  rating: number | null;
189
189
  helpful: boolean | null;
190
190
  metadata: Record<string, unknown>;
191
+ vote_count: number;
192
+ user_has_voted: boolean;
193
+ is_own: boolean;
194
+ }
195
+ /**
196
+ * Feedback visibility setting
197
+ */
198
+ type FeedbackVisibility = 'own' | 'organization' | 'all';
199
+ /**
200
+ * Project settings for requests
201
+ */
202
+ interface RequestsSettings {
203
+ feedbackVisibility: FeedbackVisibility;
204
+ allowVoting: boolean;
205
+ allowRequestCreation: boolean;
191
206
  }
192
207
  /**
193
208
  * Options for fetching requests
@@ -223,6 +238,7 @@ interface RequestsResponse {
223
238
  offset: number;
224
239
  hasMore: boolean;
225
240
  };
241
+ settings: RequestsSettings;
226
242
  }
227
243
  /**
228
244
  * Position for floating UI elements
@@ -442,6 +458,36 @@ interface GuidesResponse {
442
458
  completedGuides: string[];
443
459
  }
444
460
  type GuideEventType = 'started' | 'step_viewed' | 'step_completed' | 'completed' | 'skipped' | 'dismissed';
461
+ /**
462
+ * A feature within a feature group
463
+ */
464
+ interface Feature {
465
+ id: string;
466
+ name: string;
467
+ slug: string;
468
+ description: string | null;
469
+ status: string;
470
+ article_count: number;
471
+ }
472
+ /**
473
+ * A group of related features
474
+ */
475
+ interface FeatureGroup {
476
+ id: string;
477
+ name: string;
478
+ slug: string;
479
+ description: string | null;
480
+ color: string | null;
481
+ features: Feature[];
482
+ feature_count: number;
483
+ article_count: number;
484
+ }
485
+ /**
486
+ * Response from feature groups endpoint
487
+ */
488
+ interface FeatureGroupsResponse {
489
+ feature_groups: FeatureGroup[];
490
+ }
445
491
  interface GuideAnalyticsEvent {
446
492
  guideId: string;
447
493
  eventType: GuideEventType;
@@ -563,6 +609,21 @@ declare class CensusClient {
563
609
  * ```
564
610
  */
565
611
  getArticle(slugOrId: string): Promise<Article | null>;
612
+ /**
613
+ * Fetch feature groups with their features and article counts.
614
+ * Used for navigation in the knowledge base.
615
+ *
616
+ * @returns Feature groups with nested features
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * const { feature_groups } = await census.getFeatureGroups();
621
+ * feature_groups.forEach(group => {
622
+ * console.log(group.name, group.features.length);
623
+ * });
624
+ * ```
625
+ */
626
+ getFeatureGroups(): Promise<FeatureGroupsResponse>;
566
627
  /**
567
628
  * Fetch the current user's submitted requests (feedback, bugs, feature requests).
568
629
  * Requires a user to be identified first.
@@ -583,6 +644,29 @@ declare class CensusClient {
583
644
  * ```
584
645
  */
585
646
  getRequests(options?: RequestsOptions): Promise<RequestsResponse>;
647
+ /**
648
+ * Vote on a feedback request (toggle).
649
+ * If the user has already voted, removes the vote.
650
+ * If the user hasn't voted, adds a vote.
651
+ *
652
+ * @param feedbackId - ID of the feedback to vote on
653
+ * @returns Vote result with action taken and new vote count
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * // Vote on a feedback request
658
+ * const result = await census.vote('feedback-id-123');
659
+ * console.log(result.action); // 'added' or 'removed'
660
+ * console.log(result.vote_count); // 5
661
+ * console.log(result.user_has_voted); // true
662
+ * ```
663
+ */
664
+ vote(feedbackId: string): Promise<{
665
+ success: boolean;
666
+ action: 'added' | 'removed';
667
+ vote_count: number;
668
+ user_has_voted: boolean;
669
+ }>;
586
670
  /**
587
671
  * Track a custom analytics event.
588
672
  *
@@ -889,7 +973,7 @@ declare function useArticle(slugOrId: string): {
889
973
  * @example
890
974
  * ```tsx
891
975
  * function MyRequests() {
892
- * const { requests, isLoading, error, refetch } = useRequests();
976
+ * const { requests, isLoading, error, refetch, settings } = useRequests();
893
977
  *
894
978
  * if (isLoading) return <p>Loading...</p>;
895
979
  * if (error) return <p>Error: {error.message}</p>;
@@ -912,10 +996,44 @@ declare function useRequests(options?: RequestsOptions): {
912
996
  offset: number;
913
997
  hasMore: boolean;
914
998
  } | undefined;
999
+ settings: RequestsSettings;
915
1000
  isLoading: boolean;
916
1001
  error: Error | null;
917
1002
  refetch: () => Promise<void>;
918
1003
  };
1004
+ /**
1005
+ * Hook for voting on requests.
1006
+ *
1007
+ * @returns Object with vote function and loading state
1008
+ *
1009
+ * @example
1010
+ * ```tsx
1011
+ * function VoteButton({ feedbackId }: { feedbackId: string }) {
1012
+ * const { vote, isVoting } = useVote();
1013
+ *
1014
+ * const handleVote = async () => {
1015
+ * const result = await vote(feedbackId);
1016
+ * console.log('Voted:', result.action); // 'added' or 'removed'
1017
+ * };
1018
+ *
1019
+ * return (
1020
+ * <button onClick={handleVote} disabled={isVoting}>
1021
+ * Vote
1022
+ * </button>
1023
+ * );
1024
+ * }
1025
+ * ```
1026
+ */
1027
+ declare function useVote(): {
1028
+ vote: (feedbackId: string) => Promise<{
1029
+ success: boolean;
1030
+ action: "added" | "removed";
1031
+ vote_count: number;
1032
+ user_has_voted: boolean;
1033
+ }>;
1034
+ isVoting: boolean;
1035
+ error: Error | null;
1036
+ };
919
1037
  /**
920
1038
  * Hook for tracking events.
921
1039
  *
@@ -943,6 +1061,37 @@ declare function useTrack(): {
943
1061
  properties?: Record<string, unknown>;
944
1062
  }>) => Promise<void>;
945
1063
  };
1064
+ /**
1065
+ * Hook for fetching feature groups with their features.
1066
+ *
1067
+ * @returns Object with feature groups data and loading state
1068
+ *
1069
+ * @example
1070
+ * ```tsx
1071
+ * function FeatureNav() {
1072
+ * const { featureGroups, isLoading, error } = useFeatureGroups();
1073
+ *
1074
+ * if (isLoading) return <p>Loading...</p>;
1075
+ * if (error) return <p>Error: {error.message}</p>;
1076
+ *
1077
+ * return (
1078
+ * <ul>
1079
+ * {featureGroups.map(group => (
1080
+ * <li key={group.id}>
1081
+ * {group.name} ({group.feature_count} features)
1082
+ * </li>
1083
+ * ))}
1084
+ * </ul>
1085
+ * );
1086
+ * }
1087
+ * ```
1088
+ */
1089
+ declare function useFeatureGroups(): {
1090
+ featureGroups: FeatureGroup[];
1091
+ isLoading: boolean;
1092
+ error: Error | null;
1093
+ refetch: () => Promise<void>;
1094
+ };
946
1095
 
947
1096
  /**
948
1097
  * Floating feedback button component.
@@ -1010,4 +1159,4 @@ declare function KnowledgeBase({ showSearch, showCategories, defaultCategory, th
1010
1159
  */
1011
1160
  declare function Requests({ status, type, limit, className, showEmptyState, onRequestClick, }: RequestsProps): react_jsx_runtime.JSX.Element | null;
1012
1161
 
1013
- export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeedback, useIdentify, useRequests, useTrack };
1162
+ export { type Article, type ArticlesOptions, CensusProvider, type CensusProviderProps, type CensusTheme, type Feature, type FeatureGroup, FeedbackButton, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type FeedbackVisibility, KnowledgeBase, type KnowledgeBaseProps, type Position, type Request, Requests, type RequestsOptions, type RequestsProps, type RequestsSettings, type UserIdentity, useArticle, useArticles, useCensus, useCensusContext, useFeatureGroups, useFeedback, useIdentify, useRequests, useTrack, useVote };
@@ -1,3 +1,3 @@
1
- import {createContext,useState,useMemo,useEffect,useContext,useCallback}from'react';import {jsx,jsxs,Fragment}from'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=createContext(null);function ne({apiKey:r,baseUrl:e,debug:t,user:s,theme:o={},children:a}){let[d,u]=useState(false),[l,c]=useState(false),n=useMemo(()=>Q({apiKey:r,baseUrl:e,debug:t}),[r,e,t]);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=useMemo(()=>({client:n,theme:o,isReady:d,isIdentified:l}),[n,o,d,l]);return jsx(D.Provider,{value:p,children:a})}function ie(){let r=useContext(D);if(!r)throw new Error("useCensus must be used within a CensusProvider");return r.client}function C(){let r=useContext(D);if(!r)throw new Error("useCensusContext must be used within a CensusProvider");return r}function ae(){let{client:r}=C(),[e,t]=useState(false),[s,o]=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]=useState(false),[s,o]=useState(false),[a,d]=useState(null),[u,l]=useState(null),c=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=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]=useState(null),[a,d]=useState(true),[u,l]=useState(null),c=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 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]=useState(null),[a,d]=useState(true),[u,l]=useState(null),c=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 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]=useState(null),[d,u]=useState(true),[l,c]=useState(null),n=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 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=useCallback(async(s,o)=>{await r.track(s,o);},[r]),t=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]=useState(false),[i,k]=useState(t[0]),[I,F]=useState(""),v={...u,...s},P=fe(v),O=useCallback(()=>{R(true),p();},[p]),A=useCallback(()=>{R(false),F(""),k(t[0]);},[t]),U=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?jsxs(Fragment,{children:[jsx("div",{onClick:O,style:{cursor:"pointer"},children:d}),m&&jsx(Y,{isOpen:m,onClose:A,selectedType:i,onTypeChange:k,allowedTypes:t,message:I,onMessageChange:F,onSubmit:U,isSubmitting:c,isSuccess:n,themeStyles:P})]}):jsxs(Fragment,{children:[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&&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?jsx("div",{style:q.modal,onClick:e,children:jsxs("div",{style:{...q.modalContent,textAlign:"center",fontFamily:n.fontFamily},onClick:p=>p.stopPropagation(),children:[jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsx("h3",{style:{margin:"0 0 8px 0",color:n.textColor},children:"Thanks for your feedback!"}),jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsx("div",{style:q.modal,onClick:e,children:jsxs("div",{style:{...q.modalContent,fontFamily:n.fontFamily},onClick:p=>p.stopPropagation(),children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsx("h3",{style:{margin:0,color:n.textColor},children:"Send Feedback"}),jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxs("form",{onSubmit:u,children:[jsxs("div",{style:{marginBottom:"16px"},children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:o.map(p=>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))})]}),jsxs("div",{children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),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})]}),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]=useState(""),[c,n]=useState(t),[p,m]=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=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?jsx("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:jsx("div",{style:g.loading,children:"Loading article..."})}):O?jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:g.error,children:"Failed to load article. Please try again."})]}):v?jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsxs("article",{children:[jsx("h1",{style:{margin:"0 0 16px 0",color:i.textColor},children:v.title}),v.read_time_minutes&&jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[v.read_time_minutes," min read"]}),v.content_html?jsx("div",{style:{...g.articleContent,color:i.textColor},dangerouslySetInnerHTML:{__html:v.content_html}}):jsx("div",{style:{...g.articleContent,color:i.textColor},children:typeof v.content=="string"?v.content:"No content available."})]})]}):jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[jsx("button",{onClick:z,style:g.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:g.empty,children:"Article not found."})]}):jsxs("div",{style:{...g.container,fontFamily:i.fontFamily},className:o,children:[r&&jsx("input",{type:"text",placeholder:"Search articles...",value:u,onChange:f=>l(f.target.value),style:g.searchInput}),e&&A.length>0&&jsxs("div",{style:{marginBottom:"24px"},children:[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=>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&&jsx("div",{style:g.loading,children:"Loading articles..."}),F&&jsx("div",{style:g.error,children:"Failed to load articles. Please try again."}),!I&&!F&&k.length===0&&jsx("div",{style:g.empty,children:u?`No articles found for "${u}"`:"No articles available yet."}),!I&&!F&&k.length>0&&jsx("div",{children:k.map(f=>jsxs("div",{onClick:()=>U(f),style:g.articleCard,role:"button",tabIndex:0,onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&U(f);},children:[jsx("h3",{style:{...g.articleTitle,color:i.textColor},children:f.title}),f.seo_description&&jsx("p",{style:g.articleDescription,children:f.seo_description}),jsxs("div",{style:g.articleMeta,children:[f.category&&jsx("span",{children:f.category}),f.read_time_minutes&&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]=useState(null),{requests:c,isLoading:n,error:p,refetch:m}=H({status:r,type:e,limit:t}),R=useCallback(i=>{a?.(i);},[a]);return d?n?jsx("div",{style:x.loading,children:jsx("p",{children:"Loading requests..."})}):p?jsx("div",{style:x.error,children:jsxs("p",{children:["Failed to load requests. ",jsx("button",{onClick:m,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})}):c.length===0&&o?jsxs("div",{style:x.empty,children:[jsx("svg",{style:x.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children: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"})}),jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:"When you submit feedback, bug reports, or feature requests, they'll appear here."})]}):jsx("div",{style:x.container,className:s,children: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 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:[jsx("div",{style:x.header,children:jsxs("div",{style:x.badges,children:[jsx("span",{style:{...x.badge,color:k.color,backgroundColor:k.bg},children:k.label}),jsx("span",{style:{...x.badge,color:I.color,backgroundColor:I.bg},children:I.label})]})}),jsx("p",{style:x.message,children:i.message||"No message provided"}),jsxs("div",{style:x.meta,children:[jsx("span",{children:Ce(i.created_at)}),i.page_url&&jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",i.page_url]})]})]},i.id)})})}):o?jsx("div",{style:x.empty,children:jsx("p",{children:"Please sign in to view your requests."})}):null}
2
- export{ne as CensusProvider,ge as FeedbackButton,be as KnowledgeBase,ke as Requests,K as useArticle,$ as useArticles,ie as useCensus,C as useCensusContext,W as useFeedback,ae as useIdentify,H as useRequests,de as useTrack};//# sourceMappingURL=index.js.map
1
+ import {createContext,useState,useMemo,useEffect,useContext,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var xe="https://api.census.ai",Y=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(o=>e.apiKey.startsWith(o))||console.warn('Census: API key should start with "cs_live_" or "cs_test_"'),this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||xe,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 o=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:",o.feedbackId),{feedbackId:o.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 o=t.toString(),s=`/api/sdk/articles${o?`?${o}`:""}`,l=await this.request(s,"GET");return this.log("Fetched articles:",l.articles.length),l}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 o=await this.request(`/api/sdk/requests?${t.toString()}`,"GET");return this.log("Fetched requests:",o.requests.length),o}async vote(e){if(!this.currentUserId)throw new Error("Census: User must be identified before voting. Call identify() first.");if(!e)throw new Error("Census: feedbackId is required for vote()");let t=await this.request("/api/sdk/requests/vote","POST",{feedbackId:e,userId:this.currentUserId});return this.log("Vote result:",t.action,"for feedback:",e),t}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(o=>({eventType:o.eventType,userId:this.currentUserId,articleId:o.articleId,featureId:o.featureId,properties:o.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(),o=`/api/sdk/guides${t?`?${t}`:""}`,s=await this.request(o,"GET");return this.log("Fetched guides:",s.guides.length),s}async getGuide(e){try{let t=new URLSearchParams;this.currentUserId&&t.set("userId",this.currentUserId);let o=t.toString(),s=`/api/sdk/guides/${encodeURIComponent(e)}${o?`?${o}`:""}`,l=await this.request(s,"GET");return this.log("Fetched guide:",e),l.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,o){let s=`${this.baseUrl}${e}`,l={"X-Census-Key":this.apiKey};o&&(l["Content-Type"]="application/json"),this.log(`${t} ${e}`,o);let d=await fetch(s,{method:t,headers:l,body:o?JSON.stringify(o):void 0});if(!d.ok){let a=`Request failed with status ${d.status}`;try{a=(await d.json()).error||a;}catch{}throw {error:a,status:d.status}}return d.json()}log(...e){this.debug&&console.log("[Census]",...e);}};function le(r){return new Y(r)}var Q=createContext(null);function ke({apiKey:r,baseUrl:e,debug:t,user:o,theme:s={},children:l}){let[d,a]=useState(false),[n,c]=useState(false),i=useMemo(()=>le({apiKey:r,baseUrl:e,debug:t}),[r,e,t]);useEffect(()=>{o?i.identify(o).then(()=>{c(true),a(true);}).catch(v=>{console.error("[Census] Failed to identify user:",v),a(true);}):a(true);},[i,o]);let p=useMemo(()=>({client:i,theme:s,isReady:d,isIdentified:n}),[i,s,d,n]);return jsx(Q.Provider,{value:p,children:l})}function we(){let r=useContext(Q);if(!r)throw new Error("useCensus must be used within a CensusProvider");return r.client}function C(){let r=useContext(Q);if(!r)throw new Error("useCensusContext must be used within a CensusProvider");return r}function Ie(){let{client:r}=C(),[e,t]=useState(false),[o,s]=useState(null);return {identify:async a=>{t(true),s(null);try{await r.identify(a);}catch(n){throw s(n instanceof Error?n:new Error("Failed to identify user")),n}finally{t(false);}},reset:()=>{r.reset();},isIdentifying:e,isIdentified:r.isIdentified(),error:o}}function D(){let{client:r}=C(),[e,t]=useState(false),[o,s]=useState(false),[l,d]=useState(null),[a,n]=useState(null),c=useCallback(async p=>{t(true),s(false),d(null),n(null);try{let v=await r.submitFeedback(p);return n(v.feedbackId),s(!0),v}catch(v){let F=v instanceof Error?v:new Error("Failed to submit feedback");throw d(F),F}finally{t(false);}},[r]),i=useCallback(()=>{s(false),d(null),n(null);},[]);return {submitFeedback:c,reset:i,isSubmitting:e,isSuccess:o,error:l,feedbackId:a}}function J(r){let{client:e,isReady:t}=C(),[o,s]=useState(null),[l,d]=useState(true),[a,n]=useState(null),c=useCallback(async()=>{d(true),n(null);try{let i=await e.getArticles(r);s(i);}catch(i){n(i instanceof Error?i:new Error("Failed to fetch articles"));}finally{d(false);}},[e,r?.category,r?.search,r?.limit,r?.offset]);return useEffect(()=>{t&&c();},[t,c]),{articles:o?.articles||[],pagination:o?.pagination,isLoading:l,error:a,refetch:c}}function X(r){let{client:e,isReady:t}=C(),[o,s]=useState(null),[l,d]=useState(true),[a,n]=useState(null),c=useCallback(async()=>{if(!r){s(null),d(false);return}d(true),n(null);try{let i=await e.getArticle(r);s(i);}catch(i){n(i instanceof Error?i:new Error("Failed to fetch article"));}finally{d(false);}},[e,r]);return useEffect(()=>{t&&c();},[t,c]),{article:o,isLoading:l,error:a,refetch:c}}var Re={feedbackVisibility:"own",allowVoting:false,allowRequestCreation:true};function Z(r){let{client:e,isReady:t,isIdentified:o}=C(),[s,l]=useState(null),[d,a]=useState(true),[n,c]=useState(null),i=useCallback(async()=>{if(!o){l(null),a(false);return}a(true),c(null);try{let p=await e.getRequests(r);l(p);}catch(p){c(p instanceof Error?p:new Error("Failed to fetch requests"));}finally{a(false);}},[e,o,r?.status,r?.type,r?.limit,r?.offset]);return useEffect(()=>{t&&(o?i():a(false));},[t,o,i]),{requests:s?.requests||[],pagination:s?.pagination,settings:s?.settings||Re,isLoading:d,error:n,refetch:i}}function ee(){let{client:r}=C(),[e,t]=useState(false),[o,s]=useState(null);return {vote:useCallback(async d=>{t(true),s(null);try{return await r.vote(d)}catch(a){let n=a instanceof Error?a:new Error("Failed to vote");throw s(n),n}finally{t(false);}},[r]),isVoting:e,error:o}}function Se(){let{client:r}=C(),e=useCallback(async(o,s)=>{await r.track(o,s);},[r]),t=useCallback(async o=>{await r.trackBatch({events:o});},[r]);return {track:e,trackBatch:t}}function Ee(){let{client:r,isReady:e}=C(),[t,o]=useState([]),[s,l]=useState(true),[d,a]=useState(null),n=useCallback(async()=>{l(true),a(null);try{let c=await r.getFeatureGroups();o(c.feature_groups);}catch(c){a(c instanceof Error?c:new Error("Failed to fetch feature groups"));}finally{l(false);}},[r]);return useEffect(()=>{e&&n();},[e,n]),{featureGroups:t,isLoading:s,error:d,refetch:n}}var M={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"}},qe={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},Be={feedback:"General Feedback",bug_report:"Bug Report",feature_request:"Feature Request",article_rating:"Article Rating"},Te={feedback:"\u{1F4AC}",bug_report:"\u{1F41B}",feature_request:"\u{1F4A1}",article_rating:"\u2B50"};function _e(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 Pe({position:r="bottom-right",text:e="Feedback",allowedTypes:t=["feedback","bug_report","feature_request"],theme:o,onSubmit:s,onError:l,children:d}){let{theme:a}=C(),{submitFeedback:n,isSubmitting:c,isSuccess:i,reset:p}=D(),[v,F]=useState(false),[y,B]=useState(t[0]),[R,T]=useState(""),S={...a,...o},A=_e(S),L=useCallback(()=>{F(true),p();},[p]),E=useCallback(()=>{F(false),T(""),B(t[0]);},[t]),V=useCallback(async U=>{U.preventDefault();let g={type:y,message:R};try{await n(g),s?.(g),setTimeout(E,1500);}catch(w){l?.(w instanceof Error?w:new Error("Failed to submit feedback"));}},[y,R,n,s,l,E]);return d?jsxs(Fragment,{children:[jsx("div",{onClick:L,style:{cursor:"pointer"},children:d}),v&&jsx(ue,{isOpen:v,onClose:E,selectedType:y,onTypeChange:B,allowedTypes:t,message:R,onMessageChange:T,onSubmit:V,isSubmitting:c,isSuccess:i,themeStyles:A})]}):jsxs(Fragment,{children:[jsx("button",{onClick:L,style:{...M.button,...qe[r],backgroundColor:A.primaryColor,color:"white",borderRadius:A.borderRadius,fontFamily:A.fontFamily},"aria-label":"Open feedback form",children:e}),v&&jsx(ue,{isOpen:v,onClose:E,selectedType:y,onTypeChange:B,allowedTypes:t,message:R,onMessageChange:T,onSubmit:V,isSubmitting:c,isSuccess:i,themeStyles:A})]})}function ue({isOpen:r,onClose:e,selectedType:t,onTypeChange:o,allowedTypes:s,message:l,onMessageChange:d,onSubmit:a,isSubmitting:n,isSuccess:c,themeStyles:i}){return r?c?jsx("div",{style:M.modal,onClick:e,children:jsxs("div",{style:{...M.modalContent,textAlign:"center",fontFamily:i.fontFamily},onClick:p=>p.stopPropagation(),children:[jsx("div",{style:{fontSize:"48px",marginBottom:"16px"},children:"\u{1F389}"}),jsx("h3",{style:{margin:"0 0 8px 0",color:i.textColor},children:"Thanks for your feedback!"}),jsx("p",{style:{margin:0,color:"#666"},children:"We appreciate you taking the time to share."})]})}):jsx("div",{style:M.modal,onClick:e,children:jsxs("div",{style:{...M.modalContent,fontFamily:i.fontFamily},onClick:p=>p.stopPropagation(),children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[jsx("h3",{style:{margin:0,color:i.textColor},children:"Send Feedback"}),jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer",color:"#999",padding:"0",lineHeight:"1"},"aria-label":"Close",children:"\xD7"})]}),jsxs("form",{onSubmit:a,children:[jsxs("div",{style:{marginBottom:"16px"},children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"What kind of feedback?"}),jsx("div",{style:{display:"flex",flexWrap:"wrap"},children:s.map(p=>jsxs("button",{type:"button",onClick:()=>o(p),style:{...M.typeButton,backgroundColor:t===p?i.primaryColor:"white",color:t===p?"white":i.textColor,borderColor:t===p?i.primaryColor:"#e0e0e0"},children:[Te[p]," ",Be[p]]},p))})]}),jsxs("div",{children:[jsx("label",{style:{display:"block",marginBottom:"8px",fontSize:"13px",color:"#666",fontWeight:"500"},children:"Your message"}),jsx("textarea",{value:l,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:M.textarea,required:true})]}),jsx("button",{type:"submit",disabled:n||!l.trim(),style:{...M.submitButton,backgroundColor:i.primaryColor,color:"white",opacity:n||!l.trim()?.6:1,cursor:n||!l.trim()?"not-allowed":"pointer"},children:n?"Sending...":"Send Feedback"})]})]})}):null}var m={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 Ue(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 ze({showSearch:r=true,showCategories:e=true,defaultCategory:t,theme:o,className:s,onArticleView:l}){let{theme:d}=C(),[a,n]=useState(""),[c,i]=useState(t),[p,v]=useState(null),F={...d,...o},y=Ue(F),{articles:B,isLoading:R,error:T}=J({category:c,search:a||void 0}),{article:S,isLoading:A,error:L}=X(p||""),E=useMemo(()=>{let g=new Set;return B.forEach(w=>{w.category&&g.add(w.category);}),Array.from(g).sort()},[B]),V=g=>{v(g.slug),l?.(g);},U=()=>{v(null);};return p?A?jsx("div",{style:{...m.container,fontFamily:y.fontFamily},className:s,children:jsx("div",{style:m.loading,children:"Loading article..."})}):L?jsxs("div",{style:{...m.container,fontFamily:y.fontFamily},className:s,children:[jsx("button",{onClick:U,style:m.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:m.error,children:"Failed to load article. Please try again."})]}):S?jsxs("div",{style:{...m.container,fontFamily:y.fontFamily},className:s,children:[jsx("button",{onClick:U,style:m.backButton,children:"\u2190 Back to articles"}),jsxs("article",{children:[jsx("h1",{style:{margin:"0 0 16px 0",color:y.textColor},children:S.title}),S.read_time_minutes&&jsxs("div",{style:{fontSize:"14px",color:"#666",marginBottom:"24px"},children:[S.read_time_minutes," min read"]}),S.content_html?jsx("div",{style:{...m.articleContent,color:y.textColor},dangerouslySetInnerHTML:{__html:S.content_html}}):jsx("div",{style:{...m.articleContent,color:y.textColor},children:typeof S.content=="string"?S.content:"No content available."})]})]}):jsxs("div",{style:{...m.container,fontFamily:y.fontFamily},className:s,children:[jsx("button",{onClick:U,style:m.backButton,children:"\u2190 Back to articles"}),jsx("div",{style:m.empty,children:"Article not found."})]}):jsxs("div",{style:{...m.container,fontFamily:y.fontFamily},className:s,children:[r&&jsx("input",{type:"text",placeholder:"Search articles...",value:a,onChange:g=>n(g.target.value),style:m.searchInput}),e&&E.length>0&&jsxs("div",{style:{marginBottom:"24px"},children:[jsx("button",{onClick:()=>i(void 0),style:{...m.categoryButton,backgroundColor:c?"white":y.primaryColor,color:c?y.textColor:"white",borderColor:c?"#e0e0e0":y.primaryColor},children:"All"}),E.map(g=>jsx("button",{onClick:()=>i(g),style:{...m.categoryButton,backgroundColor:c===g?y.primaryColor:"white",color:c===g?"white":y.textColor,borderColor:c===g?y.primaryColor:"#e0e0e0"},children:g},g))]}),R&&jsx("div",{style:m.loading,children:"Loading articles..."}),T&&jsx("div",{style:m.error,children:"Failed to load articles. Please try again."}),!R&&!T&&B.length===0&&jsx("div",{style:m.empty,children:a?`No articles found for "${a}"`:"No articles available yet."}),!R&&!T&&B.length>0&&jsx("div",{children:B.map(g=>jsxs("div",{onClick:()=>V(g),style:m.articleCard,role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&V(g);},children:[jsx("h3",{style:{...m.articleTitle,color:y.textColor},children:g.title}),g.seo_description&&jsx("p",{style:m.articleDescription,children:g.seo_description}),jsxs("div",{style:m.articleMeta,children:[g.category&&jsx("span",{children:g.category}),g.read_time_minutes&&jsxs("span",{children:[g.read_time_minutes," min read"]})]})]},g.id))})]})}var f={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"},voteButton:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"8px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",cursor:"pointer",minWidth:"48px",transition:"all 0.15s"},voteButtonActive:{backgroundColor:"#dbeafe",borderColor:"#2563eb",color:"#2563eb"},voteCount:{fontSize:"14px",fontWeight:600,color:"#111827"},cardWithVote:{display:"flex",gap:"12px"},cardContent:{flex:1},form:{marginBottom:"16px",padding:"16px",backgroundColor:"#f9fafb",borderRadius:"8px",border:"1px solid #e5e7eb"},formHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},formTitle:{fontSize:"14px",fontWeight:500,color:"#111827",margin:0},typeSelector:{display:"flex",gap:"8px",marginBottom:"12px"},typeButton:{padding:"6px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",backgroundColor:"#ffffff",fontSize:"13px",cursor:"pointer",transition:"all 0.15s"},typeButtonActive:{backgroundColor:"#111827",borderColor:"#111827",color:"#ffffff"},textarea:{width:"100%",padding:"10px 12px",borderRadius:"6px",border:"1px solid #e5e7eb",fontSize:"14px",resize:"vertical",minHeight:"80px",fontFamily:"inherit",marginBottom:"12px"},submitButton:{padding:"8px 16px",borderRadius:"6px",border:"none",backgroundColor:"#111827",color:"#ffffff",fontSize:"14px",fontWeight:500,cursor:"pointer",transition:"opacity 0.15s"},successMessage:{padding:"12px",backgroundColor:"#d1fae5",borderRadius:"6px",color:"#059669",fontSize:"14px",marginBottom:"16px"},ownBadge:{display:"inline-flex",alignItems:"center",padding:"2px 6px",borderRadius:"9999px",fontSize:"11px",fontWeight:500,backgroundColor:"#f3f4f6",color:"#6b7280",marginLeft:"6px"}},fe={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"}},ge={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 Ge(r){return new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}var Le=[{value:"feedback",label:"Feedback"},{value:"bug_report",label:"Bug"},{value:"feature_request",label:"Feature"}];function Ve({status:r,type:e,limit:t=50,className:o,showEmptyState:s=true,onRequestClick:l}){let{isIdentified:d}=C(),[a,n]=useState(null),[c,i]=useState(false),[p,v]=useState("feedback"),[F,y]=useState(""),[B,R]=useState({}),{requests:T,isLoading:S,error:A,refetch:L,settings:E}=Z({status:r,type:e,limit:t}),{vote:V,isVoting:U}=ee(),{submitFeedback:g,isSubmitting:w,isSuccess:be,reset:ne}=D(),ie=useCallback(u=>{l?.(u);},[l]),ye=useCallback(async(u,_,W)=>{if(!U){R(O=>({...O,[u]:{count:W?_-1:_+1,hasVoted:!W}}));try{let O=await V(u);R(q=>({...q,[u]:{count:O.vote_count,hasVoted:O.user_has_voted}}));}catch{R(O=>({...O,[u]:{count:_,hasVoted:W}}));}}},[V,U]),me=useCallback(async u=>{if(u.preventDefault(),!(!F.trim()||w))try{await g({type:p,message:F}),y(""),i(!1),setTimeout(()=>{L(),ne();},500);}catch{}},[p,F,w,g,L,ne]),he=u=>{let _=B[u.id];return {count:_?.count??u.vote_count,hasVoted:_?.hasVoted??u.user_has_voted}};if(!d)return s?jsx("div",{style:f.empty,children:jsx("p",{children:"Please sign in to view your requests."})}):null;if(S)return jsx("div",{style:f.loading,children:jsx("p",{children:"Loading requests..."})});if(A)return jsx("div",{style:f.error,children:jsxs("p",{children:["Failed to load requests. ",jsx("button",{onClick:L,style:{color:"inherit",textDecoration:"underline",background:"none",border:"none",cursor:"pointer"},children:"Try again"})]})});let ae=()=>E.allowRequestCreation?be?jsx("div",{style:f.successMessage,children:"Thanks for your feedback! It has been submitted."}):c?jsxs("form",{onSubmit:me,style:f.form,children:[jsxs("div",{style:f.formHeader,children:[jsx("p",{style:f.formTitle,children:"Submit a request"}),jsx("button",{type:"button",onClick:()=>i(false),style:{background:"none",border:"none",cursor:"pointer",color:"#6b7280"},children:"\u2715"})]}),jsx("div",{style:f.typeSelector,children:Le.map(u=>jsx("button",{type:"button",onClick:()=>v(u.value),style:{...f.typeButton,...p===u.value?f.typeButtonActive:{}},children:u.label},u.value))}),jsx("textarea",{value:F,onChange:u=>y(u.target.value),placeholder:"Describe your request...",style:f.textarea,required:true}),jsx("button",{type:"submit",style:{...f.submitButton,opacity:w?.6:1},disabled:w,children:w?"Submitting...":"Submit"})]}):jsxs("button",{onClick:()=>i(true),style:{...f.submitButton,marginBottom:"16px",display:"flex",alignItems:"center",gap:"6px"},children:[jsx("svg",{width:"14",height:"14",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"New Request"]}):null;if(T.length===0&&s)return jsxs("div",{style:f.container,className:o,children:[ae(),jsxs("div",{style:f.empty,children:[jsx("svg",{style:f.emptyIcon,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children: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"})}),jsx("p",{style:{margin:0,fontWeight:500,color:"#111827"},children:"No requests yet"}),jsx("p",{style:{margin:"8px 0 0",fontSize:"14px"},children:E.allowRequestCreation?"Submit your first request above.":"When you submit feedback, bug reports, or feature requests, they'll appear here."})]})]});let K=E.allowVoting&&E.feedbackVisibility!=="own";return jsxs("div",{style:f.container,className:o,children:[ae(),jsx("ul",{style:f.list,children:T.map(u=>{let _=fe[u.feedback_type]||fe.feedback,W=ge[u.status]||ge.new,O=a===u.id,q=he(u);return jsx("li",{style:{...f.card,...O?f.cardHover:{}},onMouseEnter:()=>n(u.id),onMouseLeave:()=>n(null),children:jsxs("div",{style:K?f.cardWithVote:void 0,children:[K&&jsxs("button",{onClick:H=>{H.stopPropagation(),ye(u.id,q.count,q.hasVoted);},disabled:U,style:{...f.voteButton,...q.hasVoted?f.voteButtonActive:{}},title:q.hasVoted?"Remove vote":"Upvote this request",children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:q.hasVoted?"currentColor":"none",stroke:"currentColor",strokeWidth:2,children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 15l7-7 7 7"})}),jsx("span",{style:{...f.voteCount,...q.hasVoted?{color:"#2563eb"}:{}},children:q.count})]}),jsxs("div",{style:K?f.cardContent:void 0,onClick:()=>ie(u),role:"button",tabIndex:0,onKeyDown:H=>{(H.key==="Enter"||H.key===" ")&&ie(u);},children:[jsx("div",{style:f.header,children:jsxs("div",{style:f.badges,children:[jsx("span",{style:{...f.badge,color:_.color,backgroundColor:_.bg},children:_.label}),jsx("span",{style:{...f.badge,color:W.color,backgroundColor:W.bg},children:W.label}),u.is_own&&jsx("span",{style:f.ownBadge,children:"You"})]})}),jsx("p",{style:f.message,children:u.message||"No message provided"}),jsxs("div",{style:f.meta,children:[jsx("span",{children:Ge(u.created_at)}),!K&&q.count>0&&jsxs("span",{children:[q.count," vote",q.count!==1?"s":""]}),u.page_url&&jsxs("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:["From: ",u.page_url]})]})]})]})},u.id)})})]})}
2
+ export{ke as CensusProvider,Pe as FeedbackButton,ze as KnowledgeBase,Ve as Requests,X as useArticle,J as useArticles,we as useCensus,C as useCensusContext,Ee as useFeatureGroups,D as useFeedback,Ie as useIdentify,Z as useRequests,Se as useTrack,ee as useVote};//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map