<%@ Page Title="Mis Listas" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="ListViewer.aspx.cs" Inherits="PDI.Web.ListViewer" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
	<style>
		.list-viewer-layout {
			display: flex;
			gap: 1.5rem;
			height: calc(100vh - 60px - 4rem - 54px);
		}

		.list-viewer-lists {
			flex: 1;
			min-width: 0;
			overflow-y: auto;
		}

		.list-viewer-preview {
			width: 700px;
			flex-shrink: 0;
			display: flex;
			flex-direction: column;
		}

		.list-viewer-preview.card {
			background-color: #fff;
			border-radius: 8px;
			box-shadow: 0 2px 5px var(--shadow-color);
		}

		.list-container {
			margin-bottom: 2rem;
			border: 1px solid var(--border-color);
			border-radius: 8px;
			overflow: hidden;
		}

		.list-header {
			background-color: var(--wine-dark);
			color: white;
			padding: 1rem;
			font-size: 1.2rem;
			font-weight: bold;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.delete-list-btn {
			color: rgba(255,255,255,0.7);
			text-decoration: none;
			font-size: 1rem;
			transition: color 0.2s;
		}

		.delete-list-btn:hover {
			color: #ff6b6b;
		}

		.document-item {
			display: grid;
			grid-template-columns: 3fr 1.5fr auto;
			align-items: center;
			gap: 1rem;
			padding: 0.75rem 1.5rem 0.75rem 0.75rem;
			border-bottom: 1px solid var(--border-color);
			background-color: #fff;
		}

			.document-item:hover {
				background-color: var(--silver-light);
			}

		.document-name {
			display: flex;
			align-items: center;
		}

			.document-name i {
				margin-right: 0.5rem;
				color: var(--wine-light);
			}

		.document-actions {
			display: flex;
			gap: 0.75rem;
			justify-content: flex-end;
		}

		.document-actions a {
			text-decoration: none;
			color: var(--wine-light);
			font-size: 0.95rem;
			position: relative;
		}

		.document-actions a:hover {
			color: var(--wine-dark);
		}

		.empty-message {
			padding: 1rem;
			text-align: center;
			color: #777;
		}
	</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	<section id="page-list-viewer" class="page">
		<h2>Mis Listas</h2>

		<div class="list-viewer-layout">
			<div class="list-viewer-lists">
				<asp:Repeater ID="rptLists" runat="server" OnItemDataBound="rptLists_ItemDataBound" OnItemCommand="rptLists_ItemCommand">
					<ItemTemplate>
						<div class="list-container">
							<div class="list-header">
								<span><%# Eval("Name") %> (<%# Eval("Description") %>)</span>
								<asp:LinkButton ID="btnDeleteList" runat="server"
									CommandName="DeleteList"
									CommandArgument='<%# Eval("Id") %>'
									CssClass="delete-list-btn"
									data-tip="Eliminar lista">
									<i class="fas fa-trash-alt"></i>
								</asp:LinkButton>
							</div>
							<asp:Repeater ID="rptDocuments" runat="server" OnItemCommand="rptDocuments_ItemCommand">
								<HeaderTemplate>
									<div class="document-item" style="font-weight: bold; border-bottom-width: 2px;">
										<div class="document-name">Documento</div>
										<div>Fecha Creaci&oacute;n</div>
										<div class="document-actions">Acciones</div>
									</div>
								</HeaderTemplate>
								<ItemTemplate>
									<div class="document-item">
										<div class="document-name">
											<i class="fas fa-file-alt"></i>
											<%# (Eval("Documents.UserFilename") == null || Eval("Documents.UserFilename") == DBNull.Value || string.IsNullOrWhiteSpace(Eval("Documents.UserFilename").ToString()) ? ((int)Eval("Documents.Id")).ToString("D8") : Eval("Documents.UserFilename")) %>
										</div>
										<div><%# Eval("Documents.Created", "{0:yyyy-MM-dd HH:mm}") %></div>
										<div class="document-actions">
											<asp:LinkButton ID="lbPreview" runat="server"
												CommandName="PreviewDocument"
												CommandArgument='<%# Eval("Documents.Id") %>'
												data-tip="Vista Previa">
												<i class="fas fa-eye"></i>
											</asp:LinkButton>
											<asp:LinkButton ID="lbRemove" runat="server"
												CommandName="RemoveDocument"
												CommandArgument='<%# Eval("Documents.Id") %>'
												OnClientClick="return confirm('¿Está seguro que desea remover este documento de la lista?');"
												data-tip="Remover de lista">
												<i class="fas fa-trash-alt"></i>
											</asp:LinkButton>
										</div>
									</div>
								</ItemTemplate>
							</asp:Repeater>
						</div>
					</ItemTemplate>
					<FooterTemplate>
						<% if (rptLists.Items.Count == 0)
							{ %>
						<div class="empty-message">No ha creado ninguna lista a&uacute;n.</div>
						<% } %>
					</FooterTemplate>
				</asp:Repeater>
			</div>

			<div id="previewPane" runat="server" class="list-viewer-preview card" visible="false">
				<div class="card-header">
					<span class="preview-title">
						Vista Previa:
						<asp:Label ID="lblPreviewDocName" runat="server" />
					</span>
				</div>
				<div class="card-body">
					<iframe id="previewFrame" runat="server" style="width: 100%; height: 100%; border: none;"></iframe>
				</div>
			</div>
		</div>
	</section>
</asp:Content>
