import React from 'react';

interface ILogSnagProviderProps {
    project: string;
    token: string;
}
/**
 * Set up the LogSnag provider
 * @param props: ILogSnagProviderProps
 * @constructor
 */
declare const LogSnagProvider: React.FC<React.PropsWithChildren<ILogSnagProviderProps>>;

type TagKey = Lowercase<string>;
/** Tag Type **/
type Tags = Record<TagKey, string | number | boolean>;
type Parser = 'markdown' | 'text';
/**
 * Options for publishing LogSnag events
 */
interface TrackOptions {
    /**
     * Channel name
     * example: "waitlist"
     */
    channel: string;
    /**
     * Event name
     * example: "User Joined"
     */
    event: string;
    /**
     * Event description
     * example: "joe@example.com joined waitlist"
     */
    description?: string;
    /**
     * User ID
     * example: "user-123"
     */
    user_id?: string;
    /**
     * Event icon (emoji)
     * must be a single emoji
     * example: "🎉"
     */
    icon?: string;
    /**
     * Event tags
     * example: { username: "mattie" }
     */
    tags?: Tags;
    /**
     * Send push notification
     */
    notify?: boolean;
    /**
     * Parser for description
     */
    parser?: Parser;
    /**
     * Event timestamp
     */
    timestamp?: number | Date;
}

/** Properties Type **/
type IdentifyProperties = Record<TagKey, string | number | boolean>;
/**
 * Options for publishing LogSnag identify
 */
interface IdentifyOptions {
    /**
     * User ID
     * example: "user-123"
     */
    user_id: string;
    /**
     * User properties
     * example: { username: "mattie" }
     */
    properties: IdentifyProperties;
}

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
type ITracker = {
    /**
     * Set up the tracker with a token and project
     * @param token: your LogSnag token
     * @param project: your LogSnag project
     */
    setConfig: (token: string, project: string) => void;
    /**
     * Set the user id for the tracker
     * @param userId: a unique identifier for the user
     */
    setUserId: (userId: string | number) => void;
    /**
     * Clear the user id for the tracker
     */
    clearUserId: () => void;
    /**
     * Set the debug flag for the tracker
     * @param flag
     */
    setDebug: (flag: boolean) => void;
    /**
     * Track a custom event
     * @param options
     */
    track(options: TrackOptions): void;
    /**
     * Identify user traits
     * @param options
     */
    identify(options: PartialBy<IdentifyOptions, 'user_id'>): void;
};

declare global {
    interface Window {
        lsq: [keyof ITracker, ...unknown[]][] | undefined;
        ls: (...args: [keyof ITracker, ...unknown[]]) => void;
        lsi: boolean;
    }
}

/**
 * LogSnag Hook
 * @description
 */
declare const useLogSnag: () => {
    setDebug: (flag?: boolean) => void;
    setUserId: (userId: string) => void;
    clearUserId: () => void;
    track: (options: TrackOptions) => void;
    identify: (options: PartialBy<IdentifyOptions, "user_id">) => void;
};

export { LogSnagProvider, useLogSnag };
