backend:
  name: git-gateway
  branch: main

# Do not set local_backend here — it is for local dev only (with npx decap-server).
# In production it can leave CMS image previews stale until you log out and back in.

# Repo-root paths must start with "/" (see locations collection below).
# Default for page-level uploads (home gallery, etc.)
media_folder: "/public/images/pages"
public_folder: "/images/pages"

# Uploads are auto-compressed in the browser (see src/pages/nbadmin.html) and
# capped at 4 MB per image/file. The per-file limit is enforced by wrapping the
# built-in image/file widgets in JS — NOT via a top-level media_library block here.
#
# DO NOT add a top-level `media_library:` block with `name: default` (or any other
# `name`). Decap CMS treats ANY `media_library.name` as an EXTERNAL library it must
# look up via `registerMediaLibrary`; because "default" is not registered, the whole
# CMS fails to load with: "Missing external media library 'default'". The built-in
# (default) media library reads `max_file_size` only from each field's own
# `media_library.config`, which is why the limit is applied globally in JS instead.
#
# Why these limits: Netlify git-gateway commits an entry plus ALL its new media in
# one request that must stay under ~8 MB after base64 (~3–4 MB raw media per save).
# Larger batches fail with "Failed to persist entry: TypeError: Failed to fetch".
# Compression + a preSave batch-size check prevent that opaque error.

site_url: https://www.orkneyenergytrail.co.uk
display_url: https://www.orkneyenergytrail.co.uk
show_preview_links: true

# Editorial workflow gives the editor toolbar: Save (draft) + Publish.
# Delete entry lives in the entry's ⋮ menu.
publish_mode: editorial_workflow

editor:
  preview: true

collections:
  - name: "locations"
    label: "Locations"
    label_singular: "Location"
    folder: "src/content/locations"
    create: true
    extension: "md"
    format: "frontmatter"
    # The "slug" field is our URL id. slug: {{fields.slug}} makes the entry slug equal
    # that field.
    slug: "{{fields.slug}}"
    preview_path: "locations/{{fields.slug}}"
    # Leading "/" = repo root (public/). Use {{fields.slug}} (NOT {{slug}}) here:
    # in a media_folder template Decap resolves {{slug}} from the collection
    # IDENTIFIER field (the Title), not from the Slug field. Once a location's
    # Title diverges from its Slug (which we deliberately keep fixed), {{slug}}
    # would send uploads/edited images to a Title-derived folder that doesn't
    # match the location's real folder — leaving the image broken. {{fields.slug}}
    # always resolves to the Slug field, so media stays in one predictable folder.
    media_folder: "/public/images/locations/{{fields.slug}}"
    public_folder: "/images/locations/{{fields.slug}}"
    fields:
      - { label: "Title", name: "title", widget: "string" }
      - label: "Slug (URL id)"
        name: "slug"
        widget: "string"
        pattern: ['^[a-z0-9]+(?:-[a-z0-9]+)*$', "Use lowercase letters, numbers and hyphens only (e.g. barony-mill)."]
        hint: "Forms the web address /locations/your-slug. Set once when creating a location. Do not change this yourself — image uploads are stored in a folder matching the slug. Ask the site team if a slug needs correcting."
      - { label: "Hide Location", name: "hidden", widget: "boolean", default: false, required: false }
      - { label: "One line summary", name: "oneLineSummary", widget: "string", required: false }
      - label: "Energy types"
        name: "energyTypes"
        widget: "select"
        multiple: true
        options: ["wind", "water", "fossil", "energy-systems", "solar", "heat-pump", "museums", "heritage-centres", "grid-connection"]
      - label: "Date"
        name: "date"
        widget: "string"
        hint: "Shown on the location and timeline. Use a specific year or range when possible — e.g. 1873, 1980s, 3000–2000 BC, early 1800s, 300 BC. The site assigns an era automatically (Neolithic Age, Viking Age, Early modern Age, 19th Century, 20th Century, or 21st Century) and sorts locations chronologically within that era."
      - label: "Timeline era (optional override)"
        name: "timelineEra"
        widget: "select"
        required: false
        options:
          - { label: "Auto (from Date)", value: "" }
          - { label: "Neolithic Age", value: "neolithic" }
          - { label: "Viking Age", value: "viking" }
          - { label: "Early modern Age", value: "medieval" }
          - { label: "19th Century", value: "industrial" }
          - { label: "20th Century", value: "modern" }
          - { label: "21st Century", value: "contemporary" }
        hint: "Leave on Auto unless the Date is vague and the timeline places this location in the wrong era."
      - { label: "Publicly accessible", name: "isPubliclyAccessible", widget: "boolean", default: true }
      - label: "Accessibility note"
        name: "accessibilityNote"
        widget: "string"
        required: false
        hint: "Shown in About and Visit tabs with icon. Use phrasing like Explore on foot, Viewable from a distance, or Not open to the public (see /locations legend)."
      - label: "Coordinates"
        name: "coordinates"
        widget: "string"
        required: false
        pattern: ['^\s*-?\d+(\.\d+)?\s*,\s*-?\d+(\.\d+)?\s*$', "Paste as: latitude, longitude — e.g. 59.149124, -2.990749"]
        hint: "In Google Maps, right-click the exact spot and click the latitude, longitude numbers at the top of the menu to copy them, then paste here (e.g. 59.149124, -2.990749). Leave blank if unknown."
      - { label: "What Three Words", name: "whatThreeWords", widget: "string", required: false }
      - label: "Timeline offline location map image"
        name: "offlineMapImage"
        widget: "image"
        required: false
        hint: "Optional image shown as timeline offline background for this location (recommended: /images/map/map-offline-<slug>.jpg)."
      - label: "View images"
        name: "viewImages"
        widget: "list"
        summary: "{{fields.caption || fields.alt || fields.image}}"
        hint: "Photos are auto-compressed on upload. If Save fails, add/save a few images at a time (Netlify limit ~3–4 MB of NEW media per save), then add captions."
        fields:
          - { label: "Image", name: "image", widget: "editable-image", hint: "After choosing an image you can use Edit image to crop or lighten/darken it. Edits are saved as a new file — the original is kept." }
          - { label: "Caption", name: "caption", widget: "string", required: false }
          - { label: "Alt text", name: "alt", widget: "string", required: false, hint: "Describes the image for screen readers. Used as the caption in the gallery if Caption is empty." }
      - label: "Body"
        name: "body"
        widget: "markdown"
        required: false
        editor_components: ["inline-image", "code-block"]
        hint: "About tab text (below key facts). Add images with the image button — put the caption in Alt/caption text (shown under the image)."
      - label: "View videos"
        name: "viewVideos"
        widget: "list"
        required: false
        summary: "{{fields.caption || fields.video}}"
        hint: "Uploaded video files are not shown in installed PWA/offline mode."
        fields:
          - { label: "Video (e.g. .mov)", name: "video", widget: "file" }
          - { label: "Caption", name: "caption", widget: "string", required: false }
      - label: "View embedded videos"
        name: "viewEmbeddedVideos"
        widget: "list"
        required: false
        summary: "{{fields.caption || fields.url}}"
        hint: "Embedded players are lazy-loaded on click and work in PWA when online."
        fields:
          - { label: "Video URL (YouTube/Vimeo)", name: "url", widget: "string" }
          - { label: "Thumbnail image", name: "thumbnail", widget: "image", required: false }
          - { label: "Caption", name: "caption", widget: "string", required: false }
      - label: "View 360s"
        name: "view360s"
        widget: "list"
        summary: "{{fields.caption || fields.media}}"
        hint: "Upload equirectangular panorama images only (not Google links). Prefer one at a time — panoramas are large. Photos/panos are auto-compressed on upload."
        fields:
          - label: "360 image"
            name: "media"
            widget: "file"
            choose_url: false
          - { label: "Caption", name: "caption", widget: "string", required: false }
      - label: "View 360 tours (embedded)"
        name: "view360Tours"
        widget: "list"
        required: false
        summary: "{{fields.caption || fields.embed}}"
        hint: "For connected Google Street View tours (e.g. EMEC Caldale / Billia Croo). In Google Maps open the Street View tour, choose Share → Embed a map, copy the code, and paste it here. A plain embed URL also works. Embeds need an internet connection (not shown offline)."
        fields:
          - label: "Google Maps embed (iframe code or URL)"
            name: "embed"
            widget: "text"
            pattern: ['https://([a-z0-9-]+\.)?google\.com/maps/embed', "This doesn't look like a Google Maps embed. Use Share → Embed a map in Google Maps and paste the code (or a URL). It must contain a https://www.google.com/maps/embed… address, otherwise the tour won't show on the page."]
          - { label: "Caption", name: "caption", widget: "string", required: false }
      - { label: "Visit practical info", name: "visitPractical", widget: "markdown", required: false, editor_components: ["inline-image", "code-block"], hint: "Rich text — use the toolbar for bold, lists and links. You no longer need to type HTML; existing entries still display correctly." }
      - label: "Visitor Guidelines"
        name: "visitorGuidelines"
        widget: "list"
        required: false
        fields:
          - label: "Icon"
            name: "icon"
            widget: "select"
            options:
              - { label: "Explore on foot", value: "footstep" }
              - { label: "Viewable from a distance", value: "mdi:binoculars" }
              - { label: "Not open to the public", value: "mdi:account-off-outline" }
              - { label: "Parking", value: "mdi:parking" }
              - { label: "Car / driving", value: "mdi:car" }
              - { label: "Toilets", value: "toilet" }
              - { label: "Disabled access toilets", value: "wheelchair-wc" }
              - { label: "Wheelchair accessible", value: "wheelchair" }
              - { label: "Bus route", value: "mdi:bus" }
              - { label: "Bins / litter", value: "mdi:trash-can-outline" }
              - { label: "Benches", value: "mdi:bench-back" }
              - { label: "Footpath", value: "mdi:walk" }
              - { label: "Café", value: "mdi:coffee" }
              - { label: "Dog", value: "mdi:dog" }
              - { label: "Gate", value: "mdi:gate" }
              - { label: "Wind / weather", value: "mdi:weather-windy" }
              - { label: "Camera / photography", value: "mdi:camera" }
              - { label: "Information", value: "mdi:information-outline" }
              - { label: "Map / location", value: "mdi:map-marker" }
              - { label: "Directions", value: "mdi:directions" }
              - { label: "Cycling", value: "mdi:bike" }
              - { label: "Clock / opening times", value: "mdi:clock-outline" }
              - { label: "Ticket", value: "mdi:ticket-outline" }
              - { label: "Wifi", value: "mdi:wifi" }
              - { label: "Phone", value: "mdi:phone" }
              - { label: "Email", value: "mdi:email-outline" }
              - { label: "Website", value: "mdi:web" }
              - { label: "Tree / nature", value: "mdi:tree" }
              - { label: "Water", value: "mdi:water" }
              - { label: "Fire / heat", value: "mdi:fire" }
              - { label: "Leaf / eco", value: "mdi:leaf" }
          - { label: "Guideline text", name: "text", widget: "string", required: false }

  - name: "pages"
    label: "Pages"
    files:
      - label: "Homepage"
        name: "home"
        file: "src/content/pages/home.md"
        preview_path: ""
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - label: "Banner"
            name: "banner"
            widget: "object"
            collapsed: false
            fields:
              - { label: "Title", name: "title", widget: "string", required: false }
              - { label: "Text", name: "text", widget: "text", required: false }
              - label: "Image"
                name: "image"
                widget: "object"
                required: false
                fields:
                  - { label: "URL", name: "url", widget: "image" }
                  - { label: "Alt Text", name: "alt", widget: "string", required: false }
              - { label: "Caption", name: "caption", widget: "string", required: false }
              - label: "CTA"
                name: "cta"
                widget: "object"
                required: false
                fields:
                  - { label: "Text", name: "text", widget: "string" }
                  - { label: "Link", name: "link", widget: "string" }
                  - { label: "Icon", name: "icon", widget: "string", default: "arrow-down", required: false }
          - label: "Blocks"
            name: "blocks"
            widget: "list"
            required: false
            types:
              - label: "Content"
                name: "content"
                widget: "object"
                fields:
                  - { label: "Heading", name: "heading", widget: "string", required: false }
                  - { label: "Heading Level", name: "headingLevel", widget: "select", options: ["h1", "h2", "h3", "h4", "h5", "h6"], required: false }
                  - { label: "Content", name: "content", widget: "markdown", editor_components: ["inline-image", "code-block"], hint: "Use the image button to add photos — put the caption in Alt/caption text (shown under the image)." }
              - label: "Gallery"
                name: "gallery"
                widget: "object"
                fields:
                  - { label: "Heading", name: "heading", widget: "string", required: false }
                  - { label: "Caption", name: "caption", widget: "string", required: false }
                  - { label: "Per Row", name: "perRow", widget: "number", default: 3 }
                  - label: "Images"
                    name: "images"
                    widget: "list"
                    fields:
                      - { label: "Image", name: "image", widget: "image" }
                      - { label: "Caption", name: "caption", widget: "string", required: false }
                      - { label: "Alt text", name: "alt", widget: "string", required: false, hint: "Describes the image for screen readers. Used as the caption if Caption is empty." }
              - label: "Slideshow"
                name: "slideshow"
                widget: "object"
                fields:
                  - { label: "Heading", name: "heading", widget: "string", required: false }
                  - { label: "Autoplay", name: "autoplay", widget: "boolean", default: true, required: false }
                  - { label: "Autoplay Interval", name: "autoplayInterval", widget: "number", default: 4096, required: false }
                  - label: "Images"
                    name: "images"
                    widget: "list"
                    fields:
                      - { label: "Image", name: "image", widget: "image" }
                      - { label: "Caption", name: "caption", widget: "string", required: false }
                      - { label: "Alt text", name: "alt", widget: "string", required: false, hint: "Describes the image for screen readers. Used as the caption if Caption is empty." }
              - label: "Quote"
                name: "quote"
                widget: "object"
                fields:
                  - { label: "Text", name: "text", widget: "text" }
                  - { label: "Cite", name: "cite", widget: "string", required: false }
      - label: "Map"
        name: "map"
        file: "src/content/pages/map.md"
        preview_path: "map"
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - { label: "Intro", name: "intro", widget: "markdown", required: false, editor_components: ["inline-image", "code-block"] }
          - label: "About the map popup content"
            name: "mapAboutContent"
            widget: "markdown"
            required: false
            editor_components: ["inline-image", "code-block"]
            hint: "Optional. If empty, the site uses the current default popup content."
          - label: "Responsible visitor popup content"
            name: "mapResponsibleVisitorContent"
            widget: "markdown"
            required: false
            editor_components: ["inline-image", "code-block"]
            hint: "Optional. If empty, the site uses the current default popup content."
      - label: "Timeline"
        name: "timeline"
        file: "src/content/pages/timeline.md"
        preview_path: "timeline"
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - { label: "Intro", name: "intro", widget: "text", required: false }
      - label: "Locations"
        name: "locations-page"
        file: "src/content/pages/locations.md"
        preview_path: "locations"
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - { label: "Intro", name: "intro", widget: "text", required: false }
          - { label: "Optional text below intro", name: "locationsSecondaryText", widget: "markdown", required: false, editor_components: ["inline-image", "code-block"] }
      - label: "About us"
        name: "about"
        file: "src/content/pages/about.md"
        preview_path: "about"
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - { label: "Intro", name: "intro", widget: "text", required: false }  # ← Dodato
          - label: "Blocks"  # ← Dodato
            name: "blocks"
            widget: "list"
            required: false
            types:
              - label: "Content"
                name: "content"
                widget: "object"
                fields:
                  - { label: "Heading", name: "heading", widget: "string", required: false }
                  - { label: "Heading Level", name: "headingLevel", widget: "select", options: ["h1", "h2", "h3", "h4", "h5", "h6"], required: false }
                  - { label: "Content", name: "content", widget: "markdown", editor_components: ["inline-image", "code-block"], hint: "Use the image button to add photos — put the caption in Alt/caption text (shown under the image)." }
              - label: "Gallery"
                name: "gallery"
                widget: "object"
                fields:
                  - { label: "Heading", name: "heading", widget: "string", required: false }
                  - { label: "Caption", name: "caption", widget: "string", required: false }
                  - { label: "Per Row", name: "perRow", widget: "number", default: 3 }
                  - label: "Images"
                    name: "images"
                    widget: "list"
                    fields:
                      - { label: "Image", name: "image", widget: "image" }
                      - { label: "Caption", name: "caption", widget: "string", required: false }
                      - { label: "Alt text", name: "alt", widget: "string", required: false, hint: "Describes the image for screen readers. Used as the caption if Caption is empty." }
              - label: "Quote"
                name: "quote"
                widget: "object"
                fields:
                  - { label: "Text", name: "text", widget: "text" }
                  - { label: "Cite", name: "cite", widget: "string", required: false }
      - label: "Contact"
        name: "contact"
        file: "src/content/pages/contact.md"
        preview_path: "contact"
        fields:
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Meta Title", name: "meta_title", widget: "string", required: false }
          - { label: "Meta Description", name: "meta_desc", widget: "text", required: false }
          - { label: "Intro", name: "intro", widget: "text", required: false }
          - label: "Body"
            name: "body"
            widget: "markdown"
            required: false
            editor_components: ["inline-image", "code-block"]
            hint: "Main contact page text (shown above the contact details). This is the content editors have been updating directly in the markdown file."
          - { label: "Optional text above form", name: "contactSecondaryText", widget: "markdown", required: false, editor_components: ["inline-image", "code-block"] }
