var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
import * as plugins from '../../plugins.js';
import { DeesElement, property, html, customElement, css, cssManager, unsafeCSS, state, } from '@design.estate/dees-element';
import * as sharedStyles from '../../styles/shared.styles.js';
import { demoFunc } from './upladmin-incident-form.demo.js';
let UpladminIncidentForm = (() => {
    let _classDecorators = [customElement('upladmin-incident-form')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _incident_decorators;
    let _incident_initializers = [];
    let _incident_extraInitializers = [];
    let _availableServices_decorators;
    let _availableServices_initializers = [];
    let _availableServices_extraInitializers = [];
    let _loading_decorators;
    let _loading_initializers = [];
    let _loading_extraInitializers = [];
    let _formData_decorators;
    let _formData_initializers = [];
    let _formData_extraInitializers = [];
    let _errors_decorators;
    let _errors_initializers = [];
    let _errors_extraInitializers = [];
    var UpladminIncidentForm = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _incident_decorators = [property({ type: Object })];
            _availableServices_decorators = [property({ type: Array })];
            _loading_decorators = [property({ type: Boolean })];
            _formData_decorators = [state()];
            _errors_decorators = [state()];
            __esDecorate(this, null, _incident_decorators, { kind: "accessor", name: "incident", static: false, private: false, access: { has: obj => "incident" in obj, get: obj => obj.incident, set: (obj, value) => { obj.incident = value; } }, metadata: _metadata }, _incident_initializers, _incident_extraInitializers);
            __esDecorate(this, null, _availableServices_decorators, { kind: "accessor", name: "availableServices", static: false, private: false, access: { has: obj => "availableServices" in obj, get: obj => obj.availableServices, set: (obj, value) => { obj.availableServices = value; } }, metadata: _metadata }, _availableServices_initializers, _availableServices_extraInitializers);
            __esDecorate(this, null, _loading_decorators, { kind: "accessor", name: "loading", static: false, private: false, access: { has: obj => "loading" in obj, get: obj => obj.loading, set: (obj, value) => { obj.loading = value; } }, metadata: _metadata }, _loading_initializers, _loading_extraInitializers);
            __esDecorate(this, null, _formData_decorators, { kind: "accessor", name: "formData", static: false, private: false, access: { has: obj => "formData" in obj, get: obj => obj.formData, set: (obj, value) => { obj.formData = value; } }, metadata: _metadata }, _formData_initializers, _formData_extraInitializers);
            __esDecorate(this, null, _errors_decorators, { kind: "accessor", name: "errors", static: false, private: false, access: { has: obj => "errors" in obj, get: obj => obj.errors, set: (obj, value) => { obj.errors = value; } }, metadata: _metadata }, _errors_initializers, _errors_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            UpladminIncidentForm = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        static demo = demoFunc;
        #incident_accessor_storage = __runInitializers(this, _incident_initializers, null);
        get incident() { return this.#incident_accessor_storage; }
        set incident(value) { this.#incident_accessor_storage = value; }
        #availableServices_accessor_storage = (__runInitializers(this, _incident_extraInitializers), __runInitializers(this, _availableServices_initializers, []));
        get availableServices() { return this.#availableServices_accessor_storage; }
        set availableServices(value) { this.#availableServices_accessor_storage = value; }
        #loading_accessor_storage = (__runInitializers(this, _availableServices_extraInitializers), __runInitializers(this, _loading_initializers, false));
        get loading() { return this.#loading_accessor_storage; }
        set loading(value) { this.#loading_accessor_storage = value; }
        #formData_accessor_storage = (__runInitializers(this, _loading_extraInitializers), __runInitializers(this, _formData_initializers, {
            title: '',
            severity: 'minor',
            status: 'investigating',
            affectedServices: [],
            impact: '',
            rootCause: '',
            resolution: '',
        }));
        get formData() { return this.#formData_accessor_storage; }
        set formData(value) { this.#formData_accessor_storage = value; }
        #errors_accessor_storage = (__runInitializers(this, _formData_extraInitializers), __runInitializers(this, _errors_initializers, {}));
        get errors() { return this.#errors_accessor_storage; }
        set errors(value) { this.#errors_accessor_storage = value; }
        severityIcons = (__runInitializers(this, _errors_extraInitializers), {
            critical: 'lucide:AlertCircle',
            major: 'lucide:AlertTriangle',
            minor: 'lucide:Info',
            maintenance: 'lucide:Wrench',
        });
        statusIcons = {
            investigating: 'lucide:Search',
            identified: 'lucide:Target',
            monitoring: 'lucide:Eye',
            resolved: 'lucide:CheckCircle',
            postmortem: 'lucide:FileText',
        };
        static styles = [
            plugins.domtools.elementBasic.staticStyles,
            sharedStyles.commonStyles,
            css `
      :host {
        display: block;
        font-family: ${unsafeCSS(sharedStyles.fonts.base)};
      }

      .form-container {
        background: ${sharedStyles.colors.background.secondary};
        border: 1px solid ${sharedStyles.colors.border.default};
        border-radius: ${unsafeCSS(sharedStyles.borderRadius.lg)};
        overflow: hidden;
      }

      .form-header {
        display: flex;
        align-items: center;
        gap: ${unsafeCSS(sharedStyles.spacing.md)};
        padding: ${unsafeCSS(sharedStyles.spacing.lg)};
        border-bottom: 1px solid ${sharedStyles.colors.border.default};
        background: ${sharedStyles.colors.background.muted};
      }

      .form-header dees-icon {
        --icon-color: ${cssManager.bdTheme('#f97316', '#fb923c')};
      }

      .form-title-wrapper {
        flex: 1;
      }

      .form-title {
        font-size: 18px;
        font-weight: 600;
        color: ${sharedStyles.colors.text.primary};
        margin: 0;
      }

      .form-subtitle {
        font-size: 13px;
        color: ${sharedStyles.colors.text.muted};
        margin-top: 4px;
      }

      .form-body {
        display: grid;
        gap: ${unsafeCSS(sharedStyles.spacing.lg)};
        padding: ${unsafeCSS(sharedStyles.spacing.lg)};
      }

      dees-form {
        display: contents;
      }

      .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: ${unsafeCSS(sharedStyles.spacing.md)};
      }

      @media (max-width: 600px) {
        .form-row {
          grid-template-columns: 1fr;
        }
      }

      .form-section {
        margin-top: ${unsafeCSS(sharedStyles.spacing.md)};
        padding-top: ${unsafeCSS(sharedStyles.spacing.md)};
        border-top: 1px solid ${sharedStyles.colors.border.light};
      }

      .section-title {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 14px;
        font-weight: 600;
        color: ${sharedStyles.colors.text.primary};
        margin-bottom: ${unsafeCSS(sharedStyles.spacing.md)};
      }

      .section-title dees-icon {
        --icon-color: ${sharedStyles.colors.text.muted};
      }

      .form-actions {
        display: flex;
        justify-content: flex-end;
        gap: ${unsafeCSS(sharedStyles.spacing.sm)};
        padding: ${unsafeCSS(sharedStyles.spacing.md)} ${unsafeCSS(sharedStyles.spacing.lg)};
        border-top: 1px solid ${sharedStyles.colors.border.default};
        background: ${sharedStyles.colors.background.muted};
      }

      .option-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: ${unsafeCSS(sharedStyles.spacing.sm)};
      }

      .option-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        padding: 18px 14px;
        background: ${sharedStyles.colors.background.primary};
        border: 2px solid ${sharedStyles.colors.border.default};
        border-radius: ${unsafeCSS(sharedStyles.borderRadius.base)};
        cursor: pointer;
        transition: all ${unsafeCSS(sharedStyles.durations.fast)} ${unsafeCSS(sharedStyles.easings.default)};
        text-align: center;
      }

      .option-card:hover {
        border-color: ${sharedStyles.colors.border.strong};
        background: ${sharedStyles.colors.background.muted};
      }

      .option-card.selected {
        border-color: ${sharedStyles.colors.accent.primary};
        background: ${cssManager.bdTheme('rgba(59, 130, 246, 0.05)', 'rgba(96, 165, 250, 0.1)')};
      }

      .option-card input {
        display: none;
      }

      .option-label {
        font-size: 13px;
        font-weight: 600;
        color: ${sharedStyles.colors.text.primary};
      }

      .option-desc {
        font-size: 11px;
        color: ${sharedStyles.colors.text.muted};
        line-height: 1.3;
      }

      .severity-critical dees-icon { --icon-color: ${sharedStyles.colors.status.majorOutage}; }
      .severity-major dees-icon { --icon-color: ${sharedStyles.colors.status.partialOutage}; }
      .severity-minor dees-icon { --icon-color: ${sharedStyles.colors.status.degraded}; }
      .severity-maintenance dees-icon { --icon-color: ${sharedStyles.colors.status.maintenance}; }

      .field-label {
        display: block;
        font-size: 13px;
        font-weight: 500;
        color: ${sharedStyles.colors.text.primary};
        margin-bottom: ${unsafeCSS(sharedStyles.spacing.sm)};
      }

      .field-label.required::after {
        content: ' *';
        color: ${sharedStyles.colors.accent.danger};
      }

      .services-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: ${unsafeCSS(sharedStyles.spacing.sm)};
        max-height: 220px;
        overflow-y: auto;
        padding: 4px;
      }

      .service-checkbox {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 14px;
        background: ${sharedStyles.colors.background.primary};
        border: 1px solid ${sharedStyles.colors.border.default};
        border-radius: ${unsafeCSS(sharedStyles.borderRadius.base)};
        cursor: pointer;
        transition: all ${unsafeCSS(sharedStyles.durations.fast)} ${unsafeCSS(sharedStyles.easings.default)};
      }

      .service-checkbox:hover {
        background: ${sharedStyles.colors.background.muted};
        border-color: ${sharedStyles.colors.border.strong};
      }

      .service-checkbox.selected {
        border-color: ${sharedStyles.colors.accent.primary};
        background: ${cssManager.bdTheme('rgba(59, 130, 246, 0.05)', 'rgba(96, 165, 250, 0.1)')};
      }

      .service-checkbox input {
        width: 16px;
        height: 16px;
        accent-color: ${sharedStyles.colors.accent.primary};
        cursor: pointer;
      }

      .service-checkbox label {
        flex: 1;
        font-size: 13px;
        color: ${sharedStyles.colors.text.primary};
        cursor: pointer;
      }

      .status-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        flex-shrink: 0;
      }

      .status-dot.operational { background: ${sharedStyles.colors.status.operational}; }
      .status-dot.degraded { background: ${sharedStyles.colors.status.degraded}; }
      .status-dot.partial_outage { background: ${sharedStyles.colors.status.partialOutage}; }
      .status-dot.major_outage { background: ${sharedStyles.colors.status.majorOutage}; }
      .status-dot.maintenance { background: ${sharedStyles.colors.status.maintenance}; }

      .error-text {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 12px;
        color: ${sharedStyles.colors.accent.danger};
        margin-top: ${unsafeCSS(sharedStyles.spacing.xs)};
      }

      .error-text dees-icon {
        --icon-color: ${sharedStyles.colors.accent.danger};
      }

      /* Style dees-input components */
      dees-input-text {
        --dees-input-background: ${sharedStyles.colors.background.primary};
        --dees-input-border-color: ${sharedStyles.colors.border.default};
      }
    `
        ];
        async connectedCallback() {
            await super.connectedCallback();
            if (this.incident) {
                this.formData = { ...this.incident };
            }
        }
        updated(changedProperties) {
            if (changedProperties.has('incident') && this.incident) {
                this.formData = { ...this.incident };
            }
        }
        render() {
            const isEdit = !!this.incident?.id;
            const severityOptions = [
                { value: 'critical', label: 'Critical', desc: 'Major system failure' },
                { value: 'major', label: 'Major', desc: 'Significant impact' },
                { value: 'minor', label: 'Minor', desc: 'Limited impact' },
                { value: 'maintenance', label: 'Maintenance', desc: 'Planned work' },
            ];
            const statusOptions = [
                { value: 'investigating', label: 'Investigating' },
                { value: 'identified', label: 'Identified' },
                { value: 'monitoring', label: 'Monitoring' },
                { value: 'resolved', label: 'Resolved' },
                { value: 'postmortem', label: 'Postmortem' },
            ];
            return html `
      <div class="form-container">
        <div class="form-header">
          <dees-icon .icon=${isEdit ? 'lucide:Pencil' : 'lucide:AlertTriangle'} .iconSize=${24}></dees-icon>
          <div class="form-title-wrapper">
            <h2 class="form-title">${isEdit ? 'Edit Incident' : 'Create Incident'}</h2>
            <p class="form-subtitle">
              ${isEdit ? 'Update incident details' : 'Report a new incident or maintenance'}
            </p>
          </div>
        </div>

        <div class="form-body">
          <dees-form>
            <dees-input-text
              key="title"
              label="Incident Title"
              .value="${this.formData.title}"
              placeholder="Brief description of the incident"
              required
              @changeSubject="${this.handleTitleChange}"
            ></dees-input-text>

            <div>
              <label class="field-label required">Severity</label>
              <div class="option-grid">
                ${severityOptions.map(opt => html `
                  <label
                    class="option-card severity-${opt.value} ${this.formData.severity === opt.value ? 'selected' : ''}"
                    @click="${() => this.handleSeverityChange(opt.value)}"
                  >
                    <input
                      type="radio"
                      name="severity"
                      value="${opt.value}"
                      ?checked="${this.formData.severity === opt.value}"
                    />
                    <dees-icon .icon=${this.severityIcons[opt.value]} .iconSize=${24}></dees-icon>
                    <span class="option-label">${opt.label}</span>
                    <span class="option-desc">${opt.desc}</span>
                  </label>
                `)}
              </div>
            </div>

            <div>
              <label class="field-label required">Status</label>
              <div class="option-grid">
                ${statusOptions.map(opt => html `
                  <label
                    class="option-card ${this.formData.status === opt.value ? 'selected' : ''}"
                    @click="${() => this.handleStatusChange(opt.value)}"
                  >
                    <input
                      type="radio"
                      name="status"
                      value="${opt.value}"
                      ?checked="${this.formData.status === opt.value}"
                    />
                    <dees-icon .icon=${this.statusIcons[opt.value]} .iconSize=${24}></dees-icon>
                    <span class="option-label">${opt.label}</span>
                  </label>
                `)}
              </div>
            </div>

            <div>
              <label class="field-label required">Affected Services</label>
              <div class="services-grid">
                ${this.availableServices.map(service => html `
                  <div
                    class="service-checkbox ${this.formData.affectedServices.includes(service.id) ? 'selected' : ''}"
                    @click="${() => this.toggleService(service.id)}"
                  >
                    <input
                      type="checkbox"
                      id="service-${service.id}"
                      ?checked="${this.formData.affectedServices.includes(service.id)}"
                    />
                    <span class="status-dot ${service.currentStatus}"></span>
                    <label for="service-${service.id}">${service.displayName || service.name}</label>
                  </div>
                `)}
              </div>
              ${this.errors.affectedServices ? html `
                <div class="error-text">
                  <dees-icon .icon=${'lucide:AlertCircle'} .iconSize=${12}></dees-icon>
                  ${this.errors.affectedServices}
                </div>
              ` : ''}
            </div>

            <dees-input-text
              key="impact"
              label="Impact Description"
              inputType="textarea"
              .value="${this.formData.impact}"
              placeholder="Describe how users are affected by this incident..."
              required
              @changeSubject="${this.handleImpactChange}"
            ></dees-input-text>

            <div class="form-section">
              <div class="section-title">
                <dees-icon .icon=${'lucide:FileSearch'} .iconSize=${16}></dees-icon>
                Resolution Details (Optional)
              </div>
              <div class="form-row">
                <dees-input-text
                  key="rootCause"
                  label="Root Cause"
                  inputType="textarea"
                  .value="${this.formData.rootCause || ''}"
                  placeholder="What caused this incident..."
                  @changeSubject="${this.handleRootCauseChange}"
                ></dees-input-text>

                <dees-input-text
                  key="resolution"
                  label="Resolution"
                  inputType="textarea"
                  .value="${this.formData.resolution || ''}"
                  placeholder="How was this incident resolved..."
                  @changeSubject="${this.handleResolutionChange}"
                ></dees-input-text>
              </div>
            </div>
          </dees-form>
        </div>

        <div class="form-actions">
          <dees-button type="discreet" @click="${this.handleCancel}" ?disabled="${this.loading}">
            Cancel
          </dees-button>
          <dees-button type="highlighted" @click="${this.handleSave}" ?disabled="${this.loading}">
            ${this.loading ? html `<dees-spinner .size=${16}></dees-spinner>` : ''}
            ${isEdit ? 'Update Incident' : 'Create Incident'}
          </dees-button>
        </div>
      </div>
    `;
        }
        handleTitleChange(e) {
            this.formData = { ...this.formData, title: e.detail };
            if (this.errors.title) {
                this.errors = { ...this.errors, title: '' };
            }
        }
        handleImpactChange(e) {
            this.formData = { ...this.formData, impact: e.detail };
            if (this.errors.impact) {
                this.errors = { ...this.errors, impact: '' };
            }
        }
        handleRootCauseChange(e) {
            this.formData = { ...this.formData, rootCause: e.detail };
        }
        handleResolutionChange(e) {
            this.formData = { ...this.formData, resolution: e.detail };
        }
        handleSeverityChange(severity) {
            this.formData = { ...this.formData, severity };
        }
        handleStatusChange(status) {
            this.formData = { ...this.formData, status };
        }
        toggleService(serviceId) {
            const current = this.formData.affectedServices;
            if (current.includes(serviceId)) {
                this.formData = {
                    ...this.formData,
                    affectedServices: current.filter(id => id !== serviceId)
                };
            }
            else {
                this.formData = {
                    ...this.formData,
                    affectedServices: [...current, serviceId]
                };
            }
            if (this.errors.affectedServices) {
                this.errors = { ...this.errors, affectedServices: '' };
            }
        }
        validate() {
            const errors = {};
            if (!this.formData.title?.trim()) {
                errors.title = 'Title is required';
            }
            if (this.formData.affectedServices.length === 0) {
                errors.affectedServices = 'At least one service must be selected';
            }
            if (!this.formData.impact?.trim()) {
                errors.impact = 'Impact description is required';
            }
            this.errors = errors;
            return Object.keys(errors).length === 0;
        }
        handleSave() {
            if (!this.validate()) {
                return;
            }
            this.dispatchEvent(new CustomEvent('incidentSave', {
                detail: { incident: { ...this.formData } },
                bubbles: true,
                composed: true
            }));
        }
        handleCancel() {
            this.dispatchEvent(new CustomEvent('incidentCancel', {
                bubbles: true,
                composed: true
            }));
        }
        reset() {
            this.formData = {
                title: '',
                severity: 'minor',
                status: 'investigating',
                affectedServices: [],
                impact: '',
                rootCause: '',
                resolution: '',
            };
            this.errors = {};
        }
        setIncident(incident) {
            this.formData = { ...incident };
            this.errors = {};
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return UpladminIncidentForm = _classThis;
})();
export { UpladminIncidentForm };
//# sourceMappingURL=data:application/json;base64, 