import {
  DeesElement,
  customElement,
  html,
  css,
  cssManager,
  property,
  type TemplateResult,
} from '@design.estate/dees-element';

declare global {
  interface HTMLElementTagNameMap {
    'sz-quick-actions-card': SzQuickActionsCard;
  }
}

export interface IQuickAction {
  label: string;
  icon?: string;
  primary?: boolean;
  url?: string;
}

@customElement('sz-quick-actions-card')
export class SzQuickActionsCard extends DeesElement {
  public static demo = () => html`
    <div style="padding: 24px; max-width: 800px;">
      <sz-quick-actions-card
        .actions=${[
          { label: 'Deploy Service', icon: 'plus', primary: true },
          { label: 'View All Services' },
          { label: 'Platform Services' },
          { label: 'Manage Domains' },
        ]}
      ></sz-quick-actions-card>
    </div>
  `;

  public static demoGroups = ['Dashboard'];

  @property({ type: Array })
  public accessor actions: IQuickAction[] = [];

  public static styles = [
    cssManager.defaultStyles,
    css`
      :host {
        display: block;
        height: 100%;
      }

      .card {
        background: ${cssManager.bdTheme('#ffffff', '#09090b')};
        border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
        border-radius: 8px;
        padding: 20px;
        height: 100%;
        box-sizing: border-box;
      }

      .header {
        margin-bottom: 16px;
      }

      .title {
        font-size: 16px;
        font-weight: 600;
        color: ${cssManager.bdTheme('#18181b', '#fafafa')};
      }

      .subtitle {
        font-size: 13px;
        color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
        margin-top: 2px;
      }

      .actions {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
      }

      .action-button {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 200ms ease;
        border: none;
        outline: none;
      }

      .action-button.primary {
        background: ${cssManager.bdTheme('#2563eb', '#3b82f6')};
        color: white;
      }

      .action-button.primary:hover {
        background: ${cssManager.bdTheme('#1d4ed8', '#2563eb')};
      }

      .action-button.secondary {
        background: ${cssManager.bdTheme('#ffffff', '#09090b')};
        color: ${cssManager.bdTheme('#18181b', '#fafafa')};
        border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
      }

      .action-button.secondary:hover {
        background: ${cssManager.bdTheme('#f4f4f5', '#18181b')};
        border-color: ${cssManager.bdTheme('#d4d4d8', '#3f3f46')};
      }

      .action-icon {
        width: 16px;
        height: 16px;
      }
    `,
  ];

  public render(): TemplateResult {
    return html`
      <div class="card">
        <div class="header">
          <div class="title">Quick Actions</div>
          <div class="subtitle">Common tasks and shortcuts</div>
        </div>

        <div class="actions">
          ${this.actions.map(
            (action) => html`
              <button
                class="action-button ${action.primary ? 'primary' : 'secondary'}"
                @click=${() => this.handleActionClick(action)}
              >
                ${action.icon === 'plus' ? html`
                  <svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <line x1="12" y1="5" x2="12" y2="19"></line>
                    <line x1="5" y1="12" x2="19" y2="12"></line>
                  </svg>
                ` : ''}
                ${action.label}
              </button>
            `
          )}
        </div>
      </div>
    `;
  }

  private handleActionClick(action: IQuickAction) {
    this.dispatchEvent(
      new CustomEvent('action-click', {
        detail: action,
        bubbles: true,
        composed: true,
      })
    );
  }
}
