#  /====================================================================\
# | moderncv.cls for LaTeXML                                             |
# |                                                                      |
#  >====================================================================<
# | Released to public domain.                                           |
# | Deyan Ginev <d.ginev@jacobs-university.de>                           |
# | http://dlmf.nist.gov/LaTeXML/                                        |
#  \====================================================================/
package LaTeXML::Package::Pool;

use strict;
use warnings;
use LaTeXML::Package;

LoadClass('article');

RequirePackage('calc');
RequirePackage('ifthen');
RequirePackage('url');
RequirePackage('xcolor');
RequirePackage('fancyhdr');
RequirePackage('hyperref');

RequireResource('ltx-cv.css');

RawTeX('\@add@frontmatter{ltx:creator}[role=cv]{}');
DefConstructor('\@@@address{}', "^ <ltx:contact role='address'>#1</ltx:contact>");
DefMacro('\address{}{}', '\@add@to@frontmatter{ltx:creator}{\@@@address{#1\newline #2}}');

DefMacro('\addressfont',   Tokens());
DefMacro('\addressstyle',  Tokens());
DefMacro('\addresssymbol', Tokens());

DefMacro('\cvcolumn',     Tokens());
DefMacro('\cvcolumncell', Tokens());
DefMacro('\cvdoubleitem', Tokens());
DefConstructor('\cventry{}{}{}{}{}{}',
  "<ltx:para class='ltx_cv_entry'>" .
    "<ltx:block class='ltx_cv_entry_date'>#1</ltx:block>" .
"<ltx:block class='ltx_cv_entry_content'><ltx:inline-block class='ltx_font_bold'>#2,</ltx:inline-block><ltx:inline-block> #4, #5</ltx:inline-block></ltx:block>" .
    "</ltx:para>");
DefConstructor('\cvitem{}{}',
  "<ltx:para class='ltx_cv_item'>" .
    "<ltx:block class='ltx_cv_item_label'>#1</ltx:block>" .
    "<ltx:block class='ltx_cv_item_content'>#2</ltx:block>" .
    "</ltx:para>");

DefConstructor('\@@@homepage{}', "^ <ltx:contact role='homepage'>#1</ltx:contact>");
DefMacro('\homepage{}',     '\@add@to@frontmatter{ltx:creator}{\@@@homepage{\url{#1}}}');
DefMacro('\homepagesymbol', Tokens());

DefConstructor('\@@@mobile{}', "^ <ltx:contact role='mobile'>#1</ltx:contact>");
DefMacro('\mobile{}', '\@add@to@frontmatter{ltx:creator}{\@@@mobile{#1}}');

DefConstructor('\@@cv@section{} Undigested OptionalUndigested Undigested', sub {
    my ($document, $type, $inlist, $toctitle, $title, %props) = @_;
    my $id = $props{id};
    $document->openElement("ltx:" . ToString($type),
      'xml:id' => CleanID($id),
      inlist   => ToString($inlist));
    $document->openElement('ltx:title', class => "ltx_cv");
    $document->insertElement('ltx:text', '',            class => "ltx_section_mark");
    $document->insertElement('ltx:text', $props{title}, class => "ltx_cv_heading");
    $document->closeElement('ltx:title');
    $document->insertElement('ltx:toctitle', $props{toctitle}) if $props{toctitle}; },
  properties => sub {
    my ($stomach, $type, $inlist, $toctitle, $title) = @_;
    my %props = RefStepID(ToString($type));
    $props{title} = Digest(T_CS('\@hidden@bgroup'), $title, T_CS('\@hidden@egroup'));
    $props{toctitle} = $toctitle
      && Digest(T_CS('\@hidden@bgroup'), $toctitle, T_CS('\@hidden@egroup'));
    return %props; },
  locked => 1);
Let(T_CS('\\@@numbered@section'),   T_CS('\\@@cv@section'));
Let(T_CS('\\@@unnumbered@section'), T_CS('\\@@cv@section'));

DefMacro('\closesection{}', Tokens(), locked => 1);

DefMacro('\title Semiverbatim',      '\@add@to@frontmatter{ltx:creator}{\@@@position{#1}}');
DefMacro('\email Semiverbatim',      '\@add@to@frontmatter{ltx:creator}{\@@@email{#1}}');
DefMacro('\firstname Semiverbatim',  '\@add@to@frontmatter{ltx:creator}{\@@@firstname{#1}}');
DefMacro('\familyname Semiverbatim', '\@add@to@frontmatter{ltx:creator}{\@@@familyname{#1}}');
DefMacro('\photo[]{}',               Tokens());                                               # TODO

DefConstructor('\@@@position{}',   "^ <ltx:contact role='position'>#1</ltx:contact>");
DefConstructor('\@@@email{}',      "^ <ltx:contact role='email'>#1</ltx:contact>");
DefConstructor('\@@@firstname{}',  "^ <ltx:contact role='firstname'>#1</ltx:contact>");
DefConstructor('\@@@familyname{}', "^ <ltx:contact role='familyname'>#1</ltx:contact>");

# Style-dependent, among others (TODO to flesh out the full styling framework)
DefMacro('\moderncvtheme[]{}', Tokens());
DefMacro('\moderncvcolor',     Tokens());
DefMacro('\moderncvicons',     Tokens());
DefMacro('\moderncvstyle',     Tokens());

# Classic theme depends on packages for fonts & icons, only theme supported for now:
# (partial) moderncviconsmarvosym.sty contents here:
#
# TODO: should we use them in the final HTML style? Feedback from professionals welcome.
#       for now just adding the macro support, but omitting them from the final output
DefMacro('\marvosymbol {}',    '');
DefMacro('\addresssymbol',     '');
DefMacro('\mobilephonesymbol', '📱');
DefMacro('\fixedphonesymbol',  '☎');
DefMacro('\faxphonesymbol',    '📠');
DefMacro('\emailsymbol',       '✉');
DefMacro('\homepagesymbol',    '🖰');
DefMacro('\linkedinsocialsymbol', '');  # Tikz image, needs a smart workaround (font awesome maybe?)
DefMacro('\twittersocialsymbol',  '');  # Tikz image, needs a smart workaround (font awesome maybe?)
DefMacro('\githubsocialsymbol',   '');  # Tikz image, needs a smart workaround (font awesome maybe?)

1;