{{#explorer-container hideSchema=hideSchema everEditing=everEditing}} {{#if disallow}}

{{i18n "explorer.admins_only"}}

{{else}} {{#unless selectedQueryId}}
{{text-field value=search placeholderKey="explorer.search_placeholder"}} {{d-button action=(action "showCreate") icon="plus" class="no-text btn-right" }} {{pick-files-button class="import-btn" label="explorer.import.label" icon="upload" acceptedFormatsOverride=acceptedImportFileTypes showButton=true onFilesPicked=(action "import") }}
{{#if showCreate}}
{{text-field value=newQueryName placeholderKey="explorer.create_placeholder" }} {{d-button action=(action "create") disabled=createDisabled label="explorer.create" icon="plus" }}
{{/if}} {{#if othersDirty}}
{{d-icon "exclamation-triangle"}} {{i18n "explorer.others_dirty"}}
{{/if}} {{/unless}} {{#if model.length}} {{#unless selectedItem.fake}}
{{#if selectedItem}} {{#if editing}}
{{d-button action=(action "goHome") icon="chevron-left" class="previous" }}
{{text-field value=selectedItem.name}}
{{textarea value=selectedItem.description placeholder=(i18n "explorer.description_placeholder") }}
{{else}}
{{d-button action=(action "goHome") icon="chevron-left" class="previous" }}

{{selectedItem.name}} {{#unless editDisabled}} {{d-icon "pencil-alt"}} {{/unless}}

{{selectedItem.description}}
{{/if}}
{{i18n "explorer.allow_groups"}} {{multi-select value=selectedItem.group_ids content=groupOptions allowAny=false onSelect=(action (mut selectedItem.group_ids)) }} {{#if runDisabled}} {{#unless editing}} {{d-button class="ok" action=(action "save") icon="check" }} {{d-button class="cancel" action=(action "discard") icon="times" }} {{/unless}} {{/if}}
{{! the SQL editor will show the first time you }} {{#if everEditing}}
{{ace-editor content=selectedItem.sql mode="sql"}}
{{#if hideSchema}} {{d-button action=(action "expandSchema") icon="chevron-left" class="no-text unhide" }} {{/if}}
{{explorer-schema schema=schema hideSchema=hideSchema}}
{{d-icon "discourse-expand"}}
{{else}}
{{hljs-code-view value=selectedItem.sql codeClass="sql"}}
{{/if}}
{{#if everEditing}} {{d-button action=(action "save") label="explorer.save" disabled=saveDisable }} {{else}} {{#unless editDisabled}} {{d-button action=(action "editName") label="explorer.edit" icon="pencil-alt" }} {{/unless}} {{/if}} {{d-button action=(action "download") label="explorer.export" disabled=runDisabled icon="download" }} {{#if everEditing}} {{d-button action=(action "showHelpModal") label="explorer.help.label" icon="question-circle" }} {{/if}}
{{#if selectedItem.destroyed}} {{d-button action=(action "recover") class="" icon="undo" label="explorer.recover" }} {{else}} {{#if everEditing}} {{d-button action=(action "discard") icon="undo" label="explorer.undo" disabled=saveDisabled }} {{/if}} {{d-button action=(action "destroy") class="btn-danger" icon="trash-alt" label="explorer.delete" }} {{/if}}
{{/if}}
{{#if selectedItem.hasParams}}
{{#each selectedItem.param_info as |pinfo|}} {{param-input params=selectedItem.params initialValues=parsedParams info=pinfo }} {{/each}}
{{/if}} {{#if runDisabled}} {{#if saveDisabled}} {{d-button label="explorer.run" disabled="true" class="btn-primary" }} {{else}} {{d-button action=(action "saverun") icon="play" label="explorer.saverun" class="btn-primary" }} {{/if}} {{else}} {{d-button action=(action "run") icon="play" label="explorer.run" disabled=runDisabled class="btn-primary" type="submit" }} {{/if}}

{{/unless}} {{conditional-loading-spinner condition=loading}} {{#unless selectedItem.fake}} {{#if results}}
{{#if showResults}} {{query-result query=selectedItem content=results}} {{else}} {{#each results.errors as |err|}}
{{~err}}
{{/each}} {{/if}}
{{/if}} {{/unless}} {{#if showRecentQueries}}
{{#each filteredContent as |query|}} {{else}}
{{i18n "explorer.no_search_results"}} {{/each}}
{{table-header-toggle field="name" labelKey="explorer.query_name" order=order asc=asc automatic=true }}
{{table-header-toggle field="username" labelKey="explorer.query_user" order=order asc=asc automatic=true }}
{{i18n "explorer.query_groups"}}
{{table-header-toggle field="last_run_at" labelKey="explorer.query_time" order=order asc=asc automatic=true }}
{{query.name}} {{query.description}} {{#if query.username}} {{query.username}} {{/if}} {{#each query.group_names as |group|}} {{share-report group=group query=query}} {{/each}} {{#if query.last_run_at}} {{bound-date query.last_run_at}} {{else if query.created_at}} {{bound-date query.created_at}} {{/if}}
{{/if}}
{{/if}} {{/if}} {{/explorer-container}}