<?php
    if(is_null($current)){
            if(isset($_GET['tab'])){
                $current = $_GET['tab'];
            }
            if(!isset($_GET['tab'])){
                $current = 'nb-invoice-setting-tab1';
            }
        }
        ?>
        <div class="wrap"><h1>NB PDF Template Settings</h1>
        
            <h2 class="nav-tab-wrapper">
            <?php
            foreach($tabs as $location => $tabname){
                if($current == $location){
                    $class = ' nav-tab-active';
                } else{
                    $class = '';    
                }
                echo '<a class="nav-tab'.$class.'" href="?page=nb-smart-invoice-setting-pages&tab='.$location.'">'.$tabname.'</a>';
            }
            ?>
            </h2>
            <form method="POST" class="nbd-header-form">
                <table class="form-table" role="presentation">
                    <tbody>
                        <?php
                            if(isset($current)){
                                switch($current){
                                    case 'nb-invoice-setting-tab1':
                                        ?>
                                        <tr>
                                            <th scope="row"><?php echo esc_html__("Enable Template Debug",'netbase-smart-invoice');?></th>
                                            <td>
                                                <fieldset>
                                                    <label for="users_can_register">
                                                        <input type="hidden" name="debug[selected]" value="debug">
                                                        <input <?php if(isset($this->template_setting_option["pdf_template_debug"])) { if((int)$this->template_setting_option["pdf_template_debug"] == 1){ echo esc_html("checked");}}?> name="debug[pdf_template_debug]" id="pdf_template_debug" type="checkbox" value="1">
                                                        <?php echo esc_html__("Output as HTML to the browser instead of downloading a PDF.",'netbase-smart-invoice');?>
                                                    </label>
                                                    <p class="description">(*)View invoice or delivery in html</p>
                                                </fieldset>
                                            </td>
                                        </tr>
                                        <?php
                                    break;
                                    case 'nb-invoice-setting-tab2':
                                        ?>
                                            <tr>
                                                <th scope="row"><?php echo esc_html__("Use Invoice for Order Status",'netbase-smart-invoice');?></th>
                                                <td>
                                                    <fieldset>
                                                        <label for="nb_order_status_wc-pending">
                                                            <input type="hidden" name="invoice_order[selected]" value="invoice_order">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-pending"])){ if((int)$this->template_setting_option["nb_order_status_wc-pending"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-pending]" type="checkbox" id="nb_order_status_wc-pending" value="1">
                                                            <?php echo esc_html__("Pending Payment",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_processing">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-processing"])){ if((int)$this->template_setting_option["nb_order_status_wc-processing"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-processing]" type="checkbox" id="nb_order_status_wc-processing" value="1">
                                                            <?php echo esc_html__("Processing",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_on_hol">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-on-hold"])){ if((int)$this->template_setting_option["nb_order_status_wc-on-hold"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-on-hold]" type="checkbox" id="nb_order_status_wc-on-hold" value="1">
                                                            <?php echo esc_html__("On Hold",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_completed">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-completed"])){ if((int)$this->template_setting_option["nb_order_status_wc-completed"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-completed]" type="checkbox" id="nb_order_status_wc-completed" value="1">
                                                            <?php echo esc_html__("Completed",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_cancelled">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-cancelled"] )){ if((int)$this->template_setting_option["nb_order_status_wc-cancelled"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-cancelled]" type="checkbox" id="nb_order_status_wc-cancelled" value="1">
                                                            <?php echo esc_html__("Cancelled",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_refunded">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-refunded"])){ if((int)$this->template_setting_option["nb_order_status_wc-refunded"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-refunded]" type="checkbox" id="nb_order_status_wc-refunded" value="1">
                                                            <?php echo esc_html__("Refunded",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_failed">
                                                            <input <?php if(isset($this->template_setting_option["nb_order_status_wc-failed"])){ if((int)$this->template_setting_option["nb_order_status_wc-failed"] == 1){ echo esc_html("checked");}}?> name="invoice_order[nb_order_status_wc-failed]" type="checkbox" id="nb_order_status_wc-failed" value="1">
                                                            <?php echo esc_html__("Failed",'netbase-smart-invoice');?>
                                                        </label>
                                                        <p class="description">(*)Enable invoice for order status</p>
                                                    </fieldset>
                                                </td>
                                            </tr>
                                        <?php
                                    break;
                                    case 'nb-invoice-setting-tab3':
                                        ?>
                                            <tr>
                                                <th scope="row"><?php echo esc_html__("Attach invoice PDF to",'netbase-smart-invoice');?></th>
                                                <td>
                                                    <fieldset>
                                                        <label for="new_order_email">
                                                            <input type="hidden" name="attach_invoice[selected]" value="attach_invoice">
                                                            <input <?php if(isset($this->template_setting_option["new_order_email"])){if((int)$this->template_setting_option["new_order_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[new_order_email]" type="checkbox" id="new_order_email" value="1">
                                                            <?php echo esc_html__("New Order email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="customer_invoice">
                                                            <input <?php if(isset($this->template_setting_option["customer_invoice"])){if((int)$this->template_setting_option["customer_invoice"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[customer_invoice]" type="checkbox" id="customer_invoice" value="1">
                                                            <?php echo esc_html__("Customer Invoice",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="processing_order_email">
                                                            <input <?php if(isset($this->template_setting_option["processing_order_email"])){if((int)$this->template_setting_option["processing_order_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[processing_order_email]" type="checkbox" id="processing_order_email" value="1">
                                                            <?php echo esc_html__("Processing Order Email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="completed_order_email">
                                                            <input <?php if(isset($this->template_setting_option["completed_order_email"])){ if((int)$this->template_setting_option["completed_order_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[completed_order_email]" type="checkbox" id="completed_order_email" value="1">
                                                            <?php echo esc_html__("Completed Order email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="users_can_register">
                                                            <input <?php if(isset($this->template_setting_option["users_can_register"])){ if((int)$this->template_setting_option["users_can_register"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[users_can_register]" type="checkbox" id="cancelled_order_email" value="1">
                                                            <?php echo esc_html__("Cancelled order email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="failed_order_email">
                                                            <input <?php if(isset($this->template_setting_option["failed_order_email"])){ if((int)$this->template_setting_option["failed_order_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[failed_order_email]" type="checkbox" id="failed_order_email" value="1">
                                                            <?php echo esc_html__("Failed order email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="order_onhold_email">
                                                            <input <?php if(isset($this->template_setting_option["order_onhold_email"])){ if((int)$this->template_setting_option["order_onhold_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[order_onhold_email]" type="checkbox" id="order_onhold_email" value="1">
                                                            <?php echo esc_html__("Order on-hold email",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label for="refunded_order_email">
                                                            <input <?php if(isset($this->template_setting_option["refunded_order_email"])){ if((int)$this->template_setting_option["refunded_order_email"] == 1){ echo esc_html("checked");}}?>  name="attach_invoice[refunded_order_email]" type="checkbox" id="refunded_order_email" value="1">
                                                            <?php echo esc_html__("Refunded order email",'netbase-smart-invoice');?>
                                                        </label>
                                                        <p class="description">(*)Enable send email delivery with invoice for each order status</p>
                                                    </fieldset>
                                                </td>
                                            </tr>
                                        <?php
                                    break;
                                    case 'nb-invoice-setting-tab4':
                                        ?>
                                        <tr>
                                            <th scope="row">
                                                <label for="default_role"><?php echo esc_html__("Customer can download PDF",'netbase-smart-invoice');?></label>
                                            </th>
                                            <td>
                                                <input type="hidden" name="download_pdf[selected]" value="download_pdf">
                                                <select name="download_pdf[customer_can_download_pdf]" id="customer_can_download_pdf">
                                                    <option <?php if(isset($this->template_setting_option["customer_can_download_pdf"])){ if($this->template_setting_option["customer_can_download_pdf"] == "never"){ echo esc_html('selected="selected"');}}?> value="never"><?php echo esc_html__("Never",'netbase-smart-invoice');?></option>
                                                    <option <?php if(isset($this->template_setting_option["customer_can_download_pdf"])){ if($this->template_setting_option["customer_can_download_pdf"] == "available"){ echo esc_html('selected="selected"');}}?> value="available"><?php echo esc_html__("Only when an invoice is already created",'netbase-smart-invoice');?></option>
                                                    <option <?php if(isset($this->template_setting_option["customer_can_download_pdf"])){ if($this->template_setting_option["customer_can_download_pdf"] == "option"){ echo esc_html('selected="selected"');}}?> value="option"><?php echo esc_html__("Only for specific order status",'netbase-smart-invoice');?></option>
                                                    <option <?php if(isset($this->template_setting_option["customer_can_download_pdf"])){ if($this->template_setting_option["customer_can_download_pdf"] == "allway"){ echo esc_html('selected="selected"');}}?> value="allway"><?php echo esc_html__("Always",'netbase-smart-invoice','netbase-smart-invoice');?></option>
                                                </select>
                                                <?php 
                                                    if($this->template_setting_option["customer_can_download_pdf"] == "option"){
                                                        $customer_download = [];
                                                        if(isset($this->template_setting_option["customer_download_invoice_status"])){
                                                            $customer_download = $this->template_setting_option["customer_download_invoice_status"];
                                                        }
                                                    }
                                                ?> 
                                                <div id="customer_download_invoice_status"  style="<?php if(isset($this->template_setting_option["customer_can_download_pdf"])){ if($this->template_setting_option["customer_can_download_pdf"] == "option"){ echo esc_html(('display: block;'));} else {echo esc_html('display: none;');}}?>">
                                                    <fieldset>
                                                        <label>
                                                        <input <?php if(isset($customer_download["wc-pending"])){ if((int)$customer_download["wc-pending"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-pending]" class="field-short" value="1"> <?php echo esc_html__("Pending Payment",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                        <input <?php if(isset($customer_download["wc-processing"])) { if((int)$customer_download["wc-processing"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-processing]" class="field-short" value="1"> <?php echo esc_html__("Processing",'netbase-smart-invoice'); ?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                        <input <?php if(isset($customer_download["wc-on-hold"])) { if((int)$customer_download["wc-on-hold"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-on-hold]" class="field-short" value="1"> <?php echo esc_html__("On Hold",'netbase-smart-invoice'); ?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                            <input <?php if(isset($customer_download["wc-completed"])) { if((int)$customer_download["wc-completed"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-completed]" class="field-short" value="1"> <?php echo esc_html__("Completed",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                        <input <?php if(isset($customer_download["wc-cancelled"])) { if((int)$customer_download["wc-cancelled"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-cancelled]" class="field-short" value="1"> <?php echo esc_html__("Cancelled",'netbase-smart-invoice'); ?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                        <input <?php if(isset($customer_download["wc-refunded"])) { if((int)$customer_download["wc-refunded"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-refunded]" class="field-short" value="1"> <?php echo esc_html__("Refunded",'netbase-smart-invoice');?>
                                                        </label>
                                                    </fieldset>
                                                    <fieldset>
                                                        <label>
                                                            <input <?php if(isset($customer_download["wc-failed"])) { if((int)$customer_download["wc-failed"] == 1){ echo esc_html("checked");}}?> type="checkbox" name="customer_download_invoice_status[wc-failed]" class="field-short" value="1"><?php echo esc_html__("Failed",'netbase-smart-invoice');?>
                                                        </label>
                                                        <p class="description">(*)Allows download invoices for each order status</p>
                                                    </fieldset>
                                                </div>
                                            </td>
                                        </tr>
                                        <?php
                                    break;
                                    case 'nb-invoice-setting-tab5': 
                                        ?>
                                        <tr>
                                            <th scope="row">
                                                <label for="digits"><?php echo esc_html__("Digits",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input type="hidden" name="setting_format[selected]" value="setting_format">
                                                <input name="setting_format[digits]" type="text" id="digits" value="<?php if(isset($this->template_setting_option["digits"])){ echo esc_attr($this->template_setting_option["digits"]); }?>" class="regular-text">
                                                <p class="description" id="new-admin-email-description"><?php echo esc_html__("Appy to Invoice number & Delivery number",'netbase-smart-invoice'); ?></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row">
                                                <label for="invoice_number_start"><?php echo esc_html__("Invoice number start",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input name="setting_format[invoice_number_start]" type="text" id="invoice_number_start" value="<?php if(isset($this->template_setting_option["invoice_number_start"])){ echo esc_attr($this->template_setting_option["invoice_number_start"]);}?>" class="regular-text">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row">
                                                <label for="invoice_number_format"><?php echo esc_html__("Invoice number format",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input name="setting_format[invoice_number_format]" type="text" id="invoice_number_format" value="<?php if(isset($this->template_setting_option["invoice_number_format"])){ echo esc_attr($this->template_setting_option["invoice_number_format"]);}?>" class="regular-text">
                                                <p class="description" id="new-admin-email-description"><?php echo esc_html__("Appy to Invoice number & Delivery number",'netbase-smart-invoice'); ?></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row">
                                                <label for="delivery_number_start"><?php echo esc_html__("Delivery number start",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input name="setting_format[delivery_number_start]" type="text" id="delivery_number_start" value="<?php if(isset($this->template_setting_option["delivery_number_start"])){ echo esc_attr($this->template_setting_option["delivery_number_start"]);}?>" class="regular-text">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row">
                                                <label for="delivery_number_format"><?php echo esc_html__("Delivery number format",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input name="setting_format[delivery_number_format]" type="text" id="delivery_number_format" value="<?php if(isset($this->template_setting_option["delivery_number_format"])){ echo esc_attr($this->template_setting_option["delivery_number_format"]);}?>" class="regular-text">
                                                <p class="description" id="new-admin-email-description"><?php echo esc_html__("Shortcode: [number] [m] [Y] [d] - month, year, day from date of delivery",'netbase-smart-invoice'); ?></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row">
                                                <label for="date_format"><?php echo esc_html__("Date Format",'netbase-smart-invoice'); ?></label>
                                            </th>
                                            <td>
                                                <input name="setting_format[date_format]" type="text" id="date_format" value="<?php if(isset($this->template_setting_option["date_format"])){ echo esc_attr($this->template_setting_option["date_format"]);}?>" class="regular-text">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th scope="row"></th>
                                            <td><p class="description">(*)Setting for exporting invoice number and delivery number</p></td>
                                        </tr>
                                        <?php
                                        break;
                                    case 'nb-invoice-setting-tab6': 
                                        require_once NETBASE_SMART_INVOICE_PLUGIN_VIEW_DIR . '/backend/layout_template_import.php';
                                    break;
                                    default:;
                                }
                            }
                        ?>
                    </tbody>
                </table>
                <?php
                if(!isset($_GET['tab'])){
                    if($_GET['page'] == 'nb-smart-invoice-setting-pages'){
                        ?>
                            <p class="submit">
                                <input type="submit" name="submit" id="submit" class="button button-primary" value="Update Settings">
                            </p>
                        <?php
                        }
                }
                if(isset($_GET['tab'])){
                    if($_GET['tab'] != 'nb-invoice-setting-tab6'){
                        ?>
                            <p class="submit">
                                <input type="submit" name="submit" id="submit" class="button button-primary" value="Update Settings">
                            </p>
                        <?php
                        }
                }
                ?>
            </form>
        </div>