<?php

namespace Fab\Controller;

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

/**
 * Group.
 *
 * @package    Fab
 * @subpackage Fab/Module
 */
class Group extends Base {

    /**
     * Group Key.
     *
     * @var string
     */
    public $key;

    /**
     * Type Name.
     *
     * @var string
     */
    public $type;

    /**
     * Dependency.
     *
     * @var string
     */
    public $dependency;

    /**
     * Add group type.
     *
     * @param array $types Types.
     * @return array
     */
    public function add_group_type( $types ) {
        // If the group type already exists, return the types array.
        if ( isset( $types[ $this->key ] ) ) {
            return $types;
        }

        // Add the group type to the types array.
        $types[ $this->key ] = array(
            'text'     => $this->get_labels_group()['name'],
            'children' => array(),
        );

        return $types;
    }

    /**
     * Add fab setting types.
     *
     * @editor
     *
     * @param array $types Types.
     * @return array
     */
    public function add_fab_setting_types( $types ) {
        // Initiate group type.
        $types = $this->add_group_type( $types );

        // Initiate new type.
        $new_type = array(
            'id'   => $this->type,
            'text' => $this->get_labels_type()['name'],
        );

        // Check if it requires a dependency.
        if ( $this->dependency ) {
            $new_type['dependency'] = $this->dependency;
        }

        // Add new type to group type.
        $types[ $this->key ]['children'][] = $new_type;

        return $types;
    }

    /**
     * Add link group type.
     *
     * @param array $types The types.
     * @return array
     */
    public function add_fab_types_group( $types ) {
        $types[] = $this->type;
        return $types;
    }
}
