<!doctype html>
<html lang="ko"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>포트폴리오 관리</title>
    <link rel="stylesheet" th:href="@{/resources/kr/iotdoor/comn/site/layout/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/resources/kr/iotdoor/comn/site/layout/css/iotdoor.css?v=202404021718}">
</head>
<body class="bg-light">
<div class="container py-5">
    <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3 mb-4">
        <div>
            <h1 class="h3 mb-1">포트폴리오 관리</h1>
            <p class="text-secondary mb-0">대표이미지, 본문, 등록자, 조회수를 포함한 포트폴리오를 직접 관리합니다.</p>
        </div>
        <div class="d-flex gap-2">
            <a class="btn btn-outline-secondary" th:href="@{/mfuc/index.do}">대시보드</a>
            <a class="btn btn-primary" th:href="@{/mfuc/portfolio/form.do}">새 포트폴리오 등록</a>
        </div>
    </div>

    <div class="alert alert-success" th:if="${param.saved}" role="alert">
        포트폴리오가 저장되었습니다.
    </div>
    <div class="alert alert-success" th:if="${param.deleted}" role="alert">
        포트폴리오가 삭제되었습니다.
    </div>

    <div class="card border-0 shadow-sm">
        <div class="card-body">
            <div th:if="${#lists.isEmpty(portfolioItems)}" class="text-secondary">
                아직 등록된 포트폴리오가 없습니다.
            </div>
            <div th:unless="${#lists.isEmpty(portfolioItems)}" class="table-responsive">
                <table class="table align-middle">
                    <thead>
                    <tr>
                        <th>대표이미지</th>
                        <th>제목</th>
                        <th>등록일시</th>
                        <th>등록자</th>
                        <th>조회수</th>
                        <th>관리</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="item : ${portfolioItems}">
                        <td style="width: 140px;">
                            <img class="img-fluid rounded" th:src="${item.imageUrl}" th:alt="${item.title}">
                        </td>
                        <td>
                            <div class="fw-semibold mb-1" th:text="${item.title}">제목</div>
                            <div class="small text-secondary" th:text="${item.summary}">요약</div>
                            <a class="small" th:href="@{/portfolio/{portfolioId}(portfolioId=${item.portfolioIdntfNo})}" target="_blank">공개 페이지 보기</a>
                        </td>
                        <td th:text="${#temporals.format(item.registeredAt, 'yyyy-MM-dd HH:mm')}">2026-04-16 09:00</td>
                        <td th:text="${item.registeredByName}">관리자</td>
                        <td th:text="${item.viewCount}">0</td>
                        <td>
                            <div class="d-flex flex-column gap-2">
                                <a class="btn btn-sm btn-outline-primary"
                                   th:href="@{/mfuc/portfolio/form.do(portfolioIdntfNo=${item.portfolioIdntfNo})}">
                                    수정
                                </a>
                                <form method="post" th:action="@{/mfuc/portfolio/delete.do}">
                                    <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}">
                                    <input type="hidden" name="portfolioIdntfNo" th:value="${item.portfolioIdntfNo}">
                                    <button class="btn btn-sm btn-outline-danger" type="submit"
                                            onclick="return confirm('해당 포트폴리오를 삭제하시겠습니까?');">
                                        삭제
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>
