<?php
/**
 * Settings fields.
 *
 * @package flo-sync
 */

namespace NMFS\Admin;

defined( 'ABSPATH' ) || exit;
/**
 * Class Settings_Fields
 */
class Settings_Fields {

	/**
	 * Sync settings.
	 */
	public const SYNC_NEW_ORDERS             = 'sync_new_orders_to_hub';
	public const SYNC_ONLY_STOCK             = 'sync_only_product_stock_amount';
	public const SYNC_PRODUCT_STATUS         = 'sync_products_publish_status';
	public const SYNC_ARTICLE_AVAILABILITIES = 'sync_article_availabilities';
	public const SYNC_PRICE                  = 'sync_price';
	public const SYNC_ARTICLE_DISPLAY_ORDER  = 'sync_article_display_order';
	public const SYNC_PRODUCT_DESCRIPTION    = 'sync_product_description';
	public const SYNC_PRODUCT_PICTURES       = 'sync_pictures';
	public const SYNC_PRODUCT_TITLE          = 'sync_product_title';
	public const SYNC_CAMPAIGNS              = 'sync_campaigns';
	public const SYNC_PRODUCT_CATEGORIES     = 'sync_product_categories';
	public const ORDER_STOCK_ADJUSTMENT      = 'order_stock_adjustment';


	public const ORDER_STOCK_ADJUSTMENT_ORDER_OPEN = 'order_opened';
	public const ORDER_STOCK_ADJUSTMENT_ORDER_PAID = 'order_paid';

	/**
	 * Setup shared hooks.
	 *
	 * @param string $service_name_underscored The service name in underscored format.
	 */
	public static function setup_shared_hooks( string $service_name_underscored ): void {
		add_filter(
			'northmill_online_shared_settings_fields_' . $service_name_underscored,
			array( self::class, 'filter_fields' )
		);
	}

	/**
	 * Get settings fields.
	 *
	 * @param array $shared_fields Fields already loaded in Shared.
	 *
	 * @return array
	 */
	public static function filter_fields( array $shared_fields ): array {
		return array_merge(
			$shared_fields,
			array(
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_NEW_ORDERS,
					'label'       => function () {
						return __( 'Sync new orders to Hub', 'flo-sync' );
					},
					'default'     => true,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, new orders will be synced to Hub.', 'flo-sync' );
					},
					'priority'    => 10,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_ONLY_STOCK,
					'label'       => function () {
						return __( 'Only sync article stock amount', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, only stock amount will be synced for articles, no other article data. Also, no new articles will be synced.', 'flo-sync' );
					},
					'priority'    => 20,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRODUCT_STATUS,
					'label'       => function () {
						return __( 'Sync publish status of products', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When disabled, products will be set as draft and you can publish them manually.', 'flo-sync' );
					},
					'priority'    => 30,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRICE,
					'label'       => function () {
						return __( 'Sync article price', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, article prices are synced.', 'flo-sync' );
					},
					'priority'    => 40,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_ARTICLE_DISPLAY_ORDER,
					'label'       => function () {
						return __( 'Sync article display order', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, product display order (sorting) is synced.', 'flo-sync' );
					},
					'priority'    => 50,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRODUCT_DESCRIPTION,
					'label'       => function () {
						return __( 'Sync article description', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, article description is synced from Hub to WooCommerce. Any current content, or changes to the content, in WooCommerce will be replaced.', 'flo-sync' );
					},
					'priority'    => 60,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRODUCT_PICTURES,
					'label'       => function () {
						return __( 'Sync article pictures', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, article pictures are synced.', 'flo-sync' );
					},
					'priority'    => 70,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRODUCT_TITLE,
					'label'       => function () {
						return __( 'Sync article title', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, article titles are synced.', 'flo-sync' );
					},
					'priority'    => 80,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_ARTICLE_AVAILABILITIES,
					'label'       => function () {
						return __( 'Sync article availabilities', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, article availabilities is synced from Hub, and controls whether articles are purchasable.', 'flo-sync' ) . ' ' .
						__( 'When disabled, article availabilities have no effect on the site.', 'flo-sync' );
					},
					'priority'    => 90,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_CAMPAIGNS,
					'label'       => function () {
						return __( 'Sync campaigns', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, campaigns are synced from Hub to WooCommerce. This feature should not be used together with other discounting plugins.', 'flo-sync' );
					},
					'priority'    => 100,
				),
				array(
					'type'        => 'checkbox',
					'name'        => self::SYNC_PRODUCT_CATEGORIES,
					'label'       => function () {
						return __( 'Sync article groups', 'flo-sync' );
					},
					'default'     => false,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'When enabled, Hub article groups are synced to WooCommerce as product categories. This also updates the category for synced products, to article group as set in Hub.', 'flo-sync' );
					},
					'priority'    => 110,
				),
				array(
					'type'        => 'select',
					'name'        => self::ORDER_STOCK_ADJUSTMENT,
					'label'       => function () {
						return __( 'Adjust stock when', 'flo-sync' );
					},
					'options'     => array( self::class, 'get_order_stock_adjustment_options' ),
					'default'     => self::ORDER_STOCK_ADJUSTMENT_ORDER_PAID,
					'section'     => 'section_sync_settings',
					'description' => function () {
						return __( 'This determines when stock is adjusted in both Hub and WooCommerce.', 'flo-sync' );
					},
					'priority'    => 120,
				),
			)
		);
	}

	/**
	 * Get order stock adjustment options.
	 *
	 * @return array
	 */
	public static function get_order_stock_adjustment_options(): array {
		return array(
			self::ORDER_STOCK_ADJUSTMENT_ORDER_OPEN => __( 'Order is opened', 'flo-sync' ),
			self::ORDER_STOCK_ADJUSTMENT_ORDER_PAID => __( 'Order is paid', 'flo-sync' ),
		);
	}
}
