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/Overlay',
  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);
    });
  }
`;

/**
 * Surface overlay colors for modal backdrops and scrim layers.
 * Modal-overlay dims content behind dialogs, transparent is for invisible overlay areas.
 */
export const Surface: 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">surface</h2>
          <p class="body-14-regular text-content-on-surface-muted">Overlay colors for modals and backdrops. 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-overlay-surface-modal-overlay border border-border-surface-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">modal-overlay</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('bg-overlay-surface-modal-overlay', this)">bg-overlay-surface-modal-overlay</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-overlay-surface-transparent border border-border-surface-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">transparent</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('bg-overlay-surface-transparent', this)">bg-overlay-surface-transparent</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Hover overlay tokens used by `v-hover` (`subtle` / `default` / `strong`).
 * Same three tiers as interactive overlay layers; use these utilities when you need a solid swatch.
 */
export const Hover: 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">hover</h2>
          <p class="body-14-regular text-content-on-surface-muted">Overlay hover tiers (<code class="label-12-medium">subtle</code>, <code class="label-12-medium">default</code>, <code class="label-12-medium">strong</code>). Matches <code class="label-12-medium">v-hover</code>. 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-overlay-hover-subtle border border-border-surface-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">subtle</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('bg-overlay-hover-subtle', this)">bg-overlay-hover-subtle</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-overlay-hover-default border border-border-surface-default"></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('bg-overlay-hover-default', this)">bg-overlay-hover-default</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-overlay-hover-strong border border-border-surface-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">strong</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('bg-overlay-hover-strong', this)">bg-overlay-hover-strong</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};
