/**
 * External dependencies.
 */
import { __ } from '@wordpress/i18n';

/**
 * Attribute name for dynamic content elements.
 *
 * @since x.x.x
 *
 * @constant {string}
 */
export const DYNAMIC_CONTENT_ATTR = 'data-spectra-dc';

/**
 * Format type identifier for dynamic content.
 *
 * @since x.x.x
 *
 * @constant {string}
 */
export const DYNAMIC_CONTENT_FORMAT_TYPE = 'spectra-pro/dynamic-content';

/**
 * Configuration object defining content attributes for text-based block types.
 * Maps block types to their respective content attributes.
 *
 * @since x.x.x
 *
 * @constant {Object}
 */
export const BLOCK_CONTENT_CONFIG = {
	'spectra/content': { contentAttr: 'text' },
	'spectra/button': { contentAttr: 'text' },
	'spectra/accordion-child-header-content': { contentAttr: 'text' },
};

/**
 * Array of block types that support dynamic text content.
 * Derived from the keys of BLOCK_CONTENT_CONFIG.
 *
 * @since x.x.x
 *
 * @constant {string[]}
 */
export const SUPPORTED_BLOCKS = [ ...Object.keys( BLOCK_CONTENT_CONFIG ) ];

/**
 * Configuration object defining content attributes for image-based block types.
 * Maps block types to their respective image-related attributes.
 *
 * @since x.x.x
 *
 * @constant {Object}
 */
export const IMAGE_BLOCK_CONTENT_CONFIG = {
	'spectra/slider': { contentAttr: 'background' },
	'spectra/container': { contentAttr: 'background' },
	'spectra/modal-popup-content': { contentAttr: 'background' },
	'core/image': { contentAttr: 'url' },
	'spectra-pro/login': { contentAttr: 'background' },
};

/**
 * Array of block types that support dynamic image content.
 * Derived from the keys of IMAGE_BLOCK_CONTENT_CONFIG.
 *
 * @since x.x.x
 *
 * @constant {string[]}
 */
export const IMAGE_SUPPORTED_BLOCKS = [ ...Object.keys( IMAGE_BLOCK_CONTENT_CONFIG ) ];

/**
 * Array of block types that support dynamic link content.
 *
 * @constant {string[]}
 */
export const LINK_SUPPORTED_BLOCKS = [ 'spectra/button', 'spectra/icon', 'spectra/container', 'core/image', 'spectra-pro/register' ];

/**
 * List of available data sources for dynamic content.
 * Each source has a label and value for use in UI and processing.
 *
 * @since x.x.x
 *
 * @constant {Object[]}
 */
export const DATA_SOURCES = [
	{ label: 'Current Post', value: 'current_post' },
	{ label: 'Post Type', value: 'post_type' },
	{ label: 'Archive', value: 'archive' },
	{ label: 'Site', value: 'site' },
	{ label: 'Current User', value: 'current_user' },
	{ label: 'Request Parameter', value: 'request_parameter' },
	{ label: 'Shortcode', value: 'shortcode' },
];

/**
 * Configuration for fields available for each data source.
 * Organizes fields into groups with labels, values, and options for UI rendering.
 *
 * @since x.x.x
 *
 * @constant {Object}
 */
export const SOURCE_FIELDS = {
	current_post: [
		{
			label: __( 'Post', 'spectra-pro' ),
			value: 'post',
			options: [
				{ label: __( 'Post Title', 'spectra-pro' ), value: 'post_title' },
				{ label: __( 'Post Excerpt', 'spectra-pro' ), value: 'post_excerpt' },
				{ label: __( 'Featured Image', 'spectra-pro' ), value: 'featured_image' },
				{ label: __( 'Post Custom Field', 'spectra-pro' ), value: 'custom_field' },
				{ label: __( 'Post Date', 'spectra-pro' ), value: 'post_date' },
				{ label: __( 'Post Time', 'spectra-pro' ), value: 'post_time' },
				{ label: __( 'Post Terms', 'spectra-pro' ), value: 'post_terms' },
				{ label: __( 'Post ID', 'spectra-pro' ), value: 'post_ID' },
				{ label: __( 'Comments Number', 'spectra-pro' ), value: 'comments_number' },
			],
		},
		{
			label: __( 'Author', 'spectra-pro' ),
			value: 'author',
			options: [
				{ value: 'name', label: __( 'Name', 'spectra-pro' ) },
				{ value: 'first_name', label: __( 'First Name', 'spectra-pro' ) },
				{ value: 'last_name', label: __( 'Last Name', 'spectra-pro' ) },
				{ value: 'display_name', label: __( 'Display Name', 'spectra-pro' ) },
				{ value: 'login', label: __( 'Username', 'spectra-pro' ) },
				{ value: 'description', label: __( 'Description', 'spectra-pro' ) },
				{ value: 'nicename', label: __( 'Nickname', 'spectra-pro' ) },
				{ value: 'description', label: __( 'Bio', 'spectra-pro' ) },
				{ value: 'email', label: __( 'Email', 'spectra-pro' ) },
				{ value: 'id', label: __( 'User ID', 'spectra-pro' ) },
				{ value: 'url', label: __( 'Website', 'spectra-pro' ) },
				{ value: 'avatar', label: __( 'Avatar Image URL', 'spectra-pro' ) },
				{ value: 'author_info', label: __( 'Author Custom Field', 'spectra-pro' ) },
			],
		},
	],
	post_type: [
		{
			label: __( 'Post', 'spectra-pro' ),
			value: 'post',
			options: [
				{ label: __( 'Post Title', 'spectra-pro' ), value: 'post_title' },
				{ label: __( 'Post Excerpt', 'spectra-pro' ), value: 'post_excerpt' },
				{ label: __( 'Featured Image', 'spectra-pro' ), value: 'featured_image' },
				{ label: __( 'Post Custom Field', 'spectra-pro' ), value: 'custom_field' },
				{ label: __( 'Post Date', 'spectra-pro' ), value: 'post_date' },
				{ label: __( 'Post Time', 'spectra-pro' ), value: 'post_time' },
				{ label: __( 'Post Terms', 'spectra-pro' ), value: 'post_terms' },
				{ label: __( 'Post ID', 'spectra-pro' ), value: 'post_ID' },
				{ label: __( 'Comments Number', 'spectra-pro' ), value: 'comments_number' },
			],
		},
		{
			label: __( 'Author', 'spectra-pro' ),
			value: 'author',
			options: [
				{ value: 'name', label: __( 'Name', 'spectra-pro' ) },
				{ value: 'first_name', label: __( 'First Name', 'spectra-pro' ) },
				{ value: 'last_name', label: __( 'Last Name', 'spectra-pro' ) },
				{ value: 'display_name', label: __( 'Display Name', 'spectra-pro' ) },
				{ value: 'login', label: __( 'Username', 'spectra-pro' ) },
				{ value: 'description', label: __( 'Description', 'spectra-pro' ) },
				{ value: 'nicename', label: __( 'Nickname', 'spectra-pro' ) },
				{ value: 'description', label: __( 'Bio', 'spectra-pro' ) },
				{ value: 'email', label: __( 'Email', 'spectra-pro' ) },
				{ value: 'id', label: __( 'User ID', 'spectra-pro' ) },
				{ value: 'url', label: __( 'Website', 'spectra-pro' ) },
				{ value: 'avatar', label: __( 'Avatar Image URL', 'spectra-pro' ) },
				{ value: 'author_info', label: __( 'Author Custom Field', 'spectra-pro' ) },
			],
		},
	],
	archive: [
		{ label: __( 'Archive Title', 'spectra-pro' ), value: 'archive_title' },
		{ label: __( 'Archive Description', 'spectra-pro' ), value: 'archive_description' },
		{ label: __( 'Archive URL', 'spectra-pro' ), value: 'archive_url' },
		{ label: __( 'Archive Custom Field', 'spectra-pro' ), value: 'archive_meta' },
	],
	site: [
		{ label: 'Site Title', value: 'site_title' },
		{ label: 'Site Tagline', value: 'site_tagline' },
		{ label: 'Site URL', value: 'site_url' },
		{ label: 'Admin Email', value: 'admin_email' },
	],
	request_parameter: [
		{ label: 'Get', value: 'GET' },
		{ label: 'Post', value: 'POST' },
		{ label: 'Query Var', value: 'QUERY_VAR' },
	],
};

/**
 * Configuration for link sources and their available options.
 * Organizes link sources into groups with labels, values, and options.
 *
 * @since x.x.x
 *
 * @constant {Object[]}
 */
export const LINK_SOURCES = [
	{
		label: __( 'Choose', 'spectra-pro' ),
		value: '',
	},
	{
		label: __( 'Post', 'spectra-pro' ),
		value: 'post',
		options: [
			{ label: __( 'Post Permalink', 'spectra-pro' ), value: 'post_permalink' },
			{ label: __( 'Comments Area', 'spectra-pro' ), value: 'comments_area' },
			{ label: __( 'Featured Image', 'spectra-pro' ), value: 'featured_image' },
			{ label: __( 'Post Custom Field', 'spectra-pro' ), value: 'custom_field' },
		],
	},
	{
		label: __( 'Author', 'spectra-pro' ),
		value: 'author',
		options: [
			{ value: 'avatar', label: __( 'Avatar (Profile URL)', 'spectra-pro' ) },
			{ value: 'author_info', label: __( 'Author Custom Field', 'spectra-pro' ) },
			{ value: 'author_archive', label: __( 'Author Archive URL', 'spectra-pro' ) },
			{ value: 'author_page', label: __( 'Author Page URL', 'spectra-pro' ) },
		],
	},
];

/**
 * URL-specific field mappings for dynamic link generation.
 * Maps source types to their URL-generating fields.
 *
 * @since x.x.x
 *
 * @constant {Object}
 */
export const URL_FIELD_MAPPINGS = {
	current_post: {
		post_title: 'post_permalink',
		post_excerpt: 'post_permalink',
		post_ID: 'post_permalink',
		featured_image: 'featured_image_url',
		custom_field: 'custom_field_url',
		// Author fields automatically link to author archive
		name: 'author_archive',
		display_name: 'author_archive',
		email: 'author_archive',
		url: 'author_website',
		// Default fallback
		default: 'post_permalink',
	},
	post_type: {
		post_title: 'post_permalink',
		post_excerpt: 'post_permalink',
		post_ID: 'post_permalink',
		featured_image: 'featured_image_url',
		custom_field: 'custom_field_url',
		// Author fields automatically link to author archive
		name: 'author_archive',
		display_name: 'author_archive',
		email: 'author_archive',
		url: 'author_website',
		// Default fallback
		default: 'post_permalink',
	},
	site: {
		site_title: 'site_url',
		site_tagline: 'site_url',
		site_url: 'site_url',
		admin_email: 'site_url',
		default: 'site_url',
	},
	archive: {
		archive_title: 'archive_url',
		archive_description: 'archive_url',
		archive_url: 'archive_url',
		archive_meta: 'archive_url',
		default: 'archive_url',
	},
	current_user: {
		url: 'user_website',
		email: 'user_profile',
		default: 'user_profile',
	},
};

/**
 * Link field options for each data source.
 * These define where the dynamic link should point to.
 *
 * @since x.x.x
 *
 * @constant {Object}
 */
export const LINK_FIELD_OPTIONS = {
	current_post: [
		{ label: __( 'Post Permalink', 'spectra-pro' ), value: 'post_permalink' },
		{ label: __( 'Comments Area', 'spectra-pro' ), value: 'comments_area' },
		{ label: __( 'Featured Image URL', 'spectra-pro' ), value: 'featured_image' },
		{ label: __( 'Post Custom Field', 'spectra-pro' ), value: 'custom_field' },
		{ label: __( 'Author Archive', 'spectra-pro' ), value: 'author_archive' },
		{ label: __( 'Author Website', 'spectra-pro' ), value: 'author_website' },
		{ label: __( 'First Term Archive', 'spectra-pro' ), value: 'post_terms' },
	],
	post_type: [
		{ label: __( 'Post Permalink', 'spectra-pro' ), value: 'post_permalink' },
		{ label: __( 'Comments Area', 'spectra-pro' ), value: 'comments_area' },
		{ label: __( 'Featured Image URL', 'spectra-pro' ), value: 'featured_image' },
		{ label: __( 'Post Custom Field', 'spectra-pro' ), value: 'custom_field' },
		{ label: __( 'Author Archive', 'spectra-pro' ), value: 'author_archive' },
		{ label: __( 'Author Website', 'spectra-pro' ), value: 'author_website' },
		{ label: __( 'First Term Archive', 'spectra-pro' ), value: 'post_terms' },
	],
	site: [
		{ label: __( 'Site URL', 'spectra-pro' ), value: 'site_url' },
		{ label: __( 'Home URL', 'spectra-pro' ), value: 'home_url' },
	],
	archive: [
		{ label: __( 'Archive URL', 'spectra-pro' ), value: 'archive_url' },
		{ label: __( 'Archive Custom Field', 'spectra-pro' ), value: 'archive_meta' },
	],
	current_user: [
		{ label: __( 'User Profile URL', 'spectra-pro' ), value: 'user_profile' },
		{ label: __( 'User Website URL', 'spectra-pro' ), value: 'user_website' },
		{ label: __( 'User Custom Field', 'spectra-pro' ), value: 'custom_field' },
	],
	request_parameter: [ { label: __( 'Parameter Value as URL', 'spectra-pro' ), value: 'parameter_url' } ],
	shortcode: [ { label: __( 'Shortcode Output as URL', 'spectra-pro' ), value: 'shortcode_url' } ],
};

/**
 * Options for featured image fields.
 * Defines available metadata fields for featured images.
 *
 * @since x.x.x
 *
 * @constant {Object[]}
 */
export const FEATURED_IMAGE_OPTIONS = [
	{ value: 'title', label: __( 'Title', 'spectra-pro' ) },
	{ value: 'alt_text', label: __( 'Alt', 'spectra-pro' ) },
	{ value: 'caption', label: __( 'Caption', 'spectra-pro' ) },
	{ value: 'description', label: __( 'Description', 'spectra-pro' ) },
	{ value: 'link', label: __( 'File URL', 'spectra-pro' ) },
	{ value: 'source_url', label: __( 'Attachment URL', 'spectra-pro' ) },
];
