<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/lib/tenant.php';
require_once dirname(__DIR__) . '/lib/admin_layout.php';

require_admin();
$tenant = get_tenant();

admin_header('Getting Started', 'help');
?>
<div class="panel">
  <h2>Welcome to BarberShop Admin</h2>
  <p class="muted" style="margin:0 0 1rem">
    This is a structured content system — not a free-form page builder.
    Fill in the forms below; the public site reads that data into fixed layouts.
  </p>
  <p style="margin:0">
    Shop: <strong><?= htmlspecialchars(shop_company_name(null, $tenant ?? [])) ?></strong>
    · Public site:
    <a href="<?= APP_BASE ?>/<?= htmlspecialchars(tenant_qs($tenant)) ?>" target="_blank" rel="noopener">
      <?= htmlspecialchars(rtrim(APP_BASE, '/') . '/' . ltrim(tenant_qs($tenant), '/')) ?>
    </a>
  </p>
</div>

<div class="panel">
  <h2>First-time checklist</h2>
  <ol class="howto-list">
    <li>
      <strong>Brand your shop</strong> —
      <a href="<?= APP_BASE ?>/admin/branding.php">Branding</a>:
      primary/secondary colors, company name, font pairing, subdomain or custom domain, license info.
    </li>
    <li>
      <strong>Review images</strong> —
      <a href="<?= APP_BASE ?>/admin/media.php">Media</a>:
      this package already includes the full startup photo set under
      <code>uploads/tenant_<?= (int) ($tenant['id'] ?? 1) ?>/</code>
      (hero, staff, styles, products). Drag &amp; drop replacements as needed,
      crop to the right aspect ratio, and tag them (hero, staff, style, etc.).
    </li>
    <li>
      <strong>Write homepage content</strong> —
      <a href="<?= APP_BASE ?>/admin/content.php">Page Content</a>:
      hero headline, CTA, business address/phone, SEO, announcement bar.
      Pick the hero background from your Media library thumbnails.
    </li>
    <li>
      <strong>Build the service menu</strong> —
      <a href="<?= APP_BASE ?>/admin/services.php">Services</a>:
      name, duration, price, description. Drag the ⋮⋮ handle to reorder.
    </li>
    <li>
      <strong>Add barbers</strong> —
      <a href="<?= APP_BASE ?>/admin/staff.php">Staff</a>:
      photo, bio, specialties, hours, and which services each barber can perform.
    </li>
    <li>
      <strong>Fill the styles gallery</strong> —
      <a href="<?= APP_BASE ?>/admin/styles.php">Styles Gallery</a>:
      select a local upload (or paste a path like <code>uploads/tenant_1/look.webp</code>),
      set a category, and link each look to a service for <em>Book This Look</em>.
    </li>
    <li>
      <strong>Use the calendar</strong> —
      <a href="<?= APP_BASE ?>/admin/calendar.php">Calendar</a>:
      view and manage appointments. Public bookings from the site land here as <em>pending</em>.
    </li>
    <li>
      <strong>Preview the public site</strong> —
      open the link above and walk through Styles → Book → confirm it shows on the calendar.
    </li>
    <li>
      <strong>Give clients the Android app</strong> —
      they download one shared app from
      <a href="https://barber-shop.us/download-app.php" target="_blank" rel="noopener">barber-shop.us/download-app.php</a>
      (or your public footer link <code>/download-app.php</code>).
      Tell them to enter shop name
      <code><?= htmlspecialchars((string) ($tenant['subdomain'] ?? 'yourshop')) ?></code>.
      Android will warn about an unknown source until the app is on Google Play — that is expected.
    </li>
  </ol>
</div>

<div class="grid-2">
  <div class="panel">
    <h2>How media works</h2>
    <ul class="howto-bullets">
      <li><strong>Drag &amp; drop</strong> on Media (or click the drop zone).</li>
      <li>Images open a <strong>crop UI</strong> sized for the tag you chose (16:9 hero, 1:1 staff, 4:5 styles).</li>
      <li>Optimized copies are saved as <strong>WebP</strong> when PHP GD supports it.</li>
      <li>Elsewhere (Page Content, Styles), <strong>click a thumbnail</strong> to attach that file — you don’t need to memorize paths.</li>
      <li>Manual paths also work: <code>uploads/tenant_1/photo.webp</code> or <code>./uploads/image.jpg</code>.</li>
    </ul>
  </div>
  <div class="panel">
    <h2>How bookings work</h2>
    <ul class="howto-bullets">
      <li>Customers pick a service + date; the site shows <strong>only open time slots</strong> from barber hours minus existing bookings.</li>
      <li><em>Find first available</em> jumps to the soonest open chair (next 14 days).</li>
      <li><em>Book This Look</em> pre-selects the linked service, then they choose a slot.</li>
      <li>Requests appear on <a href="<?= APP_BASE ?>/admin/calendar.php">Calendar</a> as <strong>pending</strong> (with assigned barber).</li>
      <li>Clients are saved to the <code>users</code> table (name, phone, email) for reminders.</li>
      <li><strong>Email</strong> is the reliable reminder path (configure SMTP). Carrier text-via-email is optional — if the provider doesn’t accept it, the client uses email.</li>
      <li>Configure channels in <a href="<?= APP_BASE ?>/admin/users.php">Clients &amp; Reminders</a>; run due sends there or via <code>tools/send_reminders.php</code>.</li>
      <li>Change status to confirmed / completed / cancelled, or add walk-ins from the admin form.</li>
      <li>Clients manage their own bookings at <a href="<?= APP_BASE ?>/client/login.php<?= htmlspecialchars(tenant_qs($tenant)) ?>" target="_blank">Client login</a> (password or magic link).</li>
      <li>Cancel/reschedule notice window and fee note: <a href="<?= APP_BASE ?>/admin/policy.php">Client Policy</a> (fees noted on the booking until payments).</li>
      <li>Online pay (Stripe + PayPal/Venmo, Square later): <a href="<?= APP_BASE ?>/admin/payments.php">Payments</a>. Set booking mode to deposit/full/optional, then set per-service deposits under <a href="<?= APP_BASE ?>/admin/services.php">Services</a>.</li>
      <li>Calendar: mark no-show, waive fee, or copy a fee checkout link. Refunds from Payments → Recent payments.</li>
    </ul>
  </div>
</div>

<div class="grid-2">
  <div class="panel">
    <h2>Local URLs</h2>
    <table class="table">
      <tbody>
        <tr><td>Public shop</td><td><a href="<?= APP_BASE ?>/<?= htmlspecialchars(tenant_qs($tenant)) ?>" target="_blank"><?= APP_BASE ?>/</a></td></tr>
        <tr><td>Client portal</td><td><a href="<?= APP_BASE ?>/client/login.php<?= htmlspecialchars(tenant_qs($tenant)) ?>" target="_blank"><?= APP_BASE ?>/client/login.php</a></td></tr>
        <tr><td>Admin login</td><td><a href="<?= APP_BASE ?>/admin/login.php"><?= APP_BASE ?>/admin/login.php</a></td></tr>
        <tr><td>One-time DB setup</td><td><a href="<?= APP_BASE ?>/setup.php" target="_blank"><?= APP_BASE ?>/setup.php</a></td></tr>
        <tr><td>Run new migrations</td><td><a href="<?= APP_BASE ?>/migrate.php" target="_blank"><?= APP_BASE ?>/migrate.php</a></td></tr>
      </tbody>
    </table>
    <p class="muted" style="margin:.75rem 0 0">Default login: <code>admin</code> / <code>password32</code></p>
  </div>
  <div class="panel">
    <h2>Tips</h2>
    <ul class="howto-bullets">
      <li>Keep Apache + MySQL running in XAMPP while developing.</li>
      <li>After pulling new SQL files, open <strong>migrate.php</strong> once.</li>
      <li>Stock photo search (Pexels/Unsplash) needs API keys in config — optional.</li>
      <li>Custom domain on Branding is a routing hook for later hosting; locally use <code>?tenant=…</code>.</li>
      <li>This admin never builds arbitrary pages — only structured fields that feed fixed components.</li>
    </ul>
  </div>
</div>
<?php
admin_footer();
