<?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 Modal Tab.
 *
 * @package    Fab
 * @subpackage Fab/Helper/Metabox/Setting
 */
trait Tab_Modal {

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

        // Show layout field.
        $fields['layout'] = array(
            'type'    => 'select',
            'name'    => 'fab_modal_layout[id]',
            'label'   => __( 'Modal Layout', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the layout style for your modal window.', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['modal']['layout']['id'] ) ? $this->fab['modal']['layout']['id'] : '',
            'class'   => 'field_option_design_modal_layout_id',
            'options' => ModalFeature::$layout,
        );

        // Show size field.
        $fields['size'] = array(
            'type'    => 'select',
            'name'    => 'fab_design_size_type',
            'label'   => __( 'Modal Size', 'floating-awesome-button' ),
            'tooltip' => __( 'Choose the size for your modal window.', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['size']['type'] ) ? $this->fab['size']['type'] : '',
            'options' => ModalFeature::$size,
        );

        // Show custom size field.
        $fields['custom_size'] = array(
            'type'       => 'text',
            'name'       => 'fab_design_size_custom',
            'label'      => __( 'Custom Size', 'floating-awesome-button' ),
            'tooltip'    => __( 'Enter a custom size value', 'floating-awesome-button' ),
            'value'      => isset( $this->fab['size']['custom'] ) ? $this->fab['size']['custom'] : '',
            'visible_if' => array(
                array(
                    'field'    => 'size',
                    'operator' => '==',
                    'value'    => 'custom',
                ),
            ),
        );

        // Show navigation fields.
        $fields['navigation'] = array(
            'type'   => 'switch',
            'label'  => __( 'Navigation', 'floating-awesome-button' ),
            'docs'   => 13383,
            'fields' => array(
                'iconCover'         => array(
                    'type'  => 'switch',
                    'name'  => 'fab_modal_navigation[iconCover]',
                    'label' => __( 'Icon Cover', 'floating-awesome-button' ),
                    'value' => isset( $this->fab['modal']['navigation']['iconCover'] ) ? $this->fab['modal']['navigation']['iconCover'] : false,
                ),
                'backgroundDismiss' => array(
                    'type'       => 'switch',
                    'name'       => 'fab_modal_navigation[backgroundDismiss]',
                    'label'      => __( 'Background Dismiss', 'floating-awesome-button' ),
                    'value'      => isset( $this->fab['modal']['navigation']['backgroundDismiss'] ) ? $this->fab['modal']['navigation']['backgroundDismiss'] : false,
                    'inputClass' => 'flex',
                ),
                'maximize'          => array(
                    'type'       => 'switch',
                    'name'       => 'fab_modal_navigation[buttons][maximize]',
                    'label'      => __( 'Maximize', 'floating-awesome-button' ),
                    'value'      => isset( $this->fab['modal']['navigation']['buttons']['maximize'] ) ? $this->fab['modal']['navigation']['buttons']['maximize'] : false,
                    'inputClass' => 'flex',
                ),
                'draggable'         => array(
                    'type'       => 'switch',
                    'name'       => 'fab_modal_navigation[draggable]',
                    'label'      => __( 'Draggable', 'floating-awesome-button' ),
                    'value'      => isset( $this->fab['modal']['navigation']['draggable'] ) ? $this->fab['modal']['navigation']['draggable'] : false,
                    'inputClass' => 'flex',
                ),
                'escapeKey'         => array(
                    'type'       => 'switch',
                    'name'       => 'fab_modal_navigation[escapeKey]',
                    'label'      => __( 'Escape Key', 'floating-awesome-button' ),
                    'value'      => isset( $this->fab['modal']['navigation']['escapeKey'] ) ? $this->fab['modal']['navigation']['escapeKey'] : false,
                    'inputClass' => 'flex',
                ),
            ),
        );

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

        // Show overlay heading.
        $fields['overlay_heading'] = array(
            'type'  => 'heading',
            'label' => __( 'Overlay', 'floating-awesome-button' ),
            'info'  => __( 'Configure the modal overlay settings', 'floating-awesome-button' ),
        );

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

        // Show overlay opacity field.
        $fields['overlay_opacity'] = array(
            'type'    => 'range',
            'name'    => 'fab_modal_layout[overlay][opacity]',
            'label'   => __( 'Opacity', 'floating-awesome-button' ),
            'tooltip' => __( 'Set the opacity level for your modal overlay', 'floating-awesome-button' ),
            'value'   => isset( $this->fab['modal']['layout']['overlay']['opacity'] ) ? $this->fab['modal']['layout']['overlay']['opacity'] : 0.5,
            'min'     => 0,
            'max'     => 1,
            'step'    => 0.1,
        );

        // Show spacing heading.
        $fields['spacing_heading'] = array(
            'type'  => 'heading',
            'label' => __( 'Spacing', 'floating-awesome-button' ),
            'info'  => __( 'Configure the modal spacing settings', 'floating-awesome-button' ),
        );

        // Show padding field.
        $fields['padding'] = array(
            'type'    => 'size',
            'name'    => 'fab_modal_layout[content][padding]',
            'label'   => __( 'Padding', 'floating-awesome-button' ),
            'tooltip' => __( 'Set the padding for your modal content', 'floating-awesome-button' ),
            'options' => DesignFeature::$size['sizing'],
            'value'   => isset( $this->fab['modal']['layout']['content']['padding'] ) ? $this->fab['modal']['layout']['content']['padding'] : array(
                'top'    => 1,
                'right'  => 1,
                'bottom' => 1,
                'left'   => 1,
                'sizing' => 'rem',
            ),
        );

        // Show margin field.
        $fields['margin'] = array(
            'type'    => 'size',
            'name'    => 'fab_modal_layout[content][margin]',
            'label'   => __( 'Margin', 'floating-awesome-button' ),
            'tooltip' => __( 'Set the margin for your modal content', 'floating-awesome-button' ),
            'options' => DesignFeature::$size['sizing'],
            'value'   => isset( $this->fab['modal']['layout']['content']['margin'] ) ? $this->fab['modal']['layout']['content']['margin'] : array(
                'top'    => 1,
                'right'  => 1,
                'bottom' => 1,
                'left'   => 1,
                'sizing' => 'rem',
            ),
        );

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