<?php
/**
 * Vendor Profile ClickUp Integration Section Template
 *
 * Rendered on the WP Admin → Users → Edit User page for vendors.
 * JS behaviour (create-task button) is handled by vendor-profile.js.
 *
 * @var \WP_User $user     User object.
 * @var string   $task_id  ClickUp task ID (empty if not yet created).
 * @var string   $task_url ClickUp task URL (empty if not stored).
 * @var bool     $created  Whether a task has been created for this vendor.
 * @var string   $rest_url REST endpoint URL for creating a task.
 * @var string   $nonce    REST API nonce.
 * @package VendorTasksDokanClickUp
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<h2><?php esc_html_e( 'ClickUp Integration', 'alamin-vendor-tasks-dokan-clickup' ); ?></h2>
<table class="form-table" id="vendor-tasks-dokan-clickup-vendor-section">
	<tr>
		<th><?php esc_html_e( 'ClickUp Task', 'alamin-vendor-tasks-dokan-clickup' ); ?></th>
		<td>
			<?php if ( $task_id && $task_url ) : ?>
				<a href="<?php echo esc_url( $task_url ); ?>" target="_blank" rel="noopener noreferrer">
					<?php echo esc_html( $task_id ); ?>
				</a>
			<?php elseif ( $task_id ) : ?>
				<code><?php echo esc_html( $task_id ); ?></code>
			<?php elseif ( $created ) : ?>
				<em><?php esc_html_e( 'Task ID not stored. Task may have been created manually.', 'alamin-vendor-tasks-dokan-clickup' ); ?></em>
			<?php else : ?>
				<em><?php esc_html_e( 'No task created yet.', 'alamin-vendor-tasks-dokan-clickup' ); ?></em>
			<?php endif; ?>
		</td>
	</tr>
	<tr>
		<th><?php esc_html_e( 'Actions', 'alamin-vendor-tasks-dokan-clickup' ); ?></th>
		<td>
			<button
				type="button"
				id="vendor-tasks-dokan-clickup-create-task"
				class="button button-secondary"
				data-vendor-id="<?php echo absint( $user->ID ); ?>"
				data-rest-url="<?php echo esc_url( $rest_url ); ?>"
				data-nonce="<?php echo esc_attr( $nonce ); ?>"
			>
				<?php
				echo $created
					? esc_html__( 'Re-create ClickUp Task', 'alamin-vendor-tasks-dokan-clickup' )
					: esc_html__( 'Create ClickUp Task', 'alamin-vendor-tasks-dokan-clickup' );
				?>
			</button>
			<span id="vendor-tasks-dokan-clickup-task-result" style="margin-left:10px;"></span>
		</td>
	</tr>
</table>
