@**
 * Generate an HTML select.
 *
 * Example:
 * {{{
 * @select(
 *   field = myForm("mySelect"),
 *   options = Seq(
 *     "Foo" -> "foo text",
 *     "Bar" -> "bar text",
 *     "Baz" -> "baz text"
 *    ),
 *   Symbol("_default") -> "Choose One",
 *   Symbol("_disabled") -> Seq("FooKey", "BazKey")
 *   Symbol("cust_att_name") -> "cust_att_value"
 * )
 * }}}
 *
 * @param field The form field.
 * @param options Sequence of options as pairs of value and HTML.
 * @param args Set of extra attributes.
 * @param handler The field constructor.
 *@
@(field: play.api.data.Field, options: Seq[(String,String)], args: (Symbol,Any)*)(implicit handler: FieldConstructor, messages: play.api.i18n.MessagesProvider)
@input(field, args:_*) { (id, name, value, htmlArgs) =>
    @defining( if( htmlArgs.contains(Symbol("multiple")) ) "%s[]".format(name) else name ) { selectName =>
    @defining( field.indexes.nonEmpty && htmlArgs.contains(Symbol("multiple")) match {
            case true => field.indexes.map( i => field("[%s]".format(i)).value ).flatten.toSet
            case _ => field.value.toSet
    }){ selectedValues =>
        <select id="@id" name="@selectName" @toHtmlArgs(htmlArgs)>
            @args.toMap.get(Symbol("_default")).map { defaultValue =>
                <option class="blank" value="">@translate(defaultValue)</option>
            }
            @options.map { case (k, v) =>
                @defining( selectedValues.contains(k) ) { selected =>
                @defining( args.toMap.get(Symbol("_disabled")).exists { case s: Seq[_] => s.asInstanceOf[Seq[String]].contains(k) }){ disabled =>
                <option value="@k"@if(selected){ selected="selected"}@if(disabled){ disabled}>@v</option>
            }}}
        </select>
    }}
}
