<!--
  Copyright (C) 2010 Orbeon, Inc.

  This program is free software; you can redistribute it and/or modify it under the terms of the
  GNU Lesser General Public License as published by the Free Software Foundation; either version
  2.1 of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU Lesser General Public License for more details.

  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
  -->
<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:xbl="http://www.w3.org/ns/xbl"
         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

    <xbl:binding id="fr-us-state-binding" element="fr|us-state" xxbl:container="span" xxbl:mode="lhha binding value" xxbl:label-for="select1">

        <!-- Orbeon Form Builder Component Metadata -->
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder" xmlns:xf="http://www.w3.org/2002/xforms">
            <display-name lang="en">US State</display-name>
            <display-name lang="es">Estado de USA</display-name>
            <display-name lang="fi">Yhdysvaltojen osavaltio</display-name>
            <display-name lang="fr">Etat US</display-name>
            <display-name lang="ru">Штат США</display-name>
            <display-name lang="de">US-Staaten</display-name>
            <display-name lang="it">Stati membri USA</display-name>
            <display-name lang="nl">Amerikaanse staat</display-name>
            <display-name lang="pt">Estados dos EUA</display-name>
            <display-name lang="sv">Amerikansk delstat</display-name>
            <icon lang="en">
                <small-icon>/xbl/orbeon/us-state/us-flag.png</small-icon>
                <large-icon>/xbl/orbeon/us-state/us-flag.png</large-icon>
            </icon>
            <templates>
                <view>
                    <fr:us-state>
                        <xf:label ref=""/>
                        <xf:hint ref=""/>
                        <xf:help ref=""/>
                        <xf:alert ref=""/>
                    </fr:us-state>
                </view>
            </templates>
        </metadata>

        <xbl:resources>
            <xbl:style>
                .xbl-fr-us-state .xforms-select1-appearance-minimal,
                    .xbl-fr-us-state span.xforms-select1-appearance-minimal select { width: auto }
            </xbl:style>
        </xbl:resources>
        <xbl:implementation>
            <xf:model>
                <xf:instance src="oxf:/xbl/orbeon/us-state/states.xml" xxf:readonly="true" xxf:cache="true"/>
            </xf:model>
        </xbl:implementation>
        <xbl:template>
            <!-- NOTE: We copy the class so that classes like fr-width-10em apply to the select, but it's not great as
                 the class will also be on the XBL element. -->
            <xf:select1 appearance="minimal" ref="xxf:binding('fr-us-state-binding')" xbl:attr="appearance class" id="select1">
                <xf:item>
                    <xf:label/>
                    <xf:value/>
                </xf:item>
                <xf:itemset ref="instance()/state" xxbl:scope="inner">
                    <xf:label ref="@name"/>
                    <xf:value ref="@abbreviation"/>
                </xf:itemset>
            </xf:select1>
        </xbl:template>
    </xbl:binding>
</xbl:xbl>
