<?php require_roles('super_admin');$plans=db()->query('SELECT p.*,(SELECT COUNT(*) FROM subscriptions s WHERE s.plan_id=p.id) subscriptions_count FROM plans p ORDER BY p.price')->fetchAll();?>
<section class="panel"><div class="panel-header"><div><h2>Planos e recursos</h2><p>Modelo de receita por mensalidade, sem comissão operacional.</p></div><button class="btn btn-primary" data-modal-open="#planModal">+ Novo plano</button></div><div class="cards-list"><?php foreach($plans as $item):$features=json_features($item['features_json']);?><article class="item-card"><div class="item-cover plan-cover-fixed"><?php if(!empty($item['image'])):?><img src="<?= e(media_url($item['image'])) ?>" alt="<?= e($item['name']) ?>"><?php else:?><span class="plan-placeholder">💎</span><?php endif;?><?= status_badge($item['status']) ?></div><div class="item-body"><h3><?= e($item['name']) ?></h3><div class="item-price"><?= money($item['price']) ?><small>/<?= (int)$item['duration_days'] ?> dias</small></div><p><?= e(implode(' • ',$features)) ?></p><div class="item-meta"><span><?= (int)$item['subscriptions_count'] ?> assinaturas</span><span><?= count($features) ?> recursos</span></div><button class="btn btn-secondary btn-sm btn-block" data-modal-open="#planModal<?= (int)$item['id'] ?>">Editar plano</button></div></article><div class="modal" id="planModal<?= (int)$item['id'] ?>"><div class="modal-card"><div class="modal-head"><h2>Editar plano</h2><button class="close-btn" data-modal-close>×</button></div><?php include __DIR__.'/_plan_form.php';?></div></div><?php endforeach;?></div></section>
<div class="modal" id="planModal"><div class="modal-card"><div class="modal-head"><h2>Novo plano</h2><button class="close-btn" data-modal-close>×</button></div><?php $item=['id'=>'','name'=>'','price'=>'','duration_days'=>30,'features_json'=>'[]','status'=>'active','image'=>''];include __DIR__.'/_plan_form.php';?></div></div>
