@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>SMS 전송 내역</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.sms.history.index') }}">
        <table class="table table-bordered">
            <colgroup>
                <col width="15%" />
                <col width="*" />
            </colgroup>
            <tbody>
                <tr>
                    <th>검색</th>
                    <td>
                        <div class="row g-2">
                            <div class="col-auto">
                                <select name="field" id="field" class="form-select">
                                    <option value="tb_sms_history.tel" @if($params->field == 'tb_sms_history.tel') selected @endif>연락처</option>
                                    <option value="tb_sms_history.subject" @if($params->field == 'tb_sms_history.subject') selected @endif>제목</option>
                                    <option value="tb_sms_history.content" @if($params->field == 'tb_sms_history.content') selected @endif>내용</option>
                                    <option value="users.id" @if($params->field == 'users.id') selected @endif>회원 PK</option>
                                    <option value="users.sid" @if($params->field == 'users.sid') selected @endif>회원 ID</option>
                                    <option value="users.name" @if($params->field == 'users.name') selected @endif>회원 이름</option>
                                    <option value="users.nickname" @if($params->field == 'users.nickname') selected @endif>회원 닉네임</option>
                                    <option value="users.email" @if($params->field == 'users.email') selected @endif>회원 이메일</option>
                                    <option value="users.created_at" @if($params->field == 'users.created_at') selected @endif>회원가입 일시</option>
                                    <option value="users.last_login_at" @if($params->field == 'users.last_login_at') selected @endif>로그인 일시</option>
                                </select>
                            </div>
                            <div class="col">
                                <input type="text" name="keyword" id="keyword" class="form-control" value="{{ $params->keyword }}" placeholder="검색어를 입력하세요." />
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>전송일시</th>
                    <td>
                        <div class="row g-2">
                            <div class="col-auto">
                                <input type="text" name="start_date" id="startDate" class="form-control date-picker s-start-date" value="{{ $params->startDate }}" />
                            </div>
                            <div class="col-auto align-self-center">
                                ~
                            </div>
                            <div class="col-auto">
                                <input type="text" name="end_date" id="endDate" class="form-control date-picker s-end-date" value="{{ $params->endDate }}" />
                            </div>
                            <div class="col-sm">
                                <div class="btn-group">
                                    <button type="button" onclick="setDateRange();" class="btn btn-secondary">오늘</button>
                                    <button type="button" onclick="setDateRange('1d');" class="btn btn-secondary">어제</button>
                                    <button type="button" onclick="setDateRange('7d');" class="btn btn-secondary">1주일</button>
                                    <button type="button" onclick="setDateRange('15d');" class="btn btn-secondary">15일</button>
                                    <button type="button" onclick="setDateRange('1m');" class="btn btn-secondary">1개월</button>
                                    <button type="button" onclick="setDateRange('2m');" class="btn btn-secondary">2개월</button>
                                    <button type="button" onclick="setDateRange('3m');" class="btn btn-secondary">3개월</button>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <div class="text-center">
            <button type="submit" class="btn btn-dark">검색</button>
        </div>
    </form>
    <br/>

    <div class="row mb-2">
        <div class="col align-self-center">
            <label>전체 : {{ $smsHistoryData->total }} / {{ $smsHistoryData->rows }}</label>
        </div>
        <div class="col text-end">
            <button type="button" class="btn btn-outline-dark btn-list-delete btn-list-selected disabled" data-list-delete-url="/admin/sms/history/destroy">선택삭제</button>
        </div>
    </div>

    <form name="f_admin_list" id="fAdminList" method="post">
        @csrf
        <div class="table-responsive">
            <table class="table table-hover table-bordered table-nowrap">
                <colgroup>
                    <col width="1%"/>
                    <col width="4%"/>
                    <col width="10%"/>
                    <col width="10%"/>
                    <col width="10%"/>
                    <col width="*"/>
                    <col width="4%"/>
                    <col width="8%"/>
                    <col width="4%"/>
                    <col width="5%"/>
                    <col width="10%"/>
                </colgroup>
                <thead>
                    <tr>
                        <th><input type="checkbox" name="chk_all" id="chkAll" class="form-check-input" value="1"/></th>
                        <th>PK</th>
                        <th>연락처</th>
                        <th>수신자</th>
                        <th>제목</th>
                        <th>내용</th>
                        <th>예약여부</th>
                        <th>예약일시</th>
                        <th>상태</th>
                        <th>결과</th>
                        <th>전송일시</th>
                    </tr>
                </thead>
                <tbody>
                    @if($smsHistoryData->rows > 0)
                        @foreach($smsHistoryData->list as $row)
                        <tr>
                            <td>
                                <input type="checkbox" name="chk[]" id="chk_{{ $row->id }}" class="form-check-input list-check-box" value="{{ $row->id }}" />
                            </td>
                            <td>{{ $row->id }}</td>
                            <td>{{ $row->tel }}</td>
                            <td>
                                @if($row->name)
                                    {{ $row->name . ' (' . $row->sid . ')' }}
                                @else
                                    -
                                @endif
                            </td>
                            <td>{{ $row->subject ?: '-' }}</td>
                            <td>{{ $row->content }}</td>
                            <td>{{ $row->isReserveStr }}</td>
                            <td>{!! $row->reserveAt !!}</td>
                            <td>{{ $row->code ?: '-' }}</td>
                            <td>
                                <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#detailResultModal">
                                    보기
                                </button>
                                <div class="modal fade" id="detailResultModal" tabindex="-1" aria-labelledby="detailResultModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header bg-dark text-white">
                                                <h5 class="modal-title" id="detailResultModalLabel">처리 결과</h5>
                                                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
                                            </div>
                                            <div class="modal-body text-start">
                                                {!! stripslashes($row->message) !!}
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary m-auto" data-bs-dismiss="modal">닫기</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td>{!! $row->createdAt !!}</td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="11">
                                No data.
                            </td>
                        </tr>
                    @endif
                </tbody>
            </table>

            <div class="pagination">
                {{ $smsHistoryData->list->withQueryString()->links() }}
            </div>
        </div>
    </form>
</div>
@endsection
