<?php

/**
 * Fired during plugin deactivation
 *
 * @link       https://wordpress.org/plugins/genealogical-tree
 * @since      1.0.0
 *
 * @package    Genealogical_Tree
 * @subpackage Genealogical_Tree/includes
 */
namespace Zqe;

/**
 * Fired during plugin deactivation.
 *
 * This class defines all code necessary to run during the plugin's deactivation.
 *
 * @since      1.0.0
 * @package    Genealogical_Tree
 * @subpackage Genealogical_Tree/includes
 * @author     ak devs <akdevs.fr@gmail.com>
 */
class Genealogical_Tree_Helper {
    /**
     * It registers the custom post types and taxonomies.
     *
     * @since    1.0.0
     */
    public static function post_type_and_taxonomy() {
        $labels = array(
            'name'               => _x( 'Members', 'post type general name', 'genealogical-tree' ),
            'singular_name'      => _x( 'Member', 'post type singular name', 'genealogical-tree' ),
            'menu_name'          => _x( 'Members', 'admin menu', 'genealogical-tree' ),
            'name_admin_bar'     => _x( 'Member', 'add new on admin bar', 'genealogical-tree' ),
            'add_new'            => _x( 'Add New', 'member', 'genealogical-tree' ),
            'add_new_item'       => __( 'Add New Member', 'genealogical-tree' ),
            'new_item'           => __( 'New Member', 'genealogical-tree' ),
            'edit_item'          => __( 'Edit Member', 'genealogical-tree' ),
            'view_item'          => __( 'View Member', 'genealogical-tree' ),
            'all_items'          => __( 'Members', 'genealogical-tree' ),
            'search_items'       => __( 'Search Members', 'genealogical-tree' ),
            'parent_item_colon'  => __( 'Parent Members:', 'genealogical-tree' ),
            'featured_image'     => __( 'Member Image', 'genealogical-tree' ),
            'set_featured_image' => __( 'Set Member Image', 'genealogical-tree' ),
            'not_found'          => __( 'No members found.', 'genealogical-tree' ),
            'not_found_in_trash' => __( 'No members found in Trash.', 'genealogical-tree' ),
        );
        $supports = array('title', 'author', 'revisions');
        if ( defined( 'GENEALOGICAL_TREE_DEBUG' ) && true === \GENEALOGICAL_TREE_DEBUG ) {
            array_push( $supports, 'custom-fields' );
        }
        $args = array(
            'labels'             => $labels,
            'description'        => __( 'Description.', 'genealogical-tree' ),
            'public'             => true,
            'show_in_rest'       => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => 'genealogical-tree',
            'query_var'          => true,
            'rewrite'            => array(
                'slug' => 'gt-member',
            ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => $supports,
            'map_meta_cap'       => true,
        );
        register_post_type( 'gt-member', $args );
        $labels = array(
            'name'               => _x( 'Families', 'post type general name', 'genealogical-tree' ),
            'singular_name'      => _x( 'Family', 'post type singular name', 'genealogical-tree' ),
            'menu_name'          => _x( 'Families', 'admin menu', 'genealogical-tree' ),
            'name_admin_bar'     => _x( 'Family', 'add new on admin bar', 'genealogical-tree' ),
            'add_new'            => _x( 'Add New', 'family', 'genealogical-tree' ),
            'add_new_item'       => __( 'Add New Family', 'genealogical-tree' ),
            'new_item'           => __( 'New Family', 'genealogical-tree' ),
            'edit_item'          => __( 'Edit Family', 'genealogical-tree' ),
            'view_item'          => __( 'View Family', 'genealogical-tree' ),
            'all_items'          => __( 'Families', 'genealogical-tree' ),
            'search_items'       => __( 'Search Families', 'genealogical-tree' ),
            'parent_item_colon'  => __( 'Parent Families:', 'genealogical-tree' ),
            'not_found'          => __( 'No families found.', 'genealogical-tree' ),
            'not_found_in_trash' => __( 'No families found in Trash.', 'genealogical-tree' ),
        );
        $supports = array('title', 'author', 'revisions');
        if ( defined( 'GENEALOGICAL_TREE_DEBUG' ) && true === \GENEALOGICAL_TREE_DEBUG ) {
            array_push( $supports, 'custom-fields' );
        }
        $args = array(
            'labels'             => $labels,
            'description'        => __( 'Description.', 'genealogical-tree' ),
            'public'             => true,
            'show_in_rest'       => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => false,
            'query_var'          => true,
            'rewrite'            => array(
                'slug' => 'gt-family',
            ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => $supports,
            'map_meta_cap'       => true,
        );
        if ( defined( 'GENEALOGICAL_TREE_DEBUG' ) && true === \GENEALOGICAL_TREE_DEBUG ) {
            $args['show_in_menu'] = 'genealogical-tree';
        }
        register_post_type( 'gt-family', $args );
        $labels = array(
            'name'               => _x( 'Trees', 'post type general name', 'genealogical-tree' ),
            'singular_name'      => _x( 'Tree', 'post type singular name', 'genealogical-tree' ),
            'menu_name'          => _x( 'Trees', 'admin menu', 'genealogical-tree' ),
            'name_admin_bar'     => _x( 'Tree', 'add new on admin bar', 'genealogical-tree' ),
            'add_new'            => _x( 'Add New', 'tree', 'genealogical-tree' ),
            'add_new_item'       => __( 'Add New Tree', 'genealogical-tree' ),
            'new_item'           => __( 'New Tree', 'genealogical-tree' ),
            'edit_item'          => __( 'Edit Tree', 'genealogical-tree' ),
            'view_item'          => __( 'View Tree', 'genealogical-tree' ),
            'all_items'          => __( 'Trees', 'genealogical-tree' ),
            'search_items'       => __( 'Search Trees', 'genealogical-tree' ),
            'parent_item_colon'  => __( 'Parent Trees:', 'genealogical-tree' ),
            'not_found'          => __( 'No trees found.', 'genealogical-tree' ),
            'not_found_in_trash' => __( 'No trees found in Trash.', 'genealogical-tree' ),
        );
        $supports = array('title', 'author', 'revisions');
        if ( defined( 'GENEALOGICAL_TREE_DEBUG' ) && true === \GENEALOGICAL_TREE_DEBUG ) {
            array_push( $supports, 'custom-fields' );
        }
        $args = array(
            'labels'             => $labels,
            'description'        => __( 'Description.', 'genealogical-tree' ),
            'public'             => true,
            'show_in_rest'       => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => 'genealogical-tree',
            'query_var'          => true,
            'rewrite'            => array(
                'slug' => 'gt-tree',
            ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => $supports,
            'map_meta_cap'       => true,
        );
        register_post_type( 'gt-tree', $args );
        $labels = array(
            'name'                       => _x( 'Family Groups', 'genealogical-tree', 'genealogical-tree' ),
            'singular_name'              => _x( 'Family Group', 'taxonomy singular name', 'genealogical-tree' ),
            'search_items'               => __( 'Search Family Groups', 'genealogical-tree' ),
            'popular_items'              => __( 'Popular Family Groups', 'genealogical-tree' ),
            'all_items'                  => __( 'All Family Groups', 'genealogical-tree' ),
            'parent_item'                => __( 'Parent Family Group', 'genealogical-tree' ),
            'parent_item_colon'          => __( 'Parent Family Group', 'genealogical-tree' ),
            'edit_item'                  => __( 'Edit Family Group', 'genealogical-tree' ),
            'update_item'                => __( 'Update Family Group', 'genealogical-tree' ),
            'add_new_item'               => __( 'Add New Group', 'genealogical-tree' ),
            'new_item_name'              => __( 'New Group Name', 'genealogical-tree' ),
            'separate_items_with_commas' => __( 'Separate family group with commas', 'genealogical-tree' ),
            'add_or_remove_items'        => __( 'Add or remove family group', 'genealogical-tree' ),
            'choose_from_most_used'      => __( 'Choose from the most used family group', 'genealogical-tree' ),
            'not_found'                  => __( 'No family group found.', 'genealogical-tree' ),
            'menu_name'                  => __( 'Family Groups', 'genealogical-tree' ),
        );
        $args = array(
            'hierarchical'          => true,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_in_rest'          => true,
            'show_admin_column'     => true,
            'update_count_callback' => '_update_post_term_count',
            'query_var'             => true,
            'rewrite'               => array(
                'slug' => 'gt-family-group',
            ),
        );
        register_taxonomy( 'gt-family-group', array('gt-member', 'gt-family'), $args );
    }

    /**
     * It gets the full name of a member.
     *
     * @param int $member_id The ID of the member you want to get the full name of.
     *
     * @since    1.0.0
     */
    public function get_full_name( $member_id ) {
        $names = ( get_post_meta( $member_id, 'names' ) ? get_post_meta( $member_id, 'names' ) : array(array(
            'name' => ( get_post_meta( $member_id, 'full_name', true ) ? get_post_meta( $member_id, 'full_name', true ) : '' ),
        )) );
        foreach ( $names as $key => $value ) {
            if ( $value && !is_array( $value ) ) {
                $names[$key] = array(
                    'name' => $value,
                );
            }
        }
        foreach ( $names as $key => $value ) {
            if ( !isset( $value['name'] ) ) {
                unset($names[$key]);
            }
        }
        return $this->repear_full_name( esc_html( current( $names )['name'] ) );
    }

    /**
     * It strips all tags, trims whitespace, and replaces slashes with spaces.
     *
     * @param string $name The name of the member.
     *
     * @return string      The name of the file without the extension.
     *
     * @since    1.0.0
     */
    public function repear_full_name( $name ) {
        return wp_strip_all_tags( trim( str_replace( array('/', '\\'), array(' ', ''), $name ) ) );
    }

    /**
     * It returns an array of all the individual events
     *
     * @return array An array of all the individual events.
     *
     * @since    1.0.0
     */
    public function get_individual_events() {
        return array(
            'ADOP' => array(
                'type'  => 'ADOP',
                'title' => _x( 'Adoption', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Creation of a legally approved child-parent relationship that does not exist biologically.', 'genealogical-tree' ),
            ),
            'BAPM' => array(
                'type'  => 'BAPM',
                'title' => _x( 'Baptism', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Baptism, performed in infancy or later. ( See also BAPL and CHR. )', 'genealogical-tree' ),
            ),
            'BARM' => array(
                'type'  => 'BARM',
                'title' => _x( 'Bar Mitzvah', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'The ceremonial event held when a Jewish boy reaches age 13.', 'genealogical-tree' ),
            ),
            'BASM' => array(
                'type'  => 'BASM',
                'title' => _x( 'Bas Mitzvah', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'The ceremonial event held when a Jewish girl reaches age 13, also known as “Bat Mitzvah.”', 'genealogical-tree' ),
            ),
            'BIRT' => array(
                'type'  => 'BIRT',
                'title' => _x( 'Birth', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Entering into life.', 'genealogical-tree' ),
            ),
            'BLES' => array(
                'type'  => 'BLES',
                'title' => _x( 'Blessing', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Bestowing divine care or intercession. Sometimes given in connection with a naming ceremony.', 'genealogical-tree' ),
            ),
            'BURI' => array(
                'type'  => 'BURI',
                'title' => _x( 'Burial', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Disposing of the mortal remains of a deceased person.', 'genealogical-tree' ),
            ),
            'CENS' => array(
                'type'  => 'CENS',
                'title' => _x( 'Census', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Periodic count of the population for a designated locality, such as a national or state census.', 'genealogical-tree' ),
            ),
            'CHR'  => array(
                'type'  => 'CHR',
                'title' => _x( 'Christening', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Baptism or naming events for a child.', 'genealogical-tree' ),
            ),
            'CHRA' => array(
                'type'  => 'CHRA',
                'title' => _x( 'Adult Christening', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Baptism or naming events for an adult person.', 'genealogical-tree' ),
            ),
            'CONF' => array(
                'type'  => 'CONF',
                'title' => _x( 'Confirmation', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Conferring full church membership.', 'genealogical-tree' ),
            ),
            'CREM' => array(
                'type'  => 'CREM',
                'title' => _x( 'Cremation', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Disposal of the remains of a person\'s body by fire.', 'genealogical-tree' ),
            ),
            'DEAT' => array(
                'type'  => 'DEAT',
                'title' => _x( 'Death', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Mortal life terminates.', 'genealogical-tree' ),
            ),
            'EMIG' => array(
                'type'  => 'EMIG',
                'title' => _x( 'Emigration', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Leaving one\'s homeland with the intent of residing elsewhere.', 'genealogical-tree' ),
            ),
            'FCOM' => array(
                'type'  => 'FCOM',
                'title' => _x( 'First Communion', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'The first act of sharing in the Lord\'s supper as part of church worship.', 'genealogical-tree' ),
            ),
            'GRAD' => array(
                'type'  => 'GRAD',
                'title' => _x( 'Graduation', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Awarding educational diplomas or degrees to individuals.', 'genealogical-tree' ),
            ),
            'IMMI' => array(
                'type'  => 'IMMI',
                'title' => _x( 'Immigration', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Entering into a new locality with the intent of residing there.', 'genealogical-tree' ),
            ),
            'NATU' => array(
                'type'  => 'NATU',
                'title' => _x( 'Naturalization', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Obtaining citizenship.', 'genealogical-tree' ),
            ),
            'ORDN' => array(
                'type'  => 'ORDN',
                'title' => _x( 'Ordination', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Receiving authority to act in religious matters.', 'genealogical-tree' ),
            ),
            'PROB' => array(
                'type'  => 'PROB',
                'title' => _x( 'Probate', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Judicial determination of the validity of a will. It may indicate several related court activities over several dates.', 'genealogical-tree' ),
            ),
            'RETI' => array(
                'type'  => 'RETI',
                'title' => _x( 'Retirement', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Exiting an occupational relationship with an employer after a qualifying time period.', 'genealogical-tree' ),
            ),
            'WILL' => array(
                'type'  => 'WILL',
                'title' => _x( 'Will', 'GEDCOM event title: legal document', 'genealogical-tree' ),
                'disc'  => __( 'A legal document treated as an event, by which a person disposes of his or her estate. It takes effect after death. The event date is the date the will was signed while the person was alive. ( See also PROB )', 'genealogical-tree' ),
            ),
            'EVEN' => array(
                'type'  => 'EVEN',
                'title' => _x( 'Generic Event', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Generic Individual Event', 'genealogical-tree' ),
            ),
        );
    }

    /**
     * It returns an array of family events
     *
     * @return An array of all the events that are available for the family.
     *
     * @since    1.0.0
     */
    public function get_family_events() {
        return array(
            'ANUL' => array(
                'type'  => 'ANUL',
                'title' => _x( 'Annulment', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Declaring a marriage void from the beginning ( never existed ).', 'genealogical-tree' ),
            ),
            'CENS' => array(
                'type'  => 'CENS',
                'title' => _x( 'Census', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Periodic count of the population for a designated locality, such as a national or state census.', 'genealogical-tree' ),
            ),
            'DIV'  => array(
                'type'  => 'DIV',
                'title' => _x( 'Divorce', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Dissolving a marriage through civil action.', 'genealogical-tree' ),
            ),
            'DIVF' => array(
                'type'  => 'DIVF',
                'title' => _x( 'Divorce Filed', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Filing for a divorce by a spouse.', 'genealogical-tree' ),
            ),
            'ENGA' => array(
                'type'  => 'ENGA',
                'title' => _x( 'Engagement', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Recording or announcing an agreement between 2 people to become married.', 'genealogical-tree' ),
            ),
            'MARB' => array(
                'type'  => 'MARB',
                'title' => _x( 'Marriage Bann', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Official public notice given that 2 people intend to marry.', 'genealogical-tree' ),
            ),
            'MARC' => array(
                'type'  => 'MARC',
                'title' => _x( 'Marriage Contract', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Recording a formal agreement of marriage, including the prenuptial agreement in which marriage partners reach agreement about the property rights of 1 or both, securing property to their children.', 'genealogical-tree' ),
            ),
            'MARL' => array(
                'type'  => 'MARL',
                'title' => _x( 'Marriage License', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Obtaining a legal license to marry.', 'genealogical-tree' ),
            ),
            'MARR' => array(
                'type'  => 'MARR',
                'title' => _x( 'Marriage', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'A legal, common-law, or customary event such as a wedding or marriage ceremony that joins 2 partners to create or extend a family unit.', 'genealogical-tree' ),
            ),
            'MARS' => array(
                'type'  => 'MARS',
                'title' => _x( 'Marriage Settlement', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Creating an agreement between 2 people contemplating marriage, at which time they agree to release or modify property rights that would otherwise arise from the marriage.', 'genealogical-tree' ),
            ),
            'EVEN' => array(
                'type'  => 'EVEN',
                'title' => _x( 'Generic Event', 'GEDCOM event title', 'genealogical-tree' ),
                'disc'  => __( 'Generic Family Event', 'genealogical-tree' ),
            ),
        );
    }

    /**
     * It searches through an array of events and returns the title of the event that matches the tag
     *
     * @param string $tag The tag you're looking for.
     * @param array  $events An array of events.
     *
     * @return string The title of the event that matches the tag.
     *
     * @since    1.0.0
     */
    public function search_for_tag( $tag, $events ) {
        foreach ( $events as $key => $val ) {
            if ( $val['type'] === $tag ) {
                return $val;
            }
        }
        return null;
    }

    /**
     * It returns an array of default values for the tree shortcode
     *
     * @return array An array of default values for the tree.
     *
     * @since    1.0.0
     */
    public function tree_default_meta() {
        return array(
            'family'                     => null,
            'root'                       => null,
            'root_highlight'             => 'on',
            'gt_frontend'                => 'on',
            'style'                      => '1',
            'layout'                     => 'vr',
            'ajax'                       => false,
            'name'                       => 'full',
            'birt'                       => 'full',
            'birt_hide_alive'            => false,
            'deat'                       => 'full',
            'gender'                     => 'full',
            'sibling_order'              => 'default',
            'generation'                 => false,
            'generation_number'          => -1,
            'generation_number_ancestor' => -1,
            'generation_start_from'      => 1,
            'ancestor'                   => false,
            'popup'                      => false,
            'female_tree'                => false,
            'hide_spouse'                => false,
            'hide_un_spouse'             => false,
            'collapsible_family_root'    => false,
            'collapsible_family_spouse'  => false,
            'collapsible_family_onload'  => false,
            'treelink'                   => false,
            'background'                 => array(
                'color' => 'rgba( 0, 0, 0, .05 )',
            ),
            'marr_icon'                  => false,
            'container'                  => array(
                'background' => array(
                    'color' => '#ffffff',
                    'image' => 'linear-gradient( 90deg, #f0f0f0 1px, transparent 0 ), linear-gradient( 180deg, #f0f0f0 1px, transparent 0 )',
                    'size'  => '2.14785rem 2.14785rem',
                ),
                'border'     => array(
                    'style'  => 'solid',
                    'color'  => '#000000',
                    'width'  => '1px',
                    'radius' => '0px',
                ),
            ),
            'box'                        => array(
                'layout'     => 'vr',
                'width'      => '90px',
                'background' => array(
                    'color' => array(
                        'male'   => '#daeef3',
                        'female' => '#ffdbe0',
                        'other'  => '#ffffff',
                    ),
                ),
                'border'     => array(
                    'style'  => 'solid',
                    'color'  => array(
                        'male'   => '#000000',
                        'female' => '#000000',
                        'other'  => '#000000',
                    ),
                    'width'  => '1px',
                    'radius' => '1px',
                ),
            ),
            'thumb'                      => array(
                'show'   => false,
                'width'  => '80px',
                'border' => array(
                    'style'  => 'solid',
                    'color'  => array(
                        'male'   => '#000000',
                        'female' => '#000000',
                        'other'  => '#000000',
                    ),
                    'width'  => '1px',
                    'radius' => '1px',
                ),
            ),
            'line'                       => array(
                'border' => array(
                    'style'  => 'solid',
                    'color'  => '#000000',
                    'width'  => '1px',
                    'radius' => '1px',
                ),
            ),
            'name_text'                  => array(
                'font_family' => 'inherit',
                'font_size'   => '12px',
                'font_style'  => 'inherit',
                'font_weight' => 'regular',
                'color'       => 'inherit',
                'align'       => 'center',
            ),
            'other_text'                 => array(
                'font_family' => 'inherit',
                'font_size'   => '10px',
                'font_style'  => 'inherit',
                'font_weight' => 'regular',
                'color'       => 'inherit',
                'align'       => 'center',
            ),
        );
    }

    /**
     * It returns an array of border styles
     *
     * @return array An array of border styles.
     *
     * @since    1.0.0
     */
    public function border_style() {
        return array(
            'dotted' => __( 'Dotted', 'genealogical-tree' ),
            'dashed' => __( 'Dashed', 'genealogical-tree' ),
            'solid'  => __( 'Solid', 'genealogical-tree' ),
            'double' => __( 'Double', 'genealogical-tree' ),
            'groove' => __( 'Groove', 'genealogical-tree' ),
            'ridge'  => __( 'Ridge', 'genealogical-tree' ),
            'inset'  => __( 'Inset', 'genealogical-tree' ),
            'outset' => __( 'Outset', 'genealogical-tree' ),
            'none'   => __( 'None', 'genealogical-tree' ),
            'hidden' => __( 'Hidden', 'genealogical-tree' ),
        );
    }

    /**
     * It takes two events, strips out the date, converts the date to a timestamp, converts the timestamp
     * to a string, splits the string into an array, converts the array elements to integers, and then
     * compares the integers
     *
     * @param string $event_prev The previous event in the array.
     * @param string $event_next The next event in the array.
     *
     * @return array the difference between the two dates.
     *
     * @since    1.0.0
     */
    public function sort_events( $event_prev, $event_next ) {
        $event_prev = str_replace( array(
            'BEF',
            'EST',
            'AFT',
            'FROM',
            'TO',
            'ABT'
        ), array(
            '',
            '',
            '',
            '',
            '',
            ''
        ), $event_prev['date'] );
        $event_next = str_replace( array(
            'BEF',
            'EST',
            'AFT',
            'FROM',
            'TO',
            'ABT'
        ), array(
            '',
            '',
            '',
            '',
            '',
            ''
        ), $event_next['date'] );
        $event_prev = strtotime( $event_prev );
        $event_next = strtotime( $event_next );
        return $event_prev - $event_next;
    }

    /**
     * It sorts siblings by birth date.
     *
     * @param string $member_prev The ID of the previous sibling.
     * @param string $member_next The ID of the next sibling.
     *
     * @return array The difference between the two dates.
     *
     * @since    1.0.0
     */
    public function sort_siblings( $member_prev, $member_next ) {
        $birt_prev = $this->get_member_birt( $member_prev );
        $birt_next = $this->get_member_birt( $member_next );
        $birt_date_prev = '';
        $birt_date_next = '';
        if ( isset( $birt_prev['date'] ) && $birt_prev['date'] ) {
            $birt_date_prev = $birt_prev['date'];
        }
        if ( isset( $birt_next['date'] ) && $birt_next['date'] ) {
            $birt_date_next = $birt_next['date'];
        }
        $birt_prev = strtotime( $birt_date_prev );
        $birt_next = strtotime( $birt_date_next );
        return $birt_prev - $birt_next;
    }

    /**
     * It returns the birth event of a member
     *
     * @param string $member_id The ID of the member you want to get the birth information for.
     *
     * @return array The birth information.
     *
     * @since    1.0.0
     */
    public function get_member_birt( $member_id ) {
        $even_array = ( get_post_meta( $member_id, 'even' ) ? get_post_meta( $member_id, 'even' ) : array() );
        foreach ( $even_array as $key => $value ) {
            $even_array[$key]['tag'] = strtoupper( $even_array[$key]['tag'] );
        }
        $event = array();
        foreach ( $even_array as $key => $value ) {
            if ( 'BIRT' === $value['tag'] ) {
                $event['BIRT'][$key] = $value;
            }
        }
        $birt = ( isset( $event['BIRT'] ) && !empty( $event['BIRT'] ) ? current( $event['BIRT'] ) : array(
            'date' => '',
            'plac' => '',
        ) );
        return $birt;
    }

    /**
     * It merges two arrays.
     *
     * @param array $base The base array to merge into.
     * @param array $input The array you want to merge into the base array.
     * @param bool  $default If the input is empty, return the default.
     *
     * @return array the base array with the input array merged into it.
     */
    public function tree_merge( array $base, array $input = array(), bool $default = false ) {
        if ( empty( $input ) && $default === true ) {
            return $base;
        }
        foreach ( $base as $key => $value ) {
            if ( is_array( $value ) ) {
                $base[$key] = $this->tree_merge( $value, ( isset( $input[$key] ) && $input[$key] && is_array( $input[$key] ) ? $input[$key] : array() ) );
            } else {
                $base[$key] = ( isset( $input[$key] ) && $input[$key] ? $input[$key] : '' );
            }
        }
        return $base;
    }

}
