<?php

use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;

/* timesheet/layout-edit.html.twig */
class __TwigTemplate_b8f4c63c585bf815d2e10f3f42a66d5d78e5c1c804c9113b918b4f2d2696608c extends Template
{
    private $source;
    private $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'main' => [$this, 'block_main'],
        ];
    }

    protected function doGetParent(array $context)
    {
        // line 1
        return $this->loadTemplate(((twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", [], "any", false, false, false, 1), "xmlHttpRequest", [], "any", false, false, false, 1)) ? ("form.html.twig") : ("base.html.twig")), "timesheet/layout-edit.html.twig", 1);
    }

    protected function doDisplay(array $context, array $blocks = [])
    {
        $macros = $this->macros;
        // line 2
        $macros["widgets"] = $this->macros["widgets"] = $this->loadTemplate("macros/widgets.html.twig", "timesheet/layout-edit.html.twig", 2)->unwrap();
        // line 1
        $this->getParent($context)->display($context, array_merge($this->blocks, $blocks));
    }

    // line 4
    public function block_main($context, array $blocks = [])
    {
        $macros = $this->macros;
        // line 5
        echo "    ";
        if (twig_get_attribute($this->env, $this->source, ($context["timesheet"] ?? null), "exported", [], "any", false, false, false, 5)) {
            // line 6
            echo "        ";
            echo twig_call_macro($macros["widgets"], "macro_alert", ["warning", $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("timesheet.locked.warning", [], "flashmessages"), $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("warning", [], "flashmessages"), "warning"], 6, $context, $this->getSourceContext());
            echo "
    ";
        }
        // line 8
        echo "    ";
        $context["formEditTemplate"] = ((twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", [], "any", false, false, false, 8), "xmlHttpRequest", [], "any", false, false, false, 8)) ? ("default/_form_modal.html.twig") : ("default/_form.html.twig"));
        // line 9
        echo "    ";
        $context["formOptions"] = ["title" => ((twig_get_attribute($this->env, $this->source,         // line 10
($context["timesheet"] ?? null), "id", [], "any", false, false, false, 10)) ? ($this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("timesheet.edit")) : ($this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("create"))), "form" =>         // line 11
($context["form"] ?? null), "back" => $this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath(        // line 12
($context["route_back"] ?? null))];
        // line 14
        echo "    ";
        $this->loadTemplate("timesheet/layout-edit.html.twig", "timesheet/layout-edit.html.twig", 14, "1847614073")->display(twig_array_merge($context, ($context["formOptions"] ?? null)));
    }

    public function getTemplateName()
    {
        return "timesheet/layout-edit.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  70 => 14,  68 => 12,  67 => 11,  66 => 10,  64 => 9,  61 => 8,  55 => 6,  52 => 5,  48 => 4,  44 => 1,  42 => 2,  35 => 1,);
    }

    public function getSourceContext()
    {
        return new Source("", "timesheet/layout-edit.html.twig", "/var/www/html/kimai2/templates/timesheet/layout-edit.html.twig");
    }
}


/* timesheet/layout-edit.html.twig */
class __TwigTemplate_b8f4c63c585bf815d2e10f3f42a66d5d78e5c1c804c9113b918b4f2d2696608c___1847614073 extends Template
{
    private $source;
    private $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'form_body' => [$this, 'block_form_body'],
            'form_after' => [$this, 'block_form_after'],
        ];
    }

    protected function doGetParent(array $context)
    {
        return $this->loadTemplate(($context["formEditTemplate"] ?? null), "timesheet/layout-edit.html.twig", 14);
    }

    protected function doDisplay(array $context, array $blocks = [])
    {
        $macros = $this->macros;
        // line 15
        $context["length"] = 6;
        // line 16
        if (((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "begin", [], "any", true, true, false, 16) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 16)) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 16))) {
            // line 17
            $context["length"] = 5;
        } elseif (((twig_get_attribute($this->env, $this->source,         // line 18
($context["form"] ?? null), "begin", [], "any", true, true, false, 18) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 18)) &&  !twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 18))) {
            // line 19
            $context["length"] = 6;
        } elseif (((twig_get_attribute($this->env, $this->source,         // line 20
($context["form"] ?? null), "begin", [], "any", true, true, false, 20) &&  !twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 20)) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 20))) {
            // line 21
            $context["length"] = 10;
        } elseif ((( !twig_get_attribute($this->env, $this->source,         // line 22
($context["form"] ?? null), "begin", [], "any", true, true, false, 22) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 22)) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 22))) {
            // line 23
            $context["length"] = 10;
        }
        // line 14
        $this->getParent($context)->display($context, array_merge($this->blocks, $blocks));
    }

    // line 25
    public function block_form_body($context, array $blocks = [])
    {
        $macros = $this->macros;
        // line 26
        echo "            ";
        if (((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "begin", [], "any", true, true, false, 26) || twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 26)) || twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 26))) {
            // line 27
            echo "            <div class=\"row\">
                ";
            // line 28
            if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "begin", [], "any", true, true, false, 28)) {
                // line 29
                echo "                    <div class=\"col-md-";
                echo twig_escape_filter($this->env, ($context["length"] ?? null), "html", null, true);
                echo "\">
                        ";
                // line 30
                echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "begin", [], "any", false, false, false, 30), 'row');
                echo "
                    </div>
                ";
            }
            // line 33
            echo "                ";
            if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 33)) {
                // line 34
                echo "                    <div class=\"col-md-";
                echo twig_escape_filter($this->env, ($context["length"] ?? null), "html", null, true);
                echo "\">
                        ";
                // line 35
                echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", false, false, false, 35), 'row');
                echo "
                    </div>
                ";
            }
            // line 38
            echo "                ";
            if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 38)) {
                // line 39
                echo "                    <div class=\"col-md-2\">
                        ";
                // line 40
                echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", false, false, false, 40), 'row');
                echo "
                    </div>
                ";
            }
            // line 43
            echo "            </div>
            ";
        }
        // line 45
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "customer", [], "any", true, true, false, 45)) {
            // line 46
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "customer", [], "any", false, false, false, 46), 'row');
            echo "
            ";
        }
        // line 48
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "project", [], "any", true, true, false, 48)) {
            // line 49
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "project", [], "any", false, false, false, 49), 'row');
            echo "
            ";
        }
        // line 51
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "activity", [], "any", true, true, false, 51)) {
            // line 52
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "activity", [], "any", false, false, false, 52), 'row');
            echo "
            ";
        }
        // line 54
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "description", [], "any", true, true, false, 54)) {
            // line 55
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "description", [], "any", false, false, false, 55), 'row');
            echo "
            ";
        }
        // line 57
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "tags", [], "any", true, true, false, 57)) {
            // line 58
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "tags", [], "any", false, false, false, 58), 'row');
            echo "
            ";
        }
        // line 60
        echo "            ";
        if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "user", [], "any", true, true, false, 60)) {
            // line 61
            echo "                ";
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "user", [], "any", false, false, false, 61), 'row');
            echo "
            ";
        }
        // line 63
        echo "            ";
        if ((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "users", [], "any", true, true, false, 63) || twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "teams", [], "any", true, true, false, 63))) {
            // line 64
            echo "                ";
            $context["uLength"] = 12;
            // line 65
            echo "                ";
            if ((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "users", [], "any", true, true, false, 65) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "teams", [], "any", true, true, false, 65))) {
                // line 66
                echo "                    ";
                $context["uLength"] = 6;
                // line 67
                echo "                ";
            }
            // line 68
            echo "                <div class=\"row\">
                ";
            // line 69
            if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "users", [], "any", true, true, false, 69)) {
                // line 70
                echo "                    <div class=\"col-md-";
                echo twig_escape_filter($this->env, ($context["uLength"] ?? null), "html", null, true);
                echo "\">
                        ";
                // line 71
                echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "users", [], "any", false, false, false, 71), 'row');
                echo "
                    </div>
                ";
            }
            // line 74
            echo "                ";
            if (twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "teams", [], "any", true, true, false, 74)) {
                // line 75
                echo "                    <div class=\"col-md-";
                echo twig_escape_filter($this->env, ($context["uLength"] ?? null), "html", null, true);
                echo "\">
                        ";
                // line 76
                echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "teams", [], "any", false, false, false, 76), 'row');
                echo "
                    </div>
                ";
            }
            // line 79
            echo "                </div>
            ";
        }
        // line 81
        echo "            ";
        if ((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "fixedRate", [], "any", true, true, false, 81) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "hourlyRate", [], "any", true, true, false, 81))) {
            // line 82
            echo "            <div class=\"row\">
                <div class=\"col-md-6\">
                    ";
            // line 84
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "fixedRate", [], "any", false, false, false, 84), 'row');
            echo "
                </div>
                <div class=\"col-md-6\">
                    ";
            // line 87
            echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "hourlyRate", [], "any", false, false, false, 87), 'row');
            echo "
                </div>
            </div>
            ";
        }
        // line 91
        echo "            ";
        echo $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(($context["form"] ?? null), 'widget');
        echo "
        ";
    }

    // line 93
    public function block_form_after($context, array $blocks = [])
    {
        $macros = $this->macros;
        // line 94
        echo "            ";
        if (((twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "begin", [], "any", true, true, false, 94) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "end", [], "any", true, true, false, 94)) && twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "duration", [], "any", true, true, false, 94))) {
            // line 95
            echo "                ";
            $context["blockPrefix"] = twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["form"] ?? null), "vars", [], "any", false, false, false, 95), "id", [], "any", false, false, false, 95);
            // line 96
            echo "                <script type=\"text/javascript\">
                    \$('body').on('blur change', '#";
            // line 97
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_begin', function(ev) {
                        changedBegin(\$(this).val());
                    });

                    \$('body').on('blur change', '#";
            // line 101
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_end', function(ev) {
                        changedEnd(\$(this).val());
                    });

                    \$('body').on('blur change', '#";
            // line 105
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_duration', function(ev) {
                        changedDuration(\$(this).val());
                    });
                    
                    ";
            // line 116
            echo "
                    function changedBegin(value)
                    {
                        var endField = document.getElementById('";
            // line 119
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_end');
                        var durationField = document.getElementById('";
            // line 120
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_duration');
                        var format = endField.dataset.format;
                        var momentDuration = moment.duration(durationField.value);

                        var momentBegin = moment(value, format);
                        if (!momentBegin.isValid()) {
                            return;
                        }
                        
                        if (endField.value === '' && momentDuration.asSeconds() > 0) {
                            applyDateToField(endField, momentBegin, format);
                        }

                        var momentEnd = moment(endField.value, format);
                        if (!momentEnd.isValid()) {
                            return;
                        }
                        
                        if (momentEnd.isBefore(momentBegin)) {
                            applyDateToField(endField, momentBegin.add(momentDuration), format);
                        }

                        momentBegin = moment(value, format);
                        momentEnd = moment(endField.value, format);
                        
                        var durationMoment = moment.duration(momentEnd.diff(momentBegin));
                        var hours = Math.floor(durationMoment.asHours());
                        if (hours < 10) {
                            hours = '0' + hours;
                        }
                        
                        durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
                    }

                    ";
            // line 161
            echo "
                    function changedEnd(value)
                    {
                        var beginField = document.getElementById('";
            // line 164
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_begin');
                        var durationField = document.getElementById('";
            // line 165
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_duration');
                        var format = beginField.dataset.format;
                        var momentDuration = moment.duration(durationField.value);

                        var momentEnd = moment(value, format);
                        if (!momentEnd.isValid()) {
                            return;
                        }

                        if (beginField.value === '') {
                            applyDateToField(beginField, momentEnd, format);
                        }

                        var momentBegin = moment(beginField.value, format);
                        if (!momentBegin.isValid()) {
                            return;
                        }

                        if (momentEnd.isBefore(momentBegin)) {
                            applyDateToField(beginField, momentEnd.subtract(momentDuration), format);
                        }

                        momentBegin = moment(beginField.value, format);
                        momentEnd = moment(value, format);

                        var durationMoment = moment.duration(momentEnd.diff(momentBegin));
                        var hours = Math.floor(durationMoment.asHours());
                        if (hours < 10) {
                            hours = '0' + hours;
                        }
                        
                        durationField.value = hours + ':' + ('0' + durationMoment.minutes()).slice(-2);
                    }

                    ";
            // line 206
            echo "
                    function changedDuration(value)
                    {
                        var momentDuration = moment.duration(value);
                        if (!momentDuration.isValid()) {
                            return;
                        }
                        
                        var beginField = document.getElementById('";
            // line 214
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_begin');
                        var endField = document.getElementById('";
            // line 215
            echo twig_escape_filter($this->env, ($context["blockPrefix"] ?? null), "html", null, true);
            echo "_end');
                        var format = endField.dataset.format;
                        var begin = beginField.value;
                        var end = endField.value;
                        var duration = momentDuration.asSeconds();

                        if (begin === '' && end === '') {
                            applyDateToField(beginField, moment(), format);
                            applyDateToField(endField, moment(beginField.value, format).add(duration, 'seconds'), format); 
                        } else if (begin === '' && end !== '') {
                            applyDateToField(beginField, moment(end, format).subtract(duration, 'seconds'), format);
                        } else if (begin !== '' && duration > 0) {
                            applyDateToField(endField, moment(beginField.value, format).add(duration, 'seconds'), format); 
                        }
                    }
                    
                    function applyDateToField(field, momentObj, format)
                    {
                        field.value = momentObj.format(format);
                        if (jQuery(field).data('daterangepicker') !== undefined) {
                            jQuery(field).data('daterangepicker').setStartDate(momentObj);
                            jQuery(field).data('daterangepicker').setEndDate(momentObj);
                        }
                    }
                </script>
            ";
        }
        // line 241
        echo "        ";
    }

    public function getTemplateName()
    {
        return "timesheet/layout-edit.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  498 => 241,  469 => 215,  465 => 214,  455 => 206,  418 => 165,  414 => 164,  409 => 161,  372 => 120,  368 => 119,  363 => 116,  356 => 105,  349 => 101,  342 => 97,  339 => 96,  336 => 95,  333 => 94,  329 => 93,  322 => 91,  315 => 87,  309 => 84,  305 => 82,  302 => 81,  298 => 79,  292 => 76,  287 => 75,  284 => 74,  278 => 71,  273 => 70,  271 => 69,  268 => 68,  265 => 67,  262 => 66,  259 => 65,  256 => 64,  253 => 63,  247 => 61,  244 => 60,  238 => 58,  235 => 57,  229 => 55,  226 => 54,  220 => 52,  217 => 51,  211 => 49,  208 => 48,  202 => 46,  199 => 45,  195 => 43,  189 => 40,  186 => 39,  183 => 38,  177 => 35,  172 => 34,  169 => 33,  163 => 30,  158 => 29,  156 => 28,  153 => 27,  150 => 26,  146 => 25,  142 => 14,  139 => 23,  137 => 22,  135 => 21,  133 => 20,  131 => 19,  129 => 18,  127 => 17,  125 => 16,  123 => 15,  70 => 14,  68 => 12,  67 => 11,  66 => 10,  64 => 9,  61 => 8,  55 => 6,  52 => 5,  48 => 4,  44 => 1,  42 => 2,  35 => 1,);
    }

    public function getSourceContext()
    {
        return new Source("", "timesheet/layout-edit.html.twig", "/var/www/html/kimai2/templates/timesheet/layout-edit.html.twig");
    }
}
