<script lang="ts">
	interface Props {
		log_lvl?: number;
		lq__post_obj: any;
		// lq__post_comment_obj: any;
		// lq__post_comment_obj_li?: any;
	}

	let {
		log_lvl = $bindable(1),
		lq__post_obj
		// lq__post_comment_obj,
		// lq__post_comment_obj_li
	}: Props = $props();

	// *** Import Svelte specific
	import { fade } from 'svelte/transition';

	// *** Import other supporting libraries

	// *** Import Aether specific variables and functions
	import type { key_val } from '$lib/stores/ae_stores';
	import { ae_util } from '$lib/ae_utils/ae_utils';
	// import { core_func } from '$lib/ae_core/ae_core_functions';
	import { api } from '$lib/api/api';
	import {
		ae_snip,
		ae_loc,
		ae_sess,
		ae_api,
		ae_trig,
		slct,
		slct_trigger
	} from '$lib/stores/ae_stores';
	import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
	import { posts_func } from '$lib/ae_posts/ae_posts_functions';
	import Tiptap_editor from '$lib/elements/element_tiptap_editor.svelte';

	let prom_api__post_comment_obj: any = $state();

	let content_new_html = $state('');
	let content_changed = $state(false);
	// let notes_new_html = $state('');
	// let notes_changed = $state(false);
	let disable_submit_btn = $state(false);

	function preventDefault<T extends Event>(fn: (event: T) => void) {
		return function (event: T) {
			event.preventDefault();
			fn(event);
		};
	}

	async function handle_submit_form(event: any) {
		if (log_lvl > 1) {
			console.log('*** handle_submit_form() ***', event.target);
		}

		disable_submit_btn = true;

		let form_data = new FormData(event.target);
		if (log_lvl > 1) {
			console.log(form_data);
		}

		// Form Post object data incoming
		let post_comment_di = ae_util.extract_prefixed_form_data({
			prefix: null,
			form_data: form_data,
			trim_values: true,
			bool_tf_str: true,
			log_lvl: log_lvl
		});
		// console.log(post_comment_di);

		// Form Post object data outgoing
		let post_comment_do: key_val = {};

		if (!$idaa_slct.post_comment_id) {
			post_comment_do['post_id_random'] = $idaa_slct.post_id;
			post_comment_do['enable'] = true;
		}

		// post_comment_do['title'] = post_comment_di.title;

		// Check if the content_new_html exists and is a string
		if (typeof content_new_html === 'string') {
			console.log('New content is a string');
			post_comment_do['content'] = content_new_html;
		} else {
			console.log('New content is not a string. Do nothing.');
			// post_comment_do['content'] = event_meeting_fd.content;
		}

		post_comment_do['anonymous'] = post_comment_di.anonymous;

		post_comment_do['external_person_id'] = post_comment_di.external_person_id;
		post_comment_do['full_name'] = post_comment_di.full_name;
		post_comment_do['email'] = post_comment_di.email;
		post_comment_do['notify'] = post_comment_do.notify;

		post_comment_do['hide'] = post_comment_di.hide;
		post_comment_do['priority'] = post_comment_di.priority;
		if (post_comment_di.sort) {
			post_comment_do['sort'] = Number(post_comment_di.sort);
		} else {
			post_comment_do['sort'] = null;
		}
		if (post_comment_di.group) {
			post_comment_do['group'] = post_comment_di.group;
		} else {
			post_comment_do['group'] = null;
		}

		// NOTE: We only want to set enable value if the input is defined.
		if (typeof post_comment_di.enable !== 'undefined') {
			post_comment_do.enable = post_comment_di.enable;
		}
		// NOTE: We want to always default to false if the input is not defined.
		// post_comment_do.enable = post_comment_di.enable ?? false;

		// // Check if the notes_new_html exists and is a string
		// if (typeof $idaa_slct.post_comment_obj.notes_new_html === 'string') {
		//     console.log('New notes is a string');
		//     post_comment_do['notes'] = $idaa_slct.post_comment_obj.notes_new_html;
		// } else {
		//     console.log('New notes is not a string. Do nothing.');
		//     // post_comment_do['notes'] = event_meeting_fd.notes;
		// }

		log_lvl = 1;
		if (log_lvl) {
			console.log(post_comment_do);
		}

		if (!$idaa_slct.post_comment_id) {
			if (log_lvl) {
				console.log(
					`Current Post Comment Object List Length: ${$idaa_slct.post_comment_obj_li.length}`,
					$idaa_slct.post_comment_obj_li
				);
			}

			prom_api__post_comment_obj = await posts_func
				.create_ae_obj__post_comment({
					api_cfg: $ae_api,
					post_id: $idaa_slct.post_id,
					data_kv: post_comment_do,
					log_lvl: log_lvl
				})
				// .then(function (post_comment_obj_create_result) {
				//     if (!post_comment_obj_create_result) {
				//         console.log('The result was null or false.');
				//         return false;
				//     }

				//     $idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id_random;
				//     $idaa_slct.post_comment_obj = post_comment_obj_create_result;

				//     return post_comment_obj_create_result;
				// })
				.catch(function (error: any) {
					console.log('Something went wrong.');
					console.log(error);
					return false;
					// })
					// .finally(async () => {
				});

			$idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id_random;
			$idaa_slct.post_comment_obj = prom_api__post_comment_obj;

			disable_submit_btn = false;
			$idaa_sess.bb.show__inline_edit__post_comment_id = false;

			// Send notification to staff
			// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
			if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) {
				send_staff_notification_email();
			}

			// Send notification to the original poster
			if (
				!$ae_loc.administrator_access &&
				$ae_loc.site_cfg_json?.bb_send_poster_email &&
				$idaa_slct.post_obj.notify
			) {
				// if ($ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
				send_poster_notification_email();
			}

			// Send a notification to any other post commenters
			if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_commenter_email) {
				console.log(
					`Sending notification email to post commenters...: ${$idaa_slct.post_comment_obj_li?.length}`
				);
				if ($idaa_slct.post_comment_obj_li && $idaa_slct.post_comment_obj_li.length > 0) {
					for (const post_comment of $idaa_slct.post_comment_obj_li) {
						console.log('Post Comment ID:', post_comment.post_comment_id);
						if (
							post_comment?.email &&
							post_comment.post_comment_id !== $idaa_slct.post_comment_id &&
							post_comment?.email !== $idaa_slct.post_comment_obj?.email
						) {
							console.log(
								`Sending notification email to post commenter: ${post_comment.full_name}`,
								post_comment
							);
							send_poster_commenters_notification_email({
								post_comment_obj: post_comment
							});
						}
					}
				}
			}

			return prom_api__post_comment_obj;
		} else {
			prom_api__post_comment_obj = posts_func
				.update_ae_obj__post_comment({
					api_cfg: $ae_api,
					post_comment_id: $idaa_slct.post_comment_id,
					data_kv: post_comment_do,
					log_lvl: log_lvl
				})
				.then(function (post_comment_obj_update_result) {
					if (!post_comment_obj_update_result) {
						console.log('The result was null or false.');
						return false;
					}

					$idaa_slct.post_comment_obj = post_comment_obj_update_result;

					return post_comment_obj_update_result;
				})
				.catch(function (error: any) {
					console.log('Something went wrong.');
					console.log(error);
					return false;
				})
				.finally(() => {
					// We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???).
					// $idaa_slct.post_comment_obj = $lq__post_comment_obj;
					disable_submit_btn = false;
					$idaa_sess.bb.show__inline_edit__post_comment_id = false;

					// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
					if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) {
						send_staff_notification_email();
					}

					// For now we are not going to send a notification to the poster when a post comment has been updated.
					// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
					//     send_poster_notification_email();
					// }
				});

			return prom_api__post_comment_obj;
		}
	}

	// Updated 2024-11-15
	async function handle_delete_post_comment_obj({
		post_comment_id,
		method = 'disable'
	}: {
		post_comment_id: string;
		method?: string;
	}) {
		if (log_lvl) {
			console.log('*** handle_delete_post_comment_obj() ***');
		}

		prom_api__post_comment_obj = posts_func
			.delete_ae_obj_id__post_comment({
				api_cfg: $ae_api,
				post_comment_id: post_comment_id,
				method: method,
				log_lvl: log_lvl
			})
			.then(function (post_comment_obj_delete_result) {
				$idaa_sess.bb.show__inline_edit__post_comment_id = false;
			})
			.catch(function (error: any) {
				console.log('The result was null or false when trying to delete.', error);
			})
			.finally(() => {
				// $idaa_sess.recovery_meetings.show__modal_edit = false;
				$idaa_slct.post_comment_id = null;
				$idaa_slct.post_comment_obj = null;
			});

		return prom_api__post_comment_obj;
	}

	function send_staff_notification_email() {
		log_lvl = 1;
		if (log_lvl) {
			console.log(
				`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id} Post Title: ${$idaa_slct?.post_obj?.title}`
			);
		}
		if (log_lvl > 1) {
			console.log(`Selected Post Object:`, $idaa_slct.post_obj);
			console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj);

			// console.log($lq__post_obj);
			// console.log($lq__post_obj?.title);
			// console.log($lq__post_obj?.content);
		}

		let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;

		let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;

		let body_html = `
    <div>${$idaa_slct.post_obj.full_name},
    <p>A BB post comment has been created or updated on the post named "${$idaa_slct.post_obj.title ?? '-- not set --'}".</p>
    </div>

    <div>
    Commenter's Novi ID: ${$idaa_slct.post_comment_obj.external_person_id ?? '-- not set --'}<br>
    Commenter's Name: ${$idaa_slct.post_comment_obj.full_name ?? '-- not set --'}<br>
    Commenter's Email: ${$idaa_slct.post_comment_obj.email ?? '-- not set --'}
    </div>

    <div>
    Original Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}<br>
    Original Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}<br>
    Original Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'}
    </div>

    <br>

    <div>
    IDAA BB Post ID: ${$idaa_slct.post_id}<br>
    <p>Use this link to view the post.<br>
    Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
    </div>`;

		api.send_email({
			api_cfg: $ae_api,
			from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
			from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
			to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email,
			// to_email: 'scott+idaabbstaff@oneskyit.com',
			to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
			subject: subject,
			body_html: body_html
		});
	}

	function send_poster_notification_email() {
		log_lvl = 1;
		if (log_lvl) {
			console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
		}

		let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;

		let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;

		let body_html = `
    <div>${$idaa_slct.post_obj.full_name ?? '-- not set --'},
    <p>Your BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
    </div>

    <br>

    <div>
    IDAA BB Post ID: ${$idaa_slct.post_id}<br>
    <p>Use this link to view the post.<br>
    Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
    </div>`;

		api.send_email({
			api_cfg: $ae_api,
			from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
			from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
			// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
			to_email: $idaa_slct.post_obj.email,
			// to_email: 'scott+idaabb@oneskyit.com',
			to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster',
			subject: subject,
			body_html: body_html
		});
	}

	function send_poster_commenters_notification_email({
		post_comment_obj = $idaa_slct.post_comment_obj
	}: {
		post_comment_obj?: any;
	} = {}) {
		log_lvl = 1;
		if (log_lvl) {
			console.log(
				`*** send_poster_commenters_notification_email() *** Post ID: ${$idaa_slct.post_id}`
			);
		}

		let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;

		let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;

		let body_html = `
    <div>${post_comment_obj.full_name ?? '-- not set --'},
    <p>The BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
    </div>

    <br>

    <div>
    IDAA BB Post ID: ${$idaa_slct.post_id}<br>
    <p>Use this link to view the post.<br>
    Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
    </div>`;

		api.send_email({
			api_cfg: $ae_api,
			from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
			from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
			// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
			to_email: $idaa_slct.post_obj.email,
			// to_email: 'scott+idaabb@oneskyit.com',
			to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Post Commenter',
			subject: subject,
			body_html: body_html
		});
	}
</script>

<section
	class="
        svelte_component ae_section ae_edit post_comment_obj edit__post_comment_obj
        space-y-2 p-2
        rounded-md
        preset-filled-surface-100-900 preset-outlined-warning-400-600
        "
	class:ae_create={!$idaa_slct.post_id}
	bind:clientHeight={$ae_loc.iframe_height_modal_body}
>
	<form onsubmit={preventDefault(handle_submit_form)} class="space-y-1">
		{#await prom_api__post_comment_obj}
			<div class="awaiting alert_msg_pulse" out:fade={{ duration: 2000 }}>Saving...</div>
		{:then}
			{#if prom_api__post_comment_obj}
				<!-- <div class="awaiting" out:fade={{ duration: 2000 }}>Finished saving</div> -->
			{:else}
				<!-- <div class="awaiting" out:fade={{ duration: 2000 }}>Nothing here yet</div> -->
			{/if}
		{/await}

		<section class="text-center">
			<!-- BEGIN: section post__options -->
			<button
				type="button"
				onclick={() => {
					$idaa_sess.bb.show__inline_edit__post_comment_id = false;
				}}
				class="
                novi_btn
                btn btn-sm
                preset-filled-warning-200-800 hover:preset-filled-success-200-800
                transition
                "
				title="Cancel editing of post comment for {$idaa_slct.post_comment_obj
					?.full_name} (ID: {$idaa_slct.post_comment_obj?.post_comment_id}"
			>
				<span class="fas fa-times m-1"></span>
				Cancel Edit
			</button>
		</section>
		<!-- END: section post__options -->

		<!-- <h3 class="h3">Post Comment</h3> -->

		<input type="hidden" value={$idaa_slct.post_comment_id} />

		<div
			class="ae_section post_comment__general_information border border-gray-200 rounded p-1 space-y-1"
		>
			<!-- BEGIN: section post_comment__general_information -->

			<label for="content" class="ae_label post__content w-full">
				<span class="legend text-sm font-semibold text-gray-600 dark:text-gray-400">
					Content (comment body):
				</span>

				<Tiptap_editor
					default_minimal={true}
					html_text={$idaa_slct.post_comment_obj?.content}
					show_button_kv={{ heading__h1: false, heading__h2: false, heading__h3: false }}
					bind:new_html={content_new_html}
					bind:changed={content_changed}
					classes="bg-gray-100 dark:bg-gray-800"
					placeholder="Your post content here..."
				/>
			</label>

			<h3 class="h3">Commenter's Information</h3>
			<fieldset class="form-group">
				<legend class="text-sm text-gray-600 dark:text-gray-400">Comment as Anonymous</legend>
				<div class="flex flex-row gap-2">
					<input
						type="radio"
						id="anonymous_no"
						name="anonymous"
						value={false}
						bind:group={$idaa_slct.post_comment_obj.anonymous}
						class="radio"
					/>
					<label for="anonymous_no"><strong>No</strong>, include my name and email address</label>
				</div>
				<div class="flex flex-row gap-2">
					<input
						type="radio"
						id="anonymous_yes"
						name="anonymous"
						value={true}
						bind:group={$idaa_slct.post_comment_obj.anonymous}
						class="radio"
					/>
					<label for="anonymous_yes"
						><strong>Yes</strong>, the post will be listed as Anonymous</label
					>
				</div>
			</fieldset>

			<div>
				<label for="external_person_id" class="block form-group d-block w-100">
					<span class="text-sm text-gray-600 dark:text-gray-400">
						<span class="fas fa-link"></span> Linked with Novi ID
					</span>
					{#if !$ae_loc.trusted_access}
						<span class="fas fa-lock" title="Field is locked"></span>
						<input
							type="text"
							id="external_person_id"
							name="external_person_id"
							value={$idaa_slct.post_comment_obj.external_person_id
								? $idaa_slct.post_comment_obj.external_person_id
								: $idaa_loc.novi_uuid}
							readonly={true}
							class="input w-96 form-control"
						/>
					{:else}
						<div class="ae_highlight text-sm bg-yellow-100 p-2">
							Primary link using the Novi API UUID. This must be empty, a staff person, or an active
							member of IDAA and should be the primary contact for this meeting.
						</div>
						<span class="fas fa-unlock m-1" title="Field is unlocked"></span>
						<input
							type="text"
							id="external_person_id"
							name="external_person_id"
							value={$idaa_slct.post_comment_obj.external_person_id
								? $idaa_slct.post_comment_obj.external_person_id
								: ''}
							readonly={false}
							class="input w-96 form-control"
						/>
					{/if}
				</label>
			</div>

			<div>
				<label for="full_name" class="block form-group d-block w-75">
					<span class="text-sm text-gray-600 dark:text-gray-400">
						Name
						{#if !$ae_loc.trusted_access}
							<span class="fas fa-lock m-1" title="Field is locked"></span>
						{:else}
							<span class="fas fa-unlock m-1" title="Field is unlocked"></span>
						{/if}
					</span>
					<input
						type="text"
						id="full_name"
						name="full_name"
						value={$idaa_slct.post_comment_obj.full_name
							? $idaa_slct.post_comment_obj.full_name
							: $idaa_loc.novi_full_name}
						readonly={!$ae_loc.trusted_access}
						class="input w-96 form-control"
					/>
				</label>
			</div>

			{#if $ae_loc.trusted_access}
				<div>
					<label for="email" class="block form-group d-block w-75">
						<span class="text-sm text-gray-600 dark:text-gray-400"> Email </span>
						{#if !$ae_loc.trusted_access}
							<span class="fas fa-lock m-1" title="Field is locked"></span>
						{:else}
							<span class="fas fa-unlock m-1" title="Field is unlocked"></span>
						{/if}
						<input
							type="text"
							name="email"
							value={$idaa_slct.post_comment_obj.email
								? $idaa_slct.post_comment_obj.email
								: $idaa_loc.novi_email}
							readonly={!$ae_loc.trusted_access}
							class="input w-96 form-control"
						/>
						<span class="text-xs text-gray-600 dark:text-gray-400 italic">
							Secondary link using the Novi email address
						</span>
					</label>
				</div>
			{:else}
				<input
					type="hidden"
					name="email"
					value={$idaa_slct.post_comment_obj.email
						? $idaa_slct.post_comment_obj.email
						: $idaa_loc.novi_email}
				/>
			{/if}
		</div>
		<!-- END: section post__general_information -->

		{#if $ae_loc.trusted_access}
			<button
				type="button"
				class="
            novi_btn
            btn btn-sm float-right
            "
				class:preset-filled-success-200-800={$idaa_loc.bb.show__admin_options}
				class:preset-filled-tertiary-200-800={!$idaa_loc.bb.show__admin_options}
				onclick={() => {
					$idaa_loc.bb.show__admin_options = !$idaa_loc.bb.show__admin_options;
				}}
			>
				{#if $idaa_loc.bb.show__admin_options}
					<span class="fas fa-eye-slash m-1"></span>
				{:else}
					<span class="fas fa-eye m-1"></span>
				{/if}
				{$idaa_loc.bb.show__admin_options ? 'Hide' : 'Show'} Admin
			</button>

			<!-- BEGIN: section post__admin_options -->
			<div
				class="
            ae_section post_comment__admin_options
            space-y-1 p-2
            rounded
            preset-filled-surface-100-900 preset-outlined-error-400-600
            transition
            "
				class:hidden={!$idaa_loc.bb.show__admin_options}
			>
				<h3 class="h3">Admin Options</h3>

				<span
					class="flex flex-col md:flex-row flex-wrap gap-2 items-center justify-center md:justify-stretch w-full"
				>
					<span class="flex flex-row flex-wrap gap-2 items-center justify-evenly grow form-check">
						<fieldset class="flex flex-row gap-1 items-center justify-center">
							<legend class="legend text-sm font-semibold form-check-label">Hide</legend>
							<div>
								<input
									type="radio"
									id="hide_yes"
									name="hide"
									value={true}
									bind:group={$idaa_slct.post_comment_obj.hide}
									class="radio form-check-input"
								/>
								<label for="hide_yes">Yes</label>
							</div>
							<div>
								<input
									type="radio"
									id="hide_no"
									name="hide"
									value={false}
									bind:group={$idaa_slct.post_comment_obj.hide}
									class="radio form-check-input"
								/>
								<label for="hide_no">No</label>
							</div>
						</fieldset>

						<fieldset class="flex flex-row gap-2 items-center justify-center form-check">
							<legend class="legend text-sm font-semibold form-check-label">Priority</legend>
							<div>
								<input
									type="radio"
									id="priority_yes"
									name="priority"
									value={true}
									bind:group={$idaa_slct.post_comment_obj.priority}
									class="radio form-check-input"
								/>
								<label for="priority_yes">Yes</label>
							</div>
							<div>
								<input
									type="radio"
									id="priority_no"
									name="priority"
									value={false}
									bind:group={$idaa_slct.post_comment_obj.priority}
									class="radio form-check-input"
								/>
								<label for="priority_no">No</label>
							</div>
						</fieldset>
					</span>

					<span
						class="
                    grow
                    flex flex-row flex-wrap gap-1 items-center justify-evenly
                    col-sm-1
                "
					>
						<label class="legend text-sm font-semibold input-group"
							>Sort <input
								type="number"
								name="sort"
								value={$idaa_slct.post_comment_obj.sort}
								class="input w-24"
							/></label
						>

						<label class="legend text-sm font-semibold input-group"
							>Group <input
								type="text"
								name="group"
								value={$idaa_slct.post_comment_obj.group ?? ''}
								max="100"
								class="input w-40"
							/></label
						>
					</span>

					{#if $ae_loc.administrator_access}
						<span class="flex flex-row flex-wrap gap-1 items-center justify-evenly grow">
							<fieldset class="flex flex-row gap-2 form-check">
								<legend class="legend text-sm font-semibold form-check-label">Enable</legend>
								<div>
									<input
										type="radio"
										id="enable_yes"
										name="enable"
										value={true}
										bind:group={$idaa_slct.post_comment_obj.enable}
										class="radio form-check-input"
									/>
									<label for="enable_yes">Yes</label>
								</div>
								<div>
									<input
										type="radio"
										id="enable_no"
										name="enable"
										value={false}
										bind:group={$idaa_slct.post_comment_obj.enable}
										class="radio form-check-input"
									/>
									<label for="enable_no">No</label>
								</div>
							</fieldset>
						</span>
					{/if}
				</span>

				<!-- {#if $ae_loc.trusted_access}
        <label
            for="notes"
            >
            <span class="legend text-sm font-semibold">Internal Staff Notes</span>
            <Tiptap_editor
                default_minimal={true}
                bind:html_text={$idaa_slct.post_comment_obj.notes}
                show_button_kv={{'heading__h1': false, 'heading__h2': false, 'heading__h3': false}}
                bind:new_html={$idaa_slct.post_comment_obj.notes_new_html}
                />
        </label>
        {/if} -->
			</div>
			<!-- END: section post_comment__admin_options -->
		{/if}

		<div
			class="
            ae_section ae_options ae_row ae_actions post_comment__options post_comment__actions
            flex flex-row gap-1 items-center justify-between w-full
            d-flex align-items-center justify-content-between
        "
		>
			<div>
				<!-- BEGIN: section post_comment__options -->
				{#if $idaa_slct.post_comment_id}
					<button
						type="submit"
						disabled={disable_submit_btn}
						class="
                    novi_btn
                    btn btn-md preset-tonal-primary preset-outlined-primary-800-200 hover:preset-filled-primary-200-800
                    transition
                "
					>
						{#await prom_api__post_comment_obj}
							<span class="fas fa-spinner fa-spin m-1"></span> Saving
						{:then}
							<span class="fas fa-save m-1"></span> Save Changes
						{/await}
					</button>
				{:else}
					<button
						type="submit"
						disabled={disable_submit_btn}
						onclick={() => {
							if (!confirm('Are you sure you want to create this post?')) {
								return false;
							}
							// handle_save_post_comment_obj({post_id: $idaa_slct.post_id, method: 'create'});
						}}
						class="
                    novi_btn
                    btn btn-md preset-tonal-warning preset-outlined-warning-800-200 hover:preset-filled-warning-200-800
                    transition
                "
					>
						{#await prom_api__post_comment_obj}
							<span class="fas fa-spinner fa-spin m-1"></span> Saving
						{:then}
							<span class="fas fa-plus m-1"></span> Save New Comment
						{/await}
					</button>
				{/if}

				{#if $idaa_slct.post_comment_id}
					{#if $ae_loc.administrator_access}
						<button
							type="button"
							onclick={() => {
								if (!confirm('Are you sure you want to delete this post comment?')) {
									return false;
								}
								handle_delete_post_comment_obj({
									post_comment_id: $idaa_slct.post_comment_id,
									method: 'delete'
								});
							}}
							class="
                novi_btn
                btn btn-sm
                preset-filled-warning-400-600 hover:preset-filled-error-200-800
                "
							title="Delete record permanently"
						>
							<span class="fas fa-minus m-1"></span> Delete
						</button>
					{:else if $ae_loc.trusted_access}
						<button
							type="button"
							onclick={() => {
								if (!confirm('Are you sure you want to disable this post comment?')) {
									return false;
								}
								handle_delete_post_comment_obj({
									post_comment_id: $idaa_slct.post_comment_id,
									method: 'disable'
								});
							}}
							class="
                novi_btn
                btn btn-sm
                preset-filled-warning-200-800 hover:preset-filled-error-200-800
                transition
                "
							title="Disable record to delete"
						>
							<span class="fas fa-minus m-1"></span> Delete
						</button>
					{:else}
						<button
							type="button"
							onclick={() => {
								if (!confirm('Are you sure you want to hide this post comment?')) {
									return false;
								}
								handle_delete_post_comment_obj({
									post_comment_id: $idaa_slct.post_comment_id,
									method: 'hide'
								});
							}}
							class="
                novi_btn
                btn btn-sm
                preset-filled-warning-200-800 hover:preset-filled-error-200-800
                transition
                "
							title="Hide record to delete"
						>
							<span class="fas fa-comment-slash m-1"></span> Delete
						</button>
					{/if}
				{/if}
			</div>

			<div>
				<button
					type="button"
					onclick={() => {
						$idaa_sess.bb.show__inline_edit__post_comment_id = false;
					}}
					class="
                novi_btn
                btn btn-sm
                preset-filled-warning-200-800 hover:preset-filled-success-200-800
                transition
                "
					title="Cancel editing of post for {$idaa_slct.post_comment_obj.full_name} (ID: {$idaa_slct
						.post_comment_obj.post_comment_id}"
				>
					<span class="fas fa-times m-1"></span>
					Cancel Edit
				</button>
			</div>
		</div>
	</form>
</section>

<style lang="scss">
</style>
