<?php
/**
 *
 * Field:Fieldset
 *
 * @link       https://shapedplugin.com/
 *
 * @package Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/admin/views
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access directly.

if ( ! class_exists( 'SP_PCP_Field_fieldset_cpt' ) ) {
	/**
	 *
	 * Field: fieldset
	 *
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	class SP_PCP_Field_fieldset_cpt extends SP_PCP_Fields {
		/**
		 * The class constructor.
		 *
		 * @param array  $field The field type.
		 * @param string $value The values of the field.
		 * @param string $unique The unique ID for the field.
		 * @param string $where To where show the output CSS.
		 * @param string $parent The parent args.
		 */
		public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
			parent::__construct( $field, $value, $unique, $where, $parent );
		}
			/**
			 * Taxonomy archive settings
			 *
			 * @return array
			 */
		/**
		 * Default archive settings.
		 *
		 * @return array
		 */
		public static function archive_settings() {
			$post_types = get_post_types(
				array(
					'show_in_nav_menus' => true,
					'_builtin'          => false,
					'has_archive'       => true,
				)
			);

			$result = array();
			foreach ( $post_types as $key => $value ) {
				$shop    = '';
				$value_f = ucfirst( $value );
				if ( 'product' === $value ) {
					$shop = 'Shop/';
				}
				$result = array_merge(
					$result,
					array(
						array(
							'id'         => "post_type-$value",
							'text_on'    => __( 'Enabled', 'smart-post-show-pro' ),
							'text_off'   => __( 'Disabled', 'smart-post-show-pro' ),
							'type'       => 'switcher',
							'text_width' => 100,
							'default'    => false,
							/* translators: %1$s: shop prefix (e.g., "Shop/"), %2$s: post type name (e.g., "Product") */
							'title'      => sprintf( __( '%1$s %2$s Page', 'smart-post-show-pro' ), $shop, $value_f ),
						),
						array(
							'id'         => "sps_post_type-$value",
							'type'       => 'fieldset',
							'class'      => 'spsp_no_border',
							'dependency' => array( "post_type-$value", '==', 'true', true ),
							'fields'     => array(
								array(
									'id'          => 'pcp_which_show',
									'class'       => 'pcp_post_ids',
									'type'        => 'select',
									'title'       => __( 'The Layout To Show Products', 'smart-post-show-pro' ),
									'options'     => 'sp_post_carousel',
									'chosen'      => true,
									'sortable'    => false,
									'multiple'    => false,
									'placeholder' => __( 'Choose show(s)', 'smart-post-show-pro' ),
									'query_args'  => array(
										'posts_per_page' => -1,
									),
								),
								array(
									'id'      => 'replace_way',
									'class'   => 'pcp_post_ids',
									'type'    => 'radio',
									'title'   => __( 'The Way To Retrieve Products', 'smart-post-show-pro' ),
									'default' => 'no_change',
									'options' => array(
										'no_change'   => __( 'No change', 'smart-post-show-pro' ),
										'change_sort' => __( 'Change order only (use "Sort by" setting of the show)', 'smart-post-show-pro' ),
										'change_full' => __( 'Change completely (use all "Filter Content" of the show)', 'smart-post-show-pro' ),
									),
								),
							),
						),
					)
				);
			}
			return $result;
		}
		/**
		 * The render method.
		 *
		 * @return void
		 */
		public function render() {

			echo wp_kses_post( $this->field_before() );

			echo '<div class="spf-fieldset-content">';
			// echo self::taxonomy_settings();
			foreach ( self::archive_settings() as $field ) {

				$field_id      = ( isset( $field['id'] ) ) ? $field['id'] : '';
				$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
				$field_value   = ( isset( $this->value[ $field_id ] ) ) ? $this->value[ $field_id ] : $field_default;
				$unique_id     = ( ! empty( $this->unique ) ) ? $this->unique . '[' . $this->field['id'] . ']' : $this->field['id'];

				SP_PCP::field( $field, $field_value, $unique_id, 'field/fieldset_tx' );

			}

			echo '</div>';

			echo wp_kses_post( $this->field_after() );
		}
	}
}
