<div id="ajaxContent">
    <div class="row">
        <div class="col-md-5">
            <div class="card modern-card">
                <div class="card-header">
                    <h3 class="card-title"><?= !empty(lang('modules')) ? lang('modules') : "Modules"; ?></h3>
                    <a href="#addModuleModal" data-toggle="modal" class="btn btn-primary"><i class="fa fa-plus"></i> <?= !empty(lang('add')) ? lang('add') : "Add"; ?> <?= __('module'); ?></a>
                </div>
                <!-- /.box-header -->
                <form action="<?= base_url('admin/home/add_home_module') ?>" method="post" class="skill_form" enctype="multipart/form-data">
                    <div class="card-body">
                        <!-- csrf token -->
                        <input type="hidden" name="<?= $this->security->get_csrf_token_name(); ?>" value="<?= $this->security->get_csrf_hash(); ?>">

                        <div class="row">
                            <div class="form-group col-md-12">
                                <label for="module_id"><?= !empty(lang('module')) ? lang('module') : "module"; ?></label>

                                <div class="moduleLIst">
                                    <?php foreach ($home_module_title_list as $module): ?>
                                        <label class="custom-radio moduleIcon label-secondary">
                                            <input type="radio" name="module_id" value="<?= html_escape($module->id); ?>" <?= isset($single['module_id']) && $single['module_id'] == $module->id ? 'checked' : '' ?>> <i class="<?= $module->icon ?> fz-18 mr-5 d-color"></i><span><?= html_escape($module->name); ?></span>
                                            <div class="actionArea ml-15 d-flex gap-10">
                                                <a href="javascript:;" class="text-info" onclick="editHomeModule('<?= htmlspecialchars(json_encode($module)); ?>')"><i class="fa fa-edit"></i></a>
                                                <a href="<?= base_url('admin/home/item_delete/' . html_escape($module->id) . '/home_module_title_list'); ?>" class="text-danger action_btn"><i class="fa fa-trash"></i></a>
                                            </div>
                                        </label>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-group col-md-12">
                                <label for=""><?= __('title'); ?></label>
                                <input type="text" name="title" class="form-control" value="<?= isset($module_details['title']) ? $module_details['title'] : '' ?>">
                            </div>

                            <div class="form-group col-md-12">
                                <label for=""><?= __('overview'); ?></label>
                                <textarea name="overview" class="form-control"><?= isset($module_details['overview']) ? $module_details['overview'] : '' ?></textarea>
                            </div>
                        </div>

                        <div class="row">
                            <?php for ($i = 1; $i <= 10; $i++): ?>
                                <div class="form-group col-md-6">
                                    <label for=""><?= $i . '. ' . __('features'); ?></label>
                                    <input type="text" name="features[<?= $i ?>]" class="form-control" value="<?= isset($module_details['feature_list'][$i]) ? $module_details['feature_list'][$i] : '' ?>">
                                </div>
                            <?php endfor; ?>
                        </div>
                        <div class="row">
                            <div class="col-md-12 col-lg-12 col-sm-12 mt-10">
                                <label class="defaultImg">
                                    <input type="hidden" name="module_image" value="<?= isset($module_details['images']) && !empty($module_details['images']) ? implode(',', $module_details['images']) : ""; ?>">
                                    <?php if (isset($module_details['id']) && !empty($module_details['id'])): ?>
                                        <a href="<?= base_url('admin/home/delete_img/' . $module_details['id'] . '/home_module_list'); ?>" class="deleteImg <?= isset($module_details['images']['thumb']) && !empty($module_details['images']['thumb']) ? "" : "opacity_0" ?>" data-msg="<?= !empty(lang('want_to_delete')) ? lang('want_to_delete') : "want to delete"; ?>"><i class="fa fa-close"></i></a>
                                    <?php endif; ?>

                                    <img src="<?= isset($module_details['images']['thumb']) && !empty($module_details['images']['thumb']) ? base_url($module_details['images']['thumb']) : "" ?>" alt="" class="imgPreview <?= isset($module_details['images']['thumb']) && !empty($module_details['images']['thumb']) ? "" : "opacity_0" ?>">

                                    <div class="imgPreviewDiv <?= isset($module_details['images']['thumb']) && !empty($module_details['images']['thumb']) ? "opacity_0" : "" ?>">
                                        <i class="fa fa-upload"></i>
                                        <h4><?= lang('upload_image'); ?></h4>
                                        <p class="fw_normal mt-3"><?= lang('max'); ?>: 500 x 500 px</p>
                                    </div>

                                    <input type="file" name="file[]" class="imgFile opacity_0" data-height="0" data-width="0">
                                </label>
                                <span class="img_error"></span>
                            </div>
                        </div>

                        <input type="hidden" name="id" value="<?= isset($single['id']) && html_escape($single['id']) != 0 ? html_escape($single['id']) : 0 ?>">
                    </div><!-- /.box-body -->
                    <div class="card-footer">
                        <?php if (isset($single['id']) && html_escape($single['id']) != 0) { ?>
                            <div class="pull-left">
                                <a href="<?= base_url('admin/home/team'); ?>" class="btn btn-default btn-block btn-flat"><?= !empty(lang('cancel')) ? lang('cancel') : "cancel"; ?></a>
                            </div>
                        <?php } ?>
                        <div class="pull-right">
                            <button type="submit" name="register" class="btn btn-primary btn-block btn-flat"><?= !empty(lang('submit')) ? lang('submit') : "submit"; ?></button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="col-md-7">
            <div class="card modern-card">
                <div class="card-header">
                    <h3 class="card-title"><?= !empty(lang('team')) ? lang('team') : "team"; ?></h3>

                </div>
                <!-- /.box-header -->
                <div class="card-body">
                    <div class="upcoming_events">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th><?= !empty(lang('sl')) ? lang('sl') : "sl"; ?></th>
                                        <th><?= !empty(lang('module_name')) ? lang('module_name') : "module name"; ?></th>
                                        <th><?= !empty(lang('image')) ? lang('image') : "image"; ?></th>
                                        <th><?= !empty(lang('title')) ? lang('title') : "title"; ?></th>
                                        <th><?= !empty(lang('overview')) ? lang('overview') : "overview"; ?></th>
                                        <th><?= !empty(lang('features')) ? lang('features') : "features"; ?></th>
                                        <th><?= !empty(lang('status')) ? lang('status') : "status"; ?></th>
                                        <th><?= !empty(lang('action')) ? lang('action') : "action"; ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $i = 1;
                                    foreach ($module_list as $row): ?>
                                        <?php $details = json_decode($row['module_details']); ?>
                                        <tr>
                                            <td><?= $i; ?></td>
                                            <td><?= html_escape($row['name']); ?></td>

                                            <td>
                                                <div class="serviceImgs"><img src="<?= avatar($details->images->thumb ?? '', 'logo'); ?>" /></div>
                                            </td>

                                            <td>
                                                <?= $details->title ?? '' ?>
                                            </td>

                                            <td>
                                                <?= $details->overview ?? '' ?>
                                            </td>
                                            <td>
                                                <ul>
                                                    <?php foreach ($details->feature_list as  $key => $value): ?>
                                                        <?php if (!empty($value)): ?>
                                                            <li><i class="fa fa-check"></i> <?= htmlspecialchars($value ?? ''); ?></li>
                                                        <?php endif; ?>
                                                    <?php endforeach; ?>
                                                </ul>
                                            </td>
                                            <td>

                                                <a href="javascript:;" data-id="<?= html_escape($row['id']); ?>" data-status="<?= html_escape($row['status']); ?>" data-table="site_team" class="label <?= $row['status'] == 1 ? 'label-success' : 'label-danger' ?> change_status"> <i class="fa <?= $row['status'] == 1 ? 'fa-check' : 'fa-close' ?>"></i>&nbsp; <?= $row['status'] == 1 ? (!empty(lang('live')) ? lang('live') : "Live") : (!empty(lang('hide')) ? lang('hide') : "Hide"); ?></a>
                                            </td>
                                            <td class="actionBtnOnly">

                                                <div class="actionBtnOnly">
                                                    <a href="<?= base_url('admin/home/edit_module/' . html_escape($row['id'])); ?>" class="text-info"><i class="fa fa-edit"></i></a>

                                                    <a href="<?= base_url('admin/home/item_delete/' . html_escape($row['id']) . '/home_module_list'); ?>" class="text-danger action_btn" data-msg="<?= !empty(lang('want_to_delete')) ? lang('want_to_delete') : "want to delete"; ?>"><i class="fa fa-trash"></i></a>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php $i++;
                                    endforeach ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div><!-- /.box-body -->
            </div>
        </div>
    </div>


    <div id="addModuleModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" onsubmit="formSubmit(event,this)">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header d-flex space-between">
                    <h5 class="modal-title"><?= !empty(lang('add_new_module')) ? lang('add_new_module') : "Add New Module"; ?></h5>
                </div>
                <form action="<?= base_url("admin/home/add_module_title") ?>" method="post" class="form-submit">
                    <?= csrf(); ?>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for=""><?= lang('module_name'); ?></label>
                            <input type="text" name="name" class="form-control" value="">
                        </div>

                        <div class="form-group">
                            <label for=""><?= lang('language'); ?></label>
                            <select name="language" class="form-control" value="">
                                <option value=""><?= __('select'); ?></option>
                                <?php foreach (getLanguage('home') as $language): ?>
                                    <option value="<?= html_escape($language['slug']); ?>" <?= site_lang() == $language['slug'] ? 'selected' : '' ?>><?= html_escape($language['name']); ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for=""><?= lang('icon'); ?></label>
                            <input type="text" name="icon" class="form-control" value="" placeholder="fa fa-home">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="id" value="">
                        <div class="pull-left">
                            <a href="javascript:;" data-dismiss="modal" class="btn btn-default"><?= lang('cancel'); ?></a>
                        </div>
                        <button type="submit" class="btn btn-secondary "><?= lang('submit'); ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <script>
        function editHomeModule(data) {
            data = JSON.parse(data);
            $('#addModuleModal input[name="id"]').val(data.id);
            $('#addModuleModal input[name="name"]').val(data.name);
            $('#addModuleModal input[name="icon"]').val(data.icon);
            $('#addModuleModal select[name="language"]').val(data.language);
            $('#addModuleModal input[name="id"]').val(data.id);
            $('#addModuleModal').modal('show');
        }
    </script>
</div>