<style>
    .table > tbody > tr > td, .table > tbody > tr > th {
        padding: 1px;
        border: none;
    }
    .table-bg-color {
        background: #080a1b none repeat scroll 0 0;
        border-radius: 10px;
    }
</style>
<?php
$ToppingsStatus = array(1 => $this->lang->line('gkpos_active'), 0 => $this->lang->line('gkpos_inactive'), 2 => $this->lang->line('gkpos_archived'));
?>
<div class="hidden">
    <div id="loginFormPopup">
        <div class="popup-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="javascript:closeColorbox()" style="color: #ff0000"><i class="fa fa-close"></i></button>
                <h4 class="modal-title text-center"><?php echo $item[0]->title ?></h4>
            </div>
            <div class="modal-body">
                <div id="menuToppingsResponse" class="item-toppings-category">
                    <?php if (!empty($returnToppingsList)): ?>
                        <table class="table table-bordered table-bg-color text-center" style="color: #CCC;border: none;">
                            <tr style="background: #ff0000;">
                                <td>Toppings Category</td>
                                <td>Maximum Select</td>
                                <td>View Toppings List</td>
                                <td>Assign More</td>
                                <td>Status</td>
                            </tr>
                            <?php foreach ($returnToppingsList as $key => $rtl): ?>
                                <?php $toppingsCategoryInfo = get_topping_category_name($key); ?>
                                <tr>
                                    <td>
                                        <a style="color:#ccc;" href="javascript:void(0)" onclick="editBulkToppingsCategoryCell('<?php echo"toppings_category_" . $toppingsCategoryInfo->id ?>')" data-type="text" id="toppings_category_<?php echo $toppingsCategoryInfo->id ?>" data-name="title" data-pk="<?php echo $toppingsCategoryInfo->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscategorycell') ?>" data-title="<?php echo $this->lang->line('gkpos_category') . ' ' . $this->lang->line('gkpos_title') ?>">
                                            <?php echo $toppingsCategoryInfo->title ?>
                                        </a>
                                    </td>
                                    <td>
                                        <a style="color:#ccc;" href="javascript:void(0)" onclick="editBulkToppingsCategoryCell('<?php echo"toppings_maxselect_" . $toppingsCategoryInfo->id ?>')" data-type="text" id="toppings_maxselect_<?php echo $toppingsCategoryInfo->id ?>" data-name="max_select" data-pk="<?php echo $toppingsCategoryInfo->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscategorycell') ?>" data-title="<?php echo $this->lang->line('gkpos_category') . ' ' . $this->lang->line('gkpos_title') ?>">
                                            <?php echo $toppingsCategoryInfo->max_select ?>
                                        </a>
                                    </td>
                                    <td onclick="openCategoryToppingsList('toppingsCategory-<?php echo $key ?>')"><span style="cursor: pointer"><i class="fa fa-2x fa-folder-open"></i></span></td>
                                    <td>Coming soon</td>
                                    <td>
                                        <a style="color:#ccc;" href="javascript:void(0)" onclick="editBulkToppingsCategoryCell('<?php echo"toppingscategory_status_" . $toppingsCategoryInfo->id ?>')" data-type="select" id="toppingscategory_status_<?php echo $toppingsCategoryInfo->id ?>" data-name="status" data-pk="<?php echo $toppingsCategoryInfo->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscategorycell') ?>" data-value="<?php echo $toppingsCategoryInfo->status ?>" data-title="<?php echo $this->lang->line('gkpos_update_status') ?>">
                                            <span><?php echo $ToppingsStatus [$toppingsCategoryInfo->status] ?></span>
                                        </a>
                                    </td>
                                </tr>
                                <?php if (!empty($rtl)): ?>
                                    <tr id="toppingsCategory-<?php echo $key ?>" style="display: none;" class="toppings-list-block">
                                        <td colspan="5">
                                            <table class="table" style="width: 70%; margin: 0 auto; color: #000; border-radius: 10px; ">
                                                <tr style="background: #007299">
                                                    <td>Title</td>
                                                    <td>Price</td>
                                                    <td>Default</td>
                                                    <td>Delete</td>
                                                </tr>
                                                <?php foreach ($rtl as $artl): ?>
                                                    <tr>
                                                        <td>
                                                            <a style="color:#000;" href="javascript:void(0)" onclick="editBulkToppingsCell('<?php echo"toppings_title_" . $artl->id ?>')" data-type="text" id="toppings_title_<?php echo $artl->id ?>" data-name="title" data-pk="<?php echo $artl->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscell') ?>" data-title="<?php echo $this->lang->line('gkpos_category') . ' ' . $this->lang->line('gkpos_title') ?>">
                                                                <?php echo $artl->title ?>
                                                            </a>
                                                        </td>
                                                        <td>
                                                            <a style="color:#000;" href="javascript:void(0)" onclick="editBulkToppingsCell('<?php echo"toppings_price_" . $artl->id ?>')" data-type="text" id="toppings_price_<?php echo $artl->id ?>" data-name="price" data-pk="<?php echo $artl->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscell') ?>" data-title="<?php echo $this->lang->line('gkpos_category') . ' ' . $this->lang->line('gkpos_title') ?>">
                                                                <?php echo $artl->price ?>
                                                            </a>
                                                        </td>
                                                        <td>
                                                            <a style="color:#000;" href="javascript:void(0)" onclick="editBulkToppingsCell('<?php echo"toppings_isdefault_" . $artl->id ?>')" data-type="select" id="toppings_isdefault_<?php echo $artl->id ?>" data-name="is_default" data-pk="<?php echo $artl->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscell') ?>" data-value="<?php echo $artl->is_default ?>" data-title="<?php echo $this->lang->line('gkpos_update_status') ?>">
                                                                <span><?php echo $artl->is_default ?></span>
                                                            </a>
                                                        </td>
                                                        <td>
                                                            <a style="color:#000;" href="javascript:void(0)" onclick="editBulkToppingsCell('<?php echo"toppings_status_" . $artl->id ?>')" data-type="select" id="toppings_status_<?php echo $artl->id ?>" data-name="status" data-pk="<?php echo $artl->id ?>" data-url="<?php echo site_url('gkpos/menumanagement/editbulktoppingscell') ?>" data-value="<?php echo $artl->status ?>" data-title="<?php echo $this->lang->line('gkpos_update_status') ?>">
                                                                <span><?php echo $ToppingsStatus [$artl->status] ?></span>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                <?php endforeach; ?>
                                            </table>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </table>
                    <?php endif; ?>
                </div>

                <form class="form-horizontal" action="<?php echo site_url('gkpos/menumanagement/savebulktoppings') ?>" id="gkposToppingsBulkForm">
                    <input type="hidden" name="id" id="itemId"  value="<?php echo $item[0]->id ?>"/>
                    <input type="hidden" name="item_table" id="itemTable" value="<?php echo $item_table ?>" />
                    <input type="hidden" name="hook" id="ItemHook" value="<?php echo $hook ?>" />
                    <input type="hidden" name="toppings_category_table" value="toppings_category" />
                    <input type="hidden" name="category" value="<?php echo $category?>" />
                    <table class="table table-bordered">
                        <tr>
                            <td>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <label class="control-label">Item maximum toppings</label>
                                        <input type="text" name="max_toppings" class="form-control input-sm" value="<?php echo $item[0]->max_toppings ?>"/>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <label class="control-label">Item free toppings</label>
                                        <input type="text" name="free_toppings" class="form-control input-sm" value="<?php echo $item[0]->free_toppings ?>"/>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <label class="control-label">Toppings category name</label>
                                        <input type="text" name="category_title" class="form-control input-sm"/>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <label class="control-label">Maximum select on this category</label>
                                        <input type="text" name="max_select" class="form-control input-sm"/>
                                    </div>
                                </div>
                                <div class="col-sm-12">
                                    <input class="form-submit-button mainsystembg2 waiting-bg img-responsive delivery-info-submit-btn" type="submit" name="submit_form" value="<?php echo $this->lang->line('gkpos_numpad_key_enter') ?>" onclick="saveGkposToppingsBulkForm('gkposToppingsBulkForm')">
                                </div>
                                <?php if (!empty($toppingsList)): ?>
                                    <div class="col-sm-12">
                                        <table class="table table-condensed table-bordered">
                                            <caption class="text-center"><strong>Manage Toppings</strong></caption>
                                            <tr>
                                                <th>Check</th>
                                                <th>Title</th>
                                                <th>Price</th>
                                                <th>Default</th>
                                            </tr>
                                            <tr><td id="toppingsSelectionError" class="text-center"></td></tr>
                                            <?php foreach ($toppingsList as $atopping): ?>
                                                <tr>
                                                    <td><input data-error="#toppingsSelectionError" class="checkbox form-control input-sm" type="checkbox" name="toppings[]" value="<?php echo $atopping->id ?>"/></td>
                                                    <td><input class="form-control input-sm" type="text" name="title[<?php echo $atopping->id ?>]" value="<?php echo $atopping->title ?>"></td>
                                                    <td><input class="form-control input-sm" type="text" name="price[<?php echo $atopping->id ?>]" value="<?php echo $atopping->price ?>"></td>
                                                    <td>
                                                        <label class="radio-inline text-capitalize"><input type="radio" name="is_default[<?php echo $atopping->id ?>]" value="yes"><?php echo $this->lang->line('gkpos_yes') ?></label>
                                                        <label class="radio-inline text-capitalize"><input type="radio" name="is_default[<?php echo $atopping->id ?>]" value="no" checked="checked"><?php echo $this->lang->line('gkpos_no') ?></label>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </table>
                                    </div>
                                <?php endif; ?>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(window).bind('resize', function () {
        $('#colorbox').colorbox.resize();
    });


    function openCategoryToppingsList(block) {
        $('#' + block).slideToggle('slow', function () {
            $('#colorbox').colorbox.resize();
        });
    }
    function saveGkposToppingsBulkForm(formId) {
        $('#' + formId).validate({
            submitHandler: function () {
                var myform = document.getElementById(formId);
                var formdata = new FormData(myform);
                $.ajax({
                    url: $('#' + formId).attr('action'),
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    dataType: 'json',
                    success: function (response) {
                        if (response.success) {
                            $.colorbox.close();
                        }
                    }
                });
            },
            errorClass: "has-error",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            rules: {
                category_title: {
                    required: true
                },
                max_select: {
                    number: true,
                    required: true,
                },
                max_toppings: {
                    number: true,
                    required: true,
                },
                free_toppings: {
                    number: true,
                    required: true,
                },
                'toppings[]': {
                    required: true
                }
            },
            messages: {
                'toppings[]': {
                    required: "Check at least one"
                }
            },
            errorPlacement: function (error, element) {
                errorPlacement(error, element);
            }
        });
    }
    function editBulkToppingsCell(field) {
        $.fn.editable.defaults.mode = 'inline';
        $('#' + field).editable({
            source: function () {
                if (field.includes("status")) {
                    return [
                        {value: 1, text: '<?php echo $this->lang->line('gkpos_active') ?>'},
                        {value: 0, text: '<?php echo $this->lang->line('gkpos_inactive') ?>'},
                        {value: 2, text: '<?php echo $this->lang->line('gkpos_deleted') ?>'}
                    ]
                }
                if (field.includes("isdefault")) {
                    return [
                        {value: 'yes', text: '<?php echo $this->lang->line('gkpos_yes') ?>'},
                        {value: 'no', text: '<?php echo $this->lang->line('gkpos_no') ?>'}
                    ]
                }
                if (field.includes("bogo")) {
                    return [
                        {value: 1, text: '<?php echo $this->lang->line('gkpos_yes') ?>'},
                        {value: 0, text: '<?php echo $this->lang->line('gkpos_no') ?>'}
                    ]
                }
            }
        });
    }
    function editBulkToppingsCategoryCell(field) {
        $.fn.editable.defaults.mode = 'inline';
        $('#' + field).editable({
            source: function () {
                if (field.includes("status")) {
                    return [
                        {value: 1, text: '<?php echo $this->lang->line('gkpos_active') ?>'},
                        {value: 0, text: '<?php echo $this->lang->line('gkpos_inactive') ?>'},
                        {value: 2, text: '<?php echo $this->lang->line('gkpos_deleted') ?>'}
                    ]
                }
                if (field.includes("isdefault")) {
                    return [
                        {value: 'yes', text: '<?php echo $this->lang->line('gkpos_yes') ?>'},
                        {value: 'no', text: '<?php echo $this->lang->line('gkpos_no') ?>'}
                    ]
                }
                if (field.includes("bogo")) {
                    return [
                        {value: 1, text: '<?php echo $this->lang->line('gkpos_yes') ?>'},
                        {value: 0, text: '<?php echo $this->lang->line('gkpos_no') ?>'}
                    ]
                }
            }
        });
    }
</script>