<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! current_user_can( 'manage_options' ) ) {
	return;
}
?>
<div class="wrap smc-wrap">
	<h1><?php esc_html_e( 'Orphan Cleanup', 'smart-media-cleanup' ); ?></h1>
	<p class="description"><?php esc_html_e( 'Scan your media library for attachments that are not used anywhere. Review them and delete in bulk.', 'smart-media-cleanup' ); ?></p>

	<div class="smc-notice smc-notice--warning">
		<span class="dashicons dashicons-warning"></span>
		<div>
			<strong><?php esc_html_e( 'Deletion is permanent and cannot be undone.', 'smart-media-cleanup' ); ?></strong>
			<?php esc_html_e( 'Before deleting, review each file carefully. The plugin checks whether files are in use, but custom page builders or plugins may store image references in ways that are not detected. When in doubt, take a backup first.', 'smart-media-cleanup' ); ?>
		</div>
	</div>

	<div id="smc-scan-controls" style="margin: 20px 0;">
		<button id="smc-scan-btn" class="button button-primary"><?php esc_html_e( 'Scan Library', 'smart-media-cleanup' ); ?></button>
		<span id="smc-scan-status" style="margin-left:10px;color:#646970;"></span>
	</div>

	<div class="smc-progress-wrap" id="smc-progress-wrap">
		<div class="smc-progress-bar">
			<div class="smc-progress-bar-inner" id="smc-progress-bar-inner"></div>
		</div>
		<div class="smc-progress-label" id="smc-progress-label"></div>
	</div>

	<div id="smc-results" style="display:none;">
		<div id="smc-summary" style="margin:16px 0;"></div>

		<div class="smc-bulk-actions" style="margin-bottom:10px;">
			<label>
				<input type="checkbox" id="smc-select-all">
				<?php esc_html_e( 'Select all', 'smart-media-cleanup' ); ?>
			</label>
			<button id="smc-delete-btn" class="button button-primary" style="margin-left:12px;"><?php esc_html_e( 'Delete Selected', 'smart-media-cleanup' ); ?></button>
			<span id="smc-delete-status" style="margin-left:10px;color:#646970;"></span>
		</div>

		<table class="wp-list-table widefat fixed striped smc-orphan-table">
			<thead>
				<tr>
					<th style="width:30px;"></th>
					<th style="width:70px;"><?php esc_html_e( 'Preview', 'smart-media-cleanup' ); ?></th>
					<th><?php esc_html_e( 'Filename', 'smart-media-cleanup' ); ?></th>
					<th style="width:80px;"><?php esc_html_e( 'Size', 'smart-media-cleanup' ); ?></th>
					<th style="width:100px;"><?php esc_html_e( 'Uploaded', 'smart-media-cleanup' ); ?></th>
					<th style="width:60px;"></th>
				</tr>
			</thead>
			<tbody id="smc-orphan-tbody">
			</tbody>
		</table>
	</div>

	<div id="smc-empty" style="display:none;">
		<p><?php esc_html_e( 'No orphan attachments found. Your media library is clean!', 'smart-media-cleanup' ); ?></p>
	</div>
</div>

<!-- Confirmation modal -->
<div id="smc-modal-overlay" class="smc-modal-overlay" style="display:none;" role="dialog" aria-modal="true" aria-labelledby="smc-modal-title">
	<div class="smc-modal">
		<div class="smc-modal-header">
			<span class="dashicons dashicons-warning smc-modal-icon"></span>
			<h2 id="smc-modal-title"><?php esc_html_e( 'Permanently Delete Files?', 'smart-media-cleanup' ); ?></h2>
		</div>
		<p id="smc-modal-message"></p>
		<p class="smc-modal-caution"><?php esc_html_e( 'This action cannot be undone. The files will be permanently removed from the server.', 'smart-media-cleanup' ); ?></p>
		<div class="smc-modal-actions">
			<button id="smc-modal-cancel" class="button button-large"><?php esc_html_e( 'Cancel — Keep Files', 'smart-media-cleanup' ); ?></button>
			<button id="smc-modal-confirm" class="button button-large smc-btn-danger"><?php esc_html_e( 'Yes, Delete Permanently', 'smart-media-cleanup' ); ?></button>
		</div>
	</div>
</div>
