<?php
/**
 * Internationalization helpers.
 *
 * @package SEOvaultSEO
 * @since   1.0.0
 *
 * Text Domain:  seovault-ai
 * Domain Path:  /languages
 */

namespace SEOvaultSEO\Core;

/**
 * Text domain loading and shared translatable strings for JS localization.
 */
class I18n {

	/**
	 * Plugin text domain. Must match the main plugin header and WordPress.org slug.
	 */
	const TEXT_DOMAIN = 'seovault-ai';

	/**
	 * Load plugin translations from /languages.
	 *
	 * WordPress.org-hosted plugins are auto-loaded since 4.6; explicit loading
	 * is still required for custom .mo files in development and self-hosted installs.
	 */
	public static function load_textdomain() {
		// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Required for self-hosted installs and custom language packs outside WordPress.org.
		load_plugin_textdomain(
			self::TEXT_DOMAIN,
			false,
			dirname( plugin_basename( SEOVAULT_SEO_FILE ) ) . '/languages'
		);
	}

	/**
	 * Shared user-facing strings passed to admin JavaScript via wp_localize_script().
	 *
	 * @return array<string, string>
	 */
	public static function get_admin_script_strings() {
		return array(
			'copied_text'                 => __( 'Copied!', 'seovault-ai' ),
			'search_variables'            => __( 'Search variables…', 'seovault-ai' ),
			'select_default_social_image' => __( 'Select Default Social Image', 'seovault-ai' ),
			'set_default_image'           => __( 'Set Default Image', 'seovault-ai' ),
			'social_image_alt'            => __( 'Social Image', 'seovault-ai' ),
			'url_placeholder'             => __( 'https://...', 'seovault-ai' ),
			'error_unknown'               => __( 'Unknown error', 'seovault-ai' ),
			'save_failed'                 => __( 'Save failed.', 'seovault-ai' ),
			'templates_load_failed'       => __( 'Failed to load templates.', 'seovault-ai' ),
			'label_show'                  => __( 'Show', 'seovault-ai' ),
			'label_hide'                  => __( 'Hide', 'seovault-ai' ),
			'schema_templates_show'       => __( 'Show Schema Templates', 'seovault-ai' ),
			'schema_templates_hide'       => __( 'Hide Schema Templates', 'seovault-ai' ),
			'schema_v2_save_failed'       => __( 'Could not save schema settings.', 'seovault-ai' ),
			'schema_v2_stale'             => __( 'Schema settings were updated elsewhere. Reload the page and try again.', 'seovault-ai' ),
			'schema_v2_legacy_disabled'   => __( 'Legacy schema catalogue saving is disabled while V2 schema settings are active.', 'seovault-ai' ),
			'schema_v2_saved'             => __( 'Saved!', 'seovault-ai' ),
			'schema_v2_saving'            => __( 'Saving…', 'seovault-ai' ),
			'select_options_label'        => __( 'Options', 'seovault-ai' ),
			'migration_complete'          => __( '=== Migration Complete ===', 'seovault-ai' ),
			'migration_imported_label'    => __( 'Imported: ', 'seovault-ai' ),
			'migration_skipped_label'     => __( ' | Skipped: ', 'seovault-ai' ),
			'migration_error'             => __( 'Error: ', 'seovault-ai' ),
			'migration_ajax_error'        => __( 'AJAX Error: ', 'seovault-ai' ),
			'migration_global_imported'   => __( 'Global settings imported successfully.', 'seovault-ai' ),
			'migration_no_global_found'   => __( 'No global settings found to import.', 'seovault-ai' ),
		);
	}

	/**
	 * Meta box assessment UI strings for JavaScript.
	 *
	 * @return array<string, string>
	 */
	public static function get_metabox_script_strings() {
		return array(
			'assessment_good'      => __( 'Good', 'seovault-ai' ),
			'assessment_okay'      => __( 'Okay', 'seovault-ai' ),
			'assessment_bad'       => __( 'Needs Work', 'seovault-ai' ),
			'assessment_unknown'   => __( 'Unknown', 'seovault-ai' ),
			'analyzing'            => __( 'Analyzing...', 'seovault-ai' ),
			'keyword_load_failed'  => __( 'Could not load keyword suggestions.', 'seovault-ai' ),
			'keyword_retry'        => __( 'Could not load keyword suggestions. Please try again.', 'seovault-ai' ),
			'no_keywords_found'    => __( 'No keywords found. Try adding more content.', 'seovault-ai' ),
			'schema_checking'      => __( 'Checking…', 'seovault-ai' ),
			'schema_check'         => __( 'Check schema', 'seovault-ai' ),
			'schema_check_failed'  => __( 'Schema check failed. Please try again.', 'seovault-ai' ),
			'schema_changes_stale' => __( 'Custom schema changes have not been checked.', 'seovault-ai' ),
			'schema_live_checking' => __( 'Checking published page…', 'seovault-ai' ),
			'schema_live_check'    => __( 'Check published page', 'seovault-ai' ),
			'schema_live_failed'   => __( 'Published-page check failed. Please try again.', 'seovault-ai' ),
			'schema_review_loading'=> __( 'Loading schema details…', 'seovault-ai' ),
			'schema_review_failed' => __( 'Could not load schema details. Please try again.', 'seovault-ai' ),
			'schema_review_copied' => __( 'Diagnostics copied.', 'seovault-ai' ),
			'schema_review_copy_failed' => __( 'Could not copy diagnostics.', 'seovault-ai' ),
			'schema_add_guided_title' => __( 'Guided schema form', 'seovault-ai' ),
			'schema_guided_save' => __( 'Save draft', 'seovault-ai' ),
			'schema_guided_saving' => __( 'Saving…', 'seovault-ai' ),
			'schema_guided_cancel' => __( 'Cancel', 'seovault-ai' ),
			'schema_guided_remove' => __( 'Remove', 'seovault-ai' ),
			'schema_guided_remove_confirm' => __( 'Remove this schema draft from the post?', 'seovault-ai' ),
			'schema_guided_unsaved' => __( 'You have unsaved schema changes. Discard them?', 'seovault-ai' ),
			'schema_guided_save_failed' => __( 'Could not save the schema draft. Please try again.', 'seovault-ai' ),
			'schema_guided_ready' => __( 'Ready to publish when the page is saved.', 'seovault-ai' ),
			'schema_guided_unfinished' => __( 'Saved as unfinished setup — not published yet.', 'seovault-ai' ),
			'schema_guided_advisory' => __( 'Field hints help you fill the form. SEOvault decides readiness on the server when you save.', 'seovault-ai' ),
			'schema_guided_add_item' => __( 'Add item', 'seovault-ai' ),
			'schema_guided_remove_item' => __( 'Remove item', 'seovault-ai' ),
			'schema_guided_select_media' => __( 'Select media', 'seovault-ai' ),
			'schema_guided_visibility_legend' => __( 'Content visibility', 'seovault-ai' ),
			'schema_guided_visibility_help' => __( 'Specialized schema should match content readers can see on the page.', 'seovault-ai' ),
			'schema_guided_visibility_help_optional' => __( 'Confirm how this schema relates to visible page content.', 'seovault-ai' ),
			'schema_guided_visibility_seovault_block' => __( 'I will keep matching visible content (SEOvault block/summary when available).', 'seovault-ai' ),
			'schema_guided_visibility_confirm' => __( 'I confirm equivalent content is already visible on this page.', 'seovault-ai' ),
			'schema_guided_visibility_anchor_label' => __( 'Optional page section / anchor reference', 'seovault-ai' ),
			'schema_guided_visibility_anchor_placeholder' => __( 'e.g. #event-details or “Event section”', 'seovault-ai' ),
			'schema_guided_select_placeholder' => __( 'Select…', 'seovault-ai' ),
			/* translators: %d: number of unfinished guided-schema items still needed. */
			'schema_guided_blockers_remaining' => __( '%d item(s) still needed.', 'seovault-ai' ),
			/* translators: %d: 1-based list item index. */
			'schema_guided_list_item_label' => __( 'Item %d', 'seovault-ai' ),
			'schema_guided_field_invalid' => __( 'This field needs attention.', 'seovault-ai' ),
			'schema_source_template' => __( 'Template', 'seovault-ai' ),
			'schema_source_integration' => __( 'Integration', 'seovault-ai' ),
			'schema_source_guided' => __( 'Guided form', 'seovault-ai' ),
			/* translators: %s: Schema Health status label (e.g. Healthy). */
			'schema_health_updated' => __( 'Schema Health updated: %s', 'seovault-ai' ),
			'schema_setup_complete' => __( 'Complete', 'seovault-ai' ),
			'schema_setup_remove' => __( 'Remove', 'seovault-ai' ),
			'schema_setup_edit' => __( 'Edit', 'seovault-ai' ),
			'schema_setup_remove_confirm' => __( 'Remove this schema draft from the post?', 'seovault-ai' ),
			'schema_setup_load_failed' => __( 'Could not load that schema draft. Please try again.', 'seovault-ai' ),
			'schema_faq_block_name' => 'seovault/faq',
			'schema_howto_block_name' => 'seovault/howto',
			'schema_faq_insert_failed' => __( 'Could not insert the FAQ block. Open the block inserter and add “FAQ”, or switch to the block editor.', 'seovault-ai' ),
			'schema_howto_insert_failed' => __( 'Could not insert the How-to block. Open the block inserter and add “How-to”, or switch to the block editor.', 'seovault-ai' ),
			'schema_faq_classic_editor' => __( 'The FAQ block requires the block editor. Switch this post to the block editor to add FAQ content.', 'seovault-ai' ),
			'schema_howto_classic_editor' => __( 'The How-to block requires the block editor. Switch this post to the block editor to add How-to content.', 'seovault-ai' ),
			'schema_block_insert_failed' => __( 'Could not insert the schema block. Open the block inserter or switch to the block editor.', 'seovault-ai' ),
			'schema_block_classic_editor' => __( 'This schema block requires the block editor. Switch this post to the block editor to continue.', 'seovault-ai' ),
			'schema_custom_json_formatting' => __( 'Formatting…', 'seovault-ai' ),
			'schema_custom_json_format' => __( 'Format', 'seovault-ai' ),
			'schema_custom_json_format_ok' => __( 'JSON formatted.', 'seovault-ai' ),
			'schema_custom_json_format_failed' => __( 'Fix JSON syntax before formatting.', 'seovault-ai' ),
			'schema_custom_json_previewing' => __( 'Previewing…', 'seovault-ai' ),
			'schema_custom_json_preview' => __( 'Preview', 'seovault-ai' ),
			'schema_custom_json_preview_failed' => __( 'Could not preview custom JSON. Please try again.', 'seovault-ai' ),
			'schema_custom_json_restoring' => __( 'Restoring…', 'seovault-ai' ),
			'schema_custom_json_restore' => __( 'Restore last valid', 'seovault-ai' ),
			'schema_custom_json_restore_ok' => __( 'Last valid custom JSON restored. Save the post to keep other edits.', 'seovault-ai' ),
			'schema_custom_json_restore_failed' => __( 'No last-valid custom JSON is available to restore.', 'seovault-ai' ),
			'schema_custom_json_restore_confirm' => __( 'Restore the last valid custom JSON? Unsaved editor text will be replaced.', 'seovault-ai' ),
			'schema_suggestion_confirm_failed' => __( 'Could not prepare that block. Edit the values and try again.', 'seovault-ai' ),
			'schema_suggestion_dismiss_failed' => __( 'Could not dismiss that suggestion.', 'seovault-ai' ),
			'schema_suggestion_create' => __( 'Create block', 'seovault-ai' ),
			'schema_suggestion_creating' => __( 'Creating…', 'seovault-ai' ),
			'schema_suggestion_incomplete' => __( 'Add complete values before creating the block.', 'seovault-ai' ),
			'schema_suggestion_faq_heading' => __( 'FAQ heading', 'seovault-ai' ),
			'schema_suggestion_faq_question' => __( 'Question', 'seovault-ai' ),
			'schema_suggestion_faq_answer' => __( 'Answer', 'seovault-ai' ),
			'schema_suggestion_howto_name' => __( 'How-to name', 'seovault-ai' ),
			'schema_suggestion_howto_step' => __( 'Step', 'seovault-ai' ),
			'schema_suggestion_howto_step_text' => __( 'Step details', 'seovault-ai' ),
			'schema_suggestion_add_row' => __( 'Add row', 'seovault-ai' ),
			'schema_suggestion_remove_row' => __( 'Remove', 'seovault-ai' ),
		);
	}

	/**
	 * SEO Analyzer page strings for JavaScript.
	 *
	 * @return array<string, string>
	 */
	public static function get_analyzer_script_strings() {
		return array(
			'category_priority' => __( 'Priority', 'seovault-ai' ),
			'category_basic'    => __( 'Basic SEO', 'seovault-ai' ),
			'category_advanced' => __( 'Advanced SEO', 'seovault-ai' ),
			'grade_good'        => __( 'Excellent', 'seovault-ai' ),
			'grade_average'     => __( 'Needs Improvement', 'seovault-ai' ),
			'grade_bad'         => __( 'Poor', 'seovault-ai' ),
			'analysis_failed'   => __( 'Analysis failed.', 'seovault-ai' ),
			'last_checked'      => __( 'Last checked:', 'seovault-ai' ),
			'ajax_error'        => __( 'AJAX error: ', 'seovault-ai' ),
		);
	}

	/**
	 * Merge shared admin i18n strings into a wp_localize_script() data array.
	 *
	 * @param array<string, mixed> $data Existing localization data.
	 * @return array<string, mixed>
	 */
	public static function merge_admin_script_strings( array $data ) {
		return array_merge( self::get_admin_script_strings(), $data );
	}

	/**
	 * Merge meta box i18n strings into a wp_localize_script() data array.
	 *
	 * @param array<string, mixed> $data Existing localization data.
	 * @return array<string, mixed>
	 */
	public static function merge_metabox_script_strings( array $data ) {
		return array_merge( self::get_admin_script_strings(), self::get_metabox_script_strings(), $data );
	}
}
