<?php
namespace Fab\Metabox\Setting;

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

use Fab\Feature\Modal as ModalFeature;
use Fab\Feature\Design as DesignFeature;

/**
 * FAB Metabox Toast Tab.
 *
 * @package    Fab
 * @subpackage Fab/Helper/Metabox/Setting
 */
trait Tab_Toast {

    /**
     * Get modal tab data
     *
     * @return array Modal tab data
     */
    public function get_tab_toast() {
        $fields = array();

        // Show toast url button field.
        $fields['url_button'] = array(
            'type'       => 'text',
            'name'       => 'fab_setting_toast[url_button]',
            'label'      => __( 'Button URL', 'floating-awesome-button' ),
            'tooltip'    => __( 'URL for the toast notification button', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['url_button'] ) ? $this->fab['toast']['url_button'] : '',
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast duration field.
        $fields['duration'] = array(
            'type'       => 'number',
            'name'       => 'fab_setting_toast[duration]',
            'label'      => __( 'Duration', 'floating-awesome-button' ),
            'tooltip'    => __( 'Duration in milliseconds to show the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['duration'] ) ? $this->fab['toast']['duration'] : 3000,
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast text button field.
        $fields['text_button'] = array(
            'type'       => 'text',
            'name'       => 'fab_setting_toast[text_button]',
            'label'      => __( 'Button Text', 'floating-awesome-button' ),
            'tooltip'    => __( 'Text to display on the toast notification button', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['text_button'] ) ? $this->fab['toast']['text_button'] : '',
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast window field.
        $fields['window'] = array(
            'type'       => 'switch',
            'name'       => 'fab_setting_toast[window]',
            'label'      => __( 'Open in New Window', 'floating-awesome-button' ),
            'tooltip'    => __( 'Open the toast notification button URL in a new window', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['window'] ) ? $this->fab['toast']['window'] : false,
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast closeable field.
        $fields['closeable'] = array(
            'type'       => 'switch',
            'name'       => 'fab_setting_toast[closeable]',
            'label'      => __( 'Closeable', 'floating-awesome-button' ),
            'tooltip'    => __( 'Allow users to close the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['closeable'] ) ? $this->fab['toast']['closeable'] : false,
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast remember on click field.
        $fields['remember_on_click'] = array(
            'type'       => 'switch',
            'name'       => 'fab_setting_toast[remember_on_click]',
            'label'      => __( 'Remember on Click', 'floating-awesome-button' ),
            'tooltip'    => __( 'Remember toast notification state when clicked', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['remember_on_click'] ) ? $this->fab['toast']['remember_on_click'] : false,
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast gravity field.
        $fields['gravity'] = array(
            'type'       => 'select',
            'name'       => 'fab_setting_toast[gravity]',
            'label'      => __( 'Gravity', 'floating-awesome-button' ),
            'tooltip'    => __( 'Set the gravity position for the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['gravity'] ) ? $this->fab['toast']['gravity'] : '',
            'inputClass' => 'select2 fab_modal_layout_spacing_sizing',
            'options'    => array(
                array(
                    'id'   => 'top',
                    'text' => __( 'Top', 'floating-awesome-button' ),
                ),
                array(
                    'id'   => 'bottom',
                    'text' => __( 'Bottom', 'floating-awesome-button' ),
                ),
            ),
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast position field.
        $fields['position'] = array(
            'type'       => 'select',
            'name'       => 'fab_setting_toast[position]',
            'label'      => __( 'Position', 'floating-awesome-button' ),
            'tooltip'    => __( 'Set the position for the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['position'] ) ? $this->fab['toast']['position'] : '',
            'inputClass' => 'select2 fab_modal_layout_spacing_sizing',
            'options'    => array(
                array(
                    'id'   => 'left',
                    'text' => __( 'Left', 'floating-awesome-button' ),
                ),
                array(
                    'id'   => 'center',
                    'text' => __( 'Center', 'floating-awesome-button' ),
                ),
                array(
                    'id'   => 'right',
                    'text' => __( 'Right', 'floating-awesome-button' ),
                ),
            ),
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast background field.
        $fields['background'] = array(
            'type'       => 'colorpicker',
            'name'       => 'fab_setting_toast[background]',
            'label'      => __( 'Background', 'floating-awesome-button' ),
            'tooltip'    => __( 'Set the background color for the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['background'] ) ? $this->fab['toast']['background'] : '',
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast text color field.
        $fields['text_color'] = array(
            'type'       => 'colorpicker',
            'name'       => 'fab_setting_toast[text_color]',
            'label'      => __( 'Text Color', 'floating-awesome-button' ),
            'tooltip'    => __( 'Set the text color for the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['text_color'] ) ? $this->fab['toast']['text_color'] : '',
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

        // Set toast bar color field.
        $fields['bar_color'] = array(
            'type'       => 'colorpicker',
            'name'       => 'fab_setting_toast[bar_color]',
            'label'      => __( 'Bar Color', 'floating-awesome-button' ),
            'tooltip'    => __( 'Set the bar color for the toast notification', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['toast']['bar_color'] ) ? $this->fab['toast']['bar_color'] : '',
            'visible_if' => array(
                array(
                    'tab'      => 'setting',
                    'field'    => 'type',
                    'operator' => 'IN',
                    'value'    => apply_filters( 'fab_types_group_toast', array() ),
                ),
            ),
        );

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