import { ClubsGeneralUnit } from '@devprotocol/clubs-core';
import { UndefinedOr } from '@devprotocol/util-ts';

type PostPrimitives = {
    readonly title: string;
    readonly content: string;
    readonly options: readonly PostOption[];
};
type Posts = PostPrimitives & {
    readonly id: string;
    readonly created_by: string;
    readonly created_at: Date;
    readonly updated_at: Date;
    readonly comments: readonly Comment[];
    readonly reactions: Reactions;
    readonly masked?: boolean;
};
type PostOption = {
    readonly key: string;
    readonly value: ClubsGeneralUnit;
};
type CommentPrimitives = {
    readonly content: string;
    readonly options: readonly PostOption[];
};
type Comment = CommentPrimitives & {
    readonly id: string;
    readonly created_by: string;
    readonly created_at: Date;
    readonly updated_at: Date;
};
/**
 * Reaction is a map of emoji to users who reacted to a post
 * An emoji as the key, and an array of addresses as the users who reacted to the post
 * @example
 * {'🦜': [{createdBy: '0x0', id: '123'}, {createdBy: '0x2', id: '456'}]}
 */
type Reactions = {
    readonly [emoji: string]: readonly {
        readonly createdBy: string;
        readonly id: string;
    }[];
};
declare enum Event {
    PostCreated = "posts:event::post_created",
    RegisterOnUpdateHandler = "posts:event::register_on_update_handler",
    RegisterOnSetupHandler = "posts:event::register_on_setup_handler",
    ClickToolbar = "posts:event::click_toolbar"
}

type OnUpdateHandler = (post: PostPrimitives) => PostPrimitives | Promise<PostPrimitives>;
type OnSetupHandler = (post: PostPrimitives) => PostPrimitives | Promise<PostPrimitives>;
type OnPostCreatedHandler = (post: Posts) => void | Promise<void>;
type EventRegisterOnUpdateHandler = CustomEvent<{
    readonly handler?: OnUpdateHandler;
}>;
type EventRegisterOnSetupHandler = CustomEvent<{
    readonly handler?: OnSetupHandler;
}>;
type EventPostCreated = CustomEvent<{
    readonly post: Posts;
}>;
type EventClickToolbar = CustomEvent<{
    readonly key: string;
}>;
declare const onUpdateHandlers: Set<OnUpdateHandler>;
declare const onSetupHandlers: Set<OnSetupHandler>;
declare const handleRegisterOnUpdateHandler: (e: EventRegisterOnUpdateHandler) => Set<OnUpdateHandler>;
declare const handleRegisterOnSetupHandler: (e: EventRegisterOnSetupHandler) => Set<OnSetupHandler>;
declare const onUpdate: (handler: OnUpdateHandler) => boolean;
declare const onSetup: (handler: OnSetupHandler) => boolean;
declare const onClickToolbar: (key: string, handler: (ev: EventClickToolbar) => unknown) => false | void;
declare const emitClickToolbar: (key: string) => boolean;
declare const update: (_post: PostPrimitives) => Promise<PostPrimitives>;
declare const setup: (_post: PostPrimitives) => Promise<PostPrimitives>;
declare const EncodedPostClassName = "__input-encoded-post__";
declare const currentPost: (handler: (post: Posts) => unknown, base: Readonly<Element>) => UndefinedOr<HTMLInputElement>;
declare const onPostCreated: (handler: OnPostCreatedHandler) => false | void;
declare const PostCreated: Event;
declare const RegisterOnUpdateHandler: Event;
declare const RegisterOnSetupHandler: Event;
declare const ClickToolbar: Event;
declare const dispatchPostCreated: (post: Posts) => boolean;
declare global {
    interface DocumentEventMap {
        readonly [RegisterOnUpdateHandler]: EventRegisterOnUpdateHandler;
        readonly [PostCreated]: EventPostCreated;
        readonly [RegisterOnSetupHandler]: EventRegisterOnSetupHandler;
        readonly [ClickToolbar]: EventClickToolbar;
    }
}

export { EncodedPostClassName, type EventClickToolbar, type EventPostCreated, type EventRegisterOnSetupHandler, type EventRegisterOnUpdateHandler, type OnPostCreatedHandler, type OnSetupHandler, type OnUpdateHandler, currentPost, dispatchPostCreated, emitClickToolbar, handleRegisterOnSetupHandler, handleRegisterOnUpdateHandler, onClickToolbar, onPostCreated, onSetup, onSetupHandlers, onUpdate, onUpdateHandlers, setup, update };
