<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

// Get ticket ID from arguments
$order_id      = isset( $args['order_id'] ) ? intval( $args['order_id'] ) : 0;
$active_user   = wp_get_current_user();
$comment_args  = array(
	'post_id' => $order_id,
	'type'    => 'order_private_note',
	'user_id' => $active_user->ID,
);
$private_notes = get_comments( $comment_args );
?>
<div id="gn-order-private-notes" class="gn-order-section gn-order-notes">
	<div class="gn-head">
		<h3 class="gn-title"><?php echo esc_html__( 'Private note', 'gigneo' ); ?></h3>
		<a class="gn-link gn-link-primary" id="gn-add-order-note" data-gn-modal-toggle="gn-order-note-modal">
			<?php echo esc_html__( 'Add note', 'gigneo' ); ?>
			<i class="hi hi-plus" aria-hidden="true"></i>
		</a>
	</div>
	<div class="gn-private-note-body">
		<?php if ( ! empty( $private_notes ) ) { ?>
			<div class="gn-private-note-slider-wrapper gn-slick-slider">
				<?php foreach ( $private_notes as $private_note ) { ?>
					<div class="gn-note-slide" data-gn-order-id="<?php echo esc_attr( $private_note->comment_ID ); ?>">
						<p class="gn-description"><?php echo wp_kses( wp_trim_words( $private_note->comment_content, 50, '...' ), gigneo_allowed_html_tags() ); ?></p>
						<div class="gn-actions">
						<span class="gn-note-date">
							<?php echo esc_html( gigneo_datetime( $private_note->comment_date_gmt, get_option( 'date_format' ) ) ); ?>
							<?php echo esc_html( gigneo_datetime( $private_note->comment_date_gmt, get_option( 'time_format' ) ) ); ?>
						</span>
							<span class="gn-note-controls">
							<?php
							$fields_data = array(
								'note_id'      => esc_attr( $private_note->comment_ID ),
								'order_id'     => esc_attr( $private_note->comment_post_ID ),
								'note_content' => wp_json_encode( $private_note->comment_content ),
							);
							?>
							<button class="gn-btn gn-edit-private-note"
									data-gn-fields="<?php echo esc_attr( wp_json_encode( $fields_data ) ); ?>"
									data-gn-modal-toggle="gn-order-note-modal">
								<i class="hi hi-pencil-edit" aria-hidden="true"></i>
							</button>
							<button class="gn-btn gn-delete-private-note"
									data-gn-note-id="<?php echo esc_attr( $private_note->comment_ID ); ?>"
									data-gn-order-id="<?php echo esc_attr( $order_id ); ?>">
								<i class="hi hi-trash" aria-hidden="true"></i>
							</button>
						</span>
						</div>
					</div>
				<?php } ?>
			</div>
		<?php } ?>
	</div>
</div>
<div id="gn-order-note-modal" class=" gn-order-note-modal gn-modal-wrapper">
	<div class="gn-modal-dialog">
		<div class="gn-modal-content">
			<div class="gn-modal-info">
				<form id="gn-order-private-note-form" class="gn-theme-form">
					<div class="gn-modal-header">
						<h4 class="gn-title">
							<?php echo esc_html__( 'Private note', 'gigneo' ); ?>
							<span class="gn-status-tag"><?php echo esc_html( '' ); ?></span>
						</h4>
						<p class="gn-description"><?php echo esc_html__( 'Keep personal notes for your reference only.', 'gigneo' ); ?></p>
						<button type="button" data-gn-modal-close="gn-order-note-modal" class="gn-modal-close">
							<i class="hi hi-x-mark" aria-hidden="true"></i>
						</button>
					</div>
					<div class="gn-modal-body gn-custom-scrollbar">
						<fieldset class="gn-form-fields">
							<div class="row g-4">
								<div class="col-md-12">
									<div class="gn-form-field gn-wysiwyg-editor-two">
										<label for="gn-order-note" class="gn-required-field-label"><?php echo esc_html__( 'Description', 'gigneo' ); ?></label>
										<?php
										wp_editor(
											wp_kses_post( '' ),
											'gn-order-note',
											array(
												'textarea_name' => 'note_content',
												'textarea_id' => 'gn-note-wysiwyg',
												'media_buttons' => false,
												'quicktags' => false,
												'textarea_rows' => 7,
												'editor_class' => 'gn-wp-editor gn-required-field',
												'tinymce' => array(
													'toolbar1' => 'bold italic bullist numlist link unlink',
													'toolbar2' => '',
													'plugins'  => 'lists link',
													'directionality' => is_rtl() ? 'rtl' : 'ltr',
													'forced_root_block' => false,
													'force_br_newlines' => true,
													'force_p_newlines' => false,
													'convert_newlines_to_brs' => true,
													'valid_elements' => 'strong/b,em/i,ul,ol,li,a[href|target],br,hr',
													'invalid_elements' => 'p,pre,h1,h2,h3,h4,h5,h6,img',
													'content_style' => 'body { font-size: 14px; background-color: transparent; font-family: var(--gigneo-primary-font,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji) }',
												),
											)
										);
										?>
									</div>
								</div>
							</div>
						</fieldset>
					</div>
					<div class="gn-modal-footer">
						<input type="hidden" name="note_id" value="">
						<input type="hidden" name="order_id" value="<?php echo esc_attr( $order_id ); ?>">
						<button type="button" data-gn-modal-close="gn-order-note-modal" class="gn-btn gn-btn-outline-grey"><?php echo esc_html__( 'Cancel', 'gigneo' ); ?></button>
						<button type="submit" class="gn-btn gn-btn-primary"><?php echo esc_html__( 'Save', 'gigneo' ); ?></button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
