<div class="card-header with-icon">
  {if $sub_view == "coupons"}
    <div class="float-end">
      <button data-toggle="modal" data-url="monetization/controller.php?do=add_coupon&node_id={$user->_data['user_id']}&node_type=profile" class="btn btn-md btn-primary">
        <i class="fa fa-plus-circle"></i><span class="ml5 d-none d-lg-inline-block">{__("Generate New Coupon")}</span>
      </button>
    </div>
  {/if}
  {include file='__svg_icons.tpl' icon="monetization" class="main-icon mr15" width="24px" height="24px"}
  {__("Monetization")}
  {if $sub_view == "coupons"} &rsaquo; {__("Coupons")}{/if}
  {if $sub_view == "payments"} &rsaquo; {__("Payments")}{/if}
  {if $sub_view == "earnings"} &rsaquo; {__("Earnings")}{/if}
</div>
<div class="card-body">
  {if $sub_view == ""}

    <div class="alert alert-info">
      <div class="text">
        <strong>{__("Monetization")}</strong><br>
        {__("Now you can earn money via paid posts, paid chat, paid audio/video calls or subscriptions plans.")}
        <br>
        {if $system['monetization_commission'] > 0}
          {__("There is commission")} <strong><span class="badge rounded-pill bg-warning">{$system['monetization_commission']}%</span></strong> {__("will be deducted")}.
          <br>
        {/if}
        {if $system['monetization_money_withdraw_enabled']}
          {__("You can")} <a class="alert-link" href="{$system['system_url']}/settings/monetization/payments" target="_blank">{__("withdraw your money")}</a>
        {/if}
        {if $system['monetization_money_transfer_enabled']}
          {if $system['monetization_money_withdraw_enabled']}{__("or")} {/if}
          {__("You can transfer your money to your")} <a class="alert-link" href="{$system['system_url']}/wallet" target="_blank"><i class="fa fa-wallet"></i> {__("wallet")}</a>
        {/if}
      </div>
    </div>

    {if $system['verification_for_monetization'] && !$user->_data['user_verified']}
      <div class="alert alert-danger">
        <div class="icon">
          <i class="fa fa-exclamation-circle fa-2x"></i>
        </div>
        <div class="text">
          <strong>{__("Account Verification Required")}</strong><br>
          {__("To enable monetization your account must be verified")} <a href="{$system['system_url']}/settings/verification">{__("Verify Now")}</a>
        </div>
      </div>
    {/if}

    <div class="heading-small mb20">
      {__("Monetization Settings")}
    </div>
    <div class="pl-md-4">
      <form class="js_ajax-forms" data-url="users/settings.php?edit=monetization">
        <div class="form-table-row">
          <div class="avatar">
            {include file='__svg_icons.tpl' icon="monetization"  class="main-icon" width="40px" height="40px"}
          </div>
          <div>
            <div class="form-label h6">{__("Monetization")}</div>
            <div class="form-text d-none d-sm-block">{__("Enable or disable monetization for your content")}</div>
          </div>
          <div class="text-end">
            <label class="switch" for="user_monetization_enabled">
              <input type="checkbox" name="user_monetization_enabled" id="user_monetization_enabled" {if $user->_data['user_monetization_enabled']}checked{/if}>
              <span class="slider round"></span>
            </label>
          </div>
        </div>

        <div class="form-table-row">
          <div class="avatar">
            {include file='__svg_icons.tpl' icon="offers"  class="main-icon" width="40px" height="40px"}
          </div>
          <div>
            <div class="form-label h6">{__("Global Discount")}</div>
            <div class="form-text d-none d-sm-block">{__("Enable or disable global discount for subscriptions plans and paid posts")}</div>
          </div>
          <div class="text-end">
            <label class="switch" for="user_monetization_discount_enabled">
              <input type="checkbox" name="user_monetization_discount_enabled" id="user_monetization_discount_enabled" {if $user->_data['user_monetization_discount_enabled']}checked{/if}>
              <span class="slider round"></span>
            </label>
          </div>
        </div>

        <div class="row form-group">
          <label class="col-md-3 form-label">
            {__("Discount Percent")}
          </label>
          <div class="col-md-9">
            <input type="number" min="1" max="99" class="form-control" name="user_monetization_discount_percent" value="{$user->_data['user_monetization_discount_percent']}">
            <div class="form-text">
              {__("The discount percent to apply to all monetized content (min 1, max 99)")}
            </div>
          </div>
        </div>

        <div class="divider dashed"></div>

        <div class="heading-small mb20">
          {__("Paid Chat")}
        </div>
        <div class="pl-md-4">
          <div class="row form-group">
            <label class="col-md-3 form-label">
              {__("Chat Message")} ({$system['system_currency']})
            </label>
            <div class="col-md-9">
              <input type="text" class="form-control" name="user_monetization_chat_price" value="{$user->_data['user_monetization_chat_price']}">
              <div class="form-text">
                {__("The price you want to charge for each message sent by the user (0 for free)")}
              </div>
            </div>
          </div>

          <div class="row form-group">
            <label class="col-md-3 form-label">
              {__("Audio/Video Call")} ({$system['system_currency']})
            </label>
            <div class="col-md-9">
              <input type="text" class="form-control" name="user_monetization_call_price" value="{$user->_data['user_monetization_call_price']}">
              <div class="form-text">
                {__("The price you want to charge for each audio/video call by the user (0 for free)")}
              </div>
            </div>
          </div>
        </div>

        <div class="divider dashed"></div>

        <div class="heading-small mb20">
          {__("Subscriptions")}
        </div>
        <div class="pl-md-4">
          <div class="row form-group">
            <label class="col-md-3 form-label">
              {__("Subscriptions Plans")}
            </label>
            <div class="col-md-9">
              <div class="payment-plans">
                {foreach $monetization_plans as $plan}
                  <div class="payment-plan">
                    <div class="text-xxlg">{__($plan['title'])}</div>
                    <div class="text-xlg">{print_money($plan['price'])} / {if $plan['period_num'] != '1'}{$plan['period_num']}{/if} {__($plan['period']|ucfirst)}</div>
                    {if {$plan['custom_description']}}
                      <div>{$plan['custom_description']}</div>
                    {/if}
                    <div class="mt10">
                      <span class="text-link mr10 js_monetization-deleter" data-id="{$plan['plan_id']}">
                        <i class="fa fa-trash-alt mr5"></i>{__("Delete")}
                      </span>
                      |
                      <span data-toggle="modal" data-url="monetization/controller.php?do=edit_plan&id={$plan['plan_id']}" class="text-link ml10">
                        <i class="fa fa-pen mr5"></i>{__("Edit")}
                      </span>
                    </div>
                  </div>
                {/foreach}
                <div data-toggle="modal" data-url="monetization/controller.php?do=add_plan&node_id={$user->_data['user_id']}&node_type=profile" class="payment-plan new">
                  <div class="d-flex align-items-center justify-content-center">
                    <i class="fa fa-plus mr5"></i>
                    {__("Add New")}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-9 offset-md-3">
            <button type="submit" class="btn btn-primary">{__("Save Changes")}</button>
          </div>
        </div>

        <!-- success -->
        <div class="alert alert-success mt15 mb0 x-hidden"></div>
        <!-- success -->

        <!-- error -->
        <div class="alert alert-danger mt15 mb0 x-hidden"></div>
        <!-- error -->
      </form>
    </div>

    <div class="divider"></div>

    <div class="heading-small mb20">
      {__("Monetization Balance")}
    </div>
    <div class="pl-md-4">
      <div class="row">
        <!-- subscribers -->
        <div class="col-sm-6">
          <div class="section-title mb20">
            {__("Profile Subscribers")}
          </div>
          <div class="stat-panel bg-gradient-teal">
            <div class="stat-cell">
              <i class="fa fas fa-users bg-icon"></i>
              <div class="h3 mtb10">
                {$subscribers_count}
              </div>
            </div>
          </div>
        </div>
        <!-- subscribers -->

        <!-- money balance -->
        <div class="col-sm-6">
          <div class="section-title mb20">
            {__("Monetization Money Balance")}
          </div>
          <div class="stat-panel bg-primary">
            <div class="stat-cell">
              <i class="fa fa-donate bg-icon"></i>
              <div class="h3 mtb10">
                {print_money($user->_data['user_monetization_balance'])}
              </div>
            </div>
          </div>
        </div>
        <!-- monetization balance -->
      </div>
    </div>

  {elseif $sub_view == "coupons"}

    {if $coupons}
      <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover js_dataTable">
          <thead>
            <tr>
              <th>{__("Code")}</th>
              <th>{__("Discount")}</th>
              <th>{__("Created")}</th>
              <th>{__("Usage Details")}</th>
              <th>{__("One Time")}</th>
              <th>{__("Actions")}</th>
            </tr>
          </thead>
          <tbody>
            {foreach $coupons as $coupon}
              <tr>
                <td><span class="badge rounded-pill badge-lg bg-secondary">{$coupon['coupon_code']}</span></td>
                <td>
                  <span class="badge rounded-pill badge-lg bg-primary">{$coupon['discount_percent']}%</span>
                </td>
                <td>{$coupon['created_date']|date_format:"%e %B %Y"}</td>
                <td>
                  {if $coupon['usage_counter'] > 0}
                    <span data-toggle="modal" data-url="monetization/controller.php?do=coupon_users&coupon_id={$coupon['coupon_id']}" class="pointer text-success">
                      <i class="fa fa-users mr5"></i> <span class="badge rounded-pill badge-lg bg-success">{$coupon['usage_counter']}</span> {__("Users")}
                    </span>
                  {else}
                    {include file='__svg_icons.tpl' icon="cross" class="mr5" width="24px" height="24px"} <span class="text-muted">{__("No One")}</span>
                  {/if}
                </td>
                <td>
                  {if $coupon['is_onetime']}
                    {include file='__svg_icons.tpl' icon="checked" width="24px" height="24px"}
                  {else}
                    {include file='__svg_icons.tpl' icon="cross" width="24px" height="24px"}
                  {/if}
                </td>
                <td>
                  <!-- delete -->
                  <div class="d-inline-block" data-bs-toggle="tooltip" title='{__("Delete")}'>
                    <button class="btn btn-sm btn-icon btn-rounded btn-danger js_monetization-coupon-deleter" data-id="{$coupon['coupon_id']}">
                      <i class="fa fa-trash-alt"></i>
                    </button>
                  </div>
                  <!-- delete -->
                  <!-- share -->
                  <div class="d-inline-block" data-bs-toggle="tooltip" title='{__("Share")}'>
                    <button data-toggle="modal" data-url="monetization/controller.php?do=share_coupon&coupon_id={$coupon['coupon_id']}" class="btn btn-sm btn-icon btn-rounded btn-primary">
                      <i class="fa fa-link"></i>
                    </button>
                  </div>
                  <!-- share -->
                </td>
              </tr>
            {/foreach}
          </tbody>
        </table>
      </div>
    {else}
      {include file='_no_data.tpl'}
    {/if}

  {elseif $sub_view == "payments"}
    <div class="heading-small mb20">
      {__("Withdrawal Request")}
    </div>
    <div class="pl-md-4">
      <form class="js_ajax-forms" data-url="users/withdraw.php?type=monetization">
        <div class="row form-group">
          <label class="col-md-3 form-label">
            {__("Your Balance")}
          </label>
          <div class="col-md-9">
            <h6>
              <span class="badge badge-lg bg-info">
                {print_money($user->_data['user_monetization_balance'])}
              </span>
            </h6>
          </div>
        </div>

        <div class="row form-group">
          <label class="col-md-3 form-label">
            {__("Amount")} ({$system['system_currency']})
          </label>
          <div class="col-md-9">
            <input type="text" class="form-control" name="amount">
            <div class="form-text">
              {__("The minimum withdrawal request amount is")} {print_money($system['monetization_min_withdrawal'])}
            </div>
          </div>
        </div>

        <div class="row form-group">
          <label class="col-md-3 form-label">
            {__("Payment Method")}
          </label>
          <div class="col-md-9">
            {if in_array("paypal", $system['monetization_payment_method_array'])}
              <div class="form-check form-check-inline">
                <input type="radio" name="method" id="method_paypal" value="paypal" class="form-check-input">
                <label class="form-check-label" for="method_paypal">{__("PayPal")}</label>
              </div>
            {/if}
            {if in_array("skrill", $system['monetization_payment_method_array'])}
              <div class="form-check form-check-inline">
                <input type="radio" name="method" id="method_skrill" value="skrill" class="form-check-input">
                <label class="form-check-label" for="method_skrill">{__("Skrill")}</label>
              </div>
            {/if}
            {if in_array("bank", $system['monetization_payment_method_array'])}
              <div class="form-check form-check-inline">
                <input type="radio" name="method" id="method_bank" value="bank" class="form-check-input">
                <label class="form-check-label" for="method_bank">{__("Bank Transfer")}</label>
              </div>
            {/if}
            {if in_array("custom", $system['monetization_payment_method_array'])}
              <div class="form-check form-check-inline">
                <input type="radio" name="method" id="method_custom" value="custom" class="form-check-input">
                <label class="form-check-label" for="method_custom">{__($system['monetization_payment_method_custom'])}</label>
              </div>
            {/if}
          </div>
        </div>

        <div class="row form-group">
          <label class="col-md-3 form-label">
            {__("Transfer To")}
          </label>
          <div class="col-md-9">
            <input type="text" class="form-control" name="method_value">
          </div>
        </div>

        <div class="row">
          <div class="col-md-9 offset-md-3">
            <button type="submit" class="btn btn-primary">{__("Make a withdrawal")}</button>
          </div>
        </div>

        <!-- success -->
        <div class="alert alert-success mt15 mb0 x-hidden"></div>
        <!-- success -->

        <!-- error -->
        <div class="alert alert-danger mt15 mb0 x-hidden"></div>
        <!-- error -->
      </form>
    </div>

    <div class="divider"></div>

    <div class="heading-small mb20">
      {__("Withdrawal History")}
    </div>
    <div class="pl-md-4">
      {if $payments}
        <div class="table-responsive mt20">
          <table class="table table-striped table-bordered table-hover">
            <thead>
              <tr>
                <th>{__("ID")}</th>
                <th>{__("Amount")}</th>
                <th>{__("Method")}</th>
                <th>{__("Transfer To")}</th>
                <th>{__("Time")}</th>
                <th>{__("Status")}</th>
              </tr>
            </thead>
            <tbody>
              {foreach $payments as $payment}
                <tr>
                  <td>{$payment@iteration}</td>
                  <td>{print_money($payment['amount'])}</td>
                  <td>
                    {if $payment['method'] == "custom"}
                      {$system['monetization_payment_method_custom']}
                    {else}
                      {$payment['method']|ucfirst}
                    {/if}
                  </td>
                  <td>{$payment['method_value']}</td>
                  <td>
                    <span class="js_moment" data-time="{$payment['time']}">{$payment['time']}</span>
                  </td>
                  <td>
                    {if $payment['status'] == '0'}
                      <span class="badge rounded-pill badge-lg bg-warning">{__("Pending")}</span>
                    {elseif $payment['status'] == '1'}
                      <span class="badge rounded-pill badge-lg bg-success">{__("Approved")}</span>
                    {else}
                      <span class="badge rounded-pill badge-lg bg-danger">{__("Declined")}</span>
                    {/if}
                  </td>
                </tr>
              {/foreach}
            </tbody>
          </table>
        </div>
      {else}
        {include file='_no_transactions.tpl'}
      {/if}
    </div>
  {elseif $sub_view == "earnings"}
    <div class="row">
      <div class="col-sm-6">
        <div class="stat-panel bg-gradient-primary">
          <div class="stat-cell narrow">
            <i class="fa fa-dollar-sign bg-icon"></i>
            <span class="text-xxlg">{print_money($total_earnings)}</span><br>
            <span class="text-lg">{__("Total Earnings")}</span><br>
          </div>
        </div>
      </div>
      <div class="col-sm-6">
        <div class="stat-panel bg-gradient-info">
          <div class="stat-cell narrow">
            <i class="fa fa-dollar-sign bg-icon"></i>
            <span class="text-xxlg">{print_money($this_month_earnings)}</span><br>
            <span class="text-lg">{__("This Month Earnings")}</span><br>
          </div>
        </div>
      </div>
    </div>

    <div class="heading-small mb20">
      {__("History")}
    </div>
    <div class="pl-md-4">
      {if $earnings}
        <div class="table-responsive mt20">
          <table class="table table-striped table-bordered table-hover">
            <thead>
              <tr>
                <th>{__("ID")}</th>
                <th>{__("User")}</th>
                <th>{__("Total")}</th>
                <th>{__("Commission")}</th>
                <th>{__("Earning")}</th>
                <th>{__("Time")}</th>
              </tr>
            </thead>
            <tbody>
              {foreach $earnings as $earning}
                <tr>
                  <td>{$earning@iteration}</td>
                  <td>
                    <a href="{$system['system_url']}/{$earning['user_name']}">
                      <img src="{$earning['user_picture']}" class="rounded-circle" width="30" height="30">
                      {$earning['user_fullname']}
                    </a>
                  </td>
                  <td>{print_money($earning['price'])}</td>
                  <td>{print_money($earning['commission'])}</td>
                  <td>{print_money($earning['earning'])}</td>
                  <td>
                    <span class="js_moment" data-time="{$earning['time']}">{$earning['time']}</span>
                  </td>
                </tr>
              {/foreach}
            </tbody>
          </table>
        </div>
      {else}
        {include file='_no_transactions.tpl'}
      {/if}
    </div>
  {/if}
</div>