<div class="mb-1 pt-2 text-right btn-groups">
    <div class="btn-group" id="item-btn-group">
        <button type="button" class="btn btn-sm btn-primary sise-act save-button" data-value="save" {{ $formA['FormVars']['Hidden']['SaveButton'] }}>
            {{ $formA['FormVars']['Title']['SaveButton'] }}
        </button>
        @include('front.dabory.erp.partial.select-btn-options', [
            'selectBtns' => $formA['SelectButtonOptions'],
            'eventClassName' => 'sise-act',
        ])
    </div>
</div>

<div class="card p-2" id="sise-form">
    <button type="button" id="modal-media-btn" hidden
            class="btn btn-success btn-open-modal">
    </button>
    <div class="card-header" id="frm">
        <input type="hidden" id="Id" name="Id" value="0">
        <div class="row">
            <div class="col-12 card-header-item">
                <div class="card card card-info mb-3 mb-md-2 mb-lg-0 border-light">
{{--                    <div class="card-header p-0 mb-2">--}}
{{--                        <p class="card-title p-1 ml-2">{{ $formA['FormVars']['Title']['CardTitle1'] }}</p>--}}
{{--                    </div>--}}
                    <div class="card-body">
                        <div class="form-group {{ $formA['FormVars']['Display']['SiseType'] }} flex-column mb-2">
                            <label class="m-0">{{ $formA['FormVars']['Title']['SiseType'] }}</label>
                            <div class="d-flex align-items-center">
                                <input type="radio" value="golf" name="sisetype" class="text-center" id="sisetype-check-0"> <label class="mb-0 mr-1" for="sisetype-check-0">골프</label>
                                <input type="radio" value="condo" name="sisetype" class="text-center" id="sisetype-check-1"> <label class="mb-0 mr-1" for="sisetype-check-1">콘도</label>
                                <input type="radio" value="fitness" name="sisetype" class="text-center" id="sisetype-check-2"> <label class="mb-0 mr-1" for="sisetype-check-2">휘트니스</label>
                            </div>
                        </div>
                        <div class="form-group {{ $formA['FormVars']['Display']['Area'] }} flex-column mb-2">
                            <label class="m-0">{{ $formA['FormVars']['Title']['Area'] }}</label>
                            <select class="w-100 rounded" id="area-select">
                                <option value="100">수도권/강원/충청권</option>
                                <option value="200">영남/제주권</option>
                                <option value="300">호남권</option>
                            </select>
                        </div>
                        <div class="form-group {{ $formA['FormVars']['Display']['MembershipName'] }} flex-column mb-2">
                            <label class="m-0">{{ $formA['FormVars']['Title']['MembershipName'] }}</label>
                            <input type="text" id="membership-name-txt" class="rounded w-100" autocomplete="off"
                                   maxlength="{{ $formA['FormVars']['MaxLength']['MembershipName'] }}"
                                {{ $formA['FormVars']['Required']['MembershipName'] }}>
                        </div>
                        <div class="form-group {{ $formA['FormVars']['Display']['TodayPrice'] }} flex-column mb-2">
                            <label class="m-0">{{ $formA['FormVars']['Title']['TodayPrice'] }}</label>
                            <input type="text" id="today-price-txt" class="rounded w-100" autocomplete="off"
                                   maxlength="{{ $formA['FormVars']['MaxLength']['TodayPrice'] }}"
                                {{ $formA['FormVars']['Required']['TodayPrice'] }}>
                        </div>
                        <div class="form-group {{ $formA['FormVars']['Display']['YesterdayPrice'] }} flex-column mb-2">
                            <label class="m-0">{{ $formA['FormVars']['Title']['YesterdayPrice'] }}</label>
                            <input type="text" id="yesterday-price-txt" class="rounded w-100" autocomplete="off"
                                   maxlength="{{ $formA['FormVars']['MaxLength']['YesterdayPrice'] }}"
                                {{ $formA['FormVars']['Required']['YesterdayPrice'] }}>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@once
@push('js')
<script src="{{ csset('/js/modals-controller/a-type/common.js') }}"></script>
    <script>
        $(document).ready(async function() {
            PopupPopupForm1FormAPostSiseForm.mediaModal = await include_media_library('media-body', 'post')

            $(document).on('file.paste', '#modal-media', function (event, file_url_list, id_list, unique_key) {
                $(unique_key).val(file_url_list[0])
            });

            $('.sise-act').on('click', function () {
                // console.log($(this).data('value'))
                switch( $(this).data('value') ) {
                    case 'save': PopupPopupForm1FormAPostSiseForm.btn_act_save(); break;
                    case 'new': PopupPopupForm1FormAPostSiseForm.btn_act_new(); break;
                    case 'del': Atype.btn_act_del('#sise-form #frm', function () {
                        $('#modal-select-popup.show').trigger('list.requery')
                        $('#modal-select-popup.show').modal('hide')
                    }, 'PopupPopupForm1FormAPostSiseForm'); break;
                }
            });

        });

        (function( PopupPopupForm1FormAPostSiseForm, $, undefined ) {
            PopupPopupForm1FormAPostSiseForm.formA = {!! json_encode($formA) !!};
            PopupPopupForm1FormAPostSiseForm.mediaModal
            // PopupPopupForm1FormAPostSiseForm.state = [
            //     { Area: '독일', Value: 'Berlin', Caption: '베를린' },
            //     { Area: '영국', Value: 'London', Caption: '런던' },
            //     { Area: '일본', Value: 'Kansai', Caption: '간사이' },
            //     { Area: '일본', Value: 'Dokyo', Caption: '도쿄' },
            //     { Area: '중국', Value: 'Beijing', Caption: '베이징' },
            //     { Area: '중국', Value: 'Shanghai', Caption: '상하이' },
            //     { Area: '캐나다', Value: 'Toronto', Caption: '토론토' },
            //     { Area: '호주', Value: 'Sydney', Caption: '시드니' },
            //     { Area: '프랑스', Value: 'Paris', Caption: '파리' },
            //     { Area: '미국', Value: 'Massachusetts', Caption: '매사추세츠 주' },
            //     { Area: '미국', Value: 'Newyork', Caption: '뉴욕' },
            // ];

            // PopupPopupForm1FormAPostSiseForm.changeArea = function () {
            //     const area = $('#sise-form').find('#area-select').val()
            //     const filterState = PopupPopupForm1FormAPostSiseForm.state.filter(state => state['Area'] === area)
            //     $('#sise-form').find('#state-select').html(create_options(filterState))
            // }

            PopupPopupForm1FormAPostSiseForm.delete_media_id = function (media_dom_id) {
                $('#sise-form').find(media_dom_id).val('')
            }

            PopupPopupForm1FormAPostSiseForm.btn_act_save = function () {
                Atype.set_parameter_callback(PopupPopupForm1FormAPostSiseForm.parameter)
                Atype.btn_act_save('#sise-form #frm', function () {
                    $('#modal-select-popup.show').trigger('list.requery')
                    $('#modal-select-popup.show').modal('hide')
                }, 'PopupPopupForm1FormAPostSiseForm');
            }

            PopupPopupForm1FormAPostSiseForm.btn_act_new = async function () {
                $('#modal-select-popup.popup-popup-form1-form-a-post-sise-form .modal-header').removeClass('bg-grey-700 px-0')
                $('#modal-select-popup.popup-popup-form1-form-a-post-sise-form .modal-body button').removeClass('bg-grey-700 border-grey-700 bg-grey-700-hover')
                $('#modal-select-popup.popup-popup-form1-form-a-post-sise-form .modal-dialog').css('maxWidth', '800px');

                Atype.set_parameter_callback(PopupPopupForm1FormAPostSiseForm.parameter)
                Atype.btn_act_new('#sise-form #frm')
            }

            PopupPopupForm1FormAPostSiseForm.btn_act_new_callback = function () {
                PopupPopupForm1FormAPostSiseForm.btn_act_new()
                $('#sisetype-check-0').prop('checked', true)
                // $('#sise-form').find('#province-check').trigger('change')
                // PopupPopupForm1FormAPostSiseForm.changeArea()
            }

            PopupPopupForm1FormAPostSiseForm.show_popup_callback = async function (id) {
                PopupPopupForm1FormAPostSiseForm.btn_act_new()
                await PopupPopupForm1FormAPostSiseForm.fetch_sise(Number(id));
            }

            PopupPopupForm1FormAPostSiseForm.parameter = function () {
                const sise_form = $('#sise-form')
                let id = Number( $(sise_form).find('#Id').val() )
                let parameter = {
                    Id: id,
                    PostTypeId: 59,
                    PostTitle: $(sise_form).find('#membership-name-txt').val(),
                    Pc1: $(sise_form).find('input[name=sisetype]:checked').val(),
                    Pc2: $(sise_form).find('#area-select').val(),
                    Pc3: $(sise_form).find('#today-price-txt').val(),
                    Pc4: $(sise_form).find('#yesterday-price-txt').val(),
                    // Pc2: $(sise_form).find('#yesterday-price-txt').val(),
                    // Pc4: $(sise_form).find('#image-txt').val(),
                    // Pc5: $(sise_form).find('#logo-txt').val(),
                    // Pc6: $(sise_form).find('#state-select').val(),
                    // Pc7: $(sise_form).find('#location-txt').val(),
                    // Pc8: $(sise_form).find('#kind-txt').val(),
                    // Pc9: $(sise_form).find('#link-txt').val(),
                    // Pc10: $(sise_form).find('#lanking-txt').val(),

                    // Pt1: $(sise_form).find('#introduce-textarea').val(),

                    // Pd1: $(sise_form).find('#expenses-txt').val(),
                    // Pd2: $(sise_form).find('#semester-txt').val(),
                    // Pd3: $(sise_form).find('#top-txt').val(),
                    // Pd4: $(sise_form).find('#left-txt').val(),
                    // Pd5: $(sise_form).find('#popular-txt').val(),
                    // Pd6: $(sise_form).find('#recommend-txt').val(),
                    // Pd7: $(sise_form).find('#membership-name-txt').val().replace(/\s+/g, '_'),
                    // Pd8: $(sise_form).find('#province-check:checked').val() ?? '0',
                }
                if (id < 0) {
                    parameter = { Id: id }
                }
                console.log(parameter)

                return parameter;
            }

            PopupPopupForm1FormAPostSiseForm.fetch_sise = async function (id) {
                console.log('fetch_sise')
                console.log('api : ',PopupPopupForm1FormAPostSiseForm.formA['General']['PickApi'])

                const response = await get_api_data(PopupPopupForm1FormAPostSiseForm.formA['General']['PickApi'], {
                    Page: [ { Id: id } ]
                })

                console.log('response : ', response)

                PopupPopupForm1FormAPostSiseForm.set_sise_ui(response)
            }

            PopupPopupForm1FormAPostSiseForm.set_sise_ui = async function (response) {
                if (isEmpty(response.data) || response.data.apiStatus) {
                    return;
                }

                const sise = response.data.Page[0];
                const sise_form = $('#sise-form')
                // console.log(sise)
                console.log('sise', sise)
                $(sise_form).find('#Id').val(sise.Id)
                $(sise_form).find('#membership-name-txt').val(sise.PostTitle)
                $(sise_form).find(`input[name='sisetype'][value='${sise.Pc1}']`).prop('checked', true)
                $(sise_form).find('#area-select').val(sise.Pc2)
                $(sise_form).find('#today-price-txt').val(sise.Pc3)
                $(sise_form).find('#yesterday-price-txt').val(sise.Pc4)
                // $(sise_form).find('#province-check').prop('checked', sise.Pd8 == '1')
                // $(sise_form).find('#province-check').trigger('change')

                // PopupPopupForm1FormAPostSiseForm.changeArea()
                // $(sise_form).find('#name-kor-txt').val(sise.Pc3)
                // $(sise_form).find('#image-txt').val(sise.Pc4)
                // $(sise_form).find('#logo-txt').val(sise.Pc5)
                // $(sise_form).find('#state-select').val(sise.Pc6)
                // $(sise_form).find('#location-txt').val(sise.Pc7)
                // $(sise_form).find('#kind-txt').val(sise.Pc8)
                // $(sise_form).find('#link-txt').val(sise.Pc9)
                // $(sise_form).find('#lanking-txt').val(sise.Pc10)

                // $(sise_form).find('#introduce-textarea').val(sise.Pt1)

                // $(sise_form).find('#expenses-txt').val(sise.Pd1)
                // $(sise_form).find('#semester-txt').val(sise.Pd2)
                // $(sise_form).find('#top-txt').val(sise.Pd3)
                // $(sise_form).find('#left-txt').val(sise.Pd4)
                // $(sise_form).find('#popular-txt').val(sise.Pd5)
                // $(sise_form).find('#recommend-txt').val(sise.Pd6)

            }

        }( window.PopupPopupForm1FormAPostSiseForm = window.PopupPopupForm1FormAPostSiseForm || {}, jQuery ));
    </script>
@endpush
@endonce
