<?php
/** @var \Magetop\Advancepreview\Block\EmailSetting $block */
$fields = [
    'configure_id'=>'configure_id',
    'customer_id'=>'customer_id',
    'request_offer'=>__('Notify me when I create an offer'),
    'status_in_progress'=>__('Order status – In progress'),
    'status_checking_myfit'=>__('Order status – Checking design by myfitmix'),
    'status_design_approved'=>__('Order status –  Design approved'),
    'status_design_failed'=>__('Order status –  Design Failed, please upload a new design'),
    'status_design_fully_approved'=>__('Order status –  Design fully approved'),
    'status_shipping'=>__('Order status – Ready for shipping/Production done'),
    'status_shipped'=>__('Order status – Shipped'),
    'status_delivered'=>__('Order status – Delivered'),
];
$emailSetting = $block->getEmailSetting();
$customerGroup = $block->getCustomerGroup();
if($customerGroup <= 1) {
    unset($fields['request_offer']);
    //unset($fields['status_delivered']);
   /* unset($fields['status_checking_myfit']);
    unset($fields['status_design_approved']);
    unset($fields['status_design_failed']);
    unset($fields['status_design_fully_approved']);*/
}
?>
<form action="<?php echo $block->getUrl('advance_preview/account/saveEmailSetting') ?>" method="post">
    <?php foreach ($fields as $key => $field) : ?>
        <?php if($key == 'configure_id' || $key == 'customer_id') : ?>
        <input  type="hidden" name="<?php echo $key ?>" value="<?php echo $emailSetting[$key] ?>">
        <?php else  : ?>
            <div class="email-setting-filed">
                <div class="email-setting-filed-label">
                    <span><?php echo $field; ?></span>
                </div>
                <div class="email-setting-filed-value">
                    <label class="switch">
                        <input type="checkbox" class="txt-email-setting-filed" id="c-<?php echo $key ?>" value="<?php echo $emailSetting[$key]; ?>" <?php echo $emailSetting[$key] == 1 ? 'checked="checked"' : ''; ?>>

                        <span class="slider round"></span>
                    </label>
                </div>
            </div>
        <?php endif; ?>
        <input type="hidden" id="txt-<?php echo $key ?>" name="<?php echo $key; ?>" value="<?php echo $emailSetting[$key]; ?>">
    <?php endforeach; ?>
    <div class="email-setting-filed">
        <button type="submit" class="action primary"><?php echo __('Save') ?></button>
    </div>
</form>
<script>
    require(['jquery'],function ($) {
        $('.txt-email-setting-filed').click(function () {
            console.log("click");
            var value = $(this).is(":checked") ? 1 : 0;
            var id = $(this).attr('id');
            id = id.replace('c-','');
            console.log('#txt-'+id);
            $('#txt-'+id).val(value);
        })
    })
</script>
