{% extends 'base.html' %}
{% block title %}Program Studi{% endblock %}
{% block page_title %}Program Studi{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal"><i class="fas fa-plus me-2"></i>Tambah Prodi</button>
    <form method="POST" id="massDeleteForm">{% csrf_token %}<button type="submit" name="delete_massal" class="btn btn-danger mass-delete-btn" id="massDeleteBtn"><i class="fas fa-trash me-2"></i>Hapus Terpilih</button></form>
</div>
<div class="card border-0 shadow-sm"><div class="card-body"><div class="table-responsive"><table class="table table-hover align-middle mb-0"><thead class="bg-light"><tr><th width="40"><input type="checkbox" id="checkAll" class="form-check-input"></th><th>Nama Program Studi</th><th width="120" class="text-center">Aksi</th></tr></thead><tbody>
{% for p in prodi_all %}
<tr>
    <td><input type="checkbox" name="selected_ids" value="{{ p.id }}" form="massDeleteForm" class="form-check-input item-checkbox"></td>
    <td>{{ p.nama }}</td>
    <td class="text-center">
        <button class="btn btn-sm btn-info text-white edit-btn" data-pk="{{ p.id }}" data-nama="{{ p.nama }}" data-bs-toggle="modal" data-bs-target="#editModal"><i class="fas fa-edit"></i></button>
        <a href="{% url 'prodi_delete' p.id %}" class="btn btn-sm btn-outline-danger" onclick="return confirm('Hapus?')"><i class="fas fa-trash"></i></a>
    </td>
</tr>
{% endfor %}
</tbody></table></div></div></div>
<div class="modal fade" id="addModal" tabindex="-1"><div class="modal-dialog"><form method="POST" class="modal-content">{% csrf_token %}<div class="modal-header"><h5 class="modal-title">Tambah Prodi</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="mb-3"><label class="form-label">Nama Program Studi</label><input type="text" name="nama" class="form-control" required></div></div><div class="modal-footer"><button type="submit" class="btn btn-primary">Simpan</button></div></form></div></div>
<div class="modal fade" id="editModal" tabindex="-1"><div class="modal-dialog"><form method="POST" class="modal-content">{% csrf_token %}<input type="hidden" name="pk" id="edit_pk"><div class="modal-header"><h5 class="modal-title">Edit Prodi</h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="mb-3"><label class="form-label">Nama Program Studi</label><input type="text" name="nama" id="edit_nama" class="form-control" required></div></div><div class="modal-footer"><button type="submit" class="btn btn-primary">Update</button></div></form></div></div>
{% endblock %}
{% block scripts %}
<script>$(document).ready(function(){$('.edit-btn').on('click',function(){$('#edit_pk').val($(this).data('pk'));$('#edit_nama').val($(this).data('nama'));});});</script>
{% endblock %}