<?php

/*
 * Metaboxes Fields
 */
$prefix = 'cwpt_';
$paocfbfw_box_options = array(
    'id'           => 'cwpt',
    'title'        => esc_html__( 'Custom WC Product Type Settings', 'custom-product-type-for-woocommerce' ),
    'object_types' => array('custom-product-type'),
    'context'      => 'normal',
    'priority'     => 'high',
);
// Setup meta box
$cwpt_cmb = new_cmb2_box( $paocfbfw_box_options );
// Setting tabs
$cwpt_tabs_setting = array(
    'config' => $paocfbfw_box_options,
    'tabs'   => array(),
);
//cwpt Layouts array
$cwpt_layouts = array(
    'default'  => esc_html__( 'Default WooCommerce Layout', 'custom-product-type-for-woocommerce' ),
    'layout-1' => esc_html__( 'Layout 1', 'custom-product-type-for-woocommerce' ),
    'layout-2' => esc_html__( 'Layout 2', 'custom-product-type-for-woocommerce' ),
    'layout-3' => esc_html__( 'Layout 3', 'custom-product-type-for-woocommerce' ),
    'layout-4' => esc_html__( 'Layout 4', 'custom-product-type-for-woocommerce' ),
);
$cwpt_tabs_setting['tabs'][] = array(
    'id'     => $prefix . 'general',
    'title'  => __( 'General', 'custom-product-type-for-woocommerce' ),
    'fields' => array(
        array(
            'type'       => 'text',
            'name'       => esc_html__( 'Singular name', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'product_type_name_singular',
            'desc'       => esc_html__( 'Product Type Singular Name', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'required'    => true,
                'placeholder' => esc_html__( 'EX:(\'Book\',\'Shirt\',\'Demo\',…)', 'custom-product-type-for-woocommerce' ),
            ),
        ),
        array(
            'type'       => 'text',
            'name'       => esc_html__( 'Plural name', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'product_type_name_plural',
            'desc'       => esc_html__( 'Product Type Plural Name', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'required'    => true,
                'placeholder' => esc_html__( 'EX:(\'Books\',\'Shirts\',\'Demos\',…)', 'custom-product-type-for-woocommerce' ),
            ),
        ),
        array(
            'type'    => 'select',
            'name'    => esc_html__( 'Product Layout', 'custom-product-type-for-woocommerce' ),
            'id'      => $prefix . 'product_layout',
            'desc'    => esc_html__( 'Select a layout for this product type.', 'custom-product-type-for-woocommerce' ),
            'options' => $cwpt_layouts,
            'default' => 'default',
        ),
        array(
            'type' => 'checkbox',
            'name' => esc_html__( 'Custom Taxonomy', 'custom-product-type-for-woocommerce' ),
            'id'   => $prefix . 'custom_taxonomy',
            'desc' => esc_html__( '(Enable/Disable) Custom Taxonomy', 'custom-product-type-for-woocommerce' ),
        ),
        array(
            'type' => 'checkbox',
            'name' => esc_html__( 'Display In Shop', 'custom-product-type-for-woocommerce' ),
            'id'   => $prefix . 'show_in_shop',
            'desc' => esc_html__( '(Show/Hide) From Shop Page', 'custom-product-type-for-woocommerce' ),
        ),
        array(
            'type'    => 'checkbox',
            'name'    => esc_html__( 'Enable Badge', 'custom-product-type-for-woocommerce' ),
            'id'      => $prefix . 'enable_badge',
            'desc'    => esc_html__( 'Enable Product Badge', 'custom-product-type-for-woocommerce' ),
            'classes' => 'enable-badge',
        ),
        array(
            'type'       => 'text',
            'name'       => esc_html__( 'Badge Text', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'badge_text',
            'desc'       => esc_html__( 'Badge Text', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'placeholder'            => esc_html__( 'Badge Text', 'custom-product-type-for-woocommerce' ),
                'required'               => false,
                'data-conditional-id'    => $prefix . 'enable_badge',
                'data-conditional-value' => 'on',
            ),
            'classes'    => 'badge-text',
        ),
        array(
            'type'       => 'colorpicker',
            'name'       => esc_html__( 'Badge Background Color', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'badge_background_color',
            'desc'       => esc_html__( 'Choose Badge Background Color', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'data-conditional-id'    => $prefix . 'enable_badge',
                'data-conditional-value' => 'on',
            ),
            'default'    => '#0095ebd4',
            'classes'    => 'badge-background-color',
        ),
        array(
            'type'       => 'colorpicker',
            'name'       => esc_html__( 'Badge Text Color', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'badge_text_color',
            'desc'       => esc_html__( 'Choose Badge Text Color', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'data-conditional-id'    => $prefix . 'enable_badge',
                'data-conditional-value' => 'on',
            ),
            'default'    => '#ffff',
            'classes'    => 'badge-color',
        )
    ),
);
$cwpt_tabs_setting['tabs'][] = array(
    'id'     => $prefix . 'backend_fields',
    'title'  => __( 'Back-end Fields', 'custom-product-type-for-woocommerce' ),
    'fields' => array(
        array(
            'type'    => 'checkbox',
            'name'    => esc_html__( 'Admin Fields', 'custom-product-type-for-woocommerce' ),
            'id'      => $prefix . 'enable_admin_fields',
            'desc'    => esc_html__( 'Enable product custom admin fields.', 'custom-product-type-for-woocommerce' ),
            'classes' => 'enable_admin_fields',
        ),
        array(
            'type'       => 'text',
            'name'       => esc_html__( 'Admin Fields Tab Label', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'admin_fields_tab_label',
            'desc'       => esc_html__( 'Fields Tab Label', 'custom-product-type-for-woocommerce' ),
            'attributes' => array(
                'required'               => false,
                'placeholder'            => esc_html__( 'Label Text', 'custom-product-type-for-woocommerce' ),
                'data-conditional-id'    => $prefix . 'enable_admin_fields',
                'data-conditional-value' => 'on',
            ),
            'classes'    => 'custom-tab-label',
        ),
        array(
            'name'       => __( 'Position In Front', 'custom-product-type-for-woocommerce' ),
            'id'         => $prefix . 'front_position',
            'type'       => 'select',
            'desc'       => esc_html__( 'Position product page to show front data.', 'custom-product-type-for-woocommerce' ),
            'options'    => array(
                'woocommerce_before_add_to_cart_button' => __( 'Before Add To Cart Button', 'custom-product-type-for-woocommerce' ),
                'woocommerce_after_add_to_cart_button'  => __( 'After Add To Cart Button', 'custom-product-type-for-woocommerce' ),
                'woocommerce_product_meta_start'        => __( 'Before Product Meta', 'custom-product-type-for-woocommerce' ),
                'woocommerce_product_meta_end'          => __( 'After Product Meta', 'custom-product-type-for-woocommerce' ),
                'woocommerce_single_product_summary'    => __( 'Single Product Summary', 'custom-product-type-for-woocommerce' ),
            ),
            'attributes' => array(
                'data-conditional-id'    => wp_json_encode( array('cwpt_admin_tab_fields', 'show_front') ),
                'data-conditional-value' => wp_json_encode( array('on') ),
            ),
        ),
        array(
            'type'    => 'group',
            'name'    => esc_html__( 'Add Your fields below', 'custom-product-type-for-woocommerce' ),
            'id'      => $prefix . 'admin_tab_fields',
            'classes' => 'admin-tab-fields',
            'options' => array(
                'group_title'   => esc_html__( 'Field {#}', 'custom-product-type-for-woocommerce' ),
                'add_button'    => esc_html__( 'Add Field', 'custom-product-type-for-woocommerce' ),
                'remove_button' => esc_html__( 'Remove Field', 'custom-product-type-for-woocommerce' ),
                'sortable'      => true,
                'closed'        => true,
            ),
            'fields'  => array(
                array(
                    'name'       => __( 'Select Font Awesome Icon', 'cmb' ),
                    'id'         => 'iconselect',
                    'desc'       => 'Select Font Awesome icon',
                    'type'       => 'faiconselect',
                    'options_cb' => 'returnRayFaPre',
                    'attributes' => array(
                        'data-conditional-id'    => wp_json_encode( array('cwpt_admin_tab_fields', 'type') ),
                        'data-conditional-value' => wp_json_encode( array(
                            'text',
                            'textarea',
                            'select',
                            'radio',
                            'checkbox',
                            'number'
                        ) ),
                    ),
                ),
                array(
                    'name'    => __( 'Field Type', 'custom-product-type-for-woocommerce' ),
                    'id'      => 'type',
                    'type'    => 'select',
                    'default' => 'text',
                    'options' => array(
                        'text'     => __( 'Text', 'custom-product-type-for-woocommerce' ),
                        'textarea' => __( 'Textarea', 'custom-product-type-for-woocommerce' ),
                        'select'   => __( 'Select', 'custom-product-type-for-woocommerce' ),
                        'radio'    => __( 'Radio', 'custom-product-type-for-woocommerce' ),
                        'checkbox' => __( 'Checkbox', 'custom-product-type-for-woocommerce' ),
                        'number'   => __( 'Number', 'custom-product-type-for-woocommerce' ),
                    ),
                ),
                array(
                    'type'       => 'text',
                    'name'       => esc_html__( 'Field Label', 'custom-product-type-for-woocommerce' ),
                    'id'         => 'label',
                    'classes'    => 'field-label',
                    'desc'       => esc_html__( 'Enter field label.', 'custom-product-type-for-woocommerce' ),
                    'attributes' => array(
                        'required' => false,
                    ),
                ),
                array(
                    'type' => 'text',
                    'name' => esc_html__( 'Field Description', 'custom-product-type-for-woocommerce' ),
                    'id'   => 'description',
                    'desc' => esc_html__( 'Enter field description.', 'custom-product-type-for-woocommerce' ),
                ),
                array(
                    'name'       => __( 'Options', 'custom-product-type-for-woocommerce' ),
                    'id'         => 'options',
                    'type'       => 'textarea',
                    'desc'       => __( 'Use ( | ) To Separate options', 'custom-product-type-for-woocommerce' ),
                    'attributes' => array(
                        'data-conditional-id'    => wp_json_encode( array('cwpt_admin_tab_fields', 'type') ),
                        'data-conditional-value' => wp_json_encode( array('select', 'radio') ),
                    ),
                ),
                array(
                    'type'    => 'checkbox',
                    'name'    => esc_html__( 'Show In Front', 'custom-product-type-for-woocommerce' ),
                    'id'      => 'show_front',
                    'desc'    => esc_html__( 'Show/Hide Field On Single Product Page', 'custom-product-type-for-woocommerce' ),
                    'classes' => 'show_front',
                ),
                array(
                    'name'       => __( 'Show as link', 'custom-product-type-for-woocommerce' ),
                    'id'         => 'url',
                    'type'       => 'select',
                    'default'    => 'hide',
                    'options'    => array(
                        'show' => __( 'Show', 'custom-product-type-for-woocommerce' ),
                        'hide' => __( 'Hide', 'custom-product-type-for-woocommerce' ),
                    ),
                    'attributes' => array(
                        'data-conditional-id'    => wp_json_encode( array('cwpt_admin_tab_fields', 'type') ),
                        'data-conditional-value' => wp_json_encode( array(
                            'text',
                            'textarea',
                            'select',
                            'radio',
                            'checkbox'
                        ) ),
                    ),
                )
            ),
        )
    ),
);
$cwpt_fields = [
    'title'                            => __( 'Title', 'custom-product-type-for-woocommerce' ),
    'number'                           => __( 'Number', 'custom-product-type-for-woocommerce' ),
    'text'                             => __( 'Text', 'custom-product-type-for-woocommerce' ),
    'text_url'                         => __( 'Link', 'custom-product-type-for-woocommerce' ),
    'text_email'                       => __( 'Email', 'custom-product-type-for-woocommerce' ),
    'textarea'                         => __( 'Textarea', 'custom-product-type-for-woocommerce' ),
    'radio'                            => __( 'Radio', 'custom-product-type-for-woocommerce' ),
    'select'                           => __( 'Select', 'custom-product-type-for-woocommerce' ),
    'checkbox'                         => __( 'Checkbox', 'custom-product-type-for-woocommerce' ),
    'text_date'                        => __( 'Date Picker', 'custom-product-type-for-woocommerce' ),
    'text_datetime_timestamp'          => __( 'Date/Time', 'custom-product-type-for-woocommerce' ),
    'text_datetime_timestamp_timezone' => __( 'Date/Time With City Time Zone', 'custom-product-type-for-woocommerce' ),
    'hidden'                           => __( 'Hidden', 'custom-product-type-for-woocommerce' ),
    'colorpicker'                      => __( 'Color Picker', 'custom-product-type-for-woocommerce' ),
];
$tax_query = get_object_taxonomies( 'product', 'objects' );
$tax_array = array();
foreach ( $tax_query as $tax ) {
    $excluded_taxonomies = array(
        'product_type',
        'product_visibility',
        'product_tag',
        'product_shipping_class'
    );
    if ( in_array( $tax->name, $excluded_taxonomies ) ) {
        continue;
    }
    $tax_array[$tax->name] = $tax->label;
}
$cwpt_tabs_setting['tabs'][] = array(
    'id'     => $prefix . 'front_fields',
    'title'  => __( 'Options & Addons', 'custom-product-type-for-woocommerce' ),
    'fields' => array(array(
        'type'    => 'checkbox',
        'name'    => esc_html__( 'Front Fields', 'custom-product-type-for-woocommerce' ),
        'id'      => $prefix . 'enable_front_fields',
        'desc'    => esc_html__( 'Enable product custom fields/addons.', 'custom-product-type-for-woocommerce' ),
        'classes' => 'enable_front_fields',
    ), array(
        'type'       => 'text',
        'name'       => esc_html__( 'Front Fields Title', 'custom-product-type-for-woocommerce' ),
        'id'         => $prefix . 'front_fields_title',
        'desc'       => esc_html__( 'Fields Tab Title', 'custom-product-type-for-woocommerce' ),
        'attributes' => array(
            'required'    => false,
            'placeholder' => esc_html__( 'Title Text', 'custom-product-type-for-woocommerce' ),
        ),
        'classes'    => 'front-fields-title',
    ), array(
        'type'    => 'group',
        'name'    => esc_html__( 'Add Your fields below', 'custom-product-type-for-woocommerce' ),
        'id'      => $prefix . 'front_tab_fields',
        'classes' => 'front-tab-fields',
        'options' => array(
            'group_title'   => esc_html__( 'Field {#}', 'custom-product-type-for-woocommerce' ),
            'add_button'    => esc_html__( 'Add Field', 'custom-product-type-for-woocommerce' ),
            'remove_button' => esc_html__( 'Remove Field', 'custom-product-type-for-woocommerce' ),
            'sortable'      => true,
            'closed'        => true,
        ),
        'fields'  => array(
            array(
                'name'       => __( 'Select Font Awesome Icon', 'cmb' ),
                'id'         => 'iconselect',
                'desc'       => 'Select Font Awesome icon',
                'type'       => 'faiconselect',
                'options_cb' => 'returnRayFaPre',
            ),
            array(
                'name'    => __( 'Field Type', 'custom-product-type-for-woocommerce' ),
                'id'      => 'type',
                'type'    => 'select',
                'default' => 'text',
                'options' => $cwpt_fields,
            ),
            array(
                'type'       => 'text',
                'name'       => esc_html__( 'Field Label', 'custom-product-type-for-woocommerce' ),
                'id'         => 'label',
                'classes'    => 'field-label',
                'desc'       => esc_html__( 'Enter field label.', 'custom-product-type-for-woocommerce' ),
                'attributes' => array(
                    'required' => false,
                ),
            ),
            array(
                'type'       => 'checkbox',
                'name'       => esc_html__( 'Required', 'custom-product-type-for-woocommerce' ),
                'id'         => 'required',
                'desc'       => esc_html__( 'Mark as required.', 'custom-product-type-for-woocommerce' ),
                'classes'    => 'required',
                'attributes' => array(
                    'data-conditional-id'     => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value'  => wp_json_encode( array('buy_now') ),
                    'data-conditional-invert' => true,
                ),
            ),
            array(
                'type' => 'text',
                'name' => esc_html__( 'Field Description', 'custom-product-type-for-woocommerce' ),
                'id'   => 'description',
                'desc' => esc_html__( 'Enter field description.', 'custom-product-type-for-woocommerce' ),
            ),
            array(
                'name'       => __( 'Select Taxonomy', 'custom-product-type-for-woocommerce' ),
                'id'         => 'taxonomy',
                'type'       => 'select',
                'options'    => $tax_array,
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array(
                        'taxonomy_select',
                        'taxonomy_radio',
                        'taxonomy_radio_inline',
                        'taxonomy_radio_hierarchical',
                        'taxonomy_multicheck',
                        'taxonomy_multicheck_inline',
                        'taxonomy_multicheck_hierarchical'
                    ) ),
                ),
                'default'    => 'product_cat',
                'desc'       => __( 'Select which taxonomy to use', 'custom-product-type-for-woocommerce' ),
            ),
            array(
                'name'       => __( 'Options', 'custom-product-type-for-woocommerce' ),
                'id'         => 'options',
                'type'       => 'textarea',
                'desc'       => __( 'Use ( | ) To Separate options', 'custom-product-type-for-woocommerce' ),
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array(
                        'select',
                        'radio',
                        'taxonomy_radio',
                        'taxonomy_radio_inline',
                        'taxonomy_radio_hierarchical',
                        'checkbox',
                        'multicheck'
                    ) ),
                ),
            ),
            array(
                'name'       => __( 'Date Format', 'custom-product-type-for-woocommerce' ),
                'id'         => 'date_format',
                'type'       => 'select',
                'default'    => 'mm/dd/yy',
                'options'    => array(
                    'mm/dd/yy' => __( 'mm/dd/yy', 'custom-product-type-for-woocommerce' ),
                    'dd/mm/yy' => __( 'dd/mm/yy', 'custom-product-type-for-woocommerce' ),
                    'yy-mm-dd' => __( 'yy-mm-dd', 'custom-product-type-for-woocommerce' ),
                    'dd.mm.yy' => __( 'dd.mm.yy', 'custom-product-type-for-woocommerce' ),
                    'yy.mm.dd' => __( 'yy.mm.dd', 'custom-product-type-for-woocommerce' ),
                    'd M, y'   => __( 'd M, y', 'custom-product-type-for-woocommerce' ),
                    'MM d, yy' => __( 'MM d, yy', 'custom-product-type-for-woocommerce' ),
                ),
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array('calendar') ),
                ),
            ),
            array(
                'name'       => __( 'Show Calendar Text Input', 'custom-product-type-for-woocommerce' ),
                'id'         => 'show_calendar_input',
                'type'       => 'checkbox',
                'desc'       => __( 'Show/Hide Date Text Field', 'custom-product-type-for-woocommerce' ),
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array('calendar') ),
                ),
            ),
            array(
                'name'       => __( 'Min Date', 'custom-product-type-for-woocommerce' ),
                'id'         => 'min_date',
                'type'       => 'text_date',
                'desc'       => __( 'Enter number of days from today or specific date (MM/DD/YYYY)', 'custom-product-type-for-woocommerce' ),
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array('calendar') ),
                ),
                'default'    => '0',
            ),
            array(
                'name'       => __( 'Max Date', 'custom-product-type-for-woocommerce' ),
                'id'         => 'max_date',
                'type'       => 'text_date',
                'desc'       => __( 'Enter number of days from today or specific date (MM/DD/YYYY)', 'custom-product-type-for-woocommerce' ),
                'attributes' => array(
                    'data-conditional-id'    => wp_json_encode( array('cwpt_front_tab_fields', 'type') ),
                    'data-conditional-value' => wp_json_encode( array('calendar') ),
                ),
            )
        ),
    )),
);
$cwpt_cmb->add_field( array(
    'name' => 'Shortcode',
    'desc' => CWPT_Templates::display_shortcode(),
    'type' => 'title',
    'id'   => $prefix . 'shortcode',
) );
// var_dump(CMB2_LOADED);
// Set tabs
$cwpt_cmb->add_field( array(
    'id'   => '__tabs',
    'type' => 'tabs',
    'tabs' => $cwpt_tabs_setting,
) );