% Maintained by Matthew Bertucci, 2024-present
% Please report all issues and feature requests at https://github.com/mbertucci47/keytheorems
% This work is licensed under the LPPL version 1.3c or later: https://www.latex-project.org/lppl.txt
\ProvidesExplFile{keythms-ltx-talk-support}{\@keythms@date}{\@keythms@version}
  {keytheorems~support~for~the~ltx-talk~class}

% disable \listofkeytheorems, add warning
\msg_new:nnn { keytheorems } { beamer-listof }
  {
    \protect\listofkeytheorems\space not~supported~with~beamer
  }
\RenewDocumentCommand \listofkeytheorems { +o }
  {
    \msg_warning:nn { keytheorems } { beamer-listof }
  }

% enable overlays for theorems
\cs_new_eq:NN \__keythms_ltxtalk_orignewkeythm:nn \keythms_thm_newkeythm:nn
\cs_set_protected:Npn \keythms_thm_newkeythm:nn #1#2
  {
    \__keythms_ltxtalk_orignewkeythm:nn { #1 } { #2 }
    \NewEnvironmentCopy { keythms_ltxtalk_orig_#1 } { #1 }
    \RenewDocumentEnvironment { #1 } { d<> ={note} O{} }
      {
        \tl_if_novalue:nTF { ##1 }
          { % if on all slides, write to file for first then disable
            \int_compare:nNnT { 1 } < { \g__talk_slide_int }
              {
                \cs_set_eq:NN \__keythms_thm_addcontentsdata:nnnn \use_none:nnnn
                \cs_set_eq:NN \__keythms_thm_addstoredreverseddata:nnn \use_none:nnn
              }
          }
          {
            \begin{actionenv}<##1>
            \bool_if:NT \g__talk_slide_continue_bool
              { % prevent writing to file except on last slide for overlays
                \cs_set_eq:NN \__keythms_thm_addcontentsdata:nnnn \use_none:nnnn
                \cs_set_eq:NN \__keythms_thm_addstoredreverseddata:nnn \use_none:nnn
              }
          }
        \begin{keythms_ltxtalk_orig_#1}[##2]
      }
      {
        \end{keythms_ltxtalk_orig_#1}
        \tl_if_novalue:nF { ##1 } { \end{actionenv} }
      }
  }

% We don't want to write to the thlist file on every overlay.
% For now use ltx-talk internal boolean.
\cs_new_eq:NN \__keythms_ltxtalk_origaddcontentsdata:nnnn \__keythms_thm_addcontentsdata:nnnn
\cs_set_protected:Npn \__keythms_thm_addcontentsdata:nnnn #1#2#3#4
  {
    \bool_if:NF \g__talk_slide_continue_bool
      {
        \__keythms_ltxtalk_origaddcontentsdata:nnnn { #1 } { #2 } { #3 } { #4 }
      }
  }
\cs_new_eq:NN \__keythms_ltxtalk_origaddstoredreverseddata:nnn \__keythms_thm_addstoredreverseddata:nnn
\cs_set_protected:Npn \__keythms_thm_addstoredreverseddata:nnn #1#2#3
  {
    \bool_if:NF \g__talk_slide_continue_bool
      {
        \__keythms_ltxtalk_origaddstoredreverseddata:nnn { #1 } { #2 } { #3 }
      }
  }