<?php
namespace Fab\Metabox\Setting;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * FAB Metabox Button Tab.
 *
 * @package    Fab
 * @subpackage Fab/Helper/Metabox/Setting
 */
trait Tab_Button {

    /**
     * Get button tab data
     *
     * @return array Button tab data
     */
    public function get_tab_button() {
        $options  = \Fab\Plugin\Config::getInstance()->getConfig()->options;
        $template = $options->fab_design->template;
        $fields   = array();

        // Show color field.
        $fields['color'] = array(
            'type'    => 'colorpicker',
            'name'    => 'fab_design_template[color]',
            'label'   => __( 'Color', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the color for your button', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['template']['color'] ) ? $this->fab['template']['color'] : '',
        );

        // Show shape field if template is shape.
        if ( 'shape' === $template->name ) {
            $fields['shape'] = array(
                'type'       => 'select',
                'name'       => 'fab_design_template[shape]',
                'label'      => __( 'Shape', 'floating-awesome-button' ),
                'tooltip'    => __( 'Choose the shape for your button', 'floating-awesome-button' ),
                'value'      => isset( $this->fab['template']['shape'] ) ? $this->fab['template']['shape'] : $template->shape,
                'inputClass' => 'select2 field_option_design_template_shape',
                'options'    => \Fab\Feature\Design::$template['shape'],
            );
        }

        // Show standalone field.
        $fields['standalone'] = array(
            'type'    => 'switch',
            'name'    => 'fab_design_standalone',
            'label'   => __( 'Standalone', 'floating-awesome-button' ),
            'tooltip' => __( 'Seperates button from groups', 'floating-awesome-button' ),
            'info'    => __( 'Enable this option to separate the button from other groups, making it an individual element.', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['standalone'] ) ? $this->fab['standalone'] : false,
        );

        // Show button position field.
        $fields['position'] = array(
            'type'    => 'select',
            'name'    => 'fab_design_template[position]',
            'label'   => __( 'Position', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the position of your button', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['template']['position'] ) ? $this->fab['template']['position'] : 'right-bottom',
            'options' => \Fab\Feature\Design::$layout['position'],
        );

        // Show icon heading.
        $fields['icon_heading'] = array(
            'type'  => 'heading',
            'label' => __( 'Icon', 'floating-awesome-button' ),
            'info'  => __( 'Customize the icon that appears on your button.', 'floating-awesome-button' ),
        );

        // Show icon class field.
        $fields['icon_class'] = array(
            'type'    => 'iconpicker',
            'name'    => 'fab_design_icon_class',
            'label'   => __( 'Icon Class', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose an icon from the icon picker', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['icon_class'] ) ? $this->fab['icon_class'] : '',
        );

        // Show icon color field.
        $fields['icon_color'] = array(
            'type'    => 'colorpicker',
            'name'    => 'fab_design_template[icon][color]',
            'label'   => __( 'Icon Color', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the color for your icon', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['template']['icon']['color'] ) ? $this->fab['template']['icon']['color'] : '',
        );

        // Show tooltip heading.
        $fields['tooltip_heading'] = array(
            'type'  => 'heading',
            'label' => __( 'Tooltip', 'floating-awesome-button' ),
            'info'  => __( 'Configure the tooltip that appears when hovering over the button.', 'floating-awesome-button' ),
        );

        // Show tooltip always display field.
        $fields['tooltip_alwaysdisplay'] = array(
            'type'    => 'switch',
            'name'    => 'fab_design_tooltip[alwaysdisplay]',
            'label'   => __( 'Always Display', 'floating-awesome-button' ),
            'tooltip' => __( 'Keep the tooltip visible at all times', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['tooltip']['alwaysdisplay'] ) ? $this->fab['tooltip']['alwaysdisplay'] : false,
        );

        // Show tooltip font color field.
        $fields['tooltip_font_color'] = array(
            'type'    => 'colorpicker',
            'name'    => 'fab_design_tooltip[font][color]',
            'label'   => __( 'Font Color', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the font color for your tooltip text', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['tooltip']['font']['color'] ) ? $this->fab['tooltip']['font']['color'] : '',
        );

        return array(
            'button' => array(
                'label'      => __( 'Button', 'floating-awesome-button' ),
                'visible_if' => array(
                    array(
                        'tab'      => 'setting',
                        'field'    => 'type',
                        'operator' => 'NOTIN',
                        'value'    => apply_filters( 'fab_types_group_toast', array() ),
                    ),
                ),
                'fields'     => $fields,
            ),
        );
    }
}
