\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zennote}[2023/01/10 Version 1.0.0]

\RequirePackage[most]{tcolorbox}

\newcounter{notenumber}
\setcounter{notenumber}{1}
\counterwithin{equation}{notenumber}
\counterwithin{figure}{notenumber}
\counterwithin{table}{notenumber}
\AtBeginDocument{\counterwithin{lstlisting}{notenumber}}
\ExplSyntaxOn
\keys_define:nn{titlebox}{
    top-left.tl_set:N = \l_titlebox_topleft_tl,
    top-right.tl_set:N = \l_titlebox_topright_tl,
    bottom-left.tl_set:N = \l_titlebox_bottomleft_tl,
    bottom-right.tl_set:N = \l_titlebox_bottomright_tl,
    notenumber.code:n = {\setcounter{notenumber}{#1}},
    topic.tl_set:N = \l_titlebox_topic_tl,
    type.tl_set:N = \l_titlebox_type_tl,
}

\NewDocumentCommand{\titlebox}{m}{
    \group_begin:
    \keys_set:nn{titlebox}{#1}
    \begin{center}
    \framebox{
    \vbox{\vspace{2mm}
    \hbox to .98\textwidth {\hspace*{2mm}\tl_use:N \l_titlebox_topleft_tl
    \hfill \tl_use:N \l_titlebox_topright_tl\hspace*{2mm}} 
        \vspace{4mm}
        \hbox to .98\textwidth { \large\hfill \tl_use:N \l_titlebox_type_tl{~}\thenotenumber\c_colon_str {~} \tl_use:N \l_titlebox_topic_tl  \hfill}
        \vspace{2mm}
        \hbox to .98\textwidth {\hspace*{2mm}\tl_use:N \l_titlebox_bottomleft_tl \hfill \tl_use:N \l_titlebox_bottomright_tl\hspace*{2mm}}
    \vspace{2mm}}
    }
    \end{center}
    \group_end:
}

\tl_new:N \l_noteframe_style_tl

\tl_const:Nn \c_noteframe_style_zero_tl {}
\tl_const:Nn \c_noteframe_style_one_tl {
    borderline~west={3pt}{0pt}{\l_noteframe_color_tl!85!black}
}
\tl_const:Nn \c_noteframe_style_two_tl {
    borderline~west={3pt}{0pt}{\l_noteframe_color_tl!85!black},
    borderline~east={3pt}{0pt}{\l_noteframe_color_tl!85!black}
}

\keys_define:nn{noteframe}{
    color.tl_set:N = \l_noteframe_color_tl,
    style.tl_set:N = \l_noteframe_style_tl,
    title.tl_set:N = \l_noteframe_title_tl,
}

\keys_set:nn{noteframe}{
    color = {cyan},
    style = {one},
    title = {}
}

\NewDocumentEnvironment{noteframe}{O{}+b}{
    \group_begin:

    \keys_set:nn{noteframe}{#1}
    \use:x {
    \exp_not:n{\begin{tcolorbox}}[
        enhanced,
        boxrule=0pt,
        frame~hidden,
        \exp_not:v {c_noteframe_style_ \l_noteframe_style_tl _tl},
        colback=\tl_use:N \l_noteframe_color_tl!10!white,
        sharp~corners
    ]
    \exp_not:n{
        \tl_if_empty:NTF\l_noteframe_title_tl{}{
          \textbf{\Large \textcolor{\tl_use:N \l_noteframe_color_tl!85!black}{\tl_use:N \l_noteframe_title_tl}\\\vspace*{-2mm}\\ }  
        }
    #2
    \end{tcolorbox}  
    }
    \group_end:
    } 
}{
    
}

\ExplSyntaxOff

\pagestyle{plain}

\endinput