<tal:schedules
     tal:define="
       schedule view/schedule_data;
     "
     i18n:domain="ploneintranet"
>
  <tal:repeat repeat="day view/days">

    <strong class="day-title"><span tal:omit-tag=""
            i18n:translate=""
      >Day</span>
      ${repeat/day/number}
    </strong>
    <div class="scheduler ${view/view_mode} pat-checklist free-form"
         id="scheduler-${day}"
    >
      <div class="scheduler-hours">
        <tal:hour repeat="hour view/hour_strings">
          <span class="hour"
                id="${day}-hour-${hour}"
          >${hour}:00</span>
        </tal:hour>
      </div>

      <tal:spaces repeat="space view/spaces">
        <div class="scheduler-space"
             id="scheduler-${day}-space-${space_id}"
             tal:define="
               space_id python:view.normalize(space);
             "
        >
          <span class="space-title">${space}
            <a class="pat-inject icon-plus-circle iconified"
               href="${here/absolute_url}/@@add_talk?injection_target=scheduler-${day}-space-${space_id}&amp;space=${space_id}#document-content"
               title="Add a session"
               data-pat-inject="source: #scheduler-item::element; target: #scheduler-${day}-space-${space_id}::after"
               tal:condition="python:view.view_mode == 'mode-edit'"
               i18n:attributes="title"
               i18n:translate=""
            >Add session</a>
          </span>

          <tal:talks repeat="talk python:schedule[day][space]">
            <div class="scheduler-item state-collapsed documents-panel-closed discrete-injection"
                 id="scheduler-${day}-space-${space_id}-item-${repeat/talk/number}"
                 style="${python: view.get_talk_style(talk)}"
                 tal:define="
                   is_attending python:view.is_attending(talk);
                 "
            >
              <p class="pat-depends scheduler-join-marker ${python:'visible' if is_attending else ''}"
                 data-pat-depends="scheduler-${day}-space-${space_id}-item-${repeat/talk/number}-join"
              >
                <strong>Joining.</strong>
              </p>
              <div class="scheduler-item-content pat-subform pat-inject"
                   data-pat-inject="source: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}::element; target: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}::element"
              >

                <fieldset class="vertical edit-form"
                          tal:condition="python:view.view_mode == 'mode-edit'"
                >
                  <label>
                    <tal:i18n i18n:translate="">Title</tal:i18n>
                    <input name="session-title-${day}-space-${space_id}-item-${repeat/talk/number}"
                           type="text"
                           value="${talk/title}"
                    />
                  </label>
                  <label>
                    <tal:i18n i18n:translate="">Description</tal:i18n>
                    <textarea name="session-description-${day}-space-${space_id}-item-${repeat/talk/number}"
                              rows="5"
                    >${talk/description}</textarea>
                  </label>
                  <fieldset class="row group">
                    <label class="six columns">
                      <tal:i18n i18n:translate="">Start time</tal:i18n>
                      <input class="time"
                             name="start-time-${day}-space-${space_id}-item-${repeat/talk/number}"
                             placeholder="Time"
                             size="10"
                             type="time"
                             value="${python:talk.start.strftime('%H:%M')}"
                             i18n:attributes="placeholder"
                      />
                    </label>
                    <label class="six columns">
                      <tal:i18n i18n:translate="">End time</tal:i18n>
                      <input class="time"
                             name="end-time-${day}-space-${space_id}-item-${repeat/talk/number}"
                             placeholder="Time"
                             size="10"
                             type="time"
                             value="${python:talk.end.strftime('%H:%M')}"
                             i18n:attributes="placeholder"
                      />
                    </label>
                  </fieldset>
                </fieldset>

                <span class="session-title pat-switch"
                      data-pat-switch="selector: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}; remove: state-collapsed; add: state-expanded"
                >
                  ${talk/title}
                </span>

                <p class="session-description">
                  ${talk/description}
                </p>

                <fieldset class="button-bar">
                  <label class="small pat-button toggle-attendance pat-autosubmit pat-subform pat-inject pat-switch"
                         data-pat-inject="source: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}; target: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}"
                         data-pat-switch="selector: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}; remove: state-expanded; add: state-collapsed"
                  >
                    <input id="scheduler-${day}-space-${space_id}-item-${repeat/talk/number}-join"
                           name="scheduler-${day}-space-${space_id}-item-${repeat/talk/number}-join"
                           type="checkbox"
                           tal:attributes="
                             checked python:'checked' if is_attending else '';
                           "
                    />
                    <input name="${python:'dont-' if is_attending else ''}attend"
                           type="hidden"
                           value="${talk/UID}"
                    />
                    <span class="join"
                          i18n:translate=""
                    >Join</span>
                    <span class="dont-join"
                          i18n:translate=""
                    >Don't join</span>
                  </label>
                  <tal:mode condition="python:view.view_mode == 'mode-edit'">
                    <button class="pat-button close"
                            type="submit"
                            i18n:translate=""
                    >
                      Save &amp; close
                    </button>
                    <button class="pat-button delete icon-trash no-label pat-inject"
                            type="submit"
                            data-pat-inject="source: #scheduler-${day}-space-${space_id}; target: #scheduler-${day}-space-${space_id}"
                            i18n:translate=""
                    >
                      Delete
                    </button>
                  </tal:mode>
                  <tal:mode condition="python:view.view_mode != 'mode-edit'">
                    <button class="pat-button close pat-switch pat-inject"
                            type="button"
                            data-pat-switch="selector: #scheduler-${day}-space-${space_id}-item-${repeat/talk/number}; remove: state-expanded; add: state-collapsed"
                            i18n:translate=""
                    >
                      Close
                    </button>
                  </tal:mode>
                </fieldset>
              </div>
            </div>
          </tal:talks>
        </div>
      </tal:spaces>
    </div>
    <a class="pat-scroll"
       hidden
       href="#${day}-hour-${first_talk_hour}"
       data-pat-scroll="selector: #${day}-hour-${first_talk_hour}; trigger: auto"
       tal:define="
         first_talk_hour python:view.first_talk_hours.get(day, '10');
       "
       i18n:translate=""
    >Jump to first session.</a>
  </tal:repeat>
</tal:schedules>
