<?php

namespace Fab\Feature;

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

/**
 * Design
 *
 * @package    Fab
 * @subpackage Fab\Includes
 */
class Design extends Feature {

    /**
     * FAB Button Layout
     *
     * @var array
     */
    public static $layout = array(
        'position' => array(
            array(
                'id'   => 'left-bottom',
                'text' => 'Left Bottom',
            ),
            array(
                'id'   => 'center-bottom',
                'text' => 'Center Bottom',
            ),
            array(
                'id'   => 'right-bottom',
                'text' => 'Right Bottom',
            ),
            array(
                'id'   => 'left-top',
                'text' => 'Left Top',
            ),
            array(
                'id'   => 'center-top',
                'text' => 'Center Top',
            ),
            array(
                'id'   => 'right-top',
                'text' => 'Right Top',
            ),
        ),
    );

    /**
     * FAB Default Size Type
     *
     * @var array
     */
    public static $size = array(
        'type'   => array(
            array(
                'id'   => 'xsmall',
                'text' => 'XSmall',
            ),
            array(
                'id'   => 'small',
                'text' => 'Small',
            ),
            array(
                'id'   => 'medium',
                'text' => 'Medium',
            ),
            array(
                'id'   => 'large',
                'text' => 'Large',
            ),
            array(
                'id'   => 'xlarge',
                'text' => 'XLarge',
            ),
            array(
                'id'   => 'custom',
                'text' => 'Custom',
            ),
        ),
        'sizing' => array(
            array(
                'id'   => 'px',
                'text' => 'PX',
            ),
            array(
                'id'   => 'em',
                'text' => 'EM',
            ),
            array(
                'id'   => '%',
                'text' => '%',
            ),
            array(
                'id'   => 'rem',
                'text' => 'REM',
            ),
            array(
                'id'   => 'vw',
                'text' => 'VW',
            ),
            array(
                'id'   => 'vh',
                'text' => 'VH',
            ),
        ),
    );

    /** FAB Template */
    public static $template = array(
        'name'  => array(
            array(
                'id'   => 'hidden',
                'text' => 'Hidden',
            ),
            array(
                'id'   => 'classic',
                'text' => 'Classic',
            ),
            array(
                'id'   => 'shape',
                'text' => 'Shape',
            ),
        ),
        'shape' => array(
            array(
                'id'   => 'none',
                'text' => 'None',
            ),
            array(
                'id'   => 'bevel',
                'text' => 'Bevel',
            ),
            array(
                'id'   => 'circle',
                'text' => 'Circle',
            ),
            array(
                'id'   => 'message',
                'text' => 'Message',
            ),
            array(
                'id'   => 'octagon',
                'text' => 'Octagon',
            ),
            array(
                'id'   => 'pentagon',
                'text' => 'Pentagon',
            ),
            array(
                'id'   => 'rebbet',
                'text' => 'Rebbet',
            ),
            array(
                'id'   => 'rhombus',
                'text' => 'Rhombus',
            ),
            array(
                'id'   => 'star',
                'text' => 'Star',
            ),
            array(
                'id'   => 'square',
                'text' => 'Square',
            ),
            array(
                'id'   => 'triangle',
                'text' => 'Triangle',
            ),
        ),
    );

    /** FAB Font */
    public static $font = array(
        'style' => array(
            array(
                'id'   => 'normal',
                'text' => 'Normal',
            ),
            array(
                'id'   => 'italic',
                'text' => 'Italic',
            ),
            array(
                'id'   => 'bold',
                'text' => 'Bold',
            ),
            array(
                'id'   => 'oblique',
                'text' => 'Oblique',
            ),
        ),
    );

    /**
     * Feature construect
     *
     * @return void
     * @pattern prototype
     */
    public function __construct() {
        parent::__construct();
        $this->key         = 'core_design';
        $this->name        = 'Design';
        $this->description = 'Floating Awesome Button Design';
    }

    /**
     * Sanitize input
     */
    public function sanitize() {
        /** Grab Data */
        $this->params = $_POST;
        $this->params = $this->params['fab_design'];

        /** Sanitize Text Field */
        $this->params = (object) \FAB()->Helper->sanitizeTextField( $this->params );
    }

    /**
     * Transform data before save
     */
    public function transform() {
        /** Revalidate */
        if ( 'classic' === $this->params->template['name'] ) {
            $this->params->template['shape'] = 'none';
        }

        /** Transform */
        $this->params->template = json_decode( json_encode( $this->params->template ) );
        // $this->params->tooltip = json_decode( json_encode( $this->params->tooltip ) );
        $this->params->layout = json_decode( json_encode( $this->params->layout ) );

        /** Merge */
        $this->options = (object) array_merge(
            (array) $this->options,
            (array) $this->params
        );
        return $this->options;
    }
}
