<?php


    if('standing_order' == $model->_meta->_doctype->identifier):
    
        $mailbody = file_get_contents(storage_path('app/email-body-standing-order.txt'));
        $mailbody = \Blade::render($mailbody, $model->prepareBladeData());
        $subject = file_get_contents(storage_path('app/email-subject-standing-order.txt'));
        $subject = \Blade::render($subject, $model->prepareBladeData());
        $filename = file_get_contents(storage_path('app/filename-standing-order.txt'));
        $filename = \Blade::render($filename, $model->prepareBladeData());
        

    elseif('reverse_invoice' == $model->_meta->_doctype->identifier):

        $mailbody = "Hier das Email-Anschreiben verfassen .. ";
        $subject = \Blade::render("Stornorechnung RG-{$model->invoice_number}", $model->prepareBladeData());
        $filename = \Blade::render("Stornorechnung RG-{$model->invoice_number}", $model->prepareBladeData());

    else:
    

        $mailbody = file_get_contents(storage_path('app/email-body-invoice.txt'));
        $mailbody = \Blade::render($mailbody, $model->prepareBladeData());
        $subject = file_get_contents(storage_path('app/email-subject-invoice.txt'));
        $subject = \Blade::render($subject, $model->prepareBladeData());
        $filename = file_get_contents(storage_path('app/filename-invoice.txt'));
        $filename = \Blade::render($filename, $model->prepareBladeData());


    endif;
?>

<form id="new_email">
    <div class="form-group">
        <input type="text" class="form-control" placeholder="Betreff, optional" name="data[subject]" value="{{$subject}}">
        <small class="form-text text-muted">
            Email-Betreff
        </small>
    </div>
    <div class="form-group">
        <textarea type="text" class="form-control" placeholder="Nachricht, optional" rows="10" name="data[message]">{{$mailbody}}</textarea>
        <small class="form-text text-muted">
            Anschreiben
        </small>
    </div>
    <div class="form-group mb-3">
         @if(1 < count($mailTo = explode(',', $model->email)))
        <select class="custom-select" placeholder="Empfänger, Pflichtfeld" name="data[recipient]">
            @foreach($mailTo AS $mail)
            <option value="{{$mail}}">{{$mail}}</option>
            @endforeach
        </select>
        @else
        <input type="text" class="form-control" placeholder="Email" name="data[recipient]" value="{{$model->email}}">
        @endif
         <small class="form-text text-muted">
            Empfänger
        </small>

    </div>

    <div class="input-group">
        <input type="text" class="form-control" placeholder="Dateiname" name="data[file_name]" value="{{$filename}}">
        <div class="input-group-append">
            <button class="btn btn-outline-secondary preview_invoice" type="button" >Vorschau</button>
        </div>

    </div>
    <small class="form-text text-muted">
            Name der PDF-Datei im Anhang
        </small>

</form>
