%<*package>

\tl_new:N \l_@@_block_arga_tl
\tl_new:N \l_@@_block_argb_tl

% [parameter] block type name (only letters) , block's label (expanded) , block's display name , block's parameter , block's content
\cs_new_protected:Nn \_@@_set_block:nnnnn {

    \seq_if_in:NnTF \g_@@_block_seq {#2} {
        \msg_warning:nnn {SimpleSystemTeX} {Block Occupied} {#2}
    } {
        \phantomsection \label{#2}
        \seq_gput_right:Nn \g_@@_block_seq {#2}
        \iow_now:Nn \@auxout {
            \Register@block {#2}
        }
    }

    \iow_now:Ne \@auxout {
        \exp_not:n {\Register@blocktype {#2} {#1}} \iow_newline:
        \exp_not:n {\Register@blockname {#2} {#3}} \iow_newline:
        \exp_not:n {\Register@blockparameter {#2} {#4}} \iow_newline:
        \exp_not:n {\Register@blockcontent {#2} {#5}} \iow_newline:
        \exp_not:n {\Register@blocksectionpath {#2}} {\exp_not:V \l_@@_sectionpath_tl}
    }

}
\cs_generate_variant:Nn \_@@_set_block:nnnnn {neVVn}

% [parameter] block type name (only letters) , block's label (expanded) , block's display name , block's parameter , block's content
\cs_new_protected:Nn \_@@_print_block:nnnnn {
    \group_begin:

    % @block
    \tl_set:Nn \l_@@_block_tl {#2}
    % @blockname
    \tl_set:Nn \l_@@_blockname_tl {#3}
    % @blockparameter
    \tl_set:Nn \l_@@_blockparameter_tl {#4}
    % @blockcontent
    \tl_set:Nn \l_@@_blockcontent_tl {#5}
    \int_compare:nT {\g_@@_Automatic_List_beta_int == 1} {
        \_@@_trans_auto_list:N \l_@@_blockcontent_tl
    }

    \tl_use:c {g_@@_#1_style_tl}

    \group_end:
}
\cs_generate_variant:Nn \_@@_print_block:nnnnn {neVVn}
\cs_generate_variant:Nn \_@@_print_block:nnnnn {nnVVn}

% [parameter] block type name (only letters)
\cs_new_protected:Nn \_@@_declare_anonymous_block_type:n {

    \exp_args:Nc \NewDocumentCommand {#1} {d() d<> +m} {
        \group_begin:

        \IfValueT {##1} {
            \tl_set:Nn \l_@@_block_arga_tl {##1}
        }
        \IfValueT {##2} {
            \tl_set:Nn \l_@@_block_argb_tl {##2}
        }

        \_@@_print_block:nnVVn {#1} {} \l_@@_block_arga_tl \l_@@_block_argb_tl {##3}

        \group_end:
    }

}

% [parameter] block type name (only letters)
\cs_new_protected:Nn \_@@_declare_block_type:n {

    \exp_args:Nc \NewDocumentCommand {#1} {s m d() d<> +m} {
        \group_begin:

        \IfValueTF {##3} {
            \tl_set:Nn \l_@@_block_arga_tl {##3}
        } {
            \tl_set:Nn \l_@@_block_arga_tl {##2}
        }
        \IfValueT {##4} {
            \tl_set:Nn \l_@@_block_argb_tl {##4}
        }

        \IfBooleanF {##1} {
            \_@@_set_block:neVVn {#1} {##2} \l_@@_block_arga_tl \l_@@_block_argb_tl {##5}
        }

        \_@@_print_block:neVVn {#1} {##2} \l_@@_block_arga_tl \l_@@_block_argb_tl {##5}

        \group_end:
    }

}

%</package>