<?php



// 🔽 Then later in your output code:
if (current_user_can('manage_options')) {
    echo '<div class="firefly-admin-1" style="text-align:left;max-width:200px !important;"><div class="firefly-admin-2">Options for this ' . $label_singular . '</div>';
    echo '<div class="firefly-admin-3">';
   
    

echo '<a href="?edit_thing=' . get_the_ID() . '" style="color:black">Edit</a> | ' ;

    


    
    $is_draft = ( get_post_status( $post_id ) === 'draft' );


    /* show either “Hide” or “Show” depending on current status */
    if ( $is_draft ) {
        $show_url = wp_nonce_url(
            admin_url( 'admin-post.php?action=show_thing&post_id=' . $post_id ),
            'show_thing_' . $post_id
        );
        echo '<a href="' . esc_url( $show_url ) . '" style="color:black">Show</a>';
    } else {
        $hide_url = wp_nonce_url(
            admin_url( 'admin-post.php?action=hide_thing&post_id=' . $post_id ),
            'hide_thing_' . $post_id
        );
        echo ' <a href="' . esc_url( $hide_url ) . '" style="color:black">Hide</a>';
    }



$canbesold = get_theme_mod("firefly_thing_can_be_sold_$slug", '');

if ( $canbesold ) {
    $post_id = get_the_ID();
    $is_sold = get_post_meta( $post_id, 'sold', true );

    // Build toggle URL
    $toggle_url = add_query_arg( array(
        'toggle_sold' => $post_id,
        '_wpnonce'    => wp_create_nonce( 'toggle_sold_' . $post_id )
    ), home_url( $_SERVER['REQUEST_URI'] ) );

    // Display status + link
    if ( $is_sold ) {
        echo ' | <a href="' . esc_url( $toggle_url ) . '" style="color:black;">Mark as For Sale</a>';
    } else {
        echo ' | <a href="' . esc_url( $toggle_url ) . '" style="color:black;">Mark as Sold</a>';
    }
}





$canbesoldout = get_theme_mod("firefly_thing_can_be_sold_out_$slug", '');

if ( $canbesoldout ) {
    $post_id = get_the_ID();
    $is_soldout = get_post_meta( $post_id, 'soldout', true );

    // Build toggle URL
    $toggle_url = add_query_arg( array(
        'toggle_soldout' => $post_id,
        '_wpnonce'    => wp_create_nonce( 'toggle_soldout_' . $post_id )
    ), home_url( $_SERVER['REQUEST_URI'] ) );

    // Display status + link
    if ( $is_soldout ) {
        echo ' | <a href="' . esc_url( $toggle_url ) . '" style="color:black;">Mark as Available</a>';
    } else {
        echo ' | <a href="' . esc_url( $toggle_url ) . '" style="color:black;">Mark as Sold Out</a>';
    }
}



echo ' | <a href="?edit_thng_pictures=' . get_the_ID() . '" style="color:black">Pictures</a> ' ;


    echo ' | <a href="' . esc_url(admin_url('admin-post.php?action=delete_thing&post_id=' . get_the_ID() . '&_wpnonce=' . wp_create_nonce('delete_thing_' . get_the_ID()))) . '" style="color:black;" onclick="return confirm(\'Are you sure you want to delete this?\')">Delete</a>';


/* inside the admin-tools snippet */
$dup_nonce  = wp_create_nonce( 'duplicate_thing_' . get_the_ID() );
$dup_url    = add_query_arg( [
    'action'          => 'duplicate_thing',
    'thing_id'        => get_the_ID(),
    '_wpnonce'        => $dup_nonce,
], admin_url( 'admin-post.php' ) );

echo ' | <a href="' . esc_url( $dup_url ) . '" style="color:black">Duplicate</a>';





global $thisisjeff;
if ($thisisjeff) {
// Inside while ( $q->have_posts() ) { … }
$post_id   = get_the_ID();
$debug_url = admin_url(
    'admin-post.php?action=show_thing_meta'
    . '&post_id=' . $post_id
    . '&_wpnonce=' . wp_create_nonce( 'show_meta_' . $post_id )
);

echo ' | <a href="' . esc_url( $debug_url ) . '" target="_blank"  style="color:black">Show all data</a>';

}

    echo '</div>';
    echo '</div>';


}




