
<div class="container">
    <div class="form-group row">
        <label for="supplierName" class="col-sm-2 col-form-label">Név:</label>
        <div class="col-sm-10">
            <input readonly type="text" class="form-control" id="supplierName"
                   placeholder="Írja be a nevét" name="name" required
                   data-required="true"
                   value="{{$supplierData['name']}}"
            >
        </div>
    </div>
    <div class="form-group row">
        <label for="supplierProductGroups" class="col-sm-2 col-form-label">Termék kategóriák:</label>
        <div class="col-sm-10">
            <select class="productCategorySelect" name="productGroup"  multiple="multiple" style="width: 100%" >
                <optgroup label="Food">
                    @foreach($supplierData['product_group'] as $groupData)
                        @if($groupData['type']=='F' )
                            <option value="{{$groupData['name']}}" selected="selected">{{$groupData['name']}}</option>
                        @endif
                    @endforeach
                </optgroup>
                <optgroup label="Non Food">
                    @foreach($supplierData['product_group'] as $groupData)
{{--
                        @if($groupData['type']=='N' && $groupData['depth']==2)
--}}
                        @if($groupData['type']=='N' )
                            <option selected="selected" value="{{$groupData['name']}}" >{{$groupData['name']}}</option>
                        @endif
                    @endforeach
                </optgroup>

            </select>
        </div>
    </div>
    <div class="form-group row">
        <label for="supplierService" class="col-sm-2 col-form-label">Szolgáltatások:</label>
        <div class="col-sm-10">
            <select class="serviceSelect" name="service"  multiple="multiple" style="width: 100%" >
                    @foreach($supplierData['service'] as $serviceData)
                            <option selected="selected" value="{{$serviceData['name']}}" >{{$serviceData['name']}}</option>
                    @endforeach
            </select>
        </div>
    </div>
    <div class="form-group row">
        <label for="supplierContacts" class="col-sm-2 col-form-label">Kapcsolattartók:</label>
        <div class="col-sm-10">
            <div class="form-group row">
                <div class="col">
                    <table class="table table-striped table-hover table-sm contactTable">
                        <thead>
                        <tr>
                            <th scope="col">#</th>
                            <th scope="col">Név</th>
                            <th scope="col">Email</th>
                            <th scope="col">Telefon</th>
                            <th scope="col">Megjegyzés</th>
                        </tr>
                        </thead>
                        <tbody>

                        <template data-name="supplierContactTableRow">
                            <tr>
                                <th scope="row">[[rowNum]]
                                </th>
                                <td>[[name]]</td>
                                <td>[[email]]</td>
                                <td>[[phone]]</td>
                                <td>[[note]]</td>
                            </tr>
                        </template>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>


    <div class="form-group row">
        <label for="openHours" class="col-sm-2 col-form-label">Nyitva tartási idő:</label>
        <div class="col-sm-10">
            <textarea
                name="openHours" type="text"
                class="form-control" id="openHours" rows="3"
                readonly
            >{{$supplierData['openHours']}}</textarea>
        </div>
    </div>

    <div class="form-group row">
        <label for="ordersDeadline" class="col-sm-2 col-form-label">Megrendelések leadási határideje:</label>
        <div class="col-sm-10">
            <textarea
                name="ordersDeadline" type="text"
                class="form-control" id="ordersDeadline" rows="3"
                readonly
            >{{$supplierData['ordersDeadline']}}</textarea>
        </div>
    </div>

    <div class="form-group row">
        <label for="minOrderValue" class="col-sm-2 col-form-label">Minimum rendelési érték:</label>
        <div class="col-sm-10">

            <textarea
                name="minOrderValue" type="text"
                class="form-control" id="minOrderValue" rows="3"
                readonly
            >{{$supplierData['minOrderValue']}}"
            </textarea>
        </div>
    </div>
    <div class="form-group row">
        <label for="note" class="col-sm-2 col-form-label">Megjegyzés:</label>
        <div class="col-sm-10">
            <textarea
                name="note" type="text"
                class="form-control" id="note" rows="3"
                readonly
            >
{{$supplierData['note']}}
            </textarea>
        </div>
    </div>

    <div class="form-group row">
        <label for="supplierFiles" class="col-sm-2 col-form-label">Fájlok:</label>
        <div class="col-sm-10">
            <div class="form-group row">
                <div class="col">
                    <table class="table table-striped table-hover table-sm">
                        <thead>
                        <tr>
                            <th scope="col" style="width:40px">#</th>
                            <th scope="col">Név</th>
                            <th scope="col" style="width:160px">Dátum</th>
                            <th scope="col">fájl</th>
                        </tr>
                        </thead>
                        <tbody>
                        @php
                        $filesRowNum=1;
                        @endphp
                        @isset($files['priceList'])
                            <tr>
                                <th scope="row">{{$filesRowNum}}
                                </th>
                                <td>Árlista: {{$files['priceList']['attachment']['original_filename']}}</td>
                                <td>{{$files['priceList']['available']}}</td>
                                <td><a target="_blank" href="{{$files['priceList']['attachment']['PublicUrl']}}/{{$files['priceList']['attachment']['filename']}}"
                                       download="{{$files['priceList']['attachment']['original_filename']}}">Letöltés</a>
                                </td>
                            </tr>
                            @php
                                $filesRowNum++;
                                unset($files['priceList'])
                            @endphp
                        @endisset
                        @foreach($attachment as $attachmentData)
                            <tr>
                                <th scope="row">{{$filesRowNum}}
                                </th>
                                <td>{{$attachmentData['original_filename']}}</td>
                                <td>{{\Carbon\Carbon::parse($attachmentData['created_at'])->toDateTimeString()}}</td>
                                <td><a target="_blank" href="{{$attachmentData['PublicUrl']}}/{{$attachmentData['filename']}}"
                                       download="{{$attachmentData['original_filename']}}">Letöltés</a>
                                </td>
                            </tr>
                            @php
                                $filesRowNum++;

                            @endphp
                        @endforeach

                            <tr class="d-none">
                                <th scope="row">[[rowNum]]
                                </th>
                                <td>[[name]]</td>
                                <td>[[date]]</td>
                                <td>[[link]]</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>

<script>
    @isset($supplierData)
    console.log('most kell feldolgozn az adatokat, es beallitani az app supplierst');
    console.log({!! json_encode($supplierData) !!});
    APP.Supplier=new Supplier({!! json_encode($supplierData) !!});
    @endisset

</script>
