<div class="modal fade project-modal script-modal" id="projectScriptModal" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable"><div class="modal-content">
    <div class="modal-header px-4 py-3">
      <div>
        <div class="psql-kicker"><i class="bi bi-filetype-sql"></i> Portable SQL backup</div>
        <h5 class="modal-title mb-0"><span id="scriptProjectName"></span> · Generate SQL script</h5>
      </div>
      <button class="btn-close btn-close-white" type="button" data-bs-dismiss="modal" aria-label="Close SQL script generator"></button>
    </div>

    <div class="modal-body p-0"><div class="psql-body">

      <div class="psql-conn">
        <div><span class="psql-eyebrow">Connection</span><strong id="scriptConnLabel">—</strong></div>
        <span class="psql-engine" id="scriptEngine"></span>
      </div>

      <div class="psql-grid">
        <section class="psql-card">
          <h6><i class="bi bi-collection"></i> What to export</h6>
          <label class="psql-radio"><input type="radio" name="scriptScope" value="project" checked>
            <span>Project tables only <em data-script-count="project">—</em></span></label>
          <label class="psql-radio"><input type="radio" name="scriptScope" value="all">
            <span>All database tables <em data-script-count="all">—</em></span></label>
          <p class="psql-hint">“Project tables” are the tables this project tracks. “All database tables” dumps every table in the connected database.</p>
        </section>

        <section class="psql-card">
          <h6><i class="bi bi-layout-text-window"></i> Contents</h6>
          <label class="psql-radio"><input type="radio" name="scriptMode" value="structure"><span>Structure only</span></label>
          <label class="psql-radio"><input type="radio" name="scriptMode" value="data"><span>Data only</span></label>
          <label class="psql-radio"><input type="radio" name="scriptMode" value="both" checked><span>Structure <b>and</b> data</span></label>
          <div class="psql-rowlimit">
            <label for="scriptRowLimit">Export up to</label>
            <input type="number" id="scriptRowLimit" min="0" step="1" value="500" inputmode="numeric">
            <span>records from each table. <b>0</b> = all rows.</span>
          </div>
          <div class="psql-rowlimit psql-target">
            <label for="scriptTarget">Write the script for</label>
            <select id="scriptTarget" class="form-select form-select-sm" style="width:auto;display:inline-block">
              <option value="">Same engine as the source</option>
            </select>
          </div>
          <p class="psql-hint" id="scriptTargetHint" style="display:none"><i class="bi bi-arrow-left-right"></i>
            Converted export: table structure and seed data are rewritten in the selected engine's SQL, so the script
            runs directly on that server. Views are engine-specific and are skipped with a note.</p>
        </section>
      </div>

      <details class="psql-advanced">
        <summary><i class="bi bi-sliders2"></i> Advanced options</summary>
        <div class="psql-opts">
          <label class="psql-check"><input type="checkbox" id="scriptDropTable" checked><span><b>DROP TABLE IF EXISTS</b> before each CREATE <em>— clean re-import onto an existing database</em></span></label>
          <label class="psql-check"><input type="checkbox" id="scriptIfNotExists"><span><b>CREATE TABLE IF NOT EXISTS</b> <em>— keep existing tables (ignored when DROP is on)</em></span></label>
          <label class="psql-check"><input type="checkbox" id="scriptDisableFks" checked><span>Disable <b>foreign-key checks</b> while importing <em>— avoids table-order errors (MySQL)</em></span></label>
          <label class="psql-check"><input type="checkbox" id="scriptTransaction" checked><span>Wrap in a <b>transaction</b> <em>— all-or-nothing data load</em></span></label>
          <label class="psql-check"><input type="checkbox" id="scriptExtended" checked><span><b>Multi-row INSERTs</b> <em>— smaller, faster to import</em></span></label>
          <label class="psql-check"><input type="checkbox" id="scriptComments" checked><span>Include a <b>header &amp; section comments</b></span></label>
        </div>
      </details>

      <section class="psql-card psql-picker">
        <div class="psql-picker-head">
          <h6><i class="bi bi-table"></i> Objects <span class="text-muted" id="scriptPickCount"></span></h6>
          <label class="psql-check psql-selectall"><input type="checkbox" id="scriptSelectAll" checked><span>Select all</span></label>
        </div>
        <p class="psql-hint">Leave everything ticked to export the whole scope, or pick specific tables.</p>
        <div class="psql-objects" id="scriptObjects"></div>
      </section>

    </div></div>

    <div class="modal-footer px-4 py-3">
      <span class="psql-footnote me-auto"><i class="bi bi-shield-check"></i> Read-only: your database is never modified by this export.</span>
      <button class="btn btn-light border" type="button" data-bs-dismiss="modal">Close</button>
      <button class="btn btn-primary" id="scriptGenerate" type="button"><i class="bi bi-download me-1"></i>Generate &amp; download</button>
    </div>
  </div></div></div>
</div>
