<div ng-controller="Umbraco.Overlays.PublishDescendantsController as vm" class="umb-variant-selector-overlay">

    <div ng-if="vm.displayVariants.length === 1">
        <div class="mb3">
            <p><localize key="{{vm.labels.help.key}}" tokens="vm.labels.help.tokens"></localize></p>
        </div>

        <div class="flex mb3">
            <umb-toggle checked="vm.includeUnpublished"
                        on-click="vm.toggleIncludeUnpublished()"
                        class="mr2"
                        input-id="includeUnpublished"
                        label-on="{{vm.labels.includeUnpublished}}"
                        label-off="{{vm.labels.includeUnpublished}}"
                        label-position="right"
                        show-labels="true">
            </umb-toggle>
        </div>

    </div>

    <div ng-if="vm.displayVariants.length > 1">

        <div class="mb3">
            <p><localize key="content_publishDescendantsWithVariantsHelp">Publish variants and variants of same type underneath and thereby making their content publicly available.</localize></p>
        </div>

        <div class="flex mb3">
            <umb-toggle checked="vm.includeUnpublished"
                        on-click="vm.toggleIncludeUnpublished()"
                        class="mr2"
                        label-on="{{vm.labels.includeUnpublished}}"
                        label-off="{{vm.labels.includeUnpublished}}"
                        label-position="right"
                        show-labels="true">
            </umb-toggle>
        </div>

        <div class="umb-list umb-list--condensed">

            <div class="umb-list-item umb-list--condensed" ng-repeat="variant in vm.displayVariants track by variant.compositeId">
                <ng-form name="publishVariantSelectorForm">
                    <div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': publishVariantSelectorForm.publishVariantSelector.$invalid}">

                        <umb-checkbox input-id="{{variant.htmlId}}"
                                      name="publishVariantSelector"
                                      model="variant.publish"
                                      on-change="vm.changeSelection(variant)"
                            server-validation-field="{{variant.htmlId}}">

                            <span class="umb-variant-selector-entry__title" ng-if="!(variant.segment && variant.language)">
                                <span ng-bind="variant.displayName"></span>
                                <strong ng-if="variant.isMandatory" class="umb-control-required">*</strong>
                            </span>
                            <span class="umb-variant-selector-entry__title" ng-if="variant.segment && variant.language">
                                <span ng-bind="variant.segment"></span>
                                <span class="__secondarytitle"> — {{variant.language.name}}</span>
                                <strong ng-if="variant.isMandatory" class="umb-control-required">*</strong>
                            </span>
                            <span class="umb-variant-selector-entry__description" ng-if="!publishVariantSelectorForm.publishVariantSelector.$invalid && !(variant.notifications && variant.notifications.length > 0)">
                                <umb-variant-state variant="variant"></umb-variant-state>
                                <span ng-if="variant.isMandatory"> - </span>
                                <span ng-if="variant.isMandatory" ng-class="{'text-error': (variant.publish === false) }"><localize key="general_mandatory">Mandatory</localize></span>
                            </span>
                            <span class="umb-variant-selector-entry__description" ng-messages="publishVariantSelectorForm.publishVariantSelector.$error" show-validation-on-submit>
                                <span class="text-error" ng-message="valServerField">{{publishVariantSelectorForm.publishVariantSelector.errorMsg}}</span>
                            </span>

                        </umb-checkbox>

                        <umb-variant-notification-list notifications="variant.notifications"></umb-variant-notification-list>
                    </div>
                </ng-form>
            </div>
        </div>

    </div>

</div>
