<?php
/**
 * Unterkunft bearbeiten / Neue Unterkunft — admin/unterkunft-bearbeiten.php
 *
 * Postbox-Layout (2-Spalten) analog zu Event Manager Pro.
 *
 * @package PocketBookingPro
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

simpbook_display_trial_notice_on_admin_pages();

global $wpdb;
$simpbook_v = Simpbook_Vermietung::instance();

// Tabellen sicherstellen (falls Aktivierungs-Hook nicht lief)
$simpbook_v->tabellen_pruefen_und_erstellen();

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$simpbook_uk_id = isset( $_GET['simpbook_id'] ) ? intval( $_GET['simpbook_id'] ) : 0;
$simpbook_uk    = null;

if ( $simpbook_uk_id > 0 ) {
    $simpbook_uk = $simpbook_v->get_unterkunft( $simpbook_uk_id );
}

// Formular verarbeiten
if ( isset( $_POST['simpbook_unterkunft_speichern'] ) && check_admin_referer( 'simpbook_unterkunft_speichern' ) ) {
    $simpbook_daten = [
        'titel'               => isset( $_POST['simpbook_titel'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_titel'] ) ) : '',
        'untertitel'          => isset( $_POST['simpbook_untertitel'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_untertitel'] ) ) : '',
        'objektbeschreibung'  => isset( $_POST['simpbook_objektbeschreibung'] ) ? wp_kses_post( wp_unslash( $_POST['simpbook_objektbeschreibung'] ) ) : '',
        'status'              => isset( $_POST['simpbook_status'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_status'] ) ) : 'entwurf',
        'unterkunft_typ'      => isset( $_POST['simpbook_unterkunft_typ'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_unterkunft_typ'] ) ) : 'ferienwohnung',
        'vermietungsart'      => isset( $_POST['simpbook_vermietungsart'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_vermietungsart'] ) ) : 'gesamt',
        'preis_pro_nacht'     => isset( $_POST['simpbook_preis_pro_nacht'] ) && '' !== $_POST['simpbook_preis_pro_nacht'] ? floatval( $_POST['simpbook_preis_pro_nacht'] ) : null,
        'preis_pro_woche'     => isset( $_POST['simpbook_preis_pro_woche'] ) && '' !== $_POST['simpbook_preis_pro_woche'] ? floatval( $_POST['simpbook_preis_pro_woche'] ) : null,
        'rabatt_preis_nacht'  => isset( $_POST['simpbook_rabatt_preis_nacht'] ) && '' !== $_POST['simpbook_rabatt_preis_nacht'] ? floatval( $_POST['simpbook_rabatt_preis_nacht'] ) : null,
        'preis_anzeigen'      => isset( $_POST['simpbook_preis_anzeigen'] ) ? 1 : 0,
        'preis_auf_anfrage'   => isset( $_POST['simpbook_preis_auf_anfrage'] ) ? 1 : 0,
        'reinigungsgebuehr'   => isset( $_POST['simpbook_reinigungsgebuehr'] ) && '' !== $_POST['simpbook_reinigungsgebuehr'] ? floatval( $_POST['simpbook_reinigungsgebuehr'] ) : null,
        'kaution'             => isset( $_POST['simpbook_kaution'] ) && '' !== $_POST['simpbook_kaution'] ? floatval( $_POST['simpbook_kaution'] ) : null,
        'max_gaeste'          => isset( $_POST['simpbook_max_gaeste'] ) && '' !== $_POST['simpbook_max_gaeste'] ? intval( $_POST['simpbook_max_gaeste'] ) : null,
        'schlafplaetze'       => isset( $_POST['simpbook_schlafplaetze'] ) && '' !== $_POST['simpbook_schlafplaetze'] ? intval( $_POST['simpbook_schlafplaetze'] ) : null,
        'wohnflaeche'         => isset( $_POST['simpbook_wohnflaeche'] ) && '' !== $_POST['simpbook_wohnflaeche'] ? floatval( $_POST['simpbook_wohnflaeche'] ) : null,
        'strasse'             => isset( $_POST['simpbook_strasse'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_strasse'] ) ) : '',
        'hausnummer'          => isset( $_POST['simpbook_hausnummer'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_hausnummer'] ) ) : '',
        'plz'                 => isset( $_POST['simpbook_plz'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_plz'] ) ) : '',
        'ort'                 => isset( $_POST['simpbook_ort'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_ort'] ) ) : '',
        'bundesland'          => isset( $_POST['simpbook_bundesland'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_bundesland'] ) ) : '',
        'land'                => isset( $_POST['simpbook_land'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_land'] ) ) : 'Deutschland',
        'lage_beschreibung'   => isset( $_POST['simpbook_lage_beschreibung'] ) ? wp_kses_post( wp_unslash( $_POST['simpbook_lage_beschreibung'] ) ) : '',
        'titelbild_id'        => isset( $_POST['simpbook_titelbild_id'] ) && '' !== $_POST['simpbook_titelbild_id'] ? intval( $_POST['simpbook_titelbild_id'] ) : null,
        'mitarbeiter_id'      => isset( $_POST['simpbook_mitarbeiter_id'] ) && '' !== $_POST['simpbook_mitarbeiter_id'] ? intval( $_POST['simpbook_mitarbeiter_id'] ) : null,
        'min_naechte'         => isset( $_POST['simpbook_min_naechte'] ) && '' !== $_POST['simpbook_min_naechte'] ? intval( $_POST['simpbook_min_naechte'] ) : null,
        'max_naechte'         => isset( $_POST['simpbook_max_naechte'] ) && '' !== $_POST['simpbook_max_naechte'] ? intval( $_POST['simpbook_max_naechte'] ) : null,
        'checkin_uhrzeit'     => isset( $_POST['simpbook_checkin_uhrzeit'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_checkin_uhrzeit'] ) ) : null,
        'checkout_uhrzeit'    => isset( $_POST['simpbook_checkout_uhrzeit'] ) ? sanitize_text_field( wp_unslash( $_POST['simpbook_checkout_uhrzeit'] ) ) : null,
        'buchbar_von'         => isset( $_POST['simpbook_buchbar_von'] ) && '' !== $_POST['simpbook_buchbar_von'] ? sanitize_text_field( wp_unslash( $_POST['simpbook_buchbar_von'] ) ) : null,
        'buchbar_bis'         => isset( $_POST['simpbook_buchbar_bis'] ) && '' !== $_POST['simpbook_buchbar_bis'] ? sanitize_text_field( wp_unslash( $_POST['simpbook_buchbar_bis'] ) ) : null,
        'google_maps_anzeigen' => isset( $_POST['simpbook_google_maps_anzeigen'] ) ? 1 : 0,
        'adresse_anzeigen'    => isset( $_POST['simpbook_adresse_anzeigen'] ) ? 1 : 0,
        'sortierung'          => isset( $_POST['simpbook_sortierung'] ) ? intval( $_POST['simpbook_sortierung'] ) : 0,
    ];

    // Ausstattung als JSON
    if ( isset( $_POST['simpbook_ausstattung'] ) && is_array( $_POST['simpbook_ausstattung'] ) ) {
        $simpbook_daten['ausstattung_json'] = wp_json_encode( array_map( 'sanitize_text_field', wp_unslash( $_POST['simpbook_ausstattung'] ) ) );
    }

    // Bilder als JSON
    if ( isset( $_POST['simpbook_bilder_ids'] ) ) {
        $simpbook_bilder = array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['simpbook_bilder_ids'] ) ) ) ) );
        $simpbook_daten['bilder_json'] = wp_json_encode( $simpbook_bilder );
    }

    if ( empty( $simpbook_daten['titel'] ) ) {
        echo '<div class="notice notice-error"><p>' . esc_html__( 'Bitte geben Sie einen Titel ein.', 'simple-appointment-booking' ) . '</p></div>';
    } else {
        if ( $simpbook_uk_id > 0 && $simpbook_uk ) {
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
            $simpbook_result = $wpdb->update( $wpdb->prefix . 'simpbook_unterkuenfte', $simpbook_daten, [ 'id' => $simpbook_uk_id ] );
        } else {
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
            $simpbook_result = $wpdb->insert( $wpdb->prefix . 'simpbook_unterkuenfte', $simpbook_daten );
            $simpbook_uk_id = $wpdb->insert_id;
        }

        if ( false === $simpbook_result ) {
            echo '<div class="notice notice-error"><p>' . esc_html__( 'Fehler beim Speichern:', 'simple-appointment-booking' ) . ' ' . esc_html( $wpdb->last_error ) . '</p></div>';
        } else {
            // Tags speichern
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
            $wpdb->delete( $wpdb->prefix . 'simpbook_unterkunft_tag_zuordnungen', [ 'unterkunft_id' => $simpbook_uk_id ], [ '%d' ] );
            if ( isset( $_POST['simpbook_tags'] ) && is_array( $_POST['simpbook_tags'] ) ) {
                foreach ( array_map( 'intval', $_POST['simpbook_tags'] ) as $tag_id ) {
                    if ( $tag_id > 0 ) {
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
                        $wpdb->insert(
                            $wpdb->prefix . 'simpbook_unterkunft_tag_zuordnungen',
                            [ 'unterkunft_id' => $simpbook_uk_id, 'tag_id' => $tag_id ],
                            [ '%d', '%d' ]
                        );
                    }
                }
            }

            wp_safe_redirect( admin_url( 'admin.php?page=simpbook-unterkuenfte&simpbook_nachricht=gespeichert' ) );
            exit;
        }
    }
}

// Werte aufbereiten
$simpbook_val = function( $field, $default = '' ) use ( $simpbook_uk ) {
    return $simpbook_uk ? ( $simpbook_uk->$field ?? $default ) : $default;
};

// Tags laden
$simpbook_alle_tags  = $simpbook_v->get_tags();
$simpbook_uk_tag_ids = [];
if ( $simpbook_uk_id > 0 ) {
    $simpbook_uk_tags    = $simpbook_v->get_unterkunft_tags( $simpbook_uk_id );
    $simpbook_uk_tag_ids = wp_list_pluck( $simpbook_uk_tags, 'id' );
}

// Zimmer laden
$simpbook_zimmer = [];
if ( $simpbook_uk_id > 0 ) {
    $simpbook_zimmer = $simpbook_v->get_zimmer( $simpbook_uk_id );
}

// Gastgeber (Mitarbeiter) laden
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$simpbook_gastgeber = $wpdb->get_results( "SELECT id, name FROM {$wpdb->prefix}mitarbeiter WHERE aktiv = 1 ORDER BY name ASC" );
if ( ! is_array( $simpbook_gastgeber ) ) {
    $simpbook_gastgeber = [];
}

/**
 * Gibt das Inline-Formular für ein Zimmer aus.
 *
 * @param object|null $z Zimmer-Daten oder null für leeres Formular.
 */
function simpbook_render_zimmer_formular( $z = null ) {
    $zid = $z ? $z->id : 0;
    $val = function( $field, $default = '' ) use ( $z ) {
        return $z ? ( $z->$field ?? $default ) : $default;
    };

    $zimmer_typen = [
        'einzelzimmer'    => __( 'Einzelzimmer', 'simple-appointment-booking' ),
        'doppelzimmer'    => __( 'Doppelzimmer', 'simple-appointment-booking' ),
        'suite'           => __( 'Suite', 'simple-appointment-booking' ),
        'familienzimmer'  => __( 'Familienzimmer', 'simple-appointment-booking' ),
        'studio'          => __( 'Studio', 'simple-appointment-booking' ),
        'mehrbettzimmer'  => __( 'Mehrbettzimmer', 'simple-appointment-booking' ),
        'sonstige'        => __( 'Sonstige', 'simple-appointment-booking' ),
    ];
    ?>
    <input type="hidden" class="simpbook-zimmer-field-id" value="<?php echo esc_attr( $zid ); ?>">
    <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;">
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Name *', 'simple-appointment-booking' ); ?></label>
            <input type="text" class="simpbook-zimmer-field-name widefat" value="<?php echo esc_attr( $val( 'name' ) ); ?>" placeholder="<?php esc_attr_e( 'z.B. Deluxe Doppelzimmer', 'simple-appointment-booking' ); ?>">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Zimmer-Typ', 'simple-appointment-booking' ); ?></label>
            <select class="simpbook-zimmer-field-typ widefat">
                <?php foreach ( $zimmer_typen as $key => $label ) : ?>
                    <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $val( 'zimmer_typ', 'doppelzimmer' ), $key ); ?>><?php echo esc_html( $label ); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div style="margin-top:8px;">
        <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Beschreibung', 'simple-appointment-booking' ); ?></label>
        <textarea class="simpbook-zimmer-field-beschreibung widefat" rows="3" placeholder="<?php esc_attr_e( 'Kurze Beschreibung des Zimmers...', 'simple-appointment-booking' ); ?>"><?php echo esc_textarea( $val( 'beschreibung' ) ); ?></textarea>
    </div>
    <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;margin-top:8px;">
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Preis/Nacht (€)', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-preis widefat" value="<?php echo esc_attr( $val( 'preis_pro_nacht' ) ); ?>" min="0" step="0.01">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Preis/Woche (€)', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-preis-woche widefat" value="<?php echo esc_attr( $val( 'preis_pro_woche' ) ); ?>" min="0" step="0.01">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Rabatt/Nacht (€)', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-rabatt widefat" value="<?php echo esc_attr( $val( 'rabatt_preis_nacht' ) ); ?>" min="0" step="0.01">
        </div>
    </div>
    <div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:10px;margin-top:8px;">
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Max. Gäste', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-gaeste widefat" value="<?php echo esc_attr( $val( 'max_gaeste', 2 ) ); ?>" min="1">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Schlafplätze', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-schlafplaetze widefat" value="<?php echo esc_attr( $val( 'schlafplaetze', 2 ) ); ?>" min="1">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Größe (m²)', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-groesse widefat" value="<?php echo esc_attr( $val( 'zimmergroesse' ) ); ?>" min="0" step="0.5">
        </div>
        <div>
            <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Anzahl verfügbar', 'simple-appointment-booking' ); ?></label>
            <input type="number" class="simpbook-zimmer-field-verfuegbar widefat" value="<?php echo esc_attr( $val( 'anzahl_verfuegbar', 1 ) ); ?>" min="1">
        </div>
    </div>
    <div style="margin-top:8px;">
        <label style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Betten-Beschreibung', 'simple-appointment-booking' ); ?></label>
        <input type="text" class="simpbook-zimmer-field-betten widefat" value="<?php echo esc_attr( $val( 'betten_beschreibung' ) ); ?>" placeholder="<?php esc_attr_e( 'z.B. 1 Doppelbett + 1 Einzelbett', 'simple-appointment-booking' ); ?>">
    </div>
    <div style="display:flex;gap:10px;align-items:center;margin-top:8px;">
        <label style="font-size:11px;display:flex;align-items:center;gap:4px;">
            <input type="checkbox" class="simpbook-zimmer-field-aktiv" value="1" <?php checked( $val( 'aktiv', 1 ), 1 ); ?>>
            <?php esc_html_e( 'Aktiv', 'simple-appointment-booking' ); ?>
        </label>
    </div>
    <div style="margin-top:12px;display:flex;gap:8px;align-items:center;">
        <button type="button" class="button button-primary simpbook-zimmer-save"><?php esc_html_e( 'Zimmer speichern', 'simple-appointment-booking' ); ?></button>
        <button type="button" class="button simpbook-zimmer-cancel"><?php esc_html_e( 'Abbrechen', 'simple-appointment-booking' ); ?></button>
        <span class="spinner simpbook-zimmer-spinner" style="float:none;"></span>
    </div>
    <?php
}

// Unterkunftstypen
$simpbook_typen = [
    'ferienwohnung' => __( 'Ferienwohnung', 'simple-appointment-booking' ),
    'ferienhaus'    => __( 'Ferienhaus', 'simple-appointment-booking' ),
    'hotel'         => __( 'Hotel', 'simple-appointment-booking' ),
    'pension'       => __( 'Pension', 'simple-appointment-booking' ),
    'apartment'     => __( 'Apartment', 'simple-appointment-booking' ),
    'villa'         => __( 'Villa', 'simple-appointment-booking' ),
    'zimmer'        => __( 'Zimmer', 'simple-appointment-booking' ),
    'sonstiges'     => __( 'Sonstiges', 'simple-appointment-booking' ),
];

// Bilder aufbereiten
$simpbook_bilder_ids = [];
$simpbook_bilder_json_val = $simpbook_val( 'bilder_json', '' );
if ( ! empty( $simpbook_bilder_json_val ) ) {
    $simpbook_bilder_ids = json_decode( $simpbook_bilder_json_val, true );
    if ( ! is_array( $simpbook_bilder_ids ) ) {
        $simpbook_bilder_ids = [];
    }
}

// Ausstattung aufbereiten
$simpbook_ausstattung_arr = [];
$simpbook_ausstattung_json_val = $simpbook_val( 'ausstattung_json', '' );
if ( ! empty( $simpbook_ausstattung_json_val ) ) {
    $simpbook_ausstattung_arr = json_decode( $simpbook_ausstattung_json_val, true );
    if ( ! is_array( $simpbook_ausstattung_arr ) ) {
        $simpbook_ausstattung_arr = [];
    }
}

// Titelbild-URL
$simpbook_titelbild_url = '';
$simpbook_titelbild_id_val = $simpbook_val( 'titelbild_id' );
if ( ! empty( $simpbook_titelbild_id_val ) ) {
    $simpbook_titelbild_url = wp_get_attachment_image_url( (int) $simpbook_titelbild_id_val, 'medium' );
}

// Status für Anzeige
$simpbook_v_aktiv = ( 'aktiv' === $simpbook_val( 'status', 'entwurf' ) ) ? 1 : 0;
?>

<div class="wrap simpbook-admin-wrap">
    <h1 class="wp-heading-inline">
        <?php echo $simpbook_uk_id > 0
            ? esc_html__( 'Unterkunft bearbeiten', 'simple-appointment-booking' )
            : esc_html__( 'Neue Unterkunft', 'simple-appointment-booking' ); ?>
    </h1>
    <a href="<?php echo esc_url( admin_url( 'admin.php?page=simpbook-unterkuenfte' ) ); ?>" class="page-title-action">
        &larr; <?php esc_html_e( 'Zurück zur Liste', 'simple-appointment-booking' ); ?>
    </a>
    <hr class="wp-header-end">

    <form method="post" action="" id="simpbook-unterkunft-form" data-unterkunft-id="<?php echo esc_attr( $simpbook_uk_id ); ?>">
        <?php wp_nonce_field( 'simpbook_unterkunft_speichern' ); ?>

        <div id="poststuff">
            <div id="post-body" class="metabox-holder simpbook-columns-2">

                <!-- ============================================ -->
                <!-- HAUPTINHALT (links) -->
                <!-- ============================================ -->
                <div id="post-body-content">

                    <!-- Unterkunft Details -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Unterkunft Details', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <table class="form-table">
                                <tr>
                                    <th><label for="simpbook_titel"><?php esc_html_e( 'Titel *', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_titel" type="text" id="simpbook_titel" value="<?php echo esc_attr( $simpbook_val( 'titel' ) ); ?>" class="large-text" required></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_untertitel"><?php esc_html_e( 'Untertitel', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_untertitel" type="text" id="simpbook_untertitel" value="<?php echo esc_attr( $simpbook_val( 'untertitel' ) ); ?>" class="large-text"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_unterkunft_typ"><?php esc_html_e( 'Unterkunftstyp', 'simple-appointment-booking' ); ?></label></th>
                                    <td>
                                        <select name="simpbook_unterkunft_typ" id="simpbook_unterkunft_typ">
                                            <?php foreach ( $simpbook_typen as $key => $label ) : ?>
                                                <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $simpbook_val( 'unterkunft_typ', 'ferienwohnung' ), $key ); ?>><?php echo esc_html( $label ); ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_vermietungsart"><?php esc_html_e( 'Vermietungsart', 'simple-appointment-booking' ); ?></label></th>
                                    <td>
                                        <select name="simpbook_vermietungsart" id="simpbook_vermietungsart">
                                            <option value="gesamt" <?php selected( $simpbook_val( 'vermietungsart', 'gesamt' ), 'gesamt' ); ?>><?php esc_html_e( 'Gesamte Unterkunft', 'simple-appointment-booking' ); ?></option>
                                            <option value="zimmer" <?php selected( $simpbook_val( 'vermietungsart', 'gesamt' ), 'zimmer' ); ?>><?php esc_html_e( 'Zimmerweise', 'simple-appointment-booking' ); ?></option>
                                        </select>
                                        <p class="description"><?php esc_html_e( 'Gesamte Unterkunft: Vermietet als Ganzes. Zimmerweise: Einzelne Zimmer können separat gebucht werden (z.B. Hotel, Pension).', 'simple-appointment-booking' ); ?></p>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <!-- Beschreibung & Ausstattung -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Beschreibung & Ausstattung', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <table class="form-table">
                                <tr>
                                    <th><label for="simpbook_objektbeschreibung"><?php esc_html_e( 'Objektbeschreibung', 'simple-appointment-booking' ); ?></label></th>
                                    <td>
                                        <?php
                                        wp_editor(
                                            $simpbook_val( 'objektbeschreibung', '' ),
                                            'simpbook_objektbeschreibung',
                                            [
                                                'textarea_name' => 'simpbook_objektbeschreibung',
                                                'textarea_rows' => 10,
                                                'media_buttons' => true,
                                            ]
                                        );
                                        ?>
                                    </td>
                                </tr>
                                <tr>
                                    <th><?php esc_html_e( 'Ausstattung', 'simple-appointment-booking' ); ?></th>
                                    <td>
                                        <div id="simpbook-ausstattung-liste">
                                            <?php if ( ! empty( $simpbook_ausstattung_arr ) ) : ?>
                                                <?php foreach ( $simpbook_ausstattung_arr as $item ) : ?>
                                                    <div class="simpbook-ausstattung-item">
                                                        <input type="text" name="simpbook_ausstattung[]" value="<?php echo esc_attr( $item ); ?>" class="regular-text">
                                                        <button type="button" class="button simpbook-remove-ausstattung">&times;</button>
                                                    </div>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                        </div>
                                        <button type="button" id="simpbook-add-ausstattung" class="button" style="width:100%;margin-top:4px;">
                                            + <?php esc_html_e( 'Ausstattungsmerkmal hinzufügen', 'simple-appointment-booking' ); ?>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <!-- Adresse / Lage -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Adresse / Lage', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <table class="form-table">
                                <tr>
                                    <th><label for="simpbook_strasse"><?php esc_html_e( 'Straße', 'simple-appointment-booking' ); ?></label></th>
                                    <td>
                                        <div style="display:flex;gap:8px;">
                                            <input name="simpbook_strasse" type="text" id="simpbook_strasse" value="<?php echo esc_attr( $simpbook_val( 'strasse' ) ); ?>" class="regular-text" style="flex:1;">
                                            <input name="simpbook_hausnummer" type="text" id="simpbook_hausnummer" value="<?php echo esc_attr( $simpbook_val( 'hausnummer' ) ); ?>" class="small-text" placeholder="<?php esc_attr_e( 'Nr.', 'simple-appointment-booking' ); ?>" style="width:70px;">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_plz"><?php esc_html_e( 'PLZ / Ort', 'simple-appointment-booking' ); ?></label></th>
                                    <td>
                                        <div style="display:flex;gap:8px;">
                                            <input name="simpbook_plz" type="text" id="simpbook_plz" value="<?php echo esc_attr( $simpbook_val( 'plz' ) ); ?>" class="small-text" style="width:80px;">
                                            <input name="simpbook_ort" type="text" id="simpbook_ort" value="<?php echo esc_attr( $simpbook_val( 'ort' ) ); ?>" class="regular-text" style="flex:1;">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_bundesland"><?php esc_html_e( 'Bundesland', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_bundesland" type="text" id="simpbook_bundesland" value="<?php echo esc_attr( $simpbook_val( 'bundesland' ) ); ?>" class="regular-text"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_land"><?php esc_html_e( 'Land', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_land" type="text" id="simpbook_land" value="<?php echo esc_attr( $simpbook_val( 'land', 'Deutschland' ) ); ?>" class="regular-text"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_lage_beschreibung"><?php esc_html_e( 'Lagebeschreibung', 'simple-appointment-booking' ); ?></label></th>
                                    <td><textarea name="simpbook_lage_beschreibung" id="simpbook_lage_beschreibung" rows="4" class="large-text"><?php echo esc_textarea( $simpbook_val( 'lage_beschreibung' ) ); ?></textarea></td>
                                </tr>
                                <tr>
                                    <th><?php esc_html_e( 'Kartenoptionen', 'simple-appointment-booking' ); ?></th>
                                    <td>
                                        <label><input type="checkbox" name="simpbook_google_maps_anzeigen" value="1" <?php checked( $simpbook_val( 'google_maps_anzeigen', 1 ), 1 ); ?>> <?php esc_html_e( 'Google Maps anzeigen', 'simple-appointment-booking' ); ?></label><br>
                                        <label><input type="checkbox" name="simpbook_adresse_anzeigen" value="1" <?php checked( $simpbook_val( 'adresse_anzeigen', 1 ), 1 ); ?>> <?php esc_html_e( 'Adresse im Frontend anzeigen', 'simple-appointment-booking' ); ?></label>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <!-- Verfügbarkeit -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Verfügbarkeit', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <table class="form-table">
                                <tr>
                                    <th><label for="simpbook_min_naechte"><?php esc_html_e( 'Mindest-Nächte', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_min_naechte" type="number" id="simpbook_min_naechte" value="<?php echo esc_attr( $simpbook_val( 'min_naechte' ) ); ?>" min="1" class="small-text"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_max_naechte"><?php esc_html_e( 'Maximale Nächte', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_max_naechte" type="number" id="simpbook_max_naechte" value="<?php echo esc_attr( $simpbook_val( 'max_naechte' ) ); ?>" min="1" class="small-text"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_checkin_uhrzeit"><?php esc_html_e( 'Check-in Uhrzeit', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_checkin_uhrzeit" type="time" id="simpbook_checkin_uhrzeit" value="<?php echo esc_attr( $simpbook_val( 'checkin_uhrzeit', '15:00' ) ); ?>"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_checkout_uhrzeit"><?php esc_html_e( 'Check-out Uhrzeit', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_checkout_uhrzeit" type="time" id="simpbook_checkout_uhrzeit" value="<?php echo esc_attr( $simpbook_val( 'checkout_uhrzeit', '11:00' ) ); ?>"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_buchbar_von"><?php esc_html_e( 'Buchbar von', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_buchbar_von" type="date" id="simpbook_buchbar_von" value="<?php echo esc_attr( $simpbook_val( 'buchbar_von' ) ); ?>"></td>
                                </tr>
                                <tr>
                                    <th><label for="simpbook_buchbar_bis"><?php esc_html_e( 'Buchbar bis', 'simple-appointment-booking' ); ?></label></th>
                                    <td><input name="simpbook_buchbar_bis" type="date" id="simpbook_buchbar_bis" value="<?php echo esc_attr( $simpbook_val( 'buchbar_bis' ) ); ?>"></td>
                                </tr>
                            </table>
                            <?php if ( $simpbook_uk_id > 0 ) : ?>
                                <hr>
                                <h3><?php esc_html_e( 'Blockierte Zeiträume / Saisonpreise', 'simple-appointment-booking' ); ?></h3>
                                <p class="description"><?php esc_html_e( 'Blockierungen und Saisonpreise werden per JS-Kalender gesteuert.', 'simple-appointment-booking' ); ?></p>
                                <div id="simpbook-verfuegbarkeit-kalender" data-unterkunft-id="<?php echo esc_attr( $simpbook_uk_id ); ?>"></div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <!-- Zimmer (nur bei zimmerweiser Vermietung) -->
                    <?php if ( 'zimmer' === $simpbook_val( 'vermietungsart', 'gesamt' ) || $simpbook_uk_id > 0 ) : ?>
                    <div class="postbox" id="simpbook-zimmer-postbox" style="<?php echo 'zimmer' !== $simpbook_val( 'vermietungsart', 'gesamt' ) ? 'display:none;' : ''; ?>">
                        <h2 class="hndle"><span><?php esc_html_e( 'Zimmer verwalten', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <?php if ( $simpbook_uk_id > 0 ) : ?>
                                <!-- Zimmer-Liste -->
                                <div id="simpbook-zimmer-liste">
                                    <?php if ( ! empty( $simpbook_zimmer ) ) : ?>
                                        <?php foreach ( $simpbook_zimmer as $z ) : ?>
                                            <div class="simpbook-zimmer-row" data-zimmer-id="<?php echo esc_attr( $z->id ); ?>">
                                                <div class="simpbook-zimmer-row-header">
                                                    <div class="simpbook-zimmer-row-info">
                                                        <strong class="simpbook-zimmer-name"><?php echo esc_html( $z->name ); ?></strong>
                                                        <span class="simpbook-zimmer-meta">
                                                            <?php echo esc_html( ucfirst( $z->zimmer_typ ) ); ?>
                                                            <?php if ( $z->zimmergroesse ) : ?> &middot; <?php echo esc_html( $z->zimmergroesse ); ?> m²<?php endif; ?>
                                                            &middot; <?php echo esc_html( $z->max_gaeste ); ?> <?php esc_html_e( 'Gäste', 'simple-appointment-booking' ); ?>
                                                            <?php if ( $z->preis_pro_nacht ) : ?> &middot; <?php echo esc_html( number_format( (float) $z->preis_pro_nacht, 2, ',', '.' ) ); ?> €/<?php esc_html_e( 'Nacht', 'simple-appointment-booking' ); ?><?php endif; ?>
                                                            <?php if ( ! $z->aktiv ) : ?> &middot; <span style="color:#b32d2e;"><?php esc_html_e( 'Inaktiv', 'simple-appointment-booking' ); ?></span><?php endif; ?>
                                                        </span>
                                                    </div>
                                                    <div class="simpbook-zimmer-row-actions">
                                                        <button type="button" class="button button-small simpbook-zimmer-edit" title="<?php esc_attr_e( 'Bearbeiten', 'simple-appointment-booking' ); ?>"><span class="dashicons dashicons-edit" style="font-size:16px;width:16px;height:16px;line-height:1.8;"></span></button>
                                                        <button type="button" class="button button-small simpbook-zimmer-delete" title="<?php esc_attr_e( 'Löschen', 'simple-appointment-booking' ); ?>"><span class="dashicons dashicons-trash" style="font-size:16px;width:16px;height:16px;line-height:1.8;color:#b32d2e;"></span></button>
                                                    </div>
                                                </div>
                                                <!-- Inline-Edit-Formular (versteckt) -->
                                                <div class="simpbook-zimmer-edit-form" style="display:none;">
                                                    <?php simpbook_render_zimmer_formular( $z ); ?>
                                                </div>
                                            </div>
                                        <?php endforeach; ?>
                                    <?php endif; ?>
                                </div>

                                <!-- Neues Zimmer Formular (versteckt) -->
                                <div id="simpbook-neues-zimmer-form" style="display:none;margin-top:12px;padding:16px;background:#f6f7f7;border:1px solid #dcdcde;border-radius:4px;">
                                    <h4 style="margin:0 0 12px;"><?php esc_html_e( 'Neues Zimmer', 'simple-appointment-booking' ); ?></h4>
                                    <?php simpbook_render_zimmer_formular(); ?>
                                </div>

                                <div style="margin-top:12px;">
                                    <button type="button" id="simpbook-zimmer-hinzufuegen" class="button" style="width:100%;">
                                        <span class="dashicons dashicons-plus-alt2" style="font-size:16px;width:16px;height:16px;line-height:1.8;"></span>
                                        <?php esc_html_e( 'Zimmer hinzufügen', 'simple-appointment-booking' ); ?>
                                    </button>
                                </div>
                            <?php else : ?>
                                <p class="description"><?php esc_html_e( 'Bitte speichern Sie die Unterkunft zuerst, bevor Sie Zimmer hinzufügen.', 'simple-appointment-booking' ); ?></p>
                            <?php endif; ?>
                        </div>
                    </div>
                    <?php endif; ?>

                    <!-- Speichern (unten) -->
                    <p class="submit">
                        <button type="submit" name="simpbook_unterkunft_speichern" class="button button-primary button-large">
                            <?php echo $simpbook_uk_id > 0 ? esc_html__( 'Unterkunft aktualisieren', 'simple-appointment-booking' ) : esc_html__( 'Unterkunft erstellen', 'simple-appointment-booking' ); ?>
                        </button>
                    </p>

                </div><!-- /post-body-content -->

                <!-- ============================================ -->
                <!-- SIDEBAR (rechts) -->
                <!-- ============================================ -->
                <div id="postbox-container-1" class="postbox-container">

                    <!-- Veröffentlichen -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Veröffentlichen', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <div style="margin-bottom:12px;">
                                <label for="simpbook_status_aktiv" style="display:flex;align-items:center;gap:6px;">
                                    <input type="hidden" name="simpbook_status" value="entwurf">
                                    <input name="simpbook_status" type="checkbox" id="simpbook_status_aktiv" value="aktiv" <?php checked( $simpbook_v_aktiv, 1 ); ?>>
                                    <?php esc_html_e( 'Aktiv (im Frontend sichtbar)', 'simple-appointment-booking' ); ?>
                                </label>
                            </div>
                            <button type="submit" name="simpbook_unterkunft_speichern" class="button button-primary button-large" style="width:100%;">
                                <?php echo $simpbook_uk_id > 0 ? esc_html__( 'Unterkunft aktualisieren', 'simple-appointment-booking' ) : esc_html__( 'Unterkunft erstellen', 'simple-appointment-booking' ); ?>
                            </button>
                        </div>
                    </div>

                    <!-- Preise & Kapazität -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Preise & Kapazität', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_preis_pro_nacht" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Preis pro Nacht (€)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_preis_pro_nacht" type="number" id="simpbook_preis_pro_nacht" value="<?php echo esc_attr( $simpbook_val( 'preis_pro_nacht' ) ); ?>" min="0" step="0.01" style="width:100%;">
                            </p>
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_preis_pro_woche" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Preis pro Woche (€)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_preis_pro_woche" type="number" id="simpbook_preis_pro_woche" value="<?php echo esc_attr( $simpbook_val( 'preis_pro_woche' ) ); ?>" min="0" step="0.01" style="width:100%;">
                            </p>
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_rabatt_preis_nacht" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Rabatt-Preis/Nacht (€)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_rabatt_preis_nacht" type="number" id="simpbook_rabatt_preis_nacht" value="<?php echo esc_attr( $simpbook_val( 'rabatt_preis_nacht' ) ); ?>" min="0" step="0.01" style="width:100%;">
                                <small class="description"><?php esc_html_e( 'Wird im Frontend durchgestrichen daneben angezeigt.', 'simple-appointment-booking' ); ?></small>
                            </p>
                            <hr style="border:none;border-top:1px solid #eee;margin:10px 0;">
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_reinigungsgebuehr" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Reinigungsgebühr (€)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_reinigungsgebuehr" type="number" id="simpbook_reinigungsgebuehr" value="<?php echo esc_attr( $simpbook_val( 'reinigungsgebuehr' ) ); ?>" min="0" step="0.01" style="width:100%;">
                            </p>
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_kaution" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Kaution (€)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_kaution" type="number" id="simpbook_kaution" value="<?php echo esc_attr( $simpbook_val( 'kaution' ) ); ?>" min="0" step="0.01" style="width:100%;">
                            </p>
                            <hr style="border:none;border-top:1px solid #eee;margin:10px 0;">
                            <p style="margin-bottom:4px;">
                                <label><input type="checkbox" name="simpbook_preis_anzeigen" value="1" <?php checked( $simpbook_val( 'preis_anzeigen', 1 ), 1 ); ?>> <?php esc_html_e( 'Preis im Frontend anzeigen', 'simple-appointment-booking' ); ?></label>
                            </p>
                            <p style="margin-bottom:4px;">
                                <label><input type="checkbox" name="simpbook_preis_auf_anfrage" value="1" <?php checked( $simpbook_val( 'preis_auf_anfrage', 0 ), 1 ); ?>> <?php esc_html_e( 'Preis auf Anfrage', 'simple-appointment-booking' ); ?></label>
                            </p>
                            <hr style="border:none;border-top:1px solid #eee;margin:10px 0;">
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_max_gaeste" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Max. Gäste', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_max_gaeste" type="number" id="simpbook_max_gaeste" value="<?php echo esc_attr( $simpbook_val( 'max_gaeste' ) ); ?>" min="1" style="width:100%;">
                            </p>
                            <p style="margin-bottom:4px;">
                                <label for="simpbook_schlafplaetze" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Schlafplätze', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_schlafplaetze" type="number" id="simpbook_schlafplaetze" value="<?php echo esc_attr( $simpbook_val( 'schlafplaetze' ) ); ?>" min="1" style="width:100%;">
                            </p>
                            <p style="margin-bottom:0;">
                                <label for="simpbook_wohnflaeche" style="font-size:11px;color:#666;display:block;margin-bottom:2px;"><?php esc_html_e( 'Wohnfläche (m²)', 'simple-appointment-booking' ); ?></label>
                                <input name="simpbook_wohnflaeche" type="number" id="simpbook_wohnflaeche" value="<?php echo esc_attr( $simpbook_val( 'wohnflaeche' ) ); ?>" min="0" step="0.5" style="width:100%;">
                            </p>
                        </div>
                    </div>

                    <!-- Unterkunftsbild -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Titelbild', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <div id="simpbook-titelbild-preview" style="margin-bottom:8px;">
                                <?php if ( $simpbook_titelbild_url ) : ?>
                                    <img src="<?php echo esc_url( $simpbook_titelbild_url ); ?>" style="max-width:100%;border-radius:4px;">
                                <?php endif; ?>
                            </div>
                            <input type="hidden" name="simpbook_titelbild_id" id="simpbook_titelbild_id" value="<?php echo esc_attr( $simpbook_val( 'titelbild_id' ) ); ?>">
                            <button type="button" id="simpbook-titelbild-waehlen" class="button" style="width:100%;"><?php esc_html_e( 'Titelbild wählen', 'simple-appointment-booking' ); ?></button>
                            <button type="button" id="simpbook-titelbild-entfernen" class="button" style="width:100%;margin-top:4px;<?php echo empty( $simpbook_titelbild_id_val ) ? 'display:none;' : ''; ?>"><?php esc_html_e( 'Entfernen', 'simple-appointment-booking' ); ?></button>
                        </div>
                    </div>

                    <!-- Galerie -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Galerie-Bilder', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <div id="simpbook-galerie-preview" style="display:flex;flex-wrap:wrap;gap:8px;margin-bottom:8px;">
                                <?php foreach ( $simpbook_bilder_ids as $bild_id ) : ?>
                                    <div class="simpbook-galerie-bild" data-id="<?php echo esc_attr( $bild_id ); ?>">
                                        <?php echo wp_get_attachment_image( $bild_id, 'thumbnail', false, [ 'style' => 'border-radius:4px;width:60px;height:60px;object-fit:cover;' ] ); ?>
                                        <button type="button" class="simpbook-galerie-remove">&times;</button>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                            <input type="hidden" name="simpbook_bilder_ids" id="simpbook_bilder_ids" value="<?php echo esc_attr( implode( ',', $simpbook_bilder_ids ) ); ?>">
                            <button type="button" id="simpbook-galerie-hinzufuegen" class="button" style="width:100%;"><?php esc_html_e( 'Bilder hinzufügen', 'simple-appointment-booking' ); ?></button>
                        </div>
                    </div>

                    <!-- Tags -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Tags', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <?php if ( ! empty( $simpbook_alle_tags ) ) : ?>
                                <div style="display:flex;flex-direction:column;gap:6px;">
                                    <?php foreach ( $simpbook_alle_tags as $tag ) : ?>
                                        <label style="display:flex;align-items:center;gap:8px;padding:6px 10px;background:#f6f7f7;border:1px solid #dcdcde;border-radius:4px;cursor:pointer;">
                                            <input type="checkbox" name="simpbook_tags[]" value="<?php echo esc_attr( $tag->id ); ?>"
                                                <?php checked( in_array( (int) $tag->id, $simpbook_uk_tag_ids, true ) ); ?>>
                                            <span style="background:<?php echo esc_attr( $tag->farbe ); ?>;color:#fff;padding:2px 8px;border-radius:4px;font-size:12px;">
                                                <?php echo esc_html( $tag->name ); ?>
                                            </span>
                                        </label>
                                    <?php endforeach; ?>
                                </div>
                            <?php else : ?>
                                <p class="description"><?php esc_html_e( 'Noch keine Tags vorhanden.', 'simple-appointment-booking' ); ?>
                                <a href="<?php echo esc_url( admin_url( 'admin.php?page=simpbook-unterkunft-tags' ) ); ?>"><?php esc_html_e( 'Tags erstellen', 'simple-appointment-booking' ); ?></a></p>
                            <?php endif; ?>
                        </div>
                    </div>

                    <!-- Gastgeber -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Gastgeber', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <select name="simpbook_mitarbeiter_id" id="simpbook_mitarbeiter_id" style="width:100%;">
                                <option value=""><?php esc_html_e( '— Kein Gastgeber —', 'simple-appointment-booking' ); ?></option>
                                <?php foreach ( $simpbook_gastgeber as $gg ) : ?>
                                    <option value="<?php echo esc_attr( $gg->id ); ?>" <?php selected( $simpbook_val( 'mitarbeiter_id' ), $gg->id ); ?>><?php echo esc_html( $gg->name ); ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                    </div>

                    <!-- Sortierung -->
                    <div class="postbox">
                        <h2 class="hndle"><span><?php esc_html_e( 'Sortierung', 'simple-appointment-booking' ); ?></span></h2>
                        <div class="inside">
                            <input name="simpbook_sortierung" type="number" id="simpbook_sortierung" value="<?php echo esc_attr( $simpbook_val( 'sortierung', 0 ) ); ?>" min="0" style="width:100%;">
                        </div>
                    </div>

                </div><!-- /postbox-container-1 -->

            </div><!-- /post-body -->
        </div><!-- /poststuff -->
    </form>
</div>
