<?php

add_action( 'cmb2_admin_init', 'f4w_our_team_metaboxes' );

function f4w_our_team_metaboxes() {
    $prefix = 'f4w_';
    $field_slug = 'f4w-team-members';    
    $postType = 'otmembers';
     /**
     * Initiate the metabox
     */
    $f4w_team = new_cmb2_box( array(
        'id'            => $prefix . 'ot-meta',
        'title'         => __('Team Members', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true,
        'classes' => 'f4w-otbox',
    ) );

    $group_field_id = $f4w_team->add_field( array(
        'id'          => $prefix .'otmeta',
        'type'        => 'group',
        'options'     => array(
            'group_title'   => __( 'Team Member {#}', $field_slug ),
            'add_button'    => __( 'Add New Member', $field_slug ),
            'remove_button' => __( 'Remove Member', $field_slug ),
            'sortable'      => true, // beta
            'closed'     => true, // true to have the groups closed by default
            'remove_confirm' => esc_html__( 'Are you sure you want to remove?', $field_slug),
            
        ),
    ) );

    // Id's for group's fields only need to be unique for the group. Prefix is not needed.

    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Full Name', $field_slug),
        'id'   => $prefix .'full_name',
        'type' => 'text',
        'classes' => 'f4w-row',
    ) );

    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Job Role', $field_slug),
        'id'   => $prefix .'job_role',
        'type' => 'text',
        'classes' => 'f4w-row',
    ) );

    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Description', $field_slug),
        'id'   => $prefix .'description',
        'type' => 'textarea_small',
        'classes' => 'f4w-row',
    ) );

    $f4w_team->add_group_field( $group_field_id, array(
        'id'   => $prefix .'member_image',
        'name' => __('Member Image'.' <a class="f4w-tooltip" title="'.__( 'Recomended 600x600px Transparent Image', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>', $field_slug),
        
        'type' => 'file',
        'options' => array(
            'url' => false, // Hide the text input for the url
        ),
        'text'    => array(
            'add_upload_file_text' => 'Upload Image' // Change upload button text. Default: "Add or Upload File"
        ),
        'classes' => 'f4w-row',
        
    ) );

    /*Social Support */
    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Facebook', $field_slug),
        'id'   => $prefix .'facebook_url',
        'type' => 'text',
        'classes' => 'f4w-row-left',
    ) );
    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Instagram', $field_slug),
        'id'   => $prefix .'instagram_url',
        'type' => 'text',
        'classes' => 'f4w-row-right',
    ) );
    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Twitter', $field_slug),
        'id'   => $prefix .'twitter_url',
        'type' => 'text',
        'classes' => 'f4w-row-left',
    ) );
    $f4w_team->add_group_field( $group_field_id, array(
        'name' => __('Linked In', $field_slug),
        'id'   => $prefix .'linkedin_url',
        'type' => 'text',
        'classes' => 'f4w-row-right',
    ) );
    

    /**
     * General Settings
     *  
     * */  

    $f4w_settings = new_cmb2_box( array(
        'id'            => $prefix . 'ot-settings-meta',
        'title'         => __('General Settings', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'side',
        'priority'      => 'low',
        'show_names'    => true, 
        'classes' => 'f4w-otbox',
    ) );

    $f4w_settings->add_field( array(
        'name' => __( 'Title Text Font Size (px)'.' <a class="f4w-tooltip" title="'.__( 'Default font size 18px', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>' ),
        'id' => $prefix . 'title_font_size',
        'type' => 'text',
        'classes' => 'f4w-row',
        'default'=>'18',
        'attributes' => array(
            'type' => 'number',
          ),
    ));
    $f4w_settings->add_field( array(
        'name' => __( 'Job Role Text Font Size (px)'.' <a class="f4w-tooltip" title="'.__( 'Default font size 14px', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>'),
        'id' => $prefix . 'job_role_font_size',
        'type' => 'text',
        'classes' => 'f4w-row',
        'default'=>'14',
        'attributes' => array(
            'type' => 'number',
          ),
    ));
    $f4w_settings->add_field( array(
        'name' => __( 'Description Text Font Size (px)'.' <a class="f4w-tooltip" title="'.__( 'Default font size 14px', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>' ),
        'id' => $prefix . 'description_font_size',
        'type' => 'text',
        'classes' => 'f4w-row',
        'default'=>'14',
        'attributes' => array(
            'type' => 'number',
          ),
    ));
    $f4w_settings->add_field( array(
        'name' => __( 'Social Icon Font Size (px)'.' <a class="f4w-tooltip" title="'.__( 'Default font size 18px', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>' ),
        'id' => $prefix . 'social_icon_font_size',
        'type' => 'text',
        'classes' => 'f4w-row',
        'default'=>'18',
        'attributes' => array(
            'type' => 'number',
          ),
    ));

    $f4w_settings->add_field( array(
        'name' => __( 'Description Characters Number'.' <a class="f4w-tooltip" title="'.__( 'Number of Characters shows on Description. Default set 160 characters', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>' ),
        'id' => $prefix . 'description_characters',
        'type' => 'text',
        'classes' => 'f4w-row',
        'default'=>'160',
        'attributes' => array(
            'type' => 'number',
          ),
    ));


    /**
     * Pro Settings
     *  
     * */  

     /**
      * Layout Settings
      */

    $f4w_layout_settings = new_cmb2_box( array(
        'id'            => $prefix . 'ot-layout-settings',
        'title'         => __('Layout Settings', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'side',
        'priority'      => 'low',
        'show_names'    => true, 
        'classes' => 'f4w-otbox',
    ) );    

    $f4w_layout_settings->add_field( array(
        'name' => __( 'How many column show per row?'.' <a class="f4w-tooltip" title="'.__( 'Default set 3 column.', $field_slug ).'"><span class="f4w-help dashicons dashicons-editor-help"></span></a>' ),
        'id' => $prefix . 'column',
        'type' => 'title',
        'classes' => 'f4w-row',
        
    ));

    $f4w_layout_settings->add_field( array(
        'id'      => $prefix . 'column_box',
        'type'    => 'radio_inline',
        'options' => array(
            '2' => __( '2', 'column' ),
            '3'   => __( '3', 'column' ),
            '4'     => __( '4', 'column' ),
        ),
        'default' => '3',
    ) );


    /**
     * Help
     */
    $f4w_help = new_cmb2_box( array(
        'id'            => $prefix . 'ot-help',
        'title'         => __('Do you need help?', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'side',
        'priority'      => 'low',
        'show_names'    => true, 
        'classes' => 'f4w-otbox',
    ) );  

    $f4w_help->add_field( array(
		'id'   => $prefix . 'help',
        'type' => 'title',
        'classes' => 'f4w-row',
		'desc' => __('Here are some available options to help solve your problems. <ol><li><a href="https://www.flex4web.com/our-team/documentation" target="_blank">Read Documentation</a></li><li><a href="https://www.flex4web.com/our-team/support" target="_blank">Support</a></li></ol>', $field_slug),
    ) );

    
    /**
      * Color Settings
      */

      /* Background Color */
      $f4w_color_settings = new_cmb2_box( array(
        'id'            => $prefix . 'ot-color-settings',
        'title'         => __('Color Settings', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'normal',
        'priority'      => 'low',
        'show_names'    => true, 
        'classes' => 'f4w-otbox',
    ) ); 


    $f4w_color_settings->add_field( array(
        'name'    => __('Primary Color', $field_slug ),
        'id'      => $prefix . 'primary_color',
        'type'    => 'colorpicker',
        'default' => '#0069d9',
        'after_field' => __('<small>Default: #0069d9</small>', $field_slug ),
        'classes' => 'f4w-row',
        
    ) );
    $f4w_color_settings->add_field( array(
        'name'    => __('Secondary Color', $field_slug ),
        'id'      => $prefix . 'secondary_color',
        'type'    => 'colorpicker',
        'default' => '#2196F3',
        'after_field' => __('<small>Default: #2196F3</small>', $field_slug ),
        'classes' => 'f4w-row',
        
    ) );
    $f4w_color_settings->add_field( array(
        'name'    => __('Background Color', $field_slug ),
        'id'      => $prefix . 'background_color',
        'type'    => 'colorpicker',
        'default' => '#E3F2FD',
        'after_field' => __('<small>Default: #E3F2FD</small>', $field_slug ),
        'classes' => 'f4w-row',
        
    ) );
    $f4w_color_settings->add_field( array(
        'name'    => __('Social Icon Background Color', $field_slug ),
        'id'      => $prefix . 'social_icon_background_color',
        'type'    => 'colorpicker',
        'default' => '#0069d9',
        'after_field' => __('<small>Default: #0069d9</small>', $field_slug ),
        'classes' => 'f4w-row',
        
    ) );

    /*Font Color*/
    $f4w_font_color_settings = new_cmb2_box( array(
        'id'            => $prefix . 'ot-font-color',
        'title'         => __('Font Color Settings', $field_slug ),
        'object_types'  => array($postType), // Post type
        'context'       => 'normal',
        'priority'      => 'low',
        'show_names'    => true, 
        'classes' => 'f4w-otbox',
    ) ); 

    $f4w_font_color_settings->add_field( array(
        'name'    => __('Title Text Font Color', $field_slug ),
        'id'      => $prefix . 'title_font_color',
        'type'    => 'colorpicker',
        'default' => '#ffffff',
        'after_field' => __('<small>Default: #ffffff</small>', $field_slug ),
        'classes' => 'f4w-row',
    ) );
    $f4w_font_color_settings->add_field( array(
        'name'    => __('Job Role Text Font Color', $field_slug ),
        'id'      => $prefix . 'job_role_font_color',
        'type'    => 'colorpicker',
        'default' => '#ffffff',
        'after_field' => __('<small>Default: #ffffff</small>', $field_slug ),
        'classes' => 'f4w-row',
    ) );
    $f4w_font_color_settings->add_field( array(
        'name'    => __('Description  Text Font Color', $field_slug ),
        'id'      => $prefix . 'description_font_color',
        'type'    => 'colorpicker',
        'default' => '#333333',
        'after_field' => __('<small>Default: #333333</small>', $field_slug ),
        'classes' => 'f4w-row',
    ) );

    $f4w_font_color_settings->add_field( array(
        'name'    => __('Social Icon Font Color', $field_slug ),
        'id'      => $prefix . 'social_icon_font_color',
        'type'    => 'colorpicker',
        'default' => '#ffffff',
        'after_field' => __('<small>Default: #ffffff</small>', $field_slug ),
        'classes' => 'f4w-row',
    ) );

}