/**
 * ae_events_stores__pres_mgmt_defaults.ts
 *
 * Type definitions and defaults for the Pres Mgmt stores.
 *
 *   PressMgmtRemoteCfg   → shape of event.mod_pres_mgmt_json (server-side admin config)
 *   PresMgmtLocState     → pres_mgmt_loc (PersistedState, localStorage)
 *   PresMgmtSessState    → events_sess.pres_mgmt (in-memory, resets on page load)
 *
 * NAMING CONVENTION (enforced here, must not mix):
 *   hide__*  → feature is ON by default; true = turn it off  (default: false = visible)
 *   show__*  → feature is OFF by default; true = turn it on  (default: false = hidden)
 * Never use both hide__foo and show__foo for the same concept.
 */

// ---------------------------------------------------------------------------
// Remote config — shape of event.mod_pres_mgmt_json
// This is the admin-controlled, server-side config for an event. Every field
// here is synced into every browser unconditionally on event load — there is
// no opt-out. (Removed 2026-06-16: a `lock_config` toggle used to gate this;
// in practice every event always had it set to true and the conditional
// sync it created was an undebuggable source of stale local state — see
// PROJECT__AE_Events_PressMgmt_Config_Cleanup.md.)
// ---------------------------------------------------------------------------
export interface PressMgmtRemoteCfg {
    // Labels — event-specific terminology overrides
    label__person_external_id: string | null; // default: 'External ID'
    label__presenter_external_id: string | null; // default: 'External ID'
    label__session_poc_type: string | null; // e.g. 'champion', 'poc'
    label__session_poc_name: string | null; // e.g. 'Champion', 'Point of Contact'

    // Code visibility (visible by default)
    hide__location_code: boolean;
    hide__presentation_code: boolean;
    hide__presenter_code: boolean;
    hide__session_code: boolean;

    // Session field visibility (visible by default)
    hide__session_description: boolean;
    hide__session_location: boolean;
    hide__session_msg: boolean;
    hide__session_poc: boolean;
    hide__session_poc_biography: boolean;
    hide__session_poc_profile: boolean;
    hide__session_poc_profile_pic: boolean;

    // Presenter field visibility
    hide__presenter_biography: boolean;

    // Presentation field visibility
    hide__presentation_datetime: boolean;
    hide__presentation_description: boolean; // replaces show_content__presentation_description

    // Opt-in features (hidden by default — set true to enable)
    show__copy_access_link: boolean;
    show__email_access_link: boolean;
    show__launcher_link: boolean;
    // POC column in session list/table views. Independent of hide__session_poc
    // (the overall "is POC used at all" master switch) — that one wins if set,
    // see sync_config__event_pres_mgmt() and the session list wrapper usages.
    show__session_li_poc_field: boolean;
    // QR code sections (off by default; Trusted Access users can override locally
    // if the admin has enabled the feature for the event)
    show__session_qr: boolean;
    show__presenter_qr: boolean;

    // Requirements
    require__presenter_agree: boolean;
    require__session_agree: boolean;

    // Navigation / UI constraints
    limit__navigation: boolean;

    // File upload options (null = use system default)
    file_purpose_option_kv: Record<
        string,
        { name: string; disabled?: boolean; hidden?: boolean }
    > | null;

    // Report section visibility (key = report slug, true = hide that report)
    hide__report_kv: Record<string, boolean>;
}

// ---------------------------------------------------------------------------
// Local state — persisted to localStorage via PersistedState ('ae_pres_mgmt_loc')
// Contains both user preferences AND fields synced from PressMgmtRemoteCfg.
// Fields synced from remote are overwritten unconditionally on every event load.
// ---------------------------------------------------------------------------
export interface PresMgmtLocState {
    // --- Query / search preferences ---
    use_12h: boolean;
    qry_enabled: 'all' | 'not_enabled' | 'enabled';
    qry_hidden: 'all' | 'hidden' | 'not_hidden';
    qry_limit__files: number;
    qry_limit__presentations: number;
    qry_limit__presenters: number;
    qry_limit__sessions: number;
    qry_max: number;
    qry__files_offset_seconds: number | null;
    qry__files_sort: string;
    search_version: number;
    qry__remote_first: boolean;
    qry_and__file_count: boolean;
    save_search_text: boolean;
    saved_search__session: string | null;
    saved_search__session_location_name: string | null;
    fulltext_search_qry_str: string | null;    // persisted search text (when save_search_text=true)
    location_name_qry_str: string | null;      // persisted location filter text
    refresh_interval: number;                  // auto-refresh interval in seconds (0 = disabled)

    // --- Time window filter (onsite use: show only sessions near current time) ---
    enable_time_window: boolean;              // false = off (show all); true = apply window
    time_window_before_minutes: number;       // include sessions that started up to N min ago
    time_window_after_minutes: number;        // include sessions starting within next N min

    // --- Report display preferences (user-controlled, persisted) ---
    rpt__session_no_files: boolean;    // show "sessions with no files" report section
    rpt__session_poc_agree: boolean;   // show "session POC agreement" report section
    rpt__session_no_bio: boolean;      // show "sessions with no bio" report section
    rpt__presenter_agree: boolean;     // show "presenter agreement" report section
    qry__file_purpose: string | null;  // filter report files by purpose slug
    qry__files_min_size: number | null; // filter report files by minimum size (bytes)
    qry__session_sort: string;         // sort order for session report
    qry__presenter_sort: string;       // sort order for presenter report

    // --- Content / panel visibility (user preferences) ---
    expand__menu_opts: boolean;
    show_content__device_description: boolean;
    show_content__event_view: string | null;
    show_content__location_description: boolean;
    show_content__location_devices_sessions: 'sessions' | 'devices' | null;
    show_content__location_qr: boolean;
    show_content__presentation_description: boolean; // per-presentation expand toggle
    show_content__presenter_page_help: boolean;
    show_content__presenter_view: string | null;
    show_content__presenter_qr: boolean;
    show_content__session_description: boolean;
    show_content__session_files: boolean;
    show_content__session_help: boolean;
    show_content__session_presentations: boolean;
    show_content__session_search_view: string | null;
    show_content__session_search_help: boolean;
    show_content__session_search_room_name: boolean;
    show_content__session_view: string | null;
    show_content__session_qr: boolean;
    show_content__disabled_files: boolean;
    show_content__hidden_files: boolean;
    show_content__hidden_presentations: boolean;
    show_content__hidden_presenters: boolean;
    show_content__hidden_sessions: boolean;

    // --- List/table column visibility (user preferences) ---
    hide__device_code: boolean;
    hide__locations_msg: boolean;
    hide__session_li_location_field: boolean;
    // Also mirrors PressMgmtRemoteCfg.show__session_li_poc_field — synced
    // unconditionally, see sync_config__event_pres_mgmt().
    show__session_li_poc_field: boolean;
    // Launcher/location links in session list
    hide__launcher_link: boolean; // SvelteKit launcher
    hide__location_link: boolean;
    show__direct_download: boolean;

    // --- Menu visibility (null = use server-side default) ---
    show_menu__presenter: boolean | null;
    show_menu__session: boolean | null;
    show_menu__session_search: boolean | null;
    show_menu__event_reports: boolean | null;
    show_report: string | null;

    // --- Opt-out toggles ---
    disable_submit__opt_out: boolean;
    submit_status__opt_out: string | null;

    // --- Device/location scratch space ---
    device_kv: Record<string, any>;
    location_kv: Record<string, any>;

    // --- Synced from PressMgmtRemoteCfg (overwritten by sync_config__event_pres_mgmt) ---
    // These mirror PressMgmtRemoteCfg fields and are written unconditionally on every
    // event load. Do not set these manually — they will always be overwritten.
    label__person_external_id: string;
    label__presenter_external_id: string;
    label__session_poc_type: string;
    label__session_poc_name: string;
    hide__location_code: boolean;
    hide__presentation_code: boolean;
    hide__presentation_datetime: boolean;
    hide__presentation_description: boolean;
    hide__presenter_code: boolean;
    hide__presenter_biography: boolean;
    hide__session_code: boolean;
    hide__session_description: boolean;
    hide__session_location: boolean;
    hide__session_msg: boolean;
    hide__session_poc: boolean;
    hide__session_poc_biography: boolean;
    hide__session_poc_profile: boolean;
    hide__session_poc_profile_pic: boolean;
    show__copy_access_link: boolean;
    show__email_access_link: boolean;
    show__launcher_link: boolean;
    show__session_qr: boolean;
    show__presenter_qr: boolean;
    require__presenter_agree: boolean;
    require__session_agree: boolean;
    limit__navigation: boolean;
    file_purpose_option_kv: Record<
        string,
        { name: string; disabled?: boolean; hidden?: boolean }
    > | null;
    hide__report_kv: Record<string, boolean>;
}

// ---------------------------------------------------------------------------
// In-memory session state — resets on page load (not persisted)
// ---------------------------------------------------------------------------
export interface PresMgmtSessState {
    presenter__updated_on: string | null;
    session_updated_on: string | null;
    location_name_qry_str: string | null;
    fulltext_search_qry_str: string | null;
    status_qry__search: string | null;
    disable_submit__event_file_obj: boolean;
    show_form__search: boolean;
    show_form__search_results: boolean;
    show_content__agree_text: boolean;
    show_content__presenter_start: boolean;
    show_content__presentation_description: boolean;
    show_report: string | null;
    show_field_edit__filename: boolean;
    new_upload_list: any[] | null;
    files_uploading_count: number | null;
    qry_limit__files: number;
    qry_limit__presentations: number;
    qry_limit__presenters: number;
    qry_limit__sessions: number;
    show_fields__presentation: boolean;
    show_fields__session: boolean;
    show_modal__presenter_agree: boolean;
    show__session_poc_profile: boolean;
    show_modal__session_poc_agree: boolean;
    show__edit_location: Record<string, boolean>;
    show__edit_poc_person: Record<string, boolean>;
    show__view_alert: Record<string, boolean>;
    show__edit_alert_msg: Record<string, boolean>;
    tmp__alert_msg: Record<string, string>;
    session_qr_url: Record<string, string>;
    status_rpt: {
        recent_files: string | null;
        presenters_agree: string | null;
        presenters_biography: string | null;
        file_downloads: string | null;
    };
    rpt__session_no_files: boolean;
    rpt__session_poc_agree: boolean;
    rpt__session_no_bio: boolean;
    rpt__presenter_agree: boolean;
    tmp_val__filename_no_ext: string | null;
}

// ---------------------------------------------------------------------------
// Defaults
// ---------------------------------------------------------------------------

// Persisted pres_mgmt local config — survives browser sessions.
export const pres_mgmt_loc_defaults: PresMgmtLocState = {

    // Query / search
    use_12h: true,
    qry_enabled: 'enabled',
    qry_hidden: 'not_hidden',
    qry_limit__files: 75,
    qry_limit__presentations: 25,
    qry_limit__presenters: 500,
    qry_limit__sessions: 100,
    qry_max: 500,
    qry__files_offset_seconds: null,
    qry__files_sort: 'created_on',
    search_version: 0,
    qry__remote_first: false,
    qry_and__file_count: true,
    save_search_text: true,
    saved_search__session: null,
    saved_search__session_location_name: null,
    fulltext_search_qry_str: null,
    location_name_qry_str: null,
    refresh_interval: 0,

    // Time window filter
    enable_time_window: false,
    time_window_before_minutes: 30,
    time_window_after_minutes: 720,

    // Report display preferences
    rpt__session_no_files: true,
    rpt__session_poc_agree: false,
    rpt__session_no_bio: true,
    rpt__presenter_agree: true,
    qry__file_purpose: null,
    qry__files_min_size: null,
    qry__session_sort: 'name',
    qry__presenter_sort: 'name',

    // Content / panel visibility
    expand__menu_opts: false,
    show_content__device_description: false,
    show_content__location_description: false,
    show_content__location_devices_sessions: null,
    show_content__event_view: null,
    show_content__location_qr: false,
    show_content__presentation_description: false,
    show_content__presenter_page_help: true,
    show_content__presenter_view: null,
    show_content__presenter_qr: false,
    show_content__session_description: false,
    show_content__session_files: false,
    show_content__session_help: true,
    show_content__session_presentations: false,
    show_content__session_search_view: null,
    show_content__session_search_help: true,
    show_content__session_search_room_name: false,
    show_content__session_view: null,
    show_content__session_qr: false,
    show_content__disabled_files: false,
    show_content__hidden_files: false,
    show_content__hidden_presentations: false,
    show_content__hidden_presenters: false,
    show_content__hidden_sessions: false,

    // List/table column visibility
    hide__device_code: false,
    hide__locations_msg: false,
    hide__session_li_location_field: false,
    show__session_li_poc_field: false,
    hide__launcher_link: true,
    hide__location_link: true,
    show__direct_download: false,

    // Menu visibility
    show_menu__presenter: null,
    show_menu__session: null,
    show_menu__session_search: null,
    show_menu__event_reports: null,
    show_report: null,

    // Opt-out
    disable_submit__opt_out: true,
    submit_status__opt_out: null,

    // Scratch space
    device_kv: {},
    location_kv: {},

    // Synced from remote (defaults apply until first event load)
    label__person_external_id: 'External ID',
    label__presenter_external_id: 'External ID',
    label__session_poc_type: 'poc',
    label__session_poc_name: 'Point of Contact',
    hide__location_code: false,
    hide__presentation_code: false,
    hide__presentation_datetime: false,
    hide__presentation_description: false,
    hide__presenter_code: false,
    hide__presenter_biography: true,
    hide__session_code: false,
    hide__session_description: false,
    hide__session_location: false,
    hide__session_msg: true,
    hide__session_poc: true,
    hide__session_poc_biography: true,
    hide__session_poc_profile: false,
    hide__session_poc_profile_pic: false,
    show__copy_access_link: false,
    show__email_access_link: false,
    show__launcher_link: false,
    show__session_qr: false,
    show__presenter_qr: false,
    require__presenter_agree: false,
    require__session_agree: false,
    limit__navigation: false,
    file_purpose_option_kv: null,
    hide__report_kv: {}
};

// In-memory pres_mgmt state — resets on page load.
export const pres_mgmt_sess_defaults: PresMgmtSessState = {
    presenter__updated_on: null,
    session_updated_on: null,
    location_name_qry_str: null,
    fulltext_search_qry_str: null,
    status_qry__search: null,
    disable_submit__event_file_obj: true,
    show_form__search: true,
    show_form__search_results: true,
    show_content__agree_text: false,
    show_content__presenter_start: false,
    show_content__presentation_description: false,
    show_report: null,
    show_field_edit__filename: false,
    new_upload_list: null,
    files_uploading_count: null,
    qry_limit__files: 75,
    qry_limit__presentations: 25,
    qry_limit__presenters: 500,
    qry_limit__sessions: 100,
    show_fields__presentation: true,
    show_fields__session: true,
    show_modal__presenter_agree: false,
    show__session_poc_profile: false,
    show_modal__session_poc_agree: false,
    show__edit_location: {},
    show__edit_poc_person: {},
    show__view_alert: {},
    show__edit_alert_msg: {},
    tmp__alert_msg: {},
    session_qr_url: {},
    status_rpt: {
        recent_files: null,
        presenters_agree: null,
        presenters_biography: null,
        file_downloads: null
    },
    rpt__session_no_files: true,
    rpt__session_poc_agree: false,
    rpt__session_no_bio: true,
    rpt__presenter_agree: true,
    tmp_val__filename_no_ext: null
};
