<?php
/**
 * Metabox definition for the 'digital' custom post type.
 *
 * @package Sifency
 */

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

return [
	'digital_product_options' => [
		'title'     => esc_html__( 'Digital Product Details', 'sifency-addons' ),
		'post_type' => 'digital',
		'context'   => 'normal',
		'priority'  => 'high',
		'class'     => 'sifency-metabox',
		'fields'    => [

			// =================================================================
			// Section: General Information & Presentation
			// =================================================================
			[
				'id'    => 'digital_subtitle',
				'type'  => 'text',
				'title' => esc_html__( 'Product Subtitle / Tagline', 'sifency-addons' ),
				'desc'  => esc_html__( 'A short, descriptive line to display under the main title.', 'sifency-addons' ),
			],
			[
				'id'    => 'digital_version',
				'type'  => 'text',
				'title' => esc_html__( 'Current Version', 'sifency-addons' ),
				'desc'  => esc_html__( 'e.g., 1.2.0', 'sifency-addons' ),
			],
			[
				'id'    => 'digital_last_updated',
				'type'  => 'date',
				'title' => esc_html__( 'Last Updated Date', 'sifency-addons' ),
			],
			[
				'id'    => 'digital_badge_text',
				'type'  => 'text',
				'title' => esc_html__( 'Product Badge', 'sifency-addons' ),
				'desc'  => esc_html__( 'e.g., "New", "Updated", "Best Seller"', 'sifency-addons' ),
			],

			// =================================================================
			// Section: Pricing Model (Single Purchase vs. Subscription)
			// =================================================================
			[
				'id'      => 'digital_pricing_model',
				'type'    => 'button_set',
				'title'   => esc_html__( 'Pricing Model', 'sifency-addons' ),
				'options' => [
					'single'       => esc_html__( 'Single Purchase', 'sifency-addons' ),
					'subscription' => esc_html__( 'Subscription', 'sifency-addons' ),
				],
				'default' => 'single',
			],
			// --- Single Purchase Fields ---
			[
				'id'         => 'digital_price',
				'type'       => 'text',
				'title'      => esc_html__( 'Regular Price', 'sifency-addons' ),
				'desc'       => esc_html__( 'e.g., $29 or Free', 'sifency-addons' ),
				'dependency' => [ 'digital_pricing_model', '==', 'single' ],
			],
			[
				'id'         => 'digital_sale_price',
				'type'       => 'text',
				'title'      => esc_html__( 'Sale Price', 'sifency-addons' ),
				'desc'       => esc_html__( 'Leave blank if not on sale.', 'sifency-addons' ),
				'dependency' => [ 'digital_pricing_model', '==', 'single' ],
			],
			[
				'id'         => 'digital_purchase_link',
				'type'       => 'url',
				'title'      => esc_html__( 'Purchase URL', 'sifency-addons' ),
				'dependency' => [ 'digital_pricing_model', '==', 'single' ],
			],
			[
				'id'         => 'digital_purchase_link_text',
				'type'       => 'text',
				'title'      => esc_html__( 'Purchase URL Text', 'sifency-addons' ),
				'dependency' => [ 'digital_pricing_model', '==', 'single' ],
			],
			// --- Subscription Fields ---
			[
				'id'         => 'digital_subscription_tiers',
				'type'       => 'repeater',
				'title'      => esc_html__( 'Subscription Tiers', 'sifency-addons' ),
				'dependency' => [ 'digital_pricing_model', '==', 'subscription' ],
				'fields'     => [
					[
						'id'    => 'tier_name',
						'type'  => 'text',
						'title' => esc_html__( 'Tier Name', 'sifency-addons' ), // e.g., Personal, Business
					],
					[
						'id'    => 'tier_price',
						'type'  => 'text',
						'title' => esc_html__( 'Price', 'sifency-addons' ), // e.g., $49
					],
					[
						'id'    => 'tier_billing_cycle',
						'type'  => 'text',
						'title' => esc_html__( 'Billing Cycle', 'sifency-addons' ), // e.g., / year
					],
					[
						'id'       => 'tier_features',
						'type'     => 'wp_editor',
						'title'    => esc_html__( 'Features', 'sifency-addons' ),
						'desc'     => esc_html__( 'Enter one feature per line.', 'sifency-addons' ),
					],
					[
						'id'    => 'tier_purchase_link',
						'type'  => 'url',
						'title' => esc_html__( 'Purchase URL', 'sifency-addons' ),
					],
					[
						'id'    => 'tier_purchase_link_text',
						'type'  => 'text',
						'title' => esc_html__( 'Purchase URL Text', 'sifency-addons' ),
					],
					[
						'id'      => 'tier_highlight',
						'type'    => 'button_set',
						'title'   => esc_html__( 'Highlight This Tier?', 'sifency-addons' ),
						'options' => [ 'yes' => 'Yes', 'no' => 'No' ],
						'default' => 'no',
					],
				],
			],
			[
				'id'    => 'digital_moneyback_guarantee',
				'type'  => 'textarea',
				'title' => esc_html__( 'Moneyback Guarantee', 'sifency-addons' ),
				'desc'  => esc_html__( 'e.g., 30-day moneyback guarantee details.', 'sifency-addons' ),
				'default' => esc_html__( '14-day moneyback guarantee.', 'sifency-addons' ),
			],
			// =================================================================
			// Section: Downloadable Files
			// =================================================================
			[
				'id'     => 'digital_files',
				'type'   => 'repeater',
				'title'  => esc_html__( 'Downloadable Files', 'sifency-addons' ),
				'fields' => [
					[
						'id'    => 'file_name',
						'type'  => 'text',
						'title' => esc_html__( 'File Description', 'sifency-addons' ),
					],
					[
						'id'    => 'file_upload',
						'type'  => 'upload',
						'title' => esc_html__( 'Upload File', 'sifency-addons' ),
					],
					[
						'id'    => 'file_link', // NEW FIELD
						'type'  => 'url',
						'title' => esc_html__( 'Or Enter External URL', 'sifency-addons' ),
					],
				],
			],

			// =================================================================
			// Section: Presentation & External Links
			// =================================================================
			[
				'id'    => 'digital_live_demo_url',
				'type'  => 'url',
				'title' => esc_html__( 'Live Demo URL', 'sifency-addons' ),
			],
			[
				'id'    => 'digital_documentation_url',
				'type'  => 'url',
				'title' => esc_html__( 'Documentation URL', 'sifency-addons' ),
			],
			[
				'id'    => 'digital_video_url',
				'type'  => 'url',
				'title' => esc_html__( 'Promotional Video URL', 'sifency-addons' ),
				'desc'  => esc_html__( 'Link to a YouTube or Vimeo video.', 'sifency-addons' ),
			],
			[
				'id'     => 'digital_gallery',
				'type'   => 'repeater',
				'title'  => esc_html__( 'Product Gallery / Screenshots', 'sifency-addons' ),
				'fields' => [
					[
						'id'    => 'gallery_image',
						'type'  => 'media',
						'title' => esc_html__( 'Image', 'sifency-addons' ),
					],
				],
			],

			// =================================================================
			// Section: Additional Content (Tabs, FAQ, etc.)
			// =================================================================
			[
				'id'       => 'digital_changelog',
				'type'     => 'wp_editor',
				'title'    => esc_html__( 'Changelog / Release Notes', 'sifency-addons' ),
				'sanitize' => 'wp_kses_post',
			],
			[
				'id'     => 'digital_faq',
				'type'   => 'repeater',
				'title'  => esc_html__( 'Frequently Asked Questions (FAQ)', 'sifency-addons' ),
				'fields' => [
					[
						'id'    => 'faq_question',
						'type'  => 'text',
						'title' => esc_html__( 'Question', 'sifency-addons' ),
					],
					[
						'id'    => 'faq_answer',
						'type'  => 'textarea',
						'title' => esc_html__( 'Answer', 'sifency-addons' ),
					],
				],
			],
		],
	],
];