[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[%#
  # product: product object
  # groups:
  #   invalid   => [{ id, name, description, checked }...]
  #   mandatory => "
  #   optional  => "
  #%]

[% PROCESS group_list
    type     = "invalid"
    label    = "Groups that are not valid for the '" _ product.name _ "' product:"
    enabled  = 0
    disabled = 1
%]
[% PROCESS group_list
    type     = "mandatory"
    label    = "Mandatory '" _ product.name _ "' groups:"
    enabled  = 1
    disabled = 1
%]
[% PROCESS group_list
    type     = "optional"
    label    = "Optional '" _ product.name _ "' groups:"
    enabled  = 1
    disabled = 0
%]
<input type="hidden" name="group_verified" value="1">

[% BLOCK group_list %]
  [% RETURN UNLESS groups.$type.size %]
  [% FILTER collapse %]
    <div>
      <div>
        [% label FILTER html %]
      </div>

      [% FOREACH g = groups.$type %]
        <div>
          [% IF g.checked %]
            <input type="hidden" name="defined_groups" value="[% g.name FILTER html %]">
          [% END %]
          <input type="checkbox" value="[% g.name FILTER html %]"
            id="group_[% g.id FILTER none %]"
            [%= IF enabled %]name="groups"[% END %]
            [%= "checked" IF g.checked %]
            [%= "disabled" IF disabled %]
            [%= 'data-mandatory="1"' IF type == "mandatory" %]>
          <label for="group_[% g.id FILTER none %]" [%= IF disabled %]class="group-disabled"[% END %]>
            [% g.description FILTER html %]
          </label>
        </div>
      [% END %]
    </div>
  [% END %]
[% END %]
