import { createCalendarEventParticipantTag } from "../helpers/calendar-event.js";
import { includeNameValueTag, includeSingletonTag, modifyPublicTags } from "./tags.js";
import { addNameValueTag, removeNameValueTag, setSingletonTag } from "./tag/common.js";
import * as Geohash from "./geohash.js";
/** Sets the title of a calendar event */
export function setTitle(title) {
    return includeSingletonTag(["title", title], true);
}
/** Sets the summary of a calendar event */
export function setSummary(summary) {
    return includeSingletonTag(["summary", summary], true);
}
/** Sets the image for a calendar event */
export function setImage(image) {
    return includeSingletonTag(["image", image], true);
}
/** Adds a participant to a calendar event */
export function addParticipant(participant) {
    return includeNameValueTag(createCalendarEventParticipantTag(participant), true);
}
/** Removes a participant from a calendar event */
export function removeParticipant(pubkey) {
    return modifyPublicTags(removeNameValueTag(["p", typeof pubkey === "string" ? pubkey : pubkey.pubkey]));
}
/** Adds a location to a calendar event */
export function addLocation(location) {
    return modifyPublicTags(addNameValueTag(["location", location], true));
}
/** Removes a location from a calendar event */
export function removeLocation(location) {
    return modifyPublicTags(removeNameValueTag(["location", location]));
}
/** Adds a location to a calendar event */
export function addReferenceLink(link) {
    return modifyPublicTags(addNameValueTag(["r", new URL(link).toString()], true));
}
/** Removes a location from a calendar event */
export function removeReferenceLink(link) {
    return modifyPublicTags(removeNameValueTag(["r", new URL(link).toString()]));
}
/** Removes all locations from a calendar event */
export function clearLocations() {
    return modifyPublicTags((tags) => tags.filter((tag) => tag[0] !== "location"));
}
/** Sets the geohash for a calendar event */
export function setGeohash(geohash) {
    return Geohash.setGeohash(geohash);
}
/** Removes the geohash from a calendar event */
export function removeGeohash() {
    return Geohash.removeGeohash();
}
/** Sets the start date for a date based calendar event */
export function setStartDate(start) {
    const date = new Date(start).toISOString().split("T")[0];
    return includeSingletonTag(["start", date], true);
}
/** Sets the start time for a time based calendar event */
export function setStartTime(start, timezone) {
    const timestamp = typeof start === "number" ? start : Math.round(new Date(start).valueOf() / 1000);
    return modifyPublicTags(setSingletonTag(["start", String(timestamp)], true), timezone ? setSingletonTag(["start_tzid", timezone], true) : undefined);
}
/** Sets the end date for a date based calendar event */
export function setEndDate(end) {
    const date = new Date(end).toISOString().split("T")[0];
    return includeSingletonTag(["end", date], true);
}
/** Sets the end time for a time based calendar event */
export function setEndTime(end, timezone) {
    const timestamp = typeof end === "number" ? end : Math.round(new Date(end).valueOf() / 1000);
    return modifyPublicTags(setSingletonTag(["end", String(timestamp)], true), timezone ? setSingletonTag(["end_tzid", timezone], true) : undefined);
}
