<?php
defined( 'ABSPATH' ) || exit;
return;
/**
 * REEID — Normalize hreflang URLs
 * - Percent-encode path only
 * - Preserve scheme/host/query
 * - Avoid redirect hops on click
 */

if ( ! function_exists( 'reeid_normalize_hreflang_url' ) ) {
    function reeid_normalize_hreflang_url( string $url ): string {

        $parts = wp_parse_url( $url );
        if ( empty( $parts['path'] ) ) {
            return $url;
        }

        // Encode path safely (native slugs OK)
        $path = implode(
            '/',
            array_map( 'rawurlencode', explode( '/', ltrim( $parts['path'], '/' ) ) )
        );
        $path = '/' . $path;

        $out  = ( $parts['scheme'] ?? 'https' ) . '://' . ( $parts['host'] ?? '' );
        $out .= $path;

        if ( ! empty( $parts['query'] ) ) {
            $out .= '?' . $parts['query'];
        }

        return $out;
    }
}
