<?php
/**
 * My Documents shortcode partial.
 *
 * Variables available:
 *   $documents - array of document objects owned by current user
 *   $message   - feedback string (may be empty)
 *   $message_type - 'success' | 'error'
 *
 * @package    Edocman_Lite
 * @subpackage Edocman_Lite/public/partials
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>
<div class="edocman-lite-my-documents-wrap">

    <?php if ( ! empty( $message ) ) : ?>
        <div class="edocman-lite-notice edocman-lite-notice-<?php echo esc_attr( $message_type ); ?>"
             role="alert">
            <?php echo esc_html( $message ); ?>
        </div>
    <?php endif; ?>

    <?php if ( empty( $documents ) ) : ?>
        <p><?php esc_html_e( 'You have not uploaded any documents yet.', 'edocman-lite' ); ?></p>
    <?php else : ?>
        <table class="edocman-lite-table edocman-lite-my-documents-table">
            <thead>
                <tr>
                    <th><?php esc_html_e( 'Title', 'edocman-lite' ); ?></th>
                    <th><?php esc_html_e( 'File', 'edocman-lite' ); ?></th>
                    <th><?php esc_html_e( 'Size', 'edocman-lite' ); ?></th>
                    <th><?php esc_html_e( 'Status', 'edocman-lite' ); ?></th>
                    <th><?php esc_html_e( 'Uploaded', 'edocman-lite' ); ?></th>
                    <th><?php esc_html_e( 'Actions', 'edocman-lite' ); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ( $documents as $edocman_lite_doc ) : ?>
                <tr class="edocman-lite-doc-row" data-document-id="<?php echo esc_attr( $edocman_lite_doc->id ); ?>">
                    <td><?php echo esc_html( $edocman_lite_doc->title ); ?></td>
                    <td><?php echo esc_html( $edocman_lite_doc->original_filename ); ?></td>
                    <td><?php echo esc_html( $edocman_lite_doc->file_size ); ?></td>
                    <td>
                        <?php if ( $edocman_lite_doc->published ) : ?>
                            <span class="edocman-lite-badge edocman-lite-badge-success">
                                <?php esc_html_e( 'Published', 'edocman-lite' ); ?>
                            </span>
                        <?php else : ?>
                            <span class="edocman-lite-badge edocman-lite-badge-pending">
                                <?php esc_html_e( 'Pending', 'edocman-lite' ); ?>
                            </span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php
                        echo esc_html(
                            $edocman_lite_doc->created_time
                                ? date_i18n( get_option( 'date_format' ), strtotime( $edocman_lite_doc->created_time ) )
                                : '—'
                        );
                        ?>
                    </td>
                    <td>
                        <a
                            href="#"
                            class="edocman-lite-delete-my-doc"
                            data-document-id="<?php echo esc_attr( $edocman_lite_doc->id ); ?>"
                            data-nonce="<?php echo esc_attr( wp_create_nonce( 'edocman_lite_delete_my_doc_' . $edocman_lite_doc->id ) ); ?>"
                            aria-label="<?php esc_attr_e( 'Delete document', 'edocman-lite' ); ?>"
                            style="color:#d63638;"
                        ><?php esc_html_e( 'Delete', 'edocman-lite' ); ?></a>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
</div>
