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

if (!defined('ABSPATH')) {
	exit;
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$modules = PreciousSuite_Registry::instance()->all();
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$tasks_by_plugin = array();

if (isset($modules['gold-price'])) {
	$rates_configured = '' !== get_option('gold', '') && '' !== get_option('silver', '') && '' !== get_option('platinum', '');
	$product_total = 0;
	$product_selected_count = 0;
	$physical_product_total = 0;
	$product_weight_count = 0;

	if (post_type_exists('product')) {
		$product_statuses = array('publish', 'draft', 'pending', 'private');
		$product_query = new WP_Query(
			array(
				'post_type' => 'product',
				'post_status' => $product_statuses,
				'fields' => 'ids',
				'posts_per_page' => 1,
			)
		);
		$product_selected_query = new WP_Query(
			array(
				'post_type' => 'product',
				'post_status' => $product_statuses,
				'fields' => 'ids',
				'posts_per_page' => 1,
				'meta_query' => array(
					array(
						'key' => 'jewellery_field',
						'value' => array('1', '2', '3'),
						'compare' => 'IN',
					),
				),
			)
		);
		$physical_product_query = new WP_Query(
			array(
				'post_type' => 'product',
				'post_status' => $product_statuses,
				'fields' => 'ids',
				'posts_per_page' => 1,
				'meta_query' => array(
					'relation' => 'OR',
					array(
						'key' => '_virtual',
						'compare' => 'NOT EXISTS',
					),
					array(
						'key' => '_virtual',
						'value' => 'yes',
						'compare' => '!=',
					),
				),
			)
		);
		$product_weight_query = new WP_Query(
			array(
				'post_type' => 'product',
				'post_status' => $product_statuses,
				'fields' => 'ids',
				'posts_per_page' => 1,
				'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' => '!=',
					),
				),
			)
		);

		$product_total = (int) $product_query->found_posts;
		$product_selected_count = (int) $product_selected_query->found_posts;
		$physical_product_total = (int) $physical_product_query->found_posts;
		$product_weight_count = (int) $product_weight_query->found_posts;
	}

	$product_remaining_count = max(0, $product_total - $product_selected_count);

	$product_progress_label = sprintf(
		/* translators: 1: Number of selected products, 2: Total number of products. */
		__('%1$d/%2$d products', 'preciousuite-gold-buyback-quote-calculator'),
		$product_selected_count,
		$product_total
	);

	$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-gold-buyback-quote-calculator'),
		$product_remaining_count
	);

	$weight_remaining_count = max(0, $physical_product_total - $product_weight_count);
	$weight_progress_label = sprintf(
		/* translators: 1: Number of products with weight configured, 2: Total number of physical products. */
		__('%1$d/%2$d products', 'preciousuite-gold-buyback-quote-calculator'),
		$product_weight_count,
		$physical_product_total
	);
	$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-gold-buyback-quote-calculator'),
		$weight_remaining_count
	);

	$tasks_by_plugin['gold-price'] = array(
		'title' => __('Gold Price Based on Weight', 'preciousuite-gold-buyback-quote-calculator'),
		'tasks' => array(
			array(
				'label' => __('Add manual gold, silver, and platinum rates', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price'),
				'done' => $rates_configured,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $rates_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Select the metal option on each product', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('edit.php?post_type=product&ptgold_metal_type=none'),
				'done' => $product_total > 0 && 0 === $product_remaining_count,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('10m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $product_total > 0 ? $product_progress_label : __('0/0 products', 'preciousuite-gold-buyback-quote-calculator'),
				'note' => $product_total > 0 ? $product_remaining_label : __('No products found yet', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Select the weight option on each product', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('edit.php?post_type=product&ptgold_missing_weight=1'),
				'done' => $physical_product_total > 0 && 0 === $weight_remaining_count,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('10m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $physical_product_total > 0 ? $weight_progress_label : __('0/0 products', 'preciousuite-gold-buyback-quote-calculator'),
				'note' => $physical_product_total > 0 ? $weight_remaining_label : __('No products found yet', 'preciousuite-gold-buyback-quote-calculator'),
			),
		)
	);
}

if (is_plugin_active('preciousuite-metal-rate-charts/preciousuite-metal-rate-charts.php')) {
	$api_configured = '' !== get_option('pmrcgold_api_key', '');
	$widget1_configured = is_array(get_option('widget1_metals', false)) && !empty(get_option('widget1_metals', false)) && is_array(get_option('widget1_currencies', false)) && !empty(get_option('widget1_currencies', false));
	$widget2_configured = is_array(get_option('widget2_metals', false)) && !empty(get_option('widget2_metals', false)) && is_array(get_option('widget2_currencies', false)) && !empty(get_option('widget2_currencies', false));
	$widget3_configured = is_array(get_option('widget3_metals', false)) && !empty(get_option('widget3_metals', false)) && is_array(get_option('widget3_currencies', false)) && !empty(get_option('widget3_currencies', false));
	$widget4_configured = is_array(get_option('widget4_metals', false)) && !empty(get_option('widget4_metals', false)) && is_array(get_option('widget4_currencies', false)) && !empty(get_option('widget4_currencies', false));

	$tasks_by_plugin['gold-price-widgets'] = array(
		'title' => __('Metal Rate Charts', 'preciousuite-gold-buyback-quote-calculator'),
		'tasks' => array(
			array(
				'label' => __('Set API Key', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price-api-settings'),
				'done' => $api_configured,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('3m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $api_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Widget 1 Setup', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $widget1_configured,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $widget1_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Widget 2 Setup', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $widget2_configured,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $widget2_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Widget 3 Setup', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $widget3_configured,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $widget3_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Widget 4 Setup', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=gold-price-widgets'),
				'done' => $widget4_configured,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $widget4_configured ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			)
		)
	);
}

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-gold-buyback-quote-calculator'),
		'tasks' => array(
			array(
				'label' => __('Add manual buyback gold rate', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_rate_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $buyback_rate_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Set buyback payout percentage', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_margin_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $buyback_margin_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Select buyback currency symbol', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $buyback_currency_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('3m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $buyback_currency_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure admin WhatsApp number for buyback quotes', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $whatsapp_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $whatsapp_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure SMTP credentials for lead emails', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=preciousuite-settings'),
				'done' => $smtp_done,
				'priority' => __('Low', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('10m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $smtp_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
		)
	);
}

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 = get_option('jicg_invoice_template', '');
	$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-gold-buyback-quote-calculator'),
		'tasks' => array(
			array(
				'label' => __('Configure jewelry shop details (logo, address, name)', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=general'),
				'done' => $shop_name_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $shop_name_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Set up invoice prefix', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=invoice'),
				'done' => $invoice_prefix_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $invoice_prefix_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Set default metal and weight unit', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=metal'),
				'done' => $metal_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $metal_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure tax mode and rate', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=tax'),
				'done' => $tax_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $tax_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure certificate settings', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=certificate'),
				'done' => $cert_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $cert_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Set base currency for invoices', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=currency'),
				'done' => $currency_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $currency_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Select invoice layout template and colors', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=template'),
				'done' => $template_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $template_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure auto-email invoice settings', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=email'),
				'done' => $email_done,
				'priority' => __('Low', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $email_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure WhatsApp message sharing template', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=jicg-settings&tab=whatsapp'),
				'done' => $whatsapp_done,
				'priority' => __('Low', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('5m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $whatsapp_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
		)
	);
}

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-gold-buyback-quote-calculator'),
		'tasks' => array(
			array(
				'label' => __('Configure Razorpay Key ID', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $key_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('2m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $key_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Configure Razorpay Secret Key', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $secret_done,
				'priority' => __('High', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('3m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $secret_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
			array(
				'label' => __('Set Manual Gold Price Fallback', 'preciousuite-gold-buyback-quote-calculator'),
				'url' => admin_url('admin.php?page=ps-gs-settings'),
				'done' => $price_done,
				'priority' => __('Medium', 'preciousuite-gold-buyback-quote-calculator'),
				'duration' => __('3m', 'preciousuite-gold-buyback-quote-calculator'),
				'progress' => $price_done ? __('1/1', 'preciousuite-gold-buyback-quote-calculator') : __('0/1', 'preciousuite-gold-buyback-quote-calculator'),
			),
		)
	);
}

$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(PRECIOUSUITE_URL . 'assets/uploads/Preciousuite_Logo.png'); ?>"
								alt="<?php esc_attr_e('Preciousuite Logo', 'preciousuite-gold-buyback-quote-calculator'); ?>">
						</a>
					</div>
				</div>
			</div>
			<nav>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite')); ?>">
					<img src="<?php echo esc_url(PRECIOUSUITE_URL . 'assets/uploads/dashboard-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-gold-buyback-quote-calculator'); ?>" width="20"
						height="20" loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('General', 'preciousuite-gold-buyback-quote-calculator'); ?>
				</a>
				<a class="is-active" href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-tasks')); ?>">
					<img src="<?php echo esc_url(PRECIOUSUITE_URL . 'assets/uploads/task-list-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-gold-buyback-quote-calculator'); ?>" width="20"
						height="20" loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('Task list', 'preciousuite-gold-buyback-quote-calculator'); ?>
				</a>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-alerts')); ?>">
					<img src="<?php echo esc_url(PRECIOUSUITE_URL . 'assets/uploads/alert-center-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-gold-buyback-quote-calculator'); ?>" width="20"
						height="20" loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('Alert center', 'preciousuite-gold-buyback-quote-calculator'); ?></a>
				<a href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-configuration')); ?>">
					<img src="<?php echo esc_url(PRECIOUSUITE_URL . 'assets/uploads/first-time-configuration-icon.png'); ?>"
						alt="<?php esc_attr_e('General', 'preciousuite-gold-buyback-quote-calculator'); ?>" width="20"
						height="20" loading="lazy" style="margin-right: .75rem;" />
					<?php esc_html_e('First-time configuration', 'preciousuite-gold-buyback-quote-calculator'); ?>
				</a>
			</nav>
		</aside>

		<main class="preciousuite-dashboard-main">
			<section class="preciousuite-dashboard-hero">
				<h1><?php esc_html_e('Task list', 'preciousuite-gold-buyback-quote-calculator'); ?></h1>
				<p><?php esc_html_e('Complete these Gold Price setup steps to turn manual metal rates and product weights into dynamic WooCommerce prices.', 'preciousuite-gold-buyback-quote-calculator'); ?>
				</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-gold-buyback-quote-calculator'), $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-gold-buyback-quote-calculator'); ?></span>
								<span><?php esc_html_e('Priority', 'preciousuite-gold-buyback-quote-calculator'); ?></span>
								<span><?php esc_html_e('Est. duration', 'preciousuite-gold-buyback-quote-calculator'); ?></span>
								<span><?php esc_html_e('Progress', 'preciousuite-gold-buyback-quote-calculator'); ?></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-gold-buyback-quote-calculator'); ?>
				</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-gold-buyback-quote-calculator'); ?>
				</p>
				<a
					href="<?php echo esc_url(admin_url('admin.php?page=preciousuite-support')); ?>"><?php esc_html_e('Open setup guide →', 'preciousuite-gold-buyback-quote-calculator'); ?></a>
			</section>
		</aside>
	</div>
</div>