<?php
/**
 * Dakidarts Numerology Core - Renderer
 *
 * Handles rendering of API results to the frontend
 * (via shortcodes, templates, or Gutenberg blocks),
 * applying admin-defined styles dynamically.
 *
 * @package Dakidarts_Numerology_Core
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Dakidarts_Render {

    // Keep track of rendered forms/buttons to prevent duplicates
    private static $rendered_forms = [];
    private static $rendered_buttons = [];

    /**
     * Get admin style settings
     *
     * @return array
     */
    private static function get_styles(): array {
        return get_option( 'dakidarts_numerology_style_settings', [] );
    }

    /**
     * Render a styled button
     *
     * @param string $text Button text
     * @param string $type HTML type attribute
     * @param string $id Optional unique ID to avoid duplicate
     * @return string
     */
    public static function render_button( string $text = 'Submit', string $type = 'submit', string $id = '' ): string {
        if ( $id && in_array( $id, self::$rendered_buttons, true ) ) {
            return ''; // Already rendered
        }
        if ( $id ) self::$rendered_buttons[] = $id;

        $styles = self::get_styles();
        $style_attr = '';

        $style_attr .= ! empty( $styles['button_bg'] ) ? 'background:' . esc_attr( $styles['button_bg'] ) . ';' : '';
        $style_attr .= ! empty( $styles['button_color'] ) ? 'color:' . esc_attr( $styles['button_color'] ) . ';' : '';
        $style_attr .= ! empty( $styles['button_padding'] ) ? 'padding:' . esc_attr( $styles['button_padding'] ) . ';' : '';
        $style_attr .= ! empty( $styles['button_margin'] ) ? 'margin:' . esc_attr( $styles['button_margin'] ) . ';' : '';
        $style_attr .= ! empty( $styles['button_radius'] ) ? 'border-radius:' . esc_attr( $styles['button_radius'] ) . ';' : '';

        if ( isset( $styles['button_border_width'], $styles['button_border_style'], $styles['button_border_color'] ) ) {
            $style_attr .= 'border:' . esc_attr( $styles['button_border_width'] ) . ' '
                . esc_attr( $styles['button_border_style'] ) . ' '
                . esc_attr( $styles['button_border_color'] ) . ';';
        }

        $position = $styles['button_position'] ?? 'inherit';
        if ( $position !== 'inherit' ) {
            $style_attr .= 'display:block;margin:0 auto;text-align:' . esc_attr( $position ) . ';';
        }

        return sprintf(
            '<button type="%1$s" style="%2$s">%3$s</button>',
            esc_attr( $type ),
            esc_attr( $style_attr ),
            esc_html( $text )
        );
    }

    /**
     * Render a form using a template file
     *
     * @param string $endpoint
     * @param array  $params
     * @param string $template
     * @param string $id Optional unique ID to prevent duplicates
     * @return string
     */
    public static function render_form( string $endpoint, array $params = [], string $template = 'default', string $id = '' ): string {
    if ( $id && in_array( $id, self::$rendered_forms, true ) ) {
        return ''; // Already rendered
    }
    if ( $id ) self::$rendered_forms[] = $id;

    $template_file = plugin_dir_path( __FILE__ ) . "../templates/form-{$template}.php";
    if ( ! file_exists( $template_file ) ) {
        $template_file = plugin_dir_path( __FILE__ ) . "../templates/form-default.php";
    }

    // Get param descriptions from API endpoints
    $endpoints = Dakidarts_API::get_endpoints();
    $param_desc = isset($endpoints[$endpoint]['param_desc']) ? $endpoints[$endpoint]['param_desc'] : [];
    $required_params = isset($endpoints[$endpoint]['required']) && is_array($endpoints[$endpoint]['required'])
        ? $endpoints[$endpoint]['required']
        : $params;

    ob_start();
    include $template_file;
    return ob_get_clean();
}


    /**
     * Render API result using a template file
     *
     * @param array  $response
     * @param string $template
     * @param string $endpoint
     * @return string
     */
    public static function render_result( array $response, string $template = 'default', string $endpoint = '' ): string {
        $template_file = plugin_dir_path( __FILE__ ) . "../templates/result-{$template}.php";
        if ( ! file_exists( $template_file ) ) {
            $template_file = plugin_dir_path( __FILE__ ) . "../templates/result-default.php";
        }

        $response  = self::normalize_response( $endpoint, $response );
        $label_map = self::get_label_map( $endpoint );

        ob_start();
        include $template_file;
        $html = ob_get_clean();

        return apply_filters( 'dakidarts_numerology_render_result', $html, $response, $template, $endpoint );
    }

    /**
     * Normalize API response per endpoint and remove metadata payloads.
     *
     * @param string $endpoint
     * @param array  $response
     * @return array
     */
    private static function normalize_response( string $endpoint, array $response ): array {
        $response = self::strip_meta( $response );

        if ( empty( $endpoint ) || ! is_array( $response ) ) {
            return $response;
        }

        $order_map = [
            'life-path'          => [ 'life_path_number', 'detailed_meaning', 'summary' ],
            'sun-number'         => [ 'attitude_number', 'detailed_meaning', 'summary' ],
            'challenge-number'   => [ 'challenge_birth', 'challenge_life', 'challenge_love', 'challenge_death', 'meanings' ],
            'karmic-debt'        => [ 'karmic_number', 'life_path_number', 'detailed_meaning', 'summary' ],
            'karmic-lesson'      => [ 'karmic_lessons', 'detailed_meaning', 'karmic_lessons_summary' ],
            'personality-number' => [ 'personality_number', 'detailed_meaning', 'summary' ],
            'personal-year'      => [ 'personal_year_number', 'detailed_meaning', 'summary' ],
            'personal-month'     => [ 'personal_month_number', 'birthdate', 'target_date', 'timezone', 'meaning', 'detailed_meaning' ],
            'personal-day'       => [ 'personal_day_number', 'birthdate', 'target_date', 'timezone', 'meaning', 'detailed_meaning' ],
            'phone-number'       => [ 'phone_number', 'phone_overall_vibration', 'phone_vibration_description', 'overall_minor_numbers' ],
            'soul-expression'    => [ 'destiny_number', 'detailed_meaning', 'summary' ],
            'soul-urge'          => [ 'heart_desire_number', 'detailed_meaning', 'summary' ],
            'subconscious-self'  => [ 'subconscious_self_number', 'meaning', 'detailed_meaning' ],
            'balance-number'     => [ 'balance_number', 'detailed_meaning', 'summary' ],
            'lucky-numbers'      => [ 'lucky_numbers' ],
            'rational-thought'   => [ 'rational_thought_number', 'meaning', 'detailed_meaning' ],
            'life-period'        => [ 'life_path', 'periods' ],
            'birth-day-number'   => [ 'birth_day_number', 'keyword', 'meaning', 'detailed_meaning', 'summary' ],
            'hidden-passion'     => [ 'fullname', 'hidden_passions' ],
            'hidden-passion-positions' => [ 'name', 'letters_only', 'dominant_letters', 'hidden_passion_numbers', 'hppn', 'position_sums', 'positions_by_letter', 'gaps', 'meanings', 'detailed_meanings' ],
            'minor-personality'  => [ 'minor_personality_number', 'keyword', 'meaning', 'detailed_meaning', 'vibration', 'note', 'short_name' ],
            'minor-heart-desire' => [ 'minor_heart_desire_number', 'keyword', 'meaning', 'detailed_meaning', 'vibration', 'note', 'short_name' ],
            'minor-expression'   => [ 'minor_expression_number', 'keyword', 'meaning', 'detailed_meaning', 'vibration', 'note', 'current_name' ],
            'ancestor-reading'   => [ 'family_name', 'ancestral_number', 'meaning', 'detailed_meaning' ],
            'capstone-letter'    => [ 'name', 'capstone_letter', 'meaning', 'detailed_meaning' ],
            'cornerstone-letter' => [ 'name', 'cornerstone_letter', 'meaning', 'detailed_meaning' ],
            'compatibility-score' => [ 'person_1', 'person_2', 'compatibility_scores' ],
            'angel-number-sync'  => [ 'number', 'reduced_number', 'sequence_type', 'base_meaning', 'base_detailed_meaning', 'synchronicity_meaning' ],
            'date-meaning'        => [ 'date', 'date_number', 'meaning', 'detailed_meaning' ],
            'email-numerology'    => [ 'email', 'email_number', 'meaning', 'detailed_meaning' ],
            'mirror-path'         => [ 'life_path', 'mirror_path', 'mirror_path_meaning', 'is_master_number' ],
            'mirror-numbers'      => [ 'base', 'reduced_base', 'is_master_number', 'mirror', 'cycle', 'cycle_keywords', 'keyword', 'meaning', 'detailed_meaning' ],
            'essence-cycle'       => [ 'full_name', 'dob', 'start_year', 'cycle_summary', 'essence_table' ],
            'life-essence'        => [ 'life_essence_number', 'expression', 'soul_urge', 'life_path', 'vibration_level', 'keyword', 'meaning', 'detailed_meaning', 'summary' ],
            'transits'            => [ 'full_name', 'current_age', 'note', 'cycle_summary', 'current_transits' ],
        ];

        if ( ! isset( $order_map[ $endpoint ] ) ) {
            return $response;
        }

        $ordered = [];
        foreach ( $order_map[ $endpoint ] as $key ) {
            if ( array_key_exists( $key, $response ) ) {
                $ordered[ $key ] = $response[ $key ];
            }
        }

        foreach ( $response as $key => $value ) {
            if ( ! array_key_exists( $key, $ordered ) ) {
                $ordered[ $key ] = $value;
            }
        }

        return $ordered;
    }

    /**
     * Human-friendly labels for response keys per endpoint.
     *
     * @param string $endpoint
     * @return array
     */
    private static function get_label_map( string $endpoint ): array {
        $common = [
            'summary'                => __( 'Summary', 'dakidarts-numerology-core' ),
            'detailed_meaning'       => __( 'Detailed Meaning', 'dakidarts-numerology-core' ),
            'meaning'                => __( 'Meaning', 'dakidarts-numerology-core' ),
            'title'                  => __( 'Title', 'dakidarts-numerology-core' ),
            'overview'               => __( 'Overview', 'dakidarts-numerology-core' ),
            'strengths'              => __( 'Strengths', 'dakidarts-numerology-core' ),
            'challenges'             => __( 'Challenges', 'dakidarts-numerology-core' ),
            'ideal_career_paths'     => __( 'Ideal Career Paths', 'dakidarts-numerology-core' ),
            'life_lesson'            => __( 'Life Lesson', 'dakidarts-numerology-core' ),
            'spiritual_growth_tip'   => __( 'Spiritual Growth Tip', 'dakidarts-numerology-core' ),
            'core_theme'             => __( 'Core Theme', 'dakidarts-numerology-core' ),
            'emotional_focus'        => __( 'Emotional Focus', 'dakidarts-numerology-core' ),
            'emotional_fulfillment'  => __( 'Emotional Fulfillment', 'dakidarts-numerology-core' ),
            'key_opportunities'      => __( 'Key Opportunities', 'dakidarts-numerology-core' ),
            'major_lessons'          => __( 'Major Lessons', 'dakidarts-numerology-core' ),
            'core_lesson'            => __( 'Core Lesson', 'dakidarts-numerology-core' ),
            'core_energy'            => __( 'Core Energy', 'dakidarts-numerology-core' ),
            'core_cravings'          => __( 'Core Cravings', 'dakidarts-numerology-core' ),
            'core_inner_strength'    => __( 'Core Inner Strength', 'dakidarts-numerology-core' ),
            'core_thinking_style'    => __( 'Core Thinking Style', 'dakidarts-numerology-core' ),
            'core_reset_mechanism'   => __( 'Core Reset Mechanism', 'dakidarts-numerology-core' ),
            'growth_guidance'        => __( 'Growth Guidance', 'dakidarts-numerology-core' ),
            'growth_advice'          => __( 'Growth Advice', 'dakidarts-numerology-core' ),
            'healing_growth_path'    => __( 'Healing Growth Path', 'dakidarts-numerology-core' ),
            'common_manifestations'  => __( 'Common Manifestations', 'dakidarts-numerology-core' ),
            'challenges_to_master'   => __( 'Challenges to Master', 'dakidarts-numerology-core' ),
            'spiritual_gift'          => __( 'Spiritual Gift', 'dakidarts-numerology-core' ),
            'spiritual_gift_once_mastered' => __( 'Spiritual Gift (Once Mastered)', 'dakidarts-numerology-core' ),
            'spiritual_gift_once_healed' => __( 'Spiritual Gift (Once Healed)', 'dakidarts-numerology-core' ),
            'core_growth_area'       => __( 'Core Growth Area', 'dakidarts-numerology-core' ),
            'healing_path'           => __( 'Healing Path', 'dakidarts-numerology-core' ),
            'affirmation'            => __( 'Affirmation', 'dakidarts-numerology-core' ),
            'mantra'                 => __( 'Mantra', 'dakidarts-numerology-core' ),
            'number'                 => __( 'Number', 'dakidarts-numerology-core' ),
            'keyword'                => __( 'Keyword', 'dakidarts-numerology-core' ),
            'note'                   => __( 'Note', 'dakidarts-numerology-core' ),
            'vibration'              => __( 'Vibration', 'dakidarts-numerology-core' ),
            'description'            => __( 'Description', 'dakidarts-numerology-core' ),
            'occurrence'             => __( 'Occurrence', 'dakidarts-numerology-core' ),
            'percentage'             => __( 'Percentage', 'dakidarts-numerology-core' ),
            'cycle'                  => __( 'Cycle', 'dakidarts-numerology-core' ),
            'first_impression'       => __( 'First Impression', 'dakidarts-numerology-core' ),
            'how_others_see_you'     => __( 'How Others See You', 'dakidarts-numerology-core' ),
            'strengths_in_perception' => __( 'Strengths in Perception', 'dakidarts-numerology-core' ),
            'potential_misinterpretations' => __( 'Potential Misinterpretations', 'dakidarts-numerology-core' ),
            'potential_shadow'       => __( 'Potential Shadow', 'dakidarts-numerology-core' ),
            'shadow_potential'       => __( 'Shadow Potential', 'dakidarts-numerology-core' ),
            'shadow_side'            => __( 'Shadow Side', 'dakidarts-numerology-core' ),
            'how_it_manifests_in_challenges' => __( 'How It Manifests in Challenges', 'dakidarts-numerology-core' ),
            'how_it_manifests_in_crisis' => __( 'How It Manifests in Crisis', 'dakidarts-numerology-core' ),
            'number_meaning'         => __( 'Number Meaning', 'dakidarts-numerology-core' ),
            'first_period'           => __( 'First Period', 'dakidarts-numerology-core' ),
            'second_period'          => __( 'Second Period', 'dakidarts-numerology-core' ),
            'third_period'           => __( 'Third Period', 'dakidarts-numerology-core' ),
            'best_actions'           => __( 'Best Actions', 'dakidarts-numerology-core' ),
            'opportunities'          => __( 'Opportunities', 'dakidarts-numerology-core' ),
            'opportunities_today'    => __( 'Opportunities Today', 'dakidarts-numerology-core' ),
            'opportunities_this_month' => __( 'Opportunities This Month', 'dakidarts-numerology-core' ),
            'watch_out'              => __( 'Watch Out', 'dakidarts-numerology-core' ),
            'ideal_daily_expressions' => __( 'Ideal Daily Expressions', 'dakidarts-numerology-core' ),
            'inner_dream_number'     => __( 'Inner Dream Number', 'dakidarts-numerology-core' ),
            'lucky_number'           => __( 'Lucky Number', 'dakidarts-numerology-core' ),
            'soul_number'            => __( 'Soul Number', 'dakidarts-numerology-core' ),
            'soul_urge_number'       => __( 'Soul Urge Number', 'dakidarts-numerology-core' ),
            'personal_day'           => __( 'Personal Day', 'dakidarts-numerology-core' ),
            'personal_month'         => __( 'Personal Month', 'dakidarts-numerology-core' ),
            'personal_year'          => __( 'Personal Year', 'dakidarts-numerology-core' ),
            'life_path'              => __( 'Life Path', 'dakidarts-numerology-core' ),
            'life_path_number'       => __( 'Life Path Number', 'dakidarts-numerology-core' ),
            'birth_day_number'       => __( 'Birth Day Number', 'dakidarts-numerology-core' ),
            'minor_personality_number' => __( 'Minor Personality Number', 'dakidarts-numerology-core' ),
            'minor_heart_desire_number' => __( 'Minor Heart Desire Number', 'dakidarts-numerology-core' ),
            'short_name'             => __( 'Short Name', 'dakidarts-numerology-core' ),
            'fullname'               => __( 'Full Name', 'dakidarts-numerology-core' ),
            'current_name'           => __( 'Current Name', 'dakidarts-numerology-core' ),
            'hidden_passions'        => __( 'Hidden Passions', 'dakidarts-numerology-core' ),
            'hidden_passion_numbers' => __( 'Hidden Passion Numbers', 'dakidarts-numerology-core' ),
            'dominant_letters'       => __( 'Dominant Letters', 'dakidarts-numerology-core' ),
            'letters_only'           => __( 'Letters Only', 'dakidarts-numerology-core' ),
            'position_sums'          => __( 'Position Sums', 'dakidarts-numerology-core' ),
            'positions_by_letter'    => __( 'Positions by Letter', 'dakidarts-numerology-core' ),
            'detailed_meanings'      => __( 'Detailed Meanings', 'dakidarts-numerology-core' ),
            'gaps'                   => __( 'Gaps', 'dakidarts-numerology-core' ),
            'hppn'                   => __( 'Hidden Passion Position Number', 'dakidarts-numerology-core' ),
            'minor_expression_number' => __( 'Minor Expression Number', 'dakidarts-numerology-core' ),
            'family_name'            => __( 'Family Name', 'dakidarts-numerology-core' ),
            'ancestral_number'       => __( 'Ancestral Number', 'dakidarts-numerology-core' ),
            'capstone_letter'        => __( 'Capstone Letter', 'dakidarts-numerology-core' ),
            'cornerstone_letter'     => __( 'Cornerstone Letter', 'dakidarts-numerology-core' ),
            'compatibility_scores'   => __( 'Compatibility Scores', 'dakidarts-numerology-core' ),
            'person_1'               => __( 'Person 1', 'dakidarts-numerology-core' ),
            'person_2'               => __( 'Person 2', 'dakidarts-numerology-core' ),
            'full_name'              => __( 'Full Name', 'dakidarts-numerology-core' ),
            'initials'               => __( 'Initials', 'dakidarts-numerology-core' ),
            'dob'                    => __( 'Date of Birth', 'dakidarts-numerology-core' ),
            'attitude_number'        => __( 'Attitude Number', 'dakidarts-numerology-core' ),
            'balance_number'         => __( 'Balance Number', 'dakidarts-numerology-core' ),
            'destiny_number'         => __( 'Destiny Number', 'dakidarts-numerology-core' ),
            'heart_desire'           => __( 'Heart Desire', 'dakidarts-numerology-core' ),
            'hidden_passion'         => __( 'Hidden Passion', 'dakidarts-numerology-core' ),
            'personality'            => __( 'Personality', 'dakidarts-numerology-core' ),
            'subconscious_self_number' => __( 'Subconscious Self Number', 'dakidarts-numerology-core' ),
            'rational_thought_number'  => __( 'Rational Thought Number', 'dakidarts-numerology-core' ),
            'attitude_number_score'  => __( 'Attitude Number Score', 'dakidarts-numerology-core' ),
            'balance_number_score'   => __( 'Balance Number Score', 'dakidarts-numerology-core' ),
            'destiny_number_score'   => __( 'Destiny Number Score', 'dakidarts-numerology-core' ),
            'heart_desire_score'     => __( 'Heart Desire Score', 'dakidarts-numerology-core' ),
            'hidden_passion_score'   => __( 'Hidden Passion Score', 'dakidarts-numerology-core' ),
            'life_path_score'        => __( 'Life Path Score', 'dakidarts-numerology-core' ),
            'personality_score'      => __( 'Personality Score', 'dakidarts-numerology-core' ),
            'rational_thought_score' => __( 'Rational Thought Score', 'dakidarts-numerology-core' ),
            'subconscious_self_score' => __( 'Subconscious Self Score', 'dakidarts-numerology-core' ),
            'overall_score'          => __( 'Overall Score', 'dakidarts-numerology-core' ),
            'overall_insight'        => __( 'Overall Insight', 'dakidarts-numerology-core' ),
            'base_meaning'           => __( 'Base Meaning', 'dakidarts-numerology-core' ),
            'base_detailed_meaning'  => __( 'Base Detailed Meaning', 'dakidarts-numerology-core' ),
            'reduced_number'         => __( 'Reduced Number', 'dakidarts-numerology-core' ),
            'sequence_type'          => __( 'Sequence Type', 'dakidarts-numerology-core' ),
            'synchronicity_meaning'  => __( 'Synchronicity Meaning', 'dakidarts-numerology-core' ),
            'date_number'            => __( 'Date Number', 'dakidarts-numerology-core' ),
            'email_number'           => __( 'Email Number', 'dakidarts-numerology-core' ),
            'is_master_number'       => __( 'Is Master Number', 'dakidarts-numerology-core' ),
            'mirror_path'            => __( 'Mirror Path', 'dakidarts-numerology-core' ),
            'mirror_path_meaning'    => __( 'Mirror Path Meaning', 'dakidarts-numerology-core' ),
            'mirror'                 => __( 'Mirror', 'dakidarts-numerology-core' ),
            'base'                   => __( 'Base', 'dakidarts-numerology-core' ),
            'reduced_base'           => __( 'Reduced Base', 'dakidarts-numerology-core' ),
            'cycle'                  => __( 'Cycle', 'dakidarts-numerology-core' ),
            'cycle_keywords'         => __( 'Cycle Keywords', 'dakidarts-numerology-core' ),
            'cycle_summary'          => __( 'Cycle Summary', 'dakidarts-numerology-core' ),
            'essence_table'          => __( 'Essence Table', 'dakidarts-numerology-core' ),
            'life_essence_number'    => __( 'Life Essence Number', 'dakidarts-numerology-core' ),
            'expression'             => __( 'Expression', 'dakidarts-numerology-core' ),
            'soul_urge'              => __( 'Soul Urge', 'dakidarts-numerology-core' ),
            'vibration_level'        => __( 'Vibration Level', 'dakidarts-numerology-core' ),
            'current_age'            => __( 'Current Age', 'dakidarts-numerology-core' ),
            'current_transits'       => __( 'Current Transits', 'dakidarts-numerology-core' ),
            'Challenge of Birth'     => __( 'Challenge of Birth', 'dakidarts-numerology-core' ),
            'Challenge of Life'      => __( 'Challenge of Life', 'dakidarts-numerology-core' ),
            'Challenge of Love'      => __( 'Challenge of Love', 'dakidarts-numerology-core' ),
            'Challenge of Death'     => __( 'Challenge of Death', 'dakidarts-numerology-core' ),
        ];

        $map = [
            'life-path' => [
                'life_path_number' => __( 'Life Path Number', 'dakidarts-numerology-core' ),
            ],
            'sun-number' => [
                'attitude_number' => __( 'Attitude Number', 'dakidarts-numerology-core' ),
            ],
            'challenge-number' => [
                'challenge_birth' => __( 'Challenge at Birth', 'dakidarts-numerology-core' ),
                'challenge_life'  => __( 'Challenge in Life', 'dakidarts-numerology-core' ),
                'challenge_love'  => __( 'Challenge in Love', 'dakidarts-numerology-core' ),
                'challenge_death' => __( 'Challenge at Death', 'dakidarts-numerology-core' ),
                'meanings'        => __( 'Meanings', 'dakidarts-numerology-core' ),
                'Challenge_number'  => __( 'Challenge Number', 'dakidarts-numerology-core' ),
                'challenge_number'  => __( 'Challenge Number', 'dakidarts-numerology-core' ),
                'Challenge_summary' => __( 'Challenge Summary', 'dakidarts-numerology-core' ),
                'challenge_summary' => __( 'Challenge Summary', 'dakidarts-numerology-core' ),
            ],
            'karmic-debt' => [
                'karmic_number'    => __( 'Karmic Debt Number', 'dakidarts-numerology-core' ),
                'life_path_number' => __( 'Life Path Number', 'dakidarts-numerology-core' ),
            ],
            'karmic-lesson' => [
                'karmic_lessons'         => __( 'Karmic Lessons', 'dakidarts-numerology-core' ),
                'karmic_lessons_summary' => __( 'Karmic Lessons Summary', 'dakidarts-numerology-core' ),
                'karmic_lesson_number'   => __( 'Karmic Lesson Number', 'dakidarts-numerology-core' ),
            ],
            'personality-number' => [
                'personality_number' => __( 'Personality Number', 'dakidarts-numerology-core' ),
            ],
            'personal-year' => [
                'personal_year_number' => __( 'Personal Year Number', 'dakidarts-numerology-core' ),
            ],
            'personal-month' => [
                'personal_month_number' => __( 'Personal Month Number', 'dakidarts-numerology-core' ),
                'birthdate'             => __( 'Birthdate', 'dakidarts-numerology-core' ),
                'target_date'           => __( 'Target Date', 'dakidarts-numerology-core' ),
                'timezone'              => __( 'Timezone', 'dakidarts-numerology-core' ),
            ],
            'personal-day' => [
                'personal_day_number' => __( 'Personal Day Number', 'dakidarts-numerology-core' ),
                'birthdate'           => __( 'Birthdate', 'dakidarts-numerology-core' ),
                'target_date'         => __( 'Target Date', 'dakidarts-numerology-core' ),
                'timezone'            => __( 'Timezone', 'dakidarts-numerology-core' ),
            ],
            'phone-number' => [
                'phone_number'              => __( 'Phone Number', 'dakidarts-numerology-core' ),
                'phone_overall_vibration'   => __( 'Overall Vibration', 'dakidarts-numerology-core' ),
                'phone_vibration_description' => __( 'Vibration Description', 'dakidarts-numerology-core' ),
                'overall_minor_numbers'     => __( 'Overall Minor Numbers', 'dakidarts-numerology-core' ),
            ],
            'soul-expression' => [
                'destiny_number' => __( 'Destiny Number', 'dakidarts-numerology-core' ),
            ],
            'soul-urge' => [
                'heart_desire_number' => __( "Heart's Desire Number", 'dakidarts-numerology-core' ),
            ],
            'subconscious-self' => [
                'subconscious_self_number' => __( 'Subconscious Self Number', 'dakidarts-numerology-core' ),
            ],
            'balance-number' => [
                'balance_number' => __( 'Balance Number', 'dakidarts-numerology-core' ),
            ],
            'lucky-numbers' => [
                'lucky_numbers' => __( 'Lucky Numbers', 'dakidarts-numerology-core' ),
            ],
            'rational-thought' => [
                'rational_thought_number' => __( 'Rational Thought Number', 'dakidarts-numerology-core' ),
            ],
            'life-period' => [
                'life_path' => __( 'Life Path', 'dakidarts-numerology-core' ),
                'periods'   => __( 'Period Cycles', 'dakidarts-numerology-core' ),
            ],
        ];

        $labels = $common;
        if ( isset( $map[ $endpoint ] ) ) {
            $labels = array_merge( $labels, $map[ $endpoint ] );
        }

        return $labels;
    }

    /**
     * Remove metadata blocks recursively.
     *
     * @param mixed $data
     * @return mixed
     */
    private static function strip_meta( $data ) {
        if ( ! is_array( $data ) ) {
            return $data;
        }

        $clean = [];
        foreach ( $data as $key => $value ) {
            if ( $key === '_api_metadata_' || $key === '_enterprise' ) {
                continue;
            }

            $clean[ $key ] = self::strip_meta( $value );
        }

        return $clean;
    }

}
