@extends('admin.layouts.sub')

@section('content')
<div class="container-fluid p-3">
    <h2>SMS 자주 보내는 문자</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.popup.sms') }}">
        <div class="row g-2">
            <div class="col-auto">
                <select name="field" id="field" class="form-select">
                    <option value="tb_sms_favorite.id" @if($params->field == 'tb_sms_favorite.id') selected @endif>번호</option>
                    <option value="tb_sms_favorite.subject" @if($params->field == 'tb_sms_favorite.subject') selected @endif>제목</option>
                    <option value="tb_sms_favorite.content" @if($params->field == 'tb_sms_favorite.content') selected @endif>내용</option>
                </select>
            </div>
            <div class="col-auto">
                <div class="input-group">
                    <input type="text" name="keyword" id="keyword" class="form-control" value="{{ $params->keyword }}" placeholder="검색어를 입력하세요." />
                    <button type="submit" class="btn btn-dark">검색</button>
                </div>
            </div>
        </div>
    </form>

    <form name="f_admin_list" id="fAdminList" method="post">
        @csrf
        @if($smsFavoriteData->rows > 0)
            <div class="row row-cols-1 row-cols-md-3">
                @foreach($smsFavoriteData->list as $row)
                    <div class="col mb-4">
                        <div class="card h-100 mt-2">
                            <div class="card-body">
                                <h5 class="card-title">
                                    <p class="card-text">
                                        @if($row->type == 1) [SMS] @else [LMS] @endif - {{ $row->id }}
                                    </p>
                                    {{ $row->subject }}
                                    <input type="hidden" class="form-control" value="{{ $row->subject }}" readonly disabled />
                                </h5>
                                <p class="card-text">
                                    <hr/>
                                    {{ $row->content }}
                                    <input type="hidden" class="form-control" value="{{ $row->content }}" readonly disabled />
                                </p>
                                <a href="#" class="btn btn-primary btn-sm btn-add"
                                    data-subject="{{ $row->subject }}"
                                    data-content="{{ $row->content }}">추가</a>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
            <div class="pagination">
                {{ $smsFavoriteData->list->withQueryString()->links() }}
            </div>
        @else
            <div class="row">
                <div class="col text-center">
                    No data.
                </div>
            </div>
        @endif
    </form>
</div>

<script>
$(document).on("click", ".btn-add", function() {
    $("#smsSubject", opener.document).val(this.dataset.subject);
    $("#smsContent", opener.document).val(this.dataset.content);
    opener.byteCheck("smsContent", "contentByte");
    window.close();
});
</script>
@endsection
