<?php $sub_page = (!empty($_GET['discount'])) ? $_GET['discount'] : '';
$title = '';
if ($sub_page == 'new') {
    $title = 'کد تخفیف جدید';
    $btn_text = 'افزودن';
} elseif (is_numeric($sub_page)) {
    $title = 'ویرایش کد تخفیف';
    $btn_text = 'ویرایش';
}
$message_status = array();
if (!empty($_GET['status'])) $message_status['status'] = $_GET['status'];
if (!empty($_GET['msg'])) $message_status['text'] = $_GET['msg'];
$discount_info = array();
if (is_numeric($sub_page)) $discount_info = yascode_vip::get_discount_info($sub_page); ?>
<div class="wrap editplan-page">
    <h2><?php echo $title; ?></h2>
    <a href="<?php echo add_query_arg(array('page' => 'discounts'), admin_url('admin.php')); ?>" class="page-title-action">کد های تخفیف</a>
    <div id="poststuff">
        <div class="msg-body">
            <?php if (!empty($message_status) && is_array($message_status) && !empty($message_status['text'])) {
                $status = (!empty($message_status['status'])) ? $message_status['status'] : $message_status[0];
                $sts = ($status != 'nok') ? 'success' : 'error';
                $text = (!empty($message_status['text'])) ? $message_status['text'] : ''; ?>
                <div class="custom-notice notice-<?php echo $sts; ?>">
                    <p class="content"><?php echo $text; ?></p><button type="button" class="notice-dismiss"></button>
                </div>
            <?php } ?>
        </div>

        <form action="<?php echo add_query_arg(array('page' => 'discounts', 'discount' => $sub_page), admin_url('admin.php')); ?>" method="POST">
            <input type="hidden" name="discount_id" value="<?php echo (!empty($discount_info->ID)) ? $discount_info->ID : ''; ?>" />
            <div class="input">
                <label for="">کد تخفیف</label>
                <input type="text" name="discount_title" value="<?php echo (!empty($discount_info->title)) ? $discount_info->title : ''; ?>" />
            </div>
            <div class="input">
                <label for="">درصد تخفیف (1 - 100)</label>
                <input type="text" name="discount_percent" value="<?php echo (!empty($discount_info->percentage)) ? $discount_info->percentage : ''; ?>" />
            </div>
            <div class="input">
                <label for="">تاریخ انقضا</label>
                <div class="picker datepicker">
                    <input type="text" name="discount_expire" autocomplete="off" class="datepicker" value="<?php echo (!empty($discount_info->expiration_date)) ? jdate('Y/m/d', strtotime($discount_info->expiration_date)) : ''; ?>">
                    <span class="datepicker"></span>
                </div>
            </div>
            <div class="input">
                <label for="">آیدی پلن خاص</label>
                <input type="text" name="discount_plans" value="<?php echo (!empty($discount_info->plan)) ? $discount_info->plan : ''; ?>" />
                <p class="desc">در صورتی قصد دارید بر روی پلن خاصی کد تخفیف اعمال شود آیدی پلن را وارد نمایید در غیر اینصورت خالی بگزارید ( آیدی ها با , جدا شود )</p>
            </div>
            <div class="input btn">
                <button type="submit" name="submit_edit_discount" class="button-primary"><?php echo $btn_text; ?></button>
            </div>
        </form>
    </div>
</div>