<?php
/**
 * Preciousuite task list view.
 *
 * @package Preciousuite
 */

if (!defined('ABSPATH')) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$modules = PreciousSuite_Registry::instance()->all();
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$rates_configured = '' !== get_option('gold', '') && '' !== get_option('silver', '') && '' !== get_option('platinum', '');
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$product_total = 0;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$product_selected_count = 0;

if (post_type_exists('product')) {
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_statuses = array('publish', 'draft', 'pending', 'private');
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_query = new WP_Query(
		array(
			'post_type' => 'product',
			'post_status' => $product_statuses,
			'fields' => 'ids',
			'posts_per_page' => 1,
		)
	);
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_selected_query = new WP_Query(
		array(
			'post_type' => 'product',
			'post_status' => $product_statuses,
			'fields' => 'ids',
			'posts_per_page' => 1,
			// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			'meta_query' => array(
				array(
					'key' => 'jewellery_field',
					'value' => array('1', '2', '3'),
					'compare' => 'IN',
				),
			),
		)
	);
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$physical_product_query = new WP_Query(
		array(
			'post_type' => 'product',
			'post_status' => $product_statuses,
			'fields' => 'ids',
			'posts_per_page' => 1,
			// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			'meta_query' => array(
				'relation' => 'OR',
				array(
					'key' => '_virtual',
					'compare' => 'NOT EXISTS',
				),
				array(
					'key' => '_virtual',
					'value' => 'yes',
					'compare' => '!=',
				),
			),
		)
	);
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_weight_query = new WP_Query(
		array(
			'post_type' => 'product',
			'post_status' => $product_statuses,
			'fields' => 'ids',
			'posts_per_page' => 1,
			// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			'meta_query' => array(
				'relation' => 'AND',
				array(
					'relation' => 'OR',
					array(
						'key' => '_virtual',
						'compare' => 'NOT EXISTS',
					),
					array(
						'key' => '_virtual',
						'value' => 'yes',
						'compare' => '!=',
					),
				),
				array(
					'key' => '_weight',
					'value' => '',
					'compare' => '!=',
				),
				array(
					'key' => '_weight',
					'value' => '0',
					'compare' => '!=',
				),
			),
		)
	);

	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_total = (int) $product_query->found_posts;
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_selected_count = (int) $product_selected_query->found_posts;
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$physical_product_total = (int) $physical_product_query->found_posts;
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$product_weight_count = (int) $product_weight_query->found_posts;
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$product_remaining_count = max(0, $product_total - $product_selected_count);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$product_progress_label = sprintf(
	/* translators: 1: Number of selected products, 2: Total number of products. */
	__('%1$d/%2$d products', 'preciousuite-metal-rate-charts'),
	$product_selected_count,
	$product_total
);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$product_remaining_label = sprintf(
	/* translators: %d: Number of products remaining to select a metal option. */
	_n('%d product remaining to select metal option', '%d products remaining to select metal option', $product_remaining_count, 'preciousuite-metal-rate-charts'),
	$product_remaining_count
);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$weight_remaining_count = max(0, $physical_product_total - $product_weight_count);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$weight_progress_label = sprintf(
	/* translators: 1: Number of products with weight configured, 2: Total number of physical products. */
	__('%1$d/%2$d products', 'preciousuite-metal-rate-charts'),
	$product_weight_count,
	$physical_product_total
);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$weight_remaining_label = sprintf(
	/* translators: %d: Number of products remaining to add a weight option. */
	_n('%d product remaining to add weight option', '%d products remaining to add weight option', $weight_remaining_count, 'preciousuite-metal-rate-charts'),
	$weight_remaining_count
);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$api_key_configured = '' !== get_option('pmrcgold_api_key', '');

// Widget 1: metals, currencies, enabled (header/footer)
$w1_metals = get_option('widget1_metals', false);
$w1_currencies = get_option('widget1_currencies', false);
$w1_enabled = get_option('widget1_enabled', false);
$w1_done = is_array($w1_metals) && !empty($w1_metals)
	&& is_array($w1_currencies) && !empty($w1_currencies)
	&& is_array($w1_enabled) && !empty($w1_enabled);

// Widget 2: metals, currencies
$w2_metals = get_option('widget2_metals', false);
$w2_currencies = get_option('widget2_currencies', false);
$w2_done = is_array($w2_metals) && !empty($w2_metals)
	&& is_array($w2_currencies) && !empty($w2_currencies);

// Widget 3: metals, currencies
$w3_metals = get_option('widget3_metals', false);
$w3_currencies = get_option('widget3_currencies', false);
$w3_done = is_array($w3_metals) && !empty($w3_metals)
	&& is_array($w3_currencies) && !empty($w3_currencies);

// Widget 4: metals, currencies
$w4_metals = get_option('widget4_metals', false);
$w4_currencies = get_option('widget4_currencies', false);
$w4_done = is_array($w4_metals) && !empty($w4_metals)
	&& is_array($w4_currencies) && !empty($w4_currencies);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$tasks_by_plugin = array(
	'gold-price-widgets' => array(
		'title' => __('Metal Rate Charts', 'preciousuite-metal-rate-charts'),
		'tasks' => array(
			array(
				'label' => __('Set API Key', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=gold-price-api-settings'),
				'done' => $api_key_configured,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('2m', 'preciousuite-metal-rate-charts'),
				'progress' => $api_key_configured ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
				'note' => $api_key_configured ? __('API key configured', 'preciousuite-metal-rate-charts') : __('Configure Preciousuite API key', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Widget 1 Setup – Select metals, currencies & display options', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $w1_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('3m', 'preciousuite-metal-rate-charts'),
				'progress' => $w1_done ? __('3/3', 'preciousuite-metal-rate-charts') : sprintf(
					/* translators: %d: Number of completed tasks */
					__('%d/3', 'preciousuite-metal-rate-charts'),
					(int) (is_array($w1_metals) && !empty($w1_metals)) + (int) (is_array($w1_currencies) && !empty($w1_currencies)) + (int) (is_array($w1_enabled) && !empty($w1_enabled))
				),
				'note' => $w1_done ? __('Widget 1 configured', 'preciousuite-metal-rate-charts') : __('Select metals, currencies & header/footer', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Widget 2 Setup – Select metals & currencies', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $w2_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('2m', 'preciousuite-metal-rate-charts'),
				'progress' => $w2_done ? __('2/2', 'preciousuite-metal-rate-charts') : sprintf(
					/* translators: %d: Number of completed tasks */
					__('%d/2', 'preciousuite-metal-rate-charts'),
					(int) (is_array($w2_metals) && !empty($w2_metals)) + (int) (is_array($w2_currencies) && !empty($w2_currencies))
				),
				'note' => $w2_done ? __('Widget 2 configured', 'preciousuite-metal-rate-charts') : __('Select metals & currencies for widget 2', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Widget 3 Setup – Select metals & currency', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $w3_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('2m', 'preciousuite-metal-rate-charts'),
				'progress' => $w3_done ? __('2/2', 'preciousuite-metal-rate-charts') : sprintf(
					/* translators: %d: Number of completed tasks */
					__('%d/2', 'preciousuite-metal-rate-charts'),
					(int) (is_array($w3_metals) && !empty($w3_metals)) + (int) (is_array($w3_currencies) && !empty($w3_currencies))
				),
				'note' => $w3_done ? __('Widget 3 configured', 'preciousuite-metal-rate-charts') : __('Select metals & currency for chart widget', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Widget 4 Setup – Select metals & currencies', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $w4_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('2m', 'preciousuite-metal-rate-charts'),
				'progress' => $w4_done ? __('2/2', 'preciousuite-metal-rate-charts') : sprintf(
					/* translators: %d: Number of completed tasks */
					__('%d/2', 'preciousuite-metal-rate-charts'),
					(int) (is_array($w4_metals) && !empty($w4_metals)) + (int) (is_array($w4_currencies) && !empty($w4_currencies))
				),
				'note' => $w4_done ? __('Widget 4 configured', 'preciousuite-metal-rate-charts') : __('Select metals & currencies for widget 4', 'preciousuite-metal-rate-charts'),
			),
		)
	)
);

if (isset($modules['buyback-calculator'])) {
	$buyback_rate = get_option('preciousuite_manual_gold_rate', '');
	$buyback_rate_done = '' !== $buyback_rate;
	$buyback_margin = get_option('preciousuite_buyback_margin', '');
	$buyback_margin_done = '' !== $buyback_margin;
	$buyback_currency = get_option('preciousuite_currency', '');
	$buyback_currency_done = '' !== $buyback_currency;
	$whatsapp_number = get_option('preciousuite_whatsapp_number', '');
	$whatsapp_done = '' !== $whatsapp_number;
	$smtp_enabled = get_option('preciousuite_smtp_enable', '');
	$smtp_host = get_option('preciousuite_smtp_host', '');
	$smtp_port = get_option('preciousuite_smtp_port', '');
	$smtp_user = get_option('preciousuite_smtp_username', '');
	$smtp_pass = get_option('preciousuite_smtp_password', '');
	$smtp_done = ('1' === $smtp_enabled) || ('' !== $smtp_host && '' !== $smtp_port && '0' !== $smtp_port && '' !== $smtp_user && '' !== $smtp_pass);

	$tasks_by_plugin['buyback-calculator'] = array(
		'title' => __('Gold Buyback Quote Calculator', 'preciousuite-metal-rate-charts'),
		'tasks' => array(
			array(
				'label' => __('Add manual buyback gold rate', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_rate_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $buyback_rate_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Set buyback payout percentage', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_margin_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $buyback_margin_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Select buyback currency symbol', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_currency_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('3m', 'preciousuite-metal-rate-charts'),
				'progress' => $buyback_currency_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Configure admin WhatsApp number for buyback quotes', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $whatsapp_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $whatsapp_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Configure SMTP credentials for lead emails', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $smtp_done,
				'priority' => __('Low', 'preciousuite-metal-rate-charts'),
				'duration' => __('10m', 'preciousuite-metal-rate-charts'),
				'progress' => $smtp_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
		)
	);
}

if (isset($modules['invoice-generator'])) {
	$shop_name = get_option('jicg_shop_name', '');
	$shop_name_done = '' !== $shop_name;
	$invoice_prefix = get_option('jicg_invoice_prefix', '');
	$invoice_prefix_done = '' !== $invoice_prefix;
	$default_metal = get_option('jicg_default_metal', '');
	$weight_unit = get_option('jicg_weight_unit', '');
	$metal_done = '' !== $default_metal && '' !== $weight_unit;
	$tax_mode = get_option('jicg_tax_mode', '');
	$tax_done = '' !== $tax_mode;
	$cert_title = get_option('jicg_cert_title', '');
	$cert_done = '' !== $cert_title;
	$base_currency = get_option('jicg_base_currency', '');
	$currency_done = true;
	$invoice_template = true;
	$template_done = true;
	$email_subject = get_option('jicg_email_subject', '');
	$email_done = '' !== $email_subject;
	$whatsapp_message = get_option('jicg_whatsapp_message', '');
	$whatsapp_done = '' !== $whatsapp_message;

	$tasks_by_plugin['invoice-generator'] = array(
		'title' => __('Jewelry Invoice & Certificate Generator', 'preciousuite-metal-rate-charts'),
		'tasks' => array(
			array(
				'label' => __('Configure jewelry shop details (logo, address, name)', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=general'),
				'done' => $shop_name_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $shop_name_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Set up invoice prefix', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=invoice'),
				'done' => $invoice_prefix_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $invoice_prefix_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			/*
			array(
				'label' => __('Set default metal and weight unit', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=metal'),
				'done' => $metal_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $metal_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			*/
			array(
				'label' => __('Configure tax mode and rate', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=tax'),
				'done' => $tax_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $tax_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Configure certificate settings', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=certificate'),
				'done' => $cert_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $cert_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Set base currency for invoices', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=currency'),
				'done' => $currency_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $currency_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Select invoice layout template and colors', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=template'),
				'done' => $template_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $template_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			/*
			array(
				'label' => __('Configure auto-email invoice settings', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=email'),
				'done' => $email_done,
				'priority' => __('Low', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $email_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			*/
			array(
				'label' => __('Configure WhatsApp message sharing template', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=whatsapp'),
				'done' => $whatsapp_done,
				'priority' => __('Low', 'preciousuite-metal-rate-charts'),
				'duration' => __('5m', 'preciousuite-metal-rate-charts'),
				'progress' => $whatsapp_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
		)
	);
}

if (isset($modules['gold-savings-scheme'])) {
	$razorpay_key = get_option('ps_gs_razorpay_key_id', '');
	$razorpay_secret = get_option('ps_gs_razorpay_secret_key', '');
	$manual_price = get_option('ps_gs_manual_gold_price', '');

	$key_done = '' !== $razorpay_key;
	$secret_done = '' !== $razorpay_secret;
	$price_done = '' !== $manual_price;

	$tasks_by_plugin['gold-savings-scheme'] = array(
		'title' => __('Gold Savings Scheme', 'preciousuite-metal-rate-charts'),
		'tasks' => array(
			array(
				'label' => __('Configure Razorpay Key ID', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $key_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('2m', 'preciousuite-metal-rate-charts'),
				'progress' => $key_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Configure Razorpay Secret Key', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $secret_done,
				'priority' => __('High', 'preciousuite-metal-rate-charts'),
				'duration' => __('3m', 'preciousuite-metal-rate-charts'),
				'progress' => $secret_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
			array(
				'label' => __('Set Manual Gold Price Fallback', 'preciousuite-metal-rate-charts'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $price_done,
				'priority' => __('Medium', 'preciousuite-metal-rate-charts'),
				'duration' => __('3m', 'preciousuite-metal-rate-charts'),
				'progress' => $price_done ? __('1/1', 'preciousuite-metal-rate-charts') : __('0/1', 'preciousuite-metal-rate-charts'),
			),
		)
	);
}

$task_total = 0;
$tasks_completed = 0;
foreach ($tasks_by_plugin as $plugin_data) {
	$task_total += count($plugin_data['tasks']);
	foreach ($plugin_data['tasks'] as $task) {
		if (!empty($task['done'])) {
			$tasks_completed++;
		}
	}
}
$task_progress_pct = $task_total > 0 ? round(($tasks_completed / $task_total) * 100) : 0;
?>

<div class="wrap precioussuite-wrap preciousuite-wrap preciousuite-dashboard preciousuite-task-list-page">
	<div class="preciousuite-dashboard-shell">
		<aside class="preciousuite-dashboard-nav">
			<div class="preciousuite-dashboard-brand">
				<div class="preciousuite-page-brand">
					<div class="preciousuite-box preciousuite-logo">
						<a href="<?php echo esc_url("https://www.preciousuite.com"); ?>" target="_blank"
							rel="noopener noreferrer" class="preciousuite-page-title">
							<img src="<?php echo esc_url(PMRCGOLD_URL . 'includes/precioussuite/assets/' . 'uploads/Preciousuite_Logo.png'); ?>"
								alt="<?php esc_attr_e('Preciousuite Logo', 'preciousuite-metal-rate-charts'); ?>">
						</a>
					</div>
				</div>
			</div>
			<nav>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite')); ?>">
					<img src="<?php echo esc_url(PMRCGOLD_URL . 'includes/precioussuite/assets/' . '/uploads/dashboard-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-metal-rate-charts'); ?>" width="20" height="20"
						loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('General', 'preciousuite-metal-rate-charts'); ?>
				</a>
				<a class="is-active" href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-tasks')); ?>">
					<img src="<?php echo esc_url(PMRCGOLD_URL . 'includes/precioussuite/assets/' . '/uploads/task-list-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-metal-rate-charts'); ?>" width="20" height="20"
						loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('Task list', 'preciousuite-metal-rate-charts'); ?>
				</a>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-alerts')); ?>">
					<img src="<?php echo esc_url(PMRCGOLD_URL . 'includes/precioussuite/assets/' . '/uploads/alert-center-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-metal-rate-charts'); ?>" width="20" height="20"
						loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('Alert center', 'preciousuite-metal-rate-charts'); ?></a>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-configuration')); ?>">
					<img src="<?php echo esc_url(PMRCGOLD_URL . 'includes/precioussuite/assets/' . '/uploads/first-time-configuration-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-metal-rate-charts'); ?>" width="20" height="20"
						loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('First-time configuration', 'preciousuite-metal-rate-charts'); ?>
				</a>
			</nav>
		</aside>

		<main class="preciousuite-dashboard-main">
			<section class="preciousuite-dashboard-hero">
				<h1><?php esc_html_e('Task list', 'preciousuite-metal-rate-charts'); ?></h1>
				<p><?php esc_html_e('Complete these setup steps to configure your API key and widget settings for live metal rate charts.', 'preciousuite-metal-rate-charts'); ?>
				</p>
			</section>

			<section class="preciousuite-dashboard-card preciousuite-task-card">
				<div class="preciousuite-task-summary">
					<strong><?php echo
						esc_html(
							/* translators: 1: Number of completed tasks, 2: Total number of tasks. */
							sprintf(__('Tasks %1$d/%2$d', 'preciousuite-metal-rate-charts'), $tasks_completed, $task_total)
						); ?></strong>
					<div class="preciousuite-task-progressbar" aria-hidden="true">
						<span style="width: <?php echo esc_attr($task_progress_pct); ?>%"></span>
					</div>
				</div>

				<?php foreach ($tasks_by_plugin as $plugin_data): ?>
					<div class="preciousuite-plugin-tasks-group" style="margin-bottom: 28px;">
						<h3 style="margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--ps-primary);">
							<?php echo esc_html($plugin_data['title']); ?>
						</h3>
						<div class="preciousuite-task-table" style="margin-bottom: 12px;">
							<div class="preciousuite-task-table-head">
								<span><?php esc_html_e('Task', 'preciousuite-metal-rate-charts'); ?></span>
								<span><?php esc_html_e('Priority', 'preciousuite-metal-rate-charts'); ?></span>
								<span><?php esc_html_e('Est. duration', 'preciousuite-metal-rate-charts'); ?></span>
								<span><?php esc_html_e('Progress', 'preciousuite-metal-rate-charts'); ?></span>
								<span></span>
							</div>

							<?php foreach ($plugin_data['tasks'] as $task): ?>
								<a class="preciousuite-task-table-row <?php echo $task['done'] ? 'is-done' : ''; ?>"
									href="<?php echo esc_url($task['url']); ?>">
									<span class="preciousuite-task-status" aria-hidden="true"></span>
									<span class="preciousuite-task-title">
										<strong><?php echo esc_html($task['label']); ?></strong>
										<?php if (!empty($task['note'])): ?>
											<small><?php echo esc_html($task['note']); ?></small>
										<?php endif; ?>
									</span>
									<span
										class="preciousuite-task-priority is-<?php echo esc_attr(strtolower($task['priority'])); ?>">
										<?php echo esc_html($task['priority']); ?>
									</span>
									<span class="preciousuite-task-duration"><?php echo esc_html($task['duration']); ?></span>
									<span class="preciousuite-task-pill"><?php echo esc_html($task['progress']); ?></span>
									<span class="preciousuite-task-chevron" aria-hidden="true"></span>
								</a>
							<?php endforeach; ?>
						</div>
					</div>
				<?php endforeach; ?>
			</section>
		</main>

		<aside class="preciousuite-dashboard-sidebar">
			<section class="preciousuite-sidebar-card preciousuite-side-card preciousuite-task-help">
				<h2 style="display:flex; align-items:center; gap:8px;">
					<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#4f46e5" stroke-width="2"
						stroke-linecap="round" stroke-linejoin="round">
						<circle cx="12" cy="12" r="10"></circle>
						<path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path>
						<line x1="12" y1="17" x2="12.01" y2="17"></line>
					</svg>
					<?php esc_html_e('Task help', 'preciousuite-metal-rate-charts'); ?>
				</h2>
				<p><?php esc_html_e('First save your metal rates, then open products and assign the correct metal type. Completed tasks are marked automatically.', 'preciousuite-metal-rate-charts'); ?>
				</p>
				<a
					href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-support')); ?>"><?php esc_html_e('Open setup guide →', 'preciousuite-metal-rate-charts'); ?></a>
			</section>
		</aside>
	</div>
</div>
<?php
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound