% Babelbidi: Bidi extensions for Babel.
%
% Copyright (C) 2026 Amer Amikhteh
%
% This file is part of the Babelbidi package.
%
% This work is free software: you may redistribute it and/or modify
% it under the terms of the LaTeX Project Public License as published
% by the LaTeX Project, either version 1.3c of the License, or
% (at your option) any later version.
%
% This work is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
% The full license text is available at:
% https://www.latex-project.org/lppl/
%
% This work is "maintained" by Amer Amikhteh.
%
% The current maintainer of this work is Amer Amikhteh.

\ProvidesFile{babelbidi-layout.def}[2026/11/01 v0.1.1 Layout fixes for Babelbidi]


\makeatletter


% ------------------------------------------
% Footnote rule
% ------------------------------------------

% Do not replace a rule selected by the user or another package.
\ifx\footnoterule\bbd@default@footnoterule
    \let\footnoterule\bbd@fn@rule@right
\fi


% ------------------------------------------
%   Tikz
% ------------------------------------------

\ifLuaTeX
    \ifbbd@beamerrl
    \else
        \AtBeginEnvironment{tikzpicture}{%
            \global\edef\bbd@tikz@saved@pardir{\the\pardir}%
            \pardir TLT
        }

        \AtEndEnvironment{tikzpicture}{%
            \pardir\bbd@tikz@saved@pardir
        }
    \fi


    % ------------------------------------------
    %   fancyhdr
    % ------------------------------------------

    \def\bbd@patch@fancyhdr{%
        \setlength{\headheight}{1.2em}%
    }

    \AddToHook{package/fancyhdr/after}{%
        \bbd@patch@fancyhdr
        \AddToHook{fancyhdr/head/begin}{\beginL}%
        \AddToHook{fancyhdr/head/end}{\endL}%
        \AddToHook{fancyhdr/foot/begin}{\beginL}%
        \AddToHook{fancyhdr/foot/end}{\endL}%
    }%
    \AddToHook{begindocument}{%
        \@ifpackageloaded{fancyhdr}{%
            \bbd@patch@fancyhdr
        }{}%
    }%
\fi


\makeatother

\endinput
