<%inherit file="/template.html" />
<%namespace name="tiles_html" file="/proposal/tiles.html"/>
<%namespace name="components" file="/components.html"/>
<%namespace name="forms" file="/forms.html"/>
<%namespace name="badge_tiles" file="/badge/tiles.html"/>
<%def name="title()">${_("Edit %s") % c.proposal.title|n}</%def>

<%def name="breadcrumbs()">
    ${h.proposal.breadcrumbs(c.proposal)|n} &raquo; ${_("Edit")}
</%def>

<%block name="main_content">
<div class="form_wrapper">
    <h2>${_(u'Edit &ldquo;%s&rdquo;') % c.proposal.title|n}</h2>
    <hr />

    <form name="edit_proposal" class="inplace" method="POST" action="${h.entity_url(c.proposal, in_overlay=False)}">
        ${h.field_token()|n}
        <input type="hidden" name="_method" value="PUT" />

        <fieldset>
            <legend>${_("Amendment title") if c.proposal.is_amendment else _("Proposal title")}</legend>
            <div class="input_wrapper">
                <input type="text" class="title" name="title" autofocus value="${c.proposal.title}"
                       placeholder="${_("New amendment") if c.proposal.is_amendment else _("New proposal")}" />
            </div>
        </fieldset>

        <fieldset>
            <legend>${_("Reasoning") if c.proposal.is_amendment else _("Proposal goals")}</legend>
            <p class="info">
                %if c.proposal.is_amendment:
                ${_("Give a brief explanation of the idea behind your amendment.")}
                %else:
                ${_("Give a brief description of <b>the goals</b> of your proposal.")|n}
                %endif
            </p>
            <div class="input_wrapper">
                <textarea class="description" name="text"
                          placeholder="${_('The amendment would...') if c.proposal.is_amendment else _('The proposal would...')}">${c.proposal.description.head.text}</textarea>
                ${components.formatting()}
            </div>
        </fieldset>

        %if not h.config.get_bool('adhocracy.proposal.split_badge_edit'):
        %if can.proposal.edit_badges(c.proposal) and not c.proposal.is_amendment:
        <fieldset>
            <legend>${_("Badges")}</legend>

            %if c.badges:
            <ul class="nobullet">
                %for badge in c.badges:
                <li>
                    <label>
                        <input type="checkbox" value="${badge.id}"
                               %if badge in c.proposal.badges:
                               checked="checked"
                               %endif
                               name="badge" />
                        ${badge_tiles.badge(badge)}
                    </label>
                </li>
                %endfor
            </ul>
            %else:
            <p>${_(u"No Badges")}</p>
            %endif
        </fieldset>

        <fieldset>
            <legend>${_(u"Status Badge")}</legend>

            %if c.thumbnailbadges:
            <ul class="nobullet">
                <li>
                    <label>
                        <input type="radio" value=""
                               %if all(badge not in c.proposal.thumbnails for badge in c.thumbnailbadges):
                               checked="checked"
                               %endif
                               name="thumbnailbadge" />
                        ${_(u'No Status Badge')}
                    </label>
                </li>
                %for badge in c.thumbnailbadges:
                <li>
                    <label>
                        <input type="radio" value="${badge.id}"
                               %if badge in c.proposal.thumbnails:
                               checked="checked"
                               %endif
                               name="thumbnailbadge" />
                        ${badge_tiles.badge(badge)}
                    </label>
                </li>
                %endfor
            </ul>
            %else:
            <p>${_(u"No Status Badges")}</p>
            %endif
        </fieldset>
        %endif
        %endif

        %if not c.proposal.is_amendment:
        %if c.instance.milestones:
        <fieldset>
            <legend>${_("Relates to a milestone")}</legend>
            ${tiles.milestone.select(c.proposal.milestone)}
        </fieldset>
        %endif

        %if c.categories:
        ${components.category_select('category_select', c.toplevel_question, c.categories)}
        %endif
        %endif

        <fieldset>
            <legend>${_('Collaboration and Notification')}</legend>
            %if c.can_edit_wiki:
            <div class="input_wrapper">
                <label for="wiki">
                    <input type="checkbox" ${'checked="checked"' if c.proposal.description.head.wiki == 1 else ''} name="wiki" id="wiki" value="1" />
                    ${_("Allow modifications by other users")}
                </label>
            </div>
            %endif

            %if h.has_permission('proposal.freeze'):
            ${forms.checkbox(_(u"Freeze proposal"), 'frozen')}
            %endif

            <div class="input_wrapper">
                ${components.form_watch(c.proposal)}
            </div>
        </fieldset>

        <div class="input_wrapper submit">
            ${components.savebox(h.entity_url(c.proposal, in_overlay=False))}
        </div>
    </form>
</div>
</%block>
