import type { Meta, StoryObj } from '@storybook/vue3-vite';
import { defineComponent, h } from 'vue';

const ThemePlaceholder = defineComponent({
  name: 'ThemePlaceholder',
  render() {
    return h('div');
  },
});

const meta: Meta<typeof ThemePlaceholder> = {
  title: 'CSS utility/Content',
  component: ThemePlaceholder,
  tags: ['autodocs'],
  parameters: {
    layout: 'fullscreen',
  },
};

export default meta;
type Story = StoryObj<typeof ThemePlaceholder>;

const copyScript = `
  function copyToClipboard(text, el) {
    navigator.clipboard.writeText(text).then(() => {
      el.classList.add('copied');
      setTimeout(() => el.classList.remove('copied'), 1500);
    });
  }
`;

/**
 * Text colors for content displayed on surface backgrounds.
 * Use these for headings, body text, links, and UI labels on standard backgrounds.
 * Includes primary, secondary, tertiary, muted, link, and inverse variants.
 */
export const OnSurface: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">on-surface</h2>
          <p class="body-14-regular text-content-on-surface-muted">Text colors for content on surface backgrounds. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-primary heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">primary</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-primary', this)">text-content-on-surface-primary</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-secondary heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">secondary</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-secondary', this)">text-content-on-surface-secondary</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-tertiary heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">tertiary</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-tertiary', this)">text-content-on-surface-tertiary</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-muted heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">muted</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-muted', this)">text-content-on-surface-muted</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-link heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">link</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-link', this)">text-content-on-surface-link</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-inverse border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-surface-inverse heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">inverse</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-surface-inverse', this)">text-content-on-surface-inverse</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Text colors for button labels and icons.
 * Use these to ensure proper contrast on primary, secondary, no-fill, and danger button backgrounds.
 */
export const OnButton: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">on-button</h2>
          <p class="body-14-regular text-content-on-surface-muted">Text colors for content on button backgrounds. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-button-primary-button border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-button-primary-button heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">primary-button</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-button-primary-button', this)">text-content-on-button-primary-button</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-button-secondary-button border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-button-secondary-button heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">secondary-button</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-button-secondary-button', this)">text-content-on-button-secondary-button</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-button-no-fill-button heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">no-fill-button</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-button-no-fill-button', this)">text-content-on-button-no-fill-button</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-button-danger-button border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-button-danger-button heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">danger-button</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-button-danger-button', this)">text-content-on-button-danger-button</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Text colors for content on accent-colored backgrounds.
 * Use these for badges, chips, highlights, or selected states with accent backgrounds.
 */
export const OnAccent: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">on-accent</h2>
          <p class="body-14-regular text-content-on-surface-muted">Text colors for content on accent backgrounds. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-accent-default border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-accent-default heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">default</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-accent-default', this)">text-content-on-accent-default</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-accent-soft border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-accent-soft heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">soft</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-accent-soft', this)">text-content-on-accent-soft</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Semantic text colors for status indicators like success, warning, error, info, and neutral.
 * Use these for validation messages, alerts, notifications, and status badges.
 */
export const OnStatus: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">on-status</h2>
          <p class="body-14-regular text-content-on-surface-muted">Text colors for status indicators. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-status-success border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-status-success heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">success</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-status-success', this)">text-content-on-status-success</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-status-warning border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-status-warning heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">warning</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-status-warning', this)">text-content-on-status-warning</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-status-error border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-status-error heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">error</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-status-error', this)">text-content-on-status-error</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-status-info heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">info</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-status-info', this)">text-content-on-status-info</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-secondary border border-border-surface-default flex items-center justify-center">
              <span class="text-content-on-status-neutral heading-m">Aa</span>
            </div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">neutral</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('text-content-on-status-neutral', this)">text-content-on-status-neutral</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};
