<settings-menu></settings-menu>

<wiki [url]="'https://github.com/tidusjar/Ombi/wiki/Newsletter-Settings'"></wiki>
<div *ngIf="settings">
    <fieldset>
        <legend>Newsletter</legend>
        <div class="col-md-6">
                <div class="form-group">
                    <div class="checkbox">
                        <input type="checkbox" id="enabled" [(ngModel)]="settings.enabled" ng-checked="settings.enabled"><label for="enabled">Enable</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <input type="checkbox" id="disableTv" [(ngModel)]="settings.disableTv" ng-checked="settings.disableTv"><label for="disableTv">Disable TV</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <input type="checkbox" id="disableMovies" [(ngModel)]="settings.disableMovies" ng-checked="settings.disableMovies"><label for="disableMovies">Disable Movies</label>
                    </div>
                </div>
                 <div class="form-group">
                    <label class="control-label">Subject</label>
                    <div>
                        <input type="text" class="form-control form-control-custom" [(ngModel)]="settings.notificationTemplate.subject" value="{{settings.notificationTemplate.subject}}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">Message</label>
                    <div>
                        <textarea type="text" class="form-control form-control-custom" [(ngModel)]="settings.notificationTemplate.message" value="{{settings.notificationTemplate.message}}"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div>
                        <button type="submit" id="save" (click)="onSubmit()" class="btn btn-primary-outline">Submit</button>
                        <button type="button" (click)="test()" class="btn btn-danger-outline">Test</button>
                        <button type="button" (click)="updateDatabase()" class="btn btn-info-outline" tooltipPosition="top" pTooltip="I recommend running this with a fresh Ombi install, this will set all the current *found* content to have been sent via Newsletter, 
                        if you do not do this then everything that Ombi has found in your libraries will go out on the first email!">Update Database</button>
                        
                        <button type="button" (click)="trigger()" class="btn btn-danger-outline">Trigger now</button>
                    </div>
                                 </div>
        </div>


        <div class="col-md-6">
            <small>NOTE: Please see the tooltip on the Update Database button - Please see the wiki for more information</small>
            <br/>
            <br/>
            <small>When testing, the test newsletter will go to all users that have the Admin role, please ensure that there are valid email addresses for this. The test will also only grab the latest 10 movies and 10 shows just to give you an example.</small>

            <br/>
            <br/>
            <div class="form-group row">
                <div class="col-md-12">
                    <label for="emailToAdd" class="control-label">Add External Email (For users that are not in Ombi)</label>
                </div>
                <div class="col-md-9">
                    <input type="text" [(ngModel)]="emailToAdd" class="form-control form-control-custom " id="emailToAdd" 
                    email name="emailToAdd" value="{{emailToAdd}}">
                </div>
                <div class="col-md-3">
                    <button class="btn btn-primary-outline" (click)="addEmail()" pTooltip="Don't forget to press the Submit button!">Add</button>
                </div>
            </div>

            <div class="row">
                <div *ngFor="let email of settings.externalEmails">
                    <div class="col-md-9">
                        {{email}}
                    </div>
                    <div class="col-md-3">
                        <button class="btn btn-sm btn-danger-outline" (click)="deleteEmail(email)">Delete</button>
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
</div>